- Home /
Shader for Overlapping LIghts
I have a surface shader with custom lighting that creates a crisp edge between areas that are lit and unlit. However, if I have two point lights that overlap, the area in the middle is brighter than if it were lit by only one light. I would like it to be lit 'just once'.
Here's a picture of the problem - I would like the middle part to be the same color as either side:
I'm assuming that each light writes the value, and in the middle they're added, which is why it's brighter. I've looked online and haven't been able to find any way to remove the brighter area. I assumed there would be some option to remove the additive 'blending' of the lights, but I couldn't find one.
Below is the shader I am currently using, in Unity 5.3, with forward rendering:
Shader "CrispLightBasic_NoDir" {
Properties {
_Color("Color", Color) = (1, 1, 1, 1)
_MainTex("Albedo (RGB)", 2D) = "white" {}
}
SubShader {
Tags {
"RenderType" = "Opaque"
}
CGPROGRAM
#pragma surface surf TestForward addshadow fullforwardshadows
struct Input
{
float2 uv_MainTex;
};
sampler2D _MainTex;
fixed4 _Color;
half4 LightingTestForward(SurfaceOutput s, half3 lightDir, half atten)
{
half4 c;
c.rgb = s.Albedo * _LightColor0.rgb * min(floor(300*atten), 1);
c.a = s.Alpha;
return c;
}
void surf (Input IN, inout SurfaceOutput o)
{
fixed4 c = tex2D(_MainTex, IN.uv_MainTex) * _Color;
o.Albedo = c.rgb;
o.Alpha = c.a;
}
ENDCG
}
}
Any help is greatly appreciated. Thanks!