replace _WorldSpaceLightPos0 and _LightColor0

hi,
i would like to pass the light direction and light color in C# script, i don’t want to use shader build-in variable(_WorldSpaceLightPos0 and _LightColor0), but it doesn’t work.

shader:
fixed3 ambient = UNITY_LIGHTMODEL_AMBIENT.xyz;
fixed3 worldNormal = normalize(mul(v.normal, (float3x3)_World2Object));
fixed3 worldLight = normalize(_WorldSpaceLightPos0.xyz);
fixed3 diffuse = _LightColor0.rgb * _Diffuse.rgb * saturate(dot(worldNormal, worldLight));
o.color = ambient + diffuse;

it works fine.
but if i pass the info from C# using the following code, it looks weird.

C#
Vector4 lightColor = new Vector4(m_light.color.linear.r, m_light.color.linear.g, m_light.color.linear.b);
Vector4 lightDirection = new Vector4(m_light.transform.forward.normalized.x, m_light.transform.forward.normalized.y, m_light.transform.forward.normalized.z);

shader:
fixed3 worldLight = normalize(lightDirection.xyz);
fixed3 diffuse = lightColor.rgb * _Diffuse.rgb * saturate(dot(worldNormal, worldLight));

can anybody help? thanks in advance.:slight_smile:

i found the reason.
fixed3 diffuse = lightColor.rgb * _Diffuse.rgb * saturate(dot(worldNormal, -worldLight));
invert worldLight.
thanks @ Takahashi