Shader that ignores only Directional Light?

Hi there! Does anyone know how to create let’s say bumped diffuse shader, that could ignore only Directional Light: texture shouldn’t accept any light from Directional Light source but object still has to cast shadows from it. Along with it texture should accept any other light sources (Point, Spot, etc.) Thanks in advance for your help :slight_smile:

2 Answers

2

Anyone? Please, just give me a few ideas how to perform that. Let’s say we’ve got standart Bumped Diffuse shader example:

Shader "Bumped Diffuse" {
Properties {
	_Color ("Main Color", Color) = (1,1,1,1)
	_MainTex ("Base (RGB)", 2D) = "white" {}
	_BumpMap ("Normalmap", 2D) = "bump" {}
}

SubShader {
	Tags { "RenderType"="Opaque" }
	LOD 300

CGPROGRAM
#pragma surface surf Lambert

sampler2D _MainTex;
sampler2D _BumpMap;
fixed4 _Color;

struct Input {
	float2 uv_MainTex;
	float2 uv_BumpMap;
};

void surf (Input IN, inout SurfaceOutput o) {
	fixed4 c = tex2D(_MainTex, IN.uv_MainTex) * _Color;
	o.Albedo = c.rgb;
	o.Alpha = c.a;
	o.Normal = UnpackNormal(tex2D(_BumpMap, IN.uv_BumpMap));
}
ENDCG  
}

FallBack "Diffuse"
}

As of being a 3 years old post, have you ever found a solution for this problem?

–

Shader “Bumped Diffuse” {
Properties {
_Color (“Main Color”, Color) = (1,1,1,1)
_MainTex (“Base (RGB)”, 2D) = “white” {}
_BumpMap (“Normalmap”, 2D) = “bump” {}
}

 SubShader {
     Tags { "RenderType"="Opaque" }
     LOD 300
 
 CGPROGRAM
 #pragma surface surf LambertCustom
 
 sampler2D _MainTex;
 sampler2D _BumpMap;
 fixed4 _Color;
 
 struct Input {
     float2 uv_MainTex;
     float2 uv_BumpMap;
 };

half4 LightingLambertCustom (SurfaceOutput s, half3 lightDir, half atten) {
    s.Normal = normalize (s.Normal);
    
    half diff;
    if (_WorldSpaceLightPos0.w != 0.0)
        diff = max (0, dot (s.Normal, normalize (lightDir))) * _LightColor0;
    else
        diff = 1.0;
    
    half4 c;
    c.rgb = (s.Albedo * diff) * atten;
    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;
     o.Normal = UnpackNormal(tex2D(_BumpMap, IN.uv_BumpMap));
 }
 ENDCG  
 }
 
 FallBack "Diffuse"
 }

Something like that should work. Haven’t tested, but the w swizzle mask of the _WorldSpaceLightPos variable returns whether the light hitting the object is directional (0.0) or other.