Adding alpha cutoff effect to existing shader using UsePass

Hi,

I feel like this should be fairly straight-forward, but I’m not getting the result I’m looking for and shaders are not exactly my forte. Essentially, what I want is for my shader to use an existing shader pass using UsePass, and then modify that result’s alpha and color. Now the color part’s easy enough, but when attempting to change the alpha I can’t get much better than either:

  1. A solid black where the transparent parts should be; or
  2. The old color shining through at full alpha.

Both old and new are vert/ frag shaders. The first has a rendertype of Opaque, with the new pass being TransparentCutout. My structure looks as follows:

Shader "My/Shader"
{
    Properties
    {
        _DissolveCutoff ("Cutoff", Range (0.0, 1.0)) = .5
        ...
    }
    SubShader
    {
        Tags { "Queue"="AlphaTest" "RenderType"="TransparentCutout" }

        UsePass "My/Other/BASE"

        Pass
        {
            ZWrite Off
            Blend DstColor Zero

            CGPROGRAM
            ...
            ENDCG
        }
    }
}

Is what I want even possible? What am I missing?

Thanks,
Patrick

Not possible. UsePass uses the pass you’re pointing to as is, but using your current shader’s Queue. I believe it uses it’s original settings for everything else, so blend mode, zwrite, etc. but I’m not positive since I avoid using UsePass ever.

The main problem is when using multi-pass rendering each pass renders in it’s entirety, then the next pass renders, etc. In the case of something like alpha test, there’s no way to un-render the previous pass; that pass already rendered and overwrote what was there before, you can’t get those pixels back in a later pass.

The best option for this might be to have a shader with a toggle and #pragma shader_feature to enable / disable alpha test code, and set the queue with the material drop down. Alternatively you can put your code in a cginc file with #ifdef blocks you enabled / disable features.

Ah, that makes sense, thanks! I just assumed the passes would be consecutive and only deliver a “final” result at the end of the shader. Thanks for the explanation!