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…
…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.
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"
}