半兰伯特
Shader "Shader/lanbert" { Properties{ } SubShader{ Tags { "RenderType" = "Opaque" } Pass { Name "FORWARD" Tags { "LightMode" = "ForwardBase" } CGPROGRAM #pragma vertex vert #pragma fragment frag #include "UnityCG.cginc" #pragma multi_compile_fwdbase_fullshadows #pragma target 3.0 struct VertexInput {//输入 float4 vertex : POSITION; //模型顶点信息 float3 normal : NORMAL; //模型法线信息 }; struct VertexOutput {//顶点着色器输出 float4 pos : SV_POSITION; //经过MVP矩阵转换到裁剪空间的顶点坐标 float3 nDirWS:TEXCOORD0;//世界坐标法线方向向量 }; VertexOutput vert(VertexInput v) { VertexOutput o = (VertexOutput)0; o.pos = UnityObjectToClipPos(v.vertex); o.nDirWS=UnityObjectToWorldNormal(v.normal); return o; } float4 frag(VertexOutput i) : COLOR { float3 nDir = i.nDirWS; float3 lDir = normalize(_WorldSpaceLightPos0.xyz);//归一化 float ndotl =dot(nDir,lDir)*0.5+0.5;//兰伯特法线和光向量点乘,转至(0,1)区间 return float4(ndotl,ndotl,ndotl,1); } ENDCG } } FallBack "Diffuse" }
标签:lesson3,VertexOutput,vertex,庄懂,ndotl,pragma,float4,TA,float3 From: https://www.cnblogs.com/lofu/p/17073799.html