3

I'm working on a project, using unity 5.4. In this projects blocks are stacked next to eachother.

However there appear some annoying weird lines. Also on android these line occur more often than on PC. For illustration purposes I added an image and video. Please zoom in on the picture to see, the line I'm speaking of, clearly.

Could anyone please provide a solution to get red of this nuissance. Thanks in advance.

Literature:

Block alignment code snippet:

for (int x = 0; x < xSize; x++)
        for (int z = 0; z < zSize; z++)
        {
            Vector3 pos = new Vector3(x, -layerDepth, z);
            InstantiateBlock(pos);
        }

Video link: https://youtu.be/5wN1Wn51d_Y

Jaswir
  • 172
  • 11
  • Can you please update your question to include a small snip of how you are positioning your cubes. – Zze Nov 16 '16 at 00:46
  • Can you please zip up your project and link it? – Zze Nov 16 '16 at 19:41
  • you simply can not "stack blocks". **it's ridiculous.** of course you'll get lines. what did you think would happen? – Fattie Dec 01 '16 at 03:39
  • it's incredibly hard to program minecraft. it has nothing to do with stacking blocks. there are many COMPLETE minecraft kits around on Unity - just get one. – Fattie Dec 01 '16 at 03:39
  • You don't have to react in such a harsh way Joe Blow. – Jaswir Dec 22 '16 at 15:07

3 Answers3

8

You have object seams!

This occurs when there is a physical or perceived gap between objects.

There are multiple causes for this.


1. Floating Point Imprecision

This could be because you are setting the position of the cubes to int's but they have floating point dimensions. The symptom for this is usually no white seams when the camera is close to the objects, and then they gradually appear as you get further away due to floating point imprecision. More.

Most of these blocks appear to line up exactly, from most camera positions. But from the occasional unfortunate position, the exact value for A's position plus its vertex at (0.5,0.5,-0.5) might be slightly different to object B's position plus its vertex at (-0.5,0.5,-0.5) . The result is that Unity shows a tiny gap, within which you can see the shadowed side of cube A.

If you consider the following on paper 3 == 1/3 * 3 this is mathematically correct, however using floats, 1/3 == 0.333333... and subsequently 3 * 0.333333... == 0.999999... BINGO! random gap between objects!

So how to solve? Use floats to calculate the positions of your objects. new vector3(1,1,1); should be new vector3(1f,1f,1f); - for example. For further reading on this try this SOP.


2. Texture Wrap-mode

If you are using textures on your objects, try changing the Wrap-Mode of your texture from wrap to clamp, or try upping the texture padding.


3. Shadow Acne - (Lighting and Shadow artifacts)

This is the arbitrary patterns of pixels in shadow when they should really be lit or NOT lit.

To prevent shadow acne, a Bias value can be added to the distance in the shadow map to ensure that pixels on the borderline definitely pass the comparison as they should, or to ensure that while rendering into the shadow map. source.

In Unity... go to your light source and then increase the Shadow Type > shadow Bias I would suggest doubling the default value of 0.05 and then continue so until fixed. You don't want to crank this value to max because...

Do not set the Bias value too high, because areas around a shadow near the GameObject casting it are sometimes falsely illuminated. This results in a disconnected shadow, making the GameObject look as if it is flying above the ground.

Community
  • 1
  • 1
Zze
  • 18,229
  • 13
  • 85
  • 118
  • I highly recommend NOT using fade / transparent, as yes this will crush your FPS as you found out. There are literally dozens of people complaining about this issue on the inter webs - so don't be disheartened. It all stems from floating point imprecision. I am going to update my answer to better explain. – Zze Nov 15 '16 at 20:42
  • You misread the comment "I manually made them overlap". It was a reaction on Julian's answer. The blocks are aligned exactly in code. – Jaswir Nov 15 '16 at 23:43
  • However I'm still stuck here with the question: How to get rid of the weird lines while not harming fps (Hack arounds allowed). – Jaswir Nov 16 '16 at 00:45
  • @RomeoTheWizard I have just overhauled my answer - I now believe you fall under number 3. – Zze Nov 16 '16 at 01:37
  • I adapted the shadow bias value, it doesn't seem to have any influence at all – Jaswir Nov 16 '16 at 12:25
  • hi @Zze ! these are all good points. but fundamentally you can't "stack blocks" in a game engine. of course you get lines. – Fattie Dec 01 '16 at 03:40
0

Are you using different blocks that you put against eachother? Your problem sounds like the blocks are not completely against eachother which causes you to see the side of the next block (this explains the camera Y changing: you might see the side better from higher up). That side will have different lighting and appear as a different/lighter colour. To check if this is the problem, try overlapping them slightly manually in the editor and see if the problem still occurs.

Julian Declercq
  • 1,536
  • 3
  • 17
  • 32
  • Yeah the blocks are against eachother. I manually made them overlap, but that isn't it. I might need to upload a video instead to make it clearer what I mean. – Jaswir Nov 12 '16 at 15:30
  • Video has been uploaded @Julian Declercq – Jaswir Nov 13 '16 at 16:25
0

Making the blocks kinematic solves that. The issue is the rigid bodies bumping up against one another.

  • Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Apr 24 '22 at 01:54