- Home /
Question by
Paulius-Liekis · Aug 14, 2013 at 10:49 PM ·
alphasurfaceshader
Changing alpha in Lighting Model has no effect
I have this line in my surface shader:
#pragma surface surf MooBoo alpha
And then this lighting model:
inline fixed4 LightingMooBoo (SurfaceOutput s, fixed3 lightDir, fixed atten)
{
fixed4 c;
c.rgb = fixed3(1, 0, 0);
// This has no effect whatsoever (1/0/0.5 - doesn't matter)
c.a = 0;
return c;
}
The alpha returned from Lighting Model has no effect. It seems that the only thing affecting it is what I write into SurfaceOutput.Alpha in surface shader, but I can not modify that afterwards (based on lighting or something like that).
Anyone has an explanation?
Comment
Answer by Paulius-Liekis · Aug 18, 2013 at 03:15 PM
So far I figured out that yes, Unity ignores alpha from Lighting model if you use alpha blending. The way around it is to use regular vertex and pixel shaders. Something like this is sufficient in my case (you might need to calculate attenuation if you want shadows and lightmaps):
half4 frag (v2f i) : COLOR
{
SurfaceOutput o;
fixed4 tex = tex2D(_MainTex, i.uv);
o.Albedo = tex.rgb * _Color.rgb;
//o.Gloss = tex.a;
o.Gloss = 1;
o.Alpha = tex.a * _Color.a;
o.Specular = _Shininess;
o.Normal = i.normal;
fixed4 col = LightingBlinnPhong (o, i.lightDir, i.viewDir, 1);
return col;
}