Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Question Surface Shaders, DrawMeshInstancedIndirect and the Depth Buffer don't seem to mix

Discussion in 'Shaders' started by BrightBit, Jun 26, 2023.

  1. BrightBit

    BrightBit

    Joined:
    Jan 22, 2013
    Posts:
    243
    I draw several trees as Instanced Geometry with Graphics.DrawMeshInstancedIndirect. The trees' material is based on a Surface Shader that uses the following keywords:

    #pragma surface surf Standard addshadow fullforwardshadows vertex:vert alphatest:_Cutoff


    The light of the lantern on the images below is faked by an additive blended camera facing billboard (that reconstructs depth and normal information of the opaque geometry around it).

    As you can see on the image labeled with "Forward": There are some weird artifacts. I have to admit that I don't fully understand what's going on. It seems as if the depth information are wrong. When using deferred rending everything works just fine.

    Do you have an idea on why this is happening?

    Additional information:
    • I enabled the generation of Depth and DepthNormal textures for the camera
    • I am using the Builtin Rendering Pipeline
    • When I disable Instancing and draw the trees individually the artifacts disappear
    • I am using Unity 2021.3.15f1

    Forward.png Deferred.png
     
    Last edited: Jun 26, 2023
  2. BrightBit

    BrightBit

    Joined:
    Jan 22, 2013
    Posts:
    243
    No one? Am I in the right forum?