I am trying to make a Surface shader that uses a directional light with it’s lightDir angle xyz properties defined from the shader properties as a Vector property rather than using the main directional light in the scene. The reason for this is I want the shadows to derive from the scene’s main directional light, but the actual light applied to be coming from a different custom angle. Is this possible? What I am having initial difficulty on is figuring out how to convert my customLightAngle vector into the correct object/ world space so I can pass it into the surface shader. Thanks for any pointers.
vec ("customLightAngle", Vector) = (45,45,45,1)
fixed4 CustomLight (SurfaceOutputCustom s, fixed3 lightDir, fixed atten)
{
lightDir = myCustomVector;
fixed diff = max (0, dot (s.Normal, lightDir.xyz ));
}
Here is what I have so far. Still can’t figure out how to correctly turn a property vector into a directional light with rotation defined by the vector’s xyz.
Shader "CustomVectorLight" {
Properties {
lightDirVec ("light vec", Vector) = (45,45,45,1)
}
SubShader {
Tags { "RenderType" = "Opaque" }
CGPROGRAM
#pragma surface surf CustomLight vertex:vert target 2.0
struct SurfaceOutputCustom {
fixed3 Albedo;
fixed3 Normal;
fixed3 Emission;
half Specular;
fixed Gloss;
fixed Alpha;
fixed3 CustomLightDir;
};
float3 lightDirVec;
fixed4 LightingCustomLight(SurfaceOutputCustom s, fixed3 lightDir, fixed atten)
{
fixed4 c;
c.rgb = max (0, dot (s.Normal, s.CustomLightDir.xyz ));
c.a = 1;
return c;
}
struct Input {
float2 uv_Tex1;
float3 lightDirVec;
};
void vert (inout appdata_full v, out Input o) {
float3 objSpaceLightPos = mul(_World2Object, float4 (lightDirVec,1)).xyz;
objSpaceLightPos = objSpaceLightPos.xyz * unity_Scale.w - v.vertex.xyz;
TANGENT_SPACE_ROTATION;
o.lightDirVec = mul (rotation, objSpaceLightPos);
}
void surf (Input IN, inout SurfaceOutputCustom o) {
o.CustomLightDir = IN.lightDirVec.xyz;
o.Albedo = .5f;
}
ENDCG
}
}