- 半兰伯特光照模型
- Diffuse = 直射光颜色 *( cosθ *0.5 +0.5)
- 兰伯特光照模型(漫反射)
- Diffuse = 直射光颜色 * max(0,cos夹角(光和法线的夹角) ) cosθ = 光方向· 法线方向
-
// Upgrade NOTE: replaced '_World2Object' with 'unity_WorldToObject' Shader "LXC/06 Diffuse Fragment HalfLambert" { Properties{ _Diffuse("Diffuse Color",Color) = (1,1,1,1) } SubShader { Pass{ Tags{ "LightMode" = "ForwardBase" } CGPROGRAM #include "Lighting.cginc" #pragma vertex vert #pragma fragment frag fixed4 _Diffuse; struct a2v { float4 vertex:POSITION; float3 normal:NORMAL; }; struct v2f { float4 position:SV_POSITION; fixed3 worldNormalDir : COLOR0; }; v2f vert(a2v v) { v2f f; f.position = UnityObjectToClipPos(v.vertex); f.worldNormalDir = mul(v.normal, (float3x3) unity_WorldToObject); return f; } fixed4 frag(v2f f) :SV_Target{ fixed3 ambient = UNITY_LIGHTMODEL_AMBIENT.rgb; fixed3 normalDir = normalize(f.worldNormalDir); fixed3 lightDir = normalize(_WorldSpaceLightPos0.xyz); //半兰伯特公式 float halfLambert = dot(normalDir, lightDir) * 0.5 + 0.5; fixed3 diffuse = _LightColor0.rgb * halfLambert *_Diffuse.rgb; fixed3 tempColor = diffuse + ambient; return fixed4(tempColor,1); } ENDCG } } Fallback "Diffuse" }
Shader-漫反射(像素实现)半兰伯特计算
猜你喜欢
转载自blog.csdn.net/qq_42459006/article/details/84109556
今日推荐
周排行