I have limited knowledge of how to write custom shaders and I’m trying to do a “simple” double sided shader that lights both sides evenly.
I got as far as making two passes to get a solid surface on both sides which both takes lighting information (instead of merely Cull Off).
Now, my problem is this: it only lights both surfaces based on the front face. So if the light is hitting the backface, both sides are dark instead. I tried flipping the normals on the back face but the moment I add the line “#pragma vertex vert”, I lose the “both sides are lit evenly” aspect that I want.
I’m not sure why it’s behaving this way and I was wondering if anyone had a solution to what I believe should be a basic thing to do with shaders… which is to apply light on both sides regardless of which side (front/back face) the light is really on.
Here’s the code:
Shader "Project/LitDoubleSided" {
Properties {
_TintColor ("Color",Color)=(0.5,0.5,0.5)
_MainTex ("Texture", 2D) = "white" {}
_Cutoff ("Cutoff", float) = 0.5
_Color ("FallbackColor",Color)=(1,1,1,1)
}
SubShader {
Tags { "RenderType"= "Opaque" }
Cull Back
LOD 200
CGPROGRAM
#pragma surface surf Standard fullforwardshadows
#pragma target 3.0
sampler2D _MainTex;
fixed3 _TintColor;
struct Input {
float2 uv_MainTex;
fixed _Cutoff;
};
half _Glossiness;
half _Metallic;
fixed4 _Color;
void surf (Input IN, inout SurfaceOutputStandard o) {
fixed4 c = tex2D (_MainTex, IN.uv_MainTex) * _Color;
o.Albedo = c.rgb * (_TintColor*2);
o.Alpha = c.a;
}
ENDCG
Cull Front
//LOD 200
CGPROGRAM
#pragma surface surf Standard fullforwardshadows
#pragma target 3.0
//#pragma vertex vert
sampler2D _MainTex;
fixed3 _TintColor;
struct Input {
float2 uv_MainTex;
fixed _Cutoff;
};
half _Glossiness;
half _Metallic;
fixed4 _Color;
void vert (inout appdata_full v) {
v.normal *= -1;
}
void surf (Input IN, inout SurfaceOutputStandard o) {
fixed4 c = tex2D (_MainTex, IN.uv_MainTex) * _Color;
o.Albedo = c.rgb * (_TintColor*2);
o.Alpha = c.a;
}
ENDCG
}
FallBack "Diffuse"
}
I tried adding a Lambert
half4 LightingSimpleLambert(SurfaceOutput s, half3 lightDir, half atten){
half NdotL=dot(s.Normal,lightDir);
half4 c;
c.rgb=s.Albedo*_LightColor0.rgb*(NdotL*atten);
c.a=s.Alpha;
return c;
}
… but that didn’t seem to do anything. Even if I were to change “#pragma surface surf Standard” to “#pragma surface surf Lambert”
I think I understand what each line does, but putting the two concept together don’t seem to work. I think I need to flip the coordinates of the light when I flip the normals of the backface but I don’t know how to achieve that.
Any help would be appreciated. Preferably in Deferred lighting but I’ll accept any suggestions.
Thanks.





