Phong 模型解释
Phong模型
1 1 inline fixed4 LightingPhong (SurfaceOutput s, fixed3 lightDir, half3 viewDir, fixed atten) 2 2 { 3 3 float diff = dot(s.Normal, lightDir); 4 4 float3 reflectionVector = normalize(2.0 * s.Normal * diff - lightDir); 5 5 float spec = pow(max(0,dot(reflectionVector,viewDir)),_SpecPower); 6 6 float3 finalSpec = _SpecularColor.rgb *spec; 7 7 fixed4 c; 8 8 c.rgb = (s.Albedo * _LightColor0.rgb * diff) + (_LightColor0.rgb * finalSpec); 9 9 c.a = 1.0; 10 10 return c; 11 11 }
--3- 计算表面法线与光照方向的点积。
--4- 将表面的法线向光线方向修正。
--5- 用修正后的法线与视点方向viewDir再计算点积。

BlinnPhong模型
1 inline fixed4 LightingCustomBlinnPhong (SurfaceOutput s, fixed3 lightDir, half3 viewDir, fixed atten) 2 { 3 float3 halfVector = normalize(lightDir + viewDir); 4 float diff = max(0, dot(s.Normal, lightDir)); 5 float nh = max(0, dot(s.Normal,halfVector)); 6 float spec = pow (nh,_SpecPower) * _SpecularColor; 7 float4 c; 8 c.rgb = (s.Albedo * _LightColor0.rgb * diff) + (_LightColor0.rgb * _SpecularColor.rgb * spec) * (atten * 2); 9 c.a = 1.0; 10 return c; 11 }
--3- 取光照方向与视点方向的中值向量。
--4-5- 分别计算diffuse与specular两个点积。
--8- 合成diffuse与specular两部分的影响。
两个模型的效果对比:
Phong模型(左)比U BlinnPhong模型(左)反射光线分布更均匀,效果更柔和。

浙公网安备 33010602011771号