Search Unity

Question Shadow depth not applied in custom lit shader

Discussion in 'Universal Render Pipeline' started by Andrew-Carvalho, Nov 2, 2020.

  1. Andrew-Carvalho

    Andrew-Carvalho

    Joined:
    Apr 22, 2013
    Posts:
    45
    Hi! I'm experimenting with some stylized shaders for a project and am currently working on receiving shadows in a custom shader. Unfortunately, I'm getting what looks like (though I could be wrong) self-shadow artifacts as if the shadow depth isn't being taken into consideration when sampling. I'm brand new to working with shaders in URP, so I may be missing something obvious.

    Specifically, in my vert program I am storing the shadow coords in the output as calculated by GetShadowCoord when passing in the result of GetVertexPositionInputs. In the frag program, I am using those shadow coords as an argument to GetMainLight to retrieve the Light struct. I am using the shadowAttenuation from the returned struct and, for now, simply multiplying it by the colour sampled from the main texture.

    The result currently looks like this. On the left, there is an object above casting a shadow. On the right, the object is in full light.

    upload_2020-11-1_21-49-22.png

    Does anyone have any thoughts? Do I need to handle the shadow depth manually and, if so, is there any documentation on how to access those values?
     
  2. Andrew-Carvalho

    Andrew-Carvalho

    Joined:
    Apr 22, 2013
    Posts:
    45
    Update:

    I woke up after a good night's sleep and realized that depth is being handled during casting, not sampling. I updated my shader to to use the built in ShadowCaster shader for the pass and the artifacts are gone

    specifically I used

    UsePass "Universal Render Pipeline/Lit/ShadowCaster