Shader Colors are doubled
This might be related to https://answers.unity.com/questions/1351430/wrong-color-in-ui-shader-with-alpha-blending.html, but that has no answers.
I feel I have a very simple shader:
Shader "Custom/MultiLayerShader" {
Properties {
_Layer0Color ("Color0", Color) = (1,1,1,1)
_Layer0Texture ("Texture0 (RGB)", 2D) = "white" {}
_Layer1Color ("Color1", Color) = (1,1,1,1)
_Layer1Texture ("Texture1 (RGB)", 2D) = "white" {}
}
SubShader {
Tags { "RenderType"="Opaque" }
LOD 200
CGPROGRAM
#pragma surface surf SimpleLambert
#pragma target 3.0
sampler2D _Layer0Texture;
sampler2D _Layer1Texture;
struct Input {
float2 uv_Layer0Texture;
float2 uv2_Layer1Texture;
};
fixed4 _Layer0Color;
fixed4 _Layer1Color;
UNITY_INSTANCING_BUFFER_START(Props)
UNITY_INSTANCING_BUFFER_END(Props)
void surf (Input IN, inout SurfaceOutput o) {
fixed4 c0 = tex2D (_Layer0Texture, IN.uv_Layer0Texture) * _Layer0Color * .5f;
fixed4 c1 = tex2D (_Layer1Texture, IN.uv2_Layer1Texture) * _Layer1Color * .5f;
fixed4 color;
color.rgb = (c0.rgb * (1 - c1.a)) + (c1.rgb * c1.a);
color.a = c0.a;
o.Albedo = color.rgb;
o.Alpha = color.a;
}
half4 LightingSimpleLambert (SurfaceOutput s, half3 lightDir, half atten) {
half NdotL = dot(s.Normal, lightDir);
half4 c;
c.rgb = s.Albedo;// * _LightColor0.rgb * (NdotL * atten * 1);
c.a = s.Alpha;
return c;
}
ENDCG
}
FallBack "Diffuse"
}
To get anywhere close to the right colors I have to cut my _Layer0Color and _Layer1Color in half. If I output these values directly without any other math, they are still 2x the color values. If I output them directly after cutting them in half I get the exact colors I expect.
After that... I don't even know what is wrong with the (1 - c1.a) calculation. If I set my Albedo to it by itself I get a sold white image, even though using c1.a by itself shows me a grayscale image I would expect. If I set: o.Albedo = .5f, I still get solid white. Oddly if I set it to .25, I get a gray of 140,140,140.
Can someone please help explain where all the extra math is coming from, how I can disable it, or how I can know the exact values I need to work around it?
Thanks.