#Fading the alpha of a surface shader by the brightness of it's lighting

1 messages · Page 1 of 1 (latest)

odd goblet
#

I'm trying to write a surface shader that fades the alpha of a surface by the brightness of the light applied to it, but i've been encountering strange/unexpected behavior in doing this.

This is the lighting function im working with:

half4 LightingSpecial(SurfaceOutput s, half3 lightDir, half atten) {
    half NdotL = 0.5;
    half4 c;
    half3 light = _LightColor0.rgb * atten * 100;

    c.rgb = s.Albedo * light * NdotL;
    c.a = s.Alpha;

    return c;
}

If i replace c.a = s.Alpha; with c.a = 0, as expected. the entire surface becomes fully transparent.
However, any math that i do to c.a that would be conditionally setting the alpha of the surface, such as c.a = s.Alpha - (light.r + light.g + light.b) does NOT reduce the alpha of the surface, no matter what the results are. Even if i do conditional logic, such as
if (light.r > 0) c.a = 0, it does not reduce the surface's alpha.

#

this is the result of if (light.r > 0) c = 1;

#

this is the result of if (light.r > 0) c = 0;

#

and this is the result of just unconditionally setting c = 0