I am learning a basic lambert lighting model shader, the shader scripts:
Shader "Unlit/NewUnlitShader"
{
Properties{
_MainColor("MainColor",Color)=(1,1,1,1)
}
SubShader
{
Pass
{
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#include "UnityCG.cginc"
#include "UnityLightingCommon.cginc"
struct v2f
{
float4 pos:SV_POSITION;
fixed4 dif:COLOR0;
};
fixed4 _MainColor;
v2f vert(appdata_base v)
{
v2f o;
o.pos = UnityObjectToClipPos(v.vertex);
//normal vector
float3 n = UnityObjectToWorldNormal(v.normal);
n=normalize(n);
//lighting direction vector
fixed3 l = normalize(_WorldSpaceLightPos0.xyz);
//calculate lambert
fixed ndotl = dot(n,l);
o.dif = _LightColor0*_MainColor*saturate(ndotl);
return o;
}
fixed4 frag(v2f i):SV_Target
{
return i.dif;
}
ENDCG
}
}
}
Something strange happen: When I create a material from this shader and assign the material to a sphere, the sphere always show black:
the left is urp/lit and the right is my shader,the shader previews is black
When I create a new project and install urp, I copy my shader to this new project, things works correct:
performs correct
So I guess I may have made some wrong settings in the old project,could anyone help me figure that out? Thanks!