Search Unity

Unity terrain Jagged shadow effect

Discussion in 'General Graphics' started by Revan3192, Mar 8, 2019.

  1. Revan3192

    Revan3192

    Joined:
    Mar 28, 2018
    Posts:
    8
    Hi everyone!

    I was wondering if anyone knows or have an idea of how to fix this problem. At certain point when I'm a bit far I see this jagged shadow effect on the terrain. Is there a way to smooth this?

    View attachment 385612

    Thanks in advance!
     
  2. Sh-Shahrabi

    Sh-Shahrabi

    Joined:
    Sep 28, 2018
    Posts:
    56
    I cant open the attachment, but that sounds like lack of precision in the depth buffer. For your shadowmapping a depth pre pass is rendered, which is used to determine if a pixel on the main camera is seen by the scene light or not. This calculation uses the depth texture of the two cameras. To compensate for the lack of precision and making sure pixels dont self shadow themselves, a bias is added to the calculation. Since the depth buffer is not linear, the bias wont work all that well for far away objects.

    To fix this, you could try increasing the precision of the depth buffer from whatever it is to a float or a double. You could also increase camera far plane's. (You would lose precision overall though, not a good solution). You could change the shadow mapping shader so that the Offset also increase based on the log of the distance. You could turn of shadow casting for faraway object (populare way), or you can implement more than one camera, where the cameras render back to front the background, clear the buffers, then foreground. They have different near and far plane and hence dont have the precision problem. This is hard to implement, and can lead to rendering errors, if the levels concept is not well suited for it.
     
  3. Revan3192

    Revan3192

    Joined:
    Mar 28, 2018
    Posts:
    8
    Hi @Sh-Shahrabi ! thanks for answering me! But I think the issue it's more related with how unity mesh terrain is built. Is like the mesh vertex normals are not smooth. I tried to attach again the screenshots so you get a better idea of the problem. Do you think is there a solution for this? so when I get far and the terrain has less resolution is still smooth?

    Images