I’m trying to make a shader with adjustable self shadow.
Shader "Custom/Test"
{
Properties
{
_Color ("Main Color", Color) = (0.5,0.5,0.5,1)
_MainTex ("Base (RGB)", 2D) = "white" {}
_Shadow("Shadow", Range(0.0, 1.0)) = 0.2
}
SubShader
{
Tags { "RenderType"="Opaque" }
CGPROGRAM
#pragma surface surf Custom fullforwardshadows exclude_path:prepass
sampler2D _MainTex;
float4 _Color;
fixed _Shadow;
struct Input
{
float2 uv_MainTex;
};
struct CustomSurfaceOutput {
half3 Albedo;
half3 Normal;
half3 Emission;
float Shadow;
half Alpha;
};
inline half4 LightingCustom (CustomSurfaceOutput s, half3 lightDir, half atten){
half NdotL = dot(s.Normal, lightDir) * s.Shadow;
half4 c;
c.rgb = s.Albedo * _LightColor0.rgb * atten + NdotL * s.Albedo;
c.a = 0;
return c;
}
void surf (Input IN, inout CustomSurfaceOutput o) {
half4 c = tex2D(_MainTex, IN.uv_MainTex) * _Color;
o.Albedo = c.rgb;
o.Alpha = c.a;
o.Shadow = _Shadow;
}
ENDCG
}
FallBack "Diffuse"
}
Here is the effect it produces. It makes surfaces facing light brighter, while surfaces turned 180 degrees away become dark. Other surfaces are lit from brighter to darker depending on their angle (surfaces at exactly 90 degrees don’t change brightness).
And here is the effect I want to achieve:
I want surfaces facing light to not change brightness, at 90 degrees to become partially dark, and at 180 degrees to become dark. Light distribution on surfaces should remain the same, but instead of being in “bright - no change - dark” range, it should be in “no change - partially dark - dark” range. I don’t want NdotL to ever produce result brighter than original texture.
I think I need to modify NdotL calculation in some way to achieve this effect, but I can’t figure how.
Please help.