Search Unity

Object made of cubes looks different based on the distance?

Discussion in 'General Graphics' started by Tudvari, Oct 27, 2018.

  1. Tudvari

    Tudvari

    Joined:
    Jun 3, 2014
    Posts:
    30
    I made a "Wall" from basic Unity3D cubes. They are placed tightly so the wall looks like one big rectangular prism.

    If I look at it from close distance, it looks as it should be: one big rectangular prism.

    But if I start moving backwards, away from the wall, the cubes' edges become visible.




    And this whole thing happens in a circular way.
    • If I just start moving backwards from the wall,
    • first I start to see the cubes' edges just at the further parts of the object, and then the pure white circle starts shrinking, the edges become visible at bigger and bigger parts of the object.
    • then a blurrier kind of edges appear at the further places and the previously appeared sharper edges circle starts shrinking as well. (this phase is shown on the image above)
    This should be some kind of shading optimization, like mipmap, right?

    How can I fix this? I want the wall to be seamless from all distances.

    Update:
    • Changing the shader to Unlit > Color, fixes the issue.
    • This thing only occurs on the lit side of the wall. The shadowy side of the wall, (which isn't lit directly by the directional light of the scene) is rendered normally.
    Some say that combining meshes could solve the issue, but that's a big workaround right?
    • Combining cubes
    • while also remembering which faces should use which material
    • and also I have to find which particular voxel got contacted i.e. when a player damages the structure
    • and based on that I have to recreate the mesh again, etc., etc.

    Thanks in advanc
     
  2. Talavaj

    Talavaj

    Joined:
    Sep 22, 2013
    Posts:
    41
    Raise the shadow/normal bias of your light source.
     
  3. Tudvari

    Tudvari

    Joined:
    Jun 3, 2014
    Posts:
    30
    Thanks, you are a life saver :)
    I've been looking for a fix for weeks, and nobody could figure it out even on stackoverflow.
    I'll never forget this, and also to look into light sources when there are rendering issues. :D
     
  4. Talavaj

    Talavaj

    Joined:
    Sep 22, 2013
    Posts:
    41
    Unfortunately, you will find that the rest of your shadows are gonna be very wrong if you raise the bias too high.
    This isn't a very good workaround.

    The true workaround for shadowmap precision problems is to make all your lights static, bake the maps, and then fix all precision problems manually in a graphic editor.
    But I don't know how practical, or if at all possible, it is for your desired application.

    Another workaround that might work for you, is to simply duplicate every cube, and make one of them to only receive shadows, and the other one to only cast them (shadows only setting).

    The issue here is the cubes casting shadows on themselves, but since they are very simple geometry, I think you can get away with the rendered mesh not being self-shadowing.
     
    Last edited: Oct 27, 2018
  5. MD_Reptile

    MD_Reptile

    Joined:
    Jan 19, 2012
    Posts:
    2,664
    If your working on a game that will have a voxel system - you should not be using cubes, as they shall quickly become too performance heavy for even a couple thousand blocks.

    Consider a true voxel mesh system like these guys are going on about:
    https://forum.unity.com/threads/after-playing-minecraft.63149/

    Now, if this is all the more cubes your ever gonna have, then in that case you might be fine...
     
  6. Tudvari

    Tudvari

    Joined:
    Jun 3, 2014
    Posts:
    30
    I did some performance estimation, and issues only appear at a that high amount of object which is very unlikely. But yes, I will fix that, if it will become an issue, but currently I'm trying to stay away from premature optimization.

    I will keep your advices in mind, thanks again :)
     
  7. hjohnsen

    hjohnsen

    Joined:
    Feb 4, 2018
    Posts:
    67
    Are you sure it's not some kind of Z fighting ? The dark pixels from cube side appear above the front side.
     
  8. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    12,348
    It’s not z fighting, no. It’s an artifact of the interaction between shadow map cascades, shadow map precision, shadow biasing, and shadow map filtering techniques.

    Shadow biasing works by pushing the shadowcasting surface away from the light, or in the case of normal biasing away from the shadow receiving surface (itself). The result for a cube is the faces are pushed inward, and slight away from the light. Increasing the bias will remove shadow acne and similar shadow artifacts, but at the cost of peter panning, or an object’s shadow not starting where the object is touching the ground. Normal biasing has less problems with that, but shrinks the object’s shadow. For objects with hard edges it only pushes each face in rather than shrinking, so a cube will end up being a bunch of intersecting planes, like a 3D # sign. The result is you get a little bit of shadowing from one of the other faces rather than the usual self shadow shadow acne you’d get with out any biasing.

    Filtering makes this both better and worse. Better because it blurs it, worse because it blurs by taking samples from a larger area of the shadowmap meaner there’s a greater chance of sampling some of that false shadowing.

    The spherical nature and increase in severity is from shadow cascades. As the camera gets further away from something, you switch to an alternate shadow map that covers a larger area with the same resolution. This means lower precision, and means the filtering is covering a larger area, making the biasing less effective and increasing the chance for shadow acne and false shadows.