I`ve been following this tutorial
, but the result turned out not as It had been excepted: the lighting on geometry with the shader applied looked inverted.
I found the cause pretty quickly though I cannot figure out why it behaves that way, here take a look(pay attention to lines 37-40):
Shader "1_Lambdert" {
Properties {
_Color ("Color", Color) = (1.0,1.0,1.0,1.0)
}
SubShader {
Pass {
Tags { "LightMode" = "ForwardBase"}
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
//user defined variables
uniform float4 _Color;
//unity defined variables
uniform float4 _LightColor0;
//base input structs
struct vertexInput{
float4 vertex : POSITION;
float3 normal : NORMAL;
};
struct vertexOutput{
float4 pos : SV_POSITION;
float4 col : COLOR;
};
//vertex functions
vertexOutput vert(vertexInput v){
vertexOutput o;
float3 normalDirection = normalize( mul( float4(v.normal,0.0), _World2Object ).xyz );
float lightDirection;
float atten = 1.0;
lightDirection = normalize( _WorldSpaceLightPos0.xyz );
float3 diffuseReflection = max( 0.0, dot(normalDirection, lightDirection));
//replacing to upper lines with these fixes the error
//float3 diffuseReflection = max( 0.0, dot(normalDirection, normalize( _WorldSpaceLightPos0.xyz )));
o.col = float4(diffuseReflection, 1.0);
o.pos = mul(UNITY_MATRIX_MVP, v.vertex);
return o;
}
//fragment function
float4 frag(vertexOutput i) : COLOR
{
return i.col;
}
ENDCG
}
}
}
Does anyone has any ideas what`s wrong with that assignment?