Search Unity

  1. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice
  2. Unity is excited to announce that we will be collaborating with TheXPlace for a summer game jam from June 13 - June 19. Learn more.
    Dismiss Notice

Terrain trees shadow caster disappearing when tree is out of camera's frustum

Discussion in 'General Graphics' started by OneOfMany, Jun 6, 2022.

  1. OneOfMany

    OneOfMany

    Joined:
    Jun 11, 2015
    Posts:
    25
    Hello,

    I, and many others have this issue: terrain trees shadow casters are disappearing when tree is out of camera's frustum. It renders the majority of lighting conditions unreachable without shadows constantly glitching in and out: Dusk, dawn, and practically every other time of the day when sun (or moon) is not almost directly above the player (from the first person's point of view of course).

    The reason is that trees behind the player which should be casting shadows are not rendered, and also are not casting shadows. When camera rotates along the up axis, bounds of trees behind the player enter the camera's frustum so the shadow suddenly appears, resulting in aggresive change of brightness, breaking immersion and severely frustrating the developer in the process.


    We are using unity's terrain system and simplest realtime global illumination imaginable: built-in rendering pipeline, with unity 2019LTS. I searched for this topic again and again with no success in solving the problem. There are many people asking, and then every thread dissolves into inactivity. Mabe the question is asked with too much specific details attached, or maybe nobody knows the answer. Which is extremely weird to me.

    I found out that assets like for example Vegetation Studio (or Vegetation Studio PRO) are testing for the directional light's position and it renders shadows (not the model or billboard) for trees that would cast shadows into camera's view. But it is a cumbersome solution, which would require us to bend to Vegetation Studio's needs, just to solve this issue.

    Is there any reasonable solution for this problem?
     
    Last edited: Jun 7, 2022
  2. CodeSmile

    CodeSmile

    Joined:
    Apr 10, 2014
    Posts:
    6,583
    This seems like a problem one shouldn't normally encounter, and I can't imagine every Unity game with terrain and trees (or other objects) facing the same challenge. I've only used terrain with objects once maybe 4 years ago and did not have any shadow issues.

    I was thinking there must be some way to extend the culling behaviour to some area around the camera, or flag the objects in some way. But I could only find this post, maybe that points in the right direction:
    https://forum.unity.com/threads/fru...ion-culling-with-shadows.475347/#post-3686362
     
  3. OneOfMany

    OneOfMany

    Joined:
    Jun 11, 2015
    Posts:
    25
    Sadly, this problem is built-in. I can't think of a way I wouldn't encounter it. There probably is a way to takle it trough manipulation of the camera projection matrix, but there is no documentation of the problem, and I have no idea how to approach it – it also sounds like it would render the whole tree, not just the shadow caster, so it would mean significant performance demnads. When I tried to google for some clues, I found one thread where a person said he once managed to resolve it with the help of the people from Unity (was working for a company who had Unity PRO subscription), but he wasn't working there anymore so he couldn't remember and share the knowledge. However, he also admitted he wouldn't be able to figure it out by himself.

    There are several intersecting and poorly documented paradigms in this issue, and it seems that people mostly choose the game design that doesn't use unity terrains, or have baked lighting.
     
    Last edited: Jun 14, 2022