oldschool Pro 有参考苏格拉底代码格式
Shader "Shader/OldSchoolPro" { Properties { _SpecularPow("SpecularPower",range(1,99)) = 30 //面板需要的参数 _EnvIntensity("EnvIntensity",range(0,1)) = 0.3 _BaseColor("BaseColor",color) = (1.0,1.0,1.0,1.0) _LigCol("LightColor",color) = (1.0,1.0,1.0,1.0) _TopCol("TopColor",color) = (1.0,1.0,1.0,1.0) _BottomCol("BottomColor",color) = (1.0,1.0,1.0,1.0) _SideCol("SideColor",color) = (1.0,1.0,1.0,1.0) _Occlusion("AO",2d) ="white"{} } SubShader { Name "FORWARD" Tags { "LightMode"="ForwardBase" } Pass { CGPROGRAM #pragma vertex vert #pragma fragment frag #include "UnityCG.cginc" #include "AutoLight.cginc" #include "Lighting.cginc" #pragma multi_compile_fwdbase_fullshadows #pragma target 3.0 float _SpecularPow; //声明变量 float _EnvIntensity; sampler2D _Occlusion; float3 _BaseColor; float3 _LigCol; float3 _TopCol; float3 _BottomCol; float3 _SideCol; struct vertexInput { float4 vertex : POSITION; float3 normal : NORMAL; float2 uv0 : TEXCOORD0;//模型的uv信息,输入的这几个值对应的名称都是固定好的,不像输出可以修改 }; struct vertexOutput { float4 pos :SV_POSITION;//裁剪空间顶点坐标 float4 posWS : TEXCOORD0;//世界空间顶点坐标 float3 nDirWS : TEXCOORD1;//世界空间法线坐标 float2 uv : TEXCOORD2; LIGHTING_COORDS(3,4) //投影相关,34编号是顺着012这样排下来的 }; vertexOutput vert (vertexInput v) { vertexOutput o = (vertexOutput)0; o.pos = UnityObjectToClipPos(v.vertex); o.posWS = mul(unity_ObjectToWorld,v.vertex); o.nDirWS = UnityObjectToWorldNormal(v.normal); o.uv = v.uv0; TRANSFER_VERTEX_TO_FRAGMENT(o) //投影相关 return o; } fixed4 frag (vertexOutput i) : SV_Target { //准备 float3 nDir = normalize(i.nDirWS); float3 lDir = _WorldSpaceLightPos0.xyz; float3 vDir = normalize(_WorldSpaceCameraPos.xyz-i.posWS.xyz); float3 rDir = reflect(-lDir, nDir); //计算 float nDotl = dot(nDir,lDir); float vDotr = dot(vDir,rDir); //Phong+lambert float Phong = pow(max(0.0,vDotr),_SpecularPow); float lambert = max(0.0, nDotl); float shadow = LIGHT_ATTENUATION(i); float3 DirectLight = (_BaseColor * lambert + Phong) * _LigCol * shadow; //计算遮罩 float topmask = max(0.0,nDir.g); float bottommask = max(0.0,-nDir.g); float sidemask = 1.0 - topmask - bottommask; //混色 float totalmask = _TopCol*topmask + _BottomCol*bottommask + _SideCol*sidemask; float3 envColor = mul(_BaseColor,mul(_EnvIntensity,totalmask)); //采样occlusion float occlusion = tex2D(_Occlusion,i.uv); float3 EnvLight = envColor * occlusion; //Final float3 FinalRGB =DirectLight + EnvLight; return float4(FinalRGB,1.0); } ENDCG } } }
标签:BaseColor,1.0,vertexOutput,color,float,庄懂,Lesson,TA,float3 From: https://www.cnblogs.com/lofu/p/17093505.html