Alpha blended shader - Show only the first alpha

Hi! :slight_smile:

I’m working with Render Textures and I’m stuck with the following problem: I have several overlapped transparent objects and my camera renders them on a texture…

65286-immy1.png

…But what I want is to render only the alpha of the closest object (in this case, the white one).

I’m currently using this simple shader, and I’d like to modify it for doing what I wrote.

Shader "Custom/TranspUnlit" {
     Properties {
         _Color("Color & Transparency", Color) = (0, 0, 0, 0.5)
         _MainTex ("Texture", 2D) = "white" {} 
     }
     SubShader {
         Lighting Off
         ZWrite Off
         Cull Back
         Blend SrcAlpha OneMinusSrcAlpha, One One
         Tags {"Queue" = "Transparent"}
         Color[_Color]
         Pass {
         	SetTexture [_MainTex]{
         		combine texture * primary
         	}
         }
     } 
     FallBack "Unlit/Transparent"
 }

Can someone help me? Thank you, all!

Hello!
I’m still trying doing this thing completely strange for me (I’m noob with shaders).
I found that the problem could be the Blend SrcAlpha OneMinusSrcAlpha, One One line.
That blend directive is for the normal additive alpha blending.

So, I changed that line with:

...
BlendOp LogicalCopy
AlphaToMask On
...

I don’t know what LogicalCopy means, but the result is pretty good… At least for high alpha values.
If alpha>128 everything is fine, else the alpha is not rendered at all.
My shader looks like this, now:

Shader "Custom/TranspUnlit/Closest Alpha Blend" {
     Properties {
         _Color("Color & Transparency", Color) = (0, 0, 0, 0.5)
         _MainTex ("Texture", 2D) = "white" {} 
     }
     SubShader {
         Lighting Off
         ZWrite Off
         Cull Back
         //Blend SrcAlpha OneMinusSrcAlpha, One One
         BlendOp LogicalCopy
         AlphaToMask On
         Tags {"Queue" = "Transparent"}
         Color[_Color]
         Pass {
         	SetTexture [_MainTex]{
         		combine texture * primary
         	}
         }
     } 
     FallBack "Unlit/Transparent"
 }

Any suggestions? :slight_smile:

im having the same proplem too :confused:

have you found a way to solve this proplem ?