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
  3. Dismiss Notice

Frustum culling and occlusion culling with shadows

Discussion in 'General Graphics' started by Chaiker, Jun 9, 2017.

  1. Chaiker

    Chaiker

    Joined:
    Apr 14, 2014
    Posts:
    63
    Hello everyone.
    I have a problem with culling my trees in my scene. Trees is culling, but with them shadows culls too. And i see that shadows disappear in game view. How i can cull tree only if i don't see tree and shadow from it?

    Thanks.
     
  2. ecv80

    ecv80

    Joined:
    Oct 1, 2017
    Posts:
    28
    Did you figure out how to do this? I have the same problem. I read one should add the shadow to the AABB volume, but then I have no idea how to do this in Unity. I'd be happy if I could simply use a bigger virtual field of view for frustum culling... Is this possible?
     
  3. ecv80

    ecv80

    Joined:
    Oct 1, 2017
    Posts:
    28
    Ok, in my case I got wrong frustum culling in portrait because I was setting the camera projection matrix and probably not setting the culling matrix right. When I stopped doing all this and simply set a new orthographic size, everything worked correctly for me.

    So I guess if you really need to set a wider/smaller frustum culling, it could be done by setting a culling matrix. I also read before this feature was available in Unity, you would change mesh bounds to make them bigger or moving their center to the frustum's center so as to not get culling, but (luckily) I didn't need to try this anymore :)
     
    JoshW_3 likes this.
  4. Predulus

    Predulus

    Joined:
    Feb 5, 2018
    Posts:
    90
    I'm having this problem - 2019.4.26f1, URP.

     
  5. aganm

    aganm

    Joined:
    Sep 25, 2019
    Posts:
    114
    Same problem, Unity 2021.3.1 LTS, in both URP and HDRP.
     
  6. codevisionary005

    codevisionary005

    Joined:
    Nov 15, 2021
    Posts:
    17
    First of all, There is nothing to fix in here and Second, no matter what version you are using, This will happen since the shadows cannot be rendered without the shadow caster which is in the mesh renderer component of the culled mesh. And since the mesh is culled(disabled), all it's components would get disabled too. This is not a bug. It's just how frustum culling works. One thing you could do is disable the shadow caster component but you wouldn't get the shadows.
     
  7. adamgolden

    adamgolden

    Joined:
    Jun 17, 2019
    Posts:
    1,556
    The solution I use is to set mesh .bounds large enough that the shadows will still be there even when the object is behind the camera.. with exactly how far behind determined by how much larger than the mesh you've set the bounds to be. However, there is a cost to these objects not being culled.. so for mobile games you might not want to consider it. Also if you have very long shadows you'd have to adjust the bounds so much that your performance would take a noticeable hit where lots of extra objects are being "kept alive" that way.
     
    Predulus likes this.