visualdesigncafe / nature-renderer

Nature Renderer is a plugin for the Unity game engine to efficiently render vegetation on your terrains.
https://visualdesigncafe.com/nature-renderer/
0 stars 0 forks source link

Shadow culling not working correctly when object is behind camera #41

Open fcortese2 opened 5 months ago

fcortese2 commented 5 months ago

Describe the bug Shadows clip in and out of existence when the object is behind the camera.

To Reproduce Steps to reproduce the behavior:

  1. Have a tree placed on terrain
  2. move camera in scene and game view to a point "inside" the shadow in a way that the object is outside camera view but the shadow is not.
  3. See error

Expected behavior Shadows should not be culled when in view

Video of issue https://drive.google.com/file/d/1YMz2pFii9ze14_0yXJvpxiXR28waz1DG/view

Project(please complete the following information):

System (please complete the following information):

Additional context Add any other context about the problem here.

Stephanommg commented 3 months ago

I have the exact same problem here. This is not acceptable for me.

Stephanommg commented 3 months ago

Please devs, answer us. I really cannot use the asset like this, and I will have to ask for refund if this is not solved. I have up to July 2 to do this.

Isn't there at least an option to disable frustum culling?

maxplooi commented 3 months ago

@Stephanommg @fcortese2 I have been looking into it but I can't reproduce this issue in any way. Every combination of meshes, bounds, and transforms seem to cull just fine. I think the easiest workaround for now is to disable the shadow culling. You can do this in the Nature Renderer Instancing.compute shader file, by disabling the code around line 219:

Change from:

#if SHADOWS
    if (meta.Shadow > 0)
    {
        if (CullShadowFrustum(
                boundsCenter,
                -boundsExtends, 
                _ShadowDirection, 
                _FrustumPlanes))
        {
            meta.Shadow = 0;
        }
    }
#endif

To:

#if SHADOWS
/*
    if (meta.Shadow > 0)
    {
        if (CullShadowFrustum(
                boundsCenter,
                -boundsExtends, 
                _ShadowDirection, 
                _FrustumPlanes))
        {
            meta.Shadow = 0;
        }
    }
*/
#endif

Note that you need to restart Nature Renderer in order to reload the shader. (Enable/disable the component, compile scripts, or enter playmode)

fcortese2 commented 3 months ago

Hey @maxplooi thanks for getting back to us.

Since the original post was made, we have moved over to working in a new Unity scene file and the issue now seems to be gone... We're still not sure if previously it was a scene corruption issue or what else, but the good news is all seems to be working fine in this new Unity scene.

Thanks for the info though, we'll try this approach if the issue shows up again at some point .

Here's some chocolate as a thanks : P

    __________________,.............,    
   /_/_/_/_/_/_/_/_/,-',  ,. -,-,--/|
  /_/_/_/_/_/_/_/,-' //  /-| / /--/ /
 /_/_/_/_/_/_/,-' `-''--'  `' '--/ /
/_/_/_/_/_/_,:................../ /
|________,'                     |/
         """""""""""""""""""""""'
Stephanommg commented 3 months ago

@Stephanommg @fcortese2 I have been looking into it but I can't reproduce this issue in any way. Every combination of meshes, bounds, and transforms seem to cull just fine. I think the easiest workaround for now is to disable the shadow culling. You can do this in the Nature Renderer Instancing.compute shader file, by disabling the code around line 219:

Change from:

#if SHADOWS
    if (meta.Shadow > 0)
    {
        if (CullShadowFrustum(
                boundsCenter,
                -boundsExtends, 
                _ShadowDirection, 
                _FrustumPlanes))
        {
            meta.Shadow = 0;
        }
    }
#endif

To:

#if SHADOWS
/*
    if (meta.Shadow > 0)
    {
        if (CullShadowFrustum(
                boundsCenter,
                -boundsExtends, 
                _ShadowDirection, 
                _FrustumPlanes))
        {
            meta.Shadow = 0;
        }
    }
*/
#endif

Note that you need to restart Nature Renderer in order to reload the shader. (Enable/disable the component, compile scripts, or enter playmode)

Thank you. It is a pitty that we have to lose about half performance to being able to properly use the tool, and even that it still provide high performance (I tested this), it may not be enough to satisfy my needs. Thus, I am insecure about using the tool like this. I also just tested this fix in one scene, and currently I don't have time to make more tests. So it would be great if you found a fix before 2 July, which is my deadline to ask for refund. Here are my current specs (for the sake of reproducing):

Unity 2021.3.16f1 SO: Windows 10 Pro 64 bits Mother Board: Gigabyte B550M DS3H (bios F18) Processor AMD Ryzen 7 3700X RAM: 32 Gb Video Card: Nvidia GeForce 3060 Ti DirectX: 12

Regarding the reply of @fcortese2, I have tested in one of my own scenes and NatureRenderer scene, and the problem appears on both.

@fcortese2 do you use the same tree models and tree shaders in both scenes (the old and the new)?

Stephanommg commented 3 months ago

@maxplooi perhaps if you provided an option in NatureRenderer to have an offset on the camera frustum (for the sake of shadow culling) this would be an workaround to solve this problem and still get the culling. image

fcortese2 commented 3 months ago

@Stephanommg yes, same trees, same shaders, etc... Issue just seems to have magically fixed itself.

Stephanommg commented 3 months ago

@maxplooi any update?

Stephanommg commented 3 months ago

@maxplooi I am still expecting an answer.