Search Unity

Surface Shaders: Ignoring clip() during shadow casting, respecting it during shadow collection

Discussion in 'Shaders' started by Iron-Warrior, Apr 28, 2020.

  1. Iron-Warrior

    Iron-Warrior

    Joined:
    Nov 3, 2009
    Posts:
    838
    Hello, I have a cube with a surface shader that runs
    clip(IN.uv_MainTex.y > 0.5 ? 1 : -1);
    as a simple clipping test. Naively the shader produces the following:

    upload_2020-4-28_15-48-0.png

    This is resolved by adding
    addshadow
    to the #pragma line:

    upload_2020-4-28_15-48-38.png

    ...which respects the clip() during shadow casting and collection. However, the output I want is as below:

    upload_2020-4-28_15-49-19.png

    Where the clip() is ignored during shadow casting and shadow collection (the above image is created by having a duplicate cube with the default Unity material and Shadows Only set). If this seems a bit odd, my use case case is to make objects between the player and the camera use dithered transparency to avoid occlusion. Ideally, the shadows would remain to make the dithering as seamless as possible. Using the frame debugger, we can see that during shadow collection the cube occludes the floor behind it.
    upload_2020-4-28_15-52-12.png
    ...so while I can get the desired effect using duplicated meshes, if there's a straightforward way to do this all in-shader I'd prefer that to make life easier in the long run (rather than having to manage duplicating/destroying new objects etc).

    Thanks for any answers,
    Erik
     

    Attached Files:

  2. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    12,352
    Iron-Warrior likes this.