Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

Artifacts in directional lights shadows as the game progresses

Discussion in 'General Graphics' started by thefirstplaybae, Jan 3, 2018.

  1. thefirstplaybae

    thefirstplaybae

    Joined:
    Feb 15, 2013
    Posts:
    16
    Hi,

    I have been working on a game of mine using Unity 2017 and have been constantly facing a weird graphical glitch. As you can see in the images, the quality of shadows go from good to unacceptably worse as the game progress. It is a simple endless game in which the light (directional) stays where it is and the camera moves in the forward direction. All the plausible reasons for such behaviour of shadows have been tested and not many make sense since the shadows are absolutely fine in the beginning of the game.



    My current project settings are these -
    1 Directional light, forward rendering path , 2X AA, shadows - soft shadows, medium resolution, 4 shadow cascades, stable fit, shadow distance - 60, near plane offset - 5 , Camera near clip - 1, far clip - 175.

    Im sure that I am not doing anything crazy with lighting, this looks more like a glitch to me. Anyone ever experienced anything like this? I am tired of debugging it and now seek some help from you guys.

    Thanks in advance.
     
  2. aleksandrk

    aleksandrk

    Unity Technologies

    Joined:
    Jul 3, 2017
    Posts:
    2,857
    Hi!

    I assume that when one progresses in your game, the world coordinate of the avatar is further and further away from the origin (0,0,0). If that's the case, you're suffering from floating-point rounding errors. Google for "floating point precision large numbers".
     
  3. thefirstplaybae

    thefirstplaybae

    Joined:
    Feb 15, 2013
    Posts:
    16
    I dont really understand what I can do to make unity not suffer from those errors since creating shadow maps is not in my hands. Am I missing something here ?
     
  4. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    12,248
    Keep the camera looking at 0,0,0 and move the world instead. Or move everything back to zero every so often.
     
  5. thefirstplaybae

    thefirstplaybae

    Joined:
    Feb 15, 2013
    Posts:
    16
    Ok that might be a solution , but this should not mean that we can not approach an endless runner with shadows like the way I did ( the obvious way). There is gonna be a huge set of changes that I will have to do to reverse my approach and I am sure that there should be a more viable explanation to this issue.
     
    Last edited: Jan 4, 2018
  6. thefirstplaybae

    thefirstplaybae

    Joined:
    Feb 15, 2013
    Posts:
    16
    And one more thing, I dont understand why this floating point precision error doesnt affect the editor and only occurs on mobile?
     
  7. aleksandrk

    aleksandrk

    Unity Technologies

    Joined:
    Jul 3, 2017
    Posts:
    2,857
    Mobile can use lower precision than desktops (e.g. 16-bit floats instead of 32, which correspond to "half" and "float" in the shader). On the desktop it will be 32 bit regardless of what the shader says. (See https://docs.unity3d.com/Manual/SL-DataTypesAndPrecision.html, "Precision, Hardware Support and Performance")
    The same thing will occur in the editor, but you'll need much larger numbers to see this effect.
     
  8. thefirstplaybae

    thefirstplaybae

    Joined:
    Feb 15, 2013
    Posts:
    16
    Yes this makes complete sense. This explains why it is happening. But I was wondering that in my game it hardly goes beyond a Z value of 300-400 before it starts behaving like this. Is this because of the same float precision error on mobile ? And if yes , is there any solution to this other than moving the entire world back ?
     
  9. aleksandrk

    aleksandrk

    Unity Technologies

    Joined:
    Jul 3, 2017
    Posts:
    2,857
    The effect you see happens around the values you have when medium precision is used.
    Are you using custom shaders or built-in ones?
    And what device are you running it on?
     
  10. thefirstplaybae

    thefirstplaybae

    Joined:
    Feb 15, 2013
    Posts:
    16
    We are using the built in standard shaders on almost everything in the game. We are experiencing this issue on android devices. I have tried it on xiaomi phones and pixel.
     
  11. aleksandrk

    aleksandrk

    Unity Technologies

    Joined:
    Jul 3, 2017
    Posts:
    2,857
    OK, this sounds suspicious enough to check this.
    Please submit a bug report :)