Search Unity

terrain casts a jagged shadow

Discussion in 'General Graphics' started by BakeMyCake, Jun 19, 2017.

  1. BakeMyCake

    BakeMyCake

    Joined:
    May 8, 2017
    Posts:
    175

    Hi everyone, as you can see from the lower left side of the above picture, my Terrain object casts a jagged shadow. Is there a way to make it's edges smooth?

    I'm not sure as to even why this happens, because I'm baking static lights onto terrain. You'd think that baked lights can be as complex as you want, since they are pretty much an image. The only thing that seems to affect this shadow is the Quality->Shadow Resolution setting. It doesn't really solve the problem though, it just makes the notches more or less tight. In the image above it is set to the highest possible setting.

    The scene has the following setup:
    A static terrain object, generated from a heightmap image:
    • Pixel error 1
    • Cast shadows true
    • Width/Length/Height 1000x1000x600
    • Heightmap resolution 1025
    • Control Texture 512
    • Base Texture 512
    A static baked directional light that casts no shadows
    A static baked point light that casts hard shadows

    Personal edition Unity, in case it bears relevance.
     
  2. theANMATOR2b

    theANMATOR2b

    Joined:
    Jul 12, 2014
    Posts:
    7,790
    To be honest I'm still learning best practices with lights myself, so dismiss any irrelevant stuff I mention.
    I believe you'll get the best shadows from directional lights instead of point lights.
    What rendering method are you using, forward/differed? What color space are you using, linear/gamma? - I don't know if that makes a difference or not

    If none of these setting changes improve the shadows I believe you'll want to start looking onto anti-aliasing processes and assets. There are several different versions and I can't claim to know the best for each particular build setup.
     
  3. BakeMyCake

    BakeMyCake

    Joined:
    May 8, 2017
    Posts:
    175
    I'm using forward rendering. Gamma color space. Changing either has no effect.

    Using a directional light produces a great shadow, that much is true. However, I'm trying to make a campfire in a middle of my terrain, so uniform shadows across the whole thing aren't what I'm looking for.

    If all else fails I guess I can do what you suggest and model my own terrain in an external program. That would most likely solve any problems, but then I'm losing the nice performance optimization that comes with the native terrain.
     
  4. BakeMyCake

    BakeMyCake

    Joined:
    May 8, 2017
    Posts:
    175
    To anyone who is struggling with the same sort of thing I recommend reloading Unity after changing your terrain scale. It is hard to tell what exactly is wrong, but it appears that reloading the environment may trigger some recalculations of outdated data.

    When I deleted the old lightmap, reloaded unity and recalculated again it worked.

    I've changed the light settings a bit to make the baking process faster for testing purposes, but this image still illustrates that the baked light is smooth, even with a scale of 1000x1000 terrain.

    I'd also like to point out that even though this concludes my trials, there is still the same exact issue when using a point light with a realtime lighting mode. If anyone needs a clumsy hack for that, I've noticed that using a spotlight with an angle less than 30 seems to produce smooth shadows, but going wider than that gives jagged edges. In theory you can add several spot lights to cover a 360 radius and achieve an approximation of a point light that way, but that's a bit drastic.
     
    theANMATOR2b likes this.