Search Unity

Receiving Shadows without ShadowCaster worked in Unity 5.3

Discussion in 'Shaders' started by jolix, May 1, 2017.

  1. jolix

    jolix

    Joined:
    May 22, 2016
    Posts:
    70
    Hi everyone!

    Receiving shadows without using a shadow caster pass in a shader used to work perfectly in 5.3. Since 5.4, I haven't been able to do that anymore.
    I was working on a water asset with Unity 5.3. I could receive shadows without having a shadow caster pass using SHADOW_COORDS, TRANSFER_SHADOW and SHADOW_ATTENUATION. (Render Queue is AlphaTest+50 (2500) )

    I need to disable the shadow caster pass, because else it writes to the Z-buffer and that would mess up the depth effects like this:


    So I test my shader on Unity 5.4, but the shadows are wrong:

    It receives the shadow of the block, through the water.

    So my guess is that the shadow calculation pipeline changed and now requires a shadow caster pass.

    What I tried without success:
    • Changing the rendering Queue and RenderType
    • Changing Zwrite On/Off
    • Using a custom shadow caster pass with ZWrite Off
    • Using a Fallback
    • Using a CommandBuffer to copy the depth buffer before the shadow caster: I managed to copy a depth buffer, but I can't seem to copy it exactly where I want.
    I know shadows are hard, but if someone knows a solution, I'd be happy to hear it!
     
  2. jolix

    jolix

    Joined:
    May 22, 2016
    Posts:
    70
    After a little research I found that shadows use the depth texture. But I'm still puzzled how Unity 5.3 could receive shadows without having it being in the depth buffer when the base forward pass is rendered.

    I see two solutions:
    • somehow copy the intermediary depth texture before the shadowcaster pass of the water plane renders
    • use a second camera with a water mask, solely to render a depth texture without the water (this sounds like overkill, but might unfortunately be the only option in Unity)
    I'll post here if I find a solution, because this might answer all questions regarding using shadows for water with depth effects.
     
    Droob likes this.