本文主要是介绍庄懂05课 Phone和Blin Phone连连看和代码,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
庄懂老师https://space.bilibili.com/6373917?spm_id_from=333.788.b_765f7570696e666f.1第五课
phone
Blinn phone
两者区别是Blinn Phone逆光下效果不好,相对Phone比较省资源(现阶段影响很小)
兰伯特加phone的连连看
-Shader "Unlit/Lap and phone code" {Properties {//定义参数_MainColor("颜色",color)=(0.129,0.683,0.613,1)_SpecularPow("高光次数",range(1,90))=30}SubShader {Tags {"RenderType"="Opaque"}LOD 100Pass {Name "FORWARD"Tags {"LightMode"="ForwardBase"}CGPROGRAM#pragma vertex vert#pragma fragment frag#include "UnityCG.cginc"#pragma multi_compile_fwdbase_fullshadows#pragma multi_compile_fog#pragma target 3.0//输入参数uniform float3 _MainColor;uniform float _SpecularPow;//输入结构struct VertexInput {float4 vertex : POSITION; //输入模型顶点信息float3 normal : NORMAL; //输入模型法线信息};//输出结构struct VertexOutput {float4 posCS : SV_POSITION; //由模型顶点信息换算的顶点屏幕位置float4 posWS : TEXCOORD1;//由模型顶点信息换算的世界顶点信息(vDir =归一化(摄像机位置- posWS))float3 nDirWS : TEXCOORD0; //由模型法线信息换算来的世界空间法线信息};//输入结构>>>顶点Shader>>>输出结构VertexOutput vert (VertexInput v) {VertexOutput o = (VertexOutput)0; //新建输出结构o.posCS = UnityObjectToClipPos( v.vertex ); //o.posWS = mul(unity_ObjectToWorld, v.vertex); o.nDirWS = UnityObjectToWorldNormal(v.normal); //把模型法线转换成世界空间法线信息return o;}//输出结构>>>像素float4 frag(VertexOutput i) : COLOR {//准备向量float3 nDir = i.nDirWS;float3 lDir = _WorldSpaceLightPos0.xyz;float3 vDir = normalize(_WorldSpaceCameraPos.xyz - i.posWS.xyz);float3 hDir = normalize(lDir + vDir);//准备点积结果float ndotl = dot(nDir,lDir);float hdotn = dot(hDir,nDir);//光照模型float lambert = max(0.0,ndotl);float blinnPhong = pow(max(0,hdotn),_SpecularPow);float3 finalColor =_MainColor * lambert + blinnPhong;//建议用3维颜色乘1维兰伯特反过来在少数情况下可能会有bugreturn float4(finalColor,1.0); //输出最终颜色}ENDCG}}FallBack "Diffuse"CustomEditor "ShaderForgeMaterialInspector"
}
兰伯特和blinn phone代码
}float4 frag(VertexOutput i) : COLOR {//输入向量float3 lDir = _WorldSpaceLightPos0.xyz;float3 nDir = i.nDirWS;float3 vDir = normalize(_WorldSpaceCameraPos.xyz - i.posWS.xyz);float3 rDir =reflect(-lDir,nDir);//点积float ndotl = dot(nDir,lDir);float ldotv = dot(rDir,vDir);//光照模型float lambert = max(0,ndotl);float phone = pow(max(0,ldotv),_SpecularPow);float3 finalRGB = _MainColor*lambert + phone;return fixed4(finalRGB,1);}
兰伯特加phone修改此段
再补充一个自己瞎练的创意题
这篇关于庄懂05课 Phone和Blin Phone连连看和代码的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!