Alpha blended shader - Show only the first alpha
Hi! :)
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.
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!
Answer by fra3point · Mar 06, 2016 at 05:41 PM
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? :)
Answer by MTDues · Feb 03, 2018 at 11:29 AM
im having the same proplem too :/
have you found a way to solve this proplem ?
@$$anonymous$$TDues I've never found a solution for the "show only closest alpha" problem, but I'll give this a new try in few days. I think I can do it. :)
Your answer
Follow this Question
Related Questions
Lerping normal maps in shadergraph 0 Answers
A Blend Shader That Uses Vertex Information 0 Answers
(using shader blending to) remove white background from an image at runtime 3 Answers
How to make a shader with multiple textures, one color for each texture? 0 Answers
How to modify depth blended shader for second camera/reflection projection? 0 Answers