- Home /
Why is Alpha Cutoff Shader affected by glow?
My player character uses an Alpha-Cutoff-Diffuse shader to render, and the glow from the Image Effects/Glow is getting drawn on top of the player character.
Is there a way to alter the Alpha-Cutoff shader so that the glow won't show through it?
Shader "Custom/Alpha Cut Off"
{
Properties
{
_MainTex ("Base (RGB) Trans (A)", 2D) = "white" {}
_Cutoff ("Alpha cutoff", Range(0,1)) = 0.5
}
SubShader
{
Tags {"Queue"="AlphaTest" "IgnoreProjector"="True" "RenderType"="TransparentCutout"}
LOD 200
CGPROGRAM
#pragma surface surf Lambert alphatest:_Cutoff
sampler2D _MainTex;
struct Input
{
float2 uv_MainTex;
};
void surf (Input IN, inout SurfaceOutput o)
{
fixed4 c = tex2D(_MainTex, IN.uv_MainTex);
o.Albedo = c.rgb;
o.Alpha = c.a;
}
ENDCG
}
Fallback "Transparent/Cutout/VertexLit"
}
Its a guess - but I presume that the alpha cutout shader is still writing to the o.Alpha of the output pixel and that this is in some way getting into the final image. If that happens then things with a high alpha glow.
Perhaps, and it's just perhaps, modifying the shader to say:
o.Alpha = c.a < _Cutoff ? 0 : c.a;
You would need to add a float _Cutoff variable above the surf function.
If you mean that the character is glowing where it isn't transparent then I can't quite figure out how to do it.
Actually scrub that - I can: you could modify the final colour of the pixel with a finalcolor: function and remove the alpha from that.
#pragma surface surf Lambert alphatest:_Cutoff finalcolor:final
void final(Input IN, SurfaceOutput o, inout fixed4 color) {
color.a = 0; //or whatever
}
"color.a = 0"
tried this, and the result is nothing being drawn at all.
Hmm, I was afraid of that. Did you try the o.Alpha = line?
Answer by markpdolby · Nov 08, 2012 at 04:59 PM
I believe it is because the glow effect uses the alpha channel to deter-main where it should blur and increase the brightness: http://docs.unity3d.com/Documentation/Components/script-GlowEffect.html
You could try using a modified version that this guy on the forums did: http://forum.unity3d.com/threads/13107-Glow-effect-with-adjustable-threshold-(enjoy)
Answer by Curious-George · Feb 12, 2013 at 12:12 AM
Finally found the answer to this one. The alpha has to be set to zero, or else the object glows, but if the alpha is set to zero, you see nothing n screen....... unless you use the right blend mode!
Blend One Zero color.a = 0;
Your answer
Follow this Question
Related Questions
Planet/Atmosphere shader problem. 0 Answers
How to create a Surface Shader in Unity? 1 Answer
Glowing column of light 1 Answer
Glow Effect 3 Answers
Rune glow effect on stones? 1 Answer