Hi I just started learing unity shaders, - Unite 2015 - Writing Shaders - YouTube
But when creating a difuse lightinig shader with single directional light
everytime _Object2World is replaced by unity_ObjectToWorld with a upgrade message on top
I tried searching for it but the bug is issue is closed in latest version of unity
My Unity ver - 5.4.0f3
// Upgrade NOTE: replaced '_Object2World' with 'unity_ObjectToWorld'
// Upgrade NOTE: replaced '_Object2World' with 'unity_ObjectToWorld'
Shader "Unlit/Custom_Diffuse"
{
Properties {
// Texture field in inspector where we assign texture to the model
_MainTexture("Main Texture",2D) = "white"{}
}
SubShader {
PASS {
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
fixed4 _Color;
sampler2D _MainTexture;
float4 _LightColor0;
struct appData {
float4 vertex : POSITION;
float3 normal : NORMAL;
float2 texCoord : TEXCOORD0;
};
struct v2f {
float4 pos : SV_POSITION;
float3 normal : NORMAL;
float2 texCoord : TEXCOORD0;
};
v2f vert (appData IN) {
v2f OUT;
OUT.pos = mul(UNITY_MATRIX_MVP,IN.vertex);
// Directly used from model space to modelspace
// OUT.normal = IN.NORMAL;
// float4 (IN.normal,0.0) - normal is a float3 type variable declared in appData
// But we need float4 so this line converts float3 to float4 type casting we can say
//mul() to convert the normal from model space to world space as light is in world space
// _Object2World is a unity internal variable
//mul().xyz - swizling the resultant of mul is float4, this converts to float3
OUT.normal = mul(float4(IN.normal,0.0),unity_ObjectToWorld).xyz;
// just pass the texture coodinates of the UV map to the semantics in fragment
// Directly used from model space to modelspace
OUT.texCoord = IN.texCoord;
return OUT;
}
fixed4 frag(v2f IN) : COLOR{
// wraps the texture data to the UV coordinates recieved from the vertex function
float4 texColor = tex2D(_MainTexture,IN.texCoord);
float3 normalDirection = normalize(IN.normal);
float3 lightDirection = normalize(_WorldSpaceLightPos0.xyz);
float3 diffuse = _LightColor0.rgb * max(0.0,dot(normalDirection,lightDirection));
return _Color * texColor * float4(diffuse,1);
}
ENDCG
}
}
}