(一)phong模型 (1)emissive(自发光) (2)ambient(环境光)
fixed3 ambient = UNITY_LIGHTMODEL_AMBIENT.xyz;【光源照射物体主要为反射和折射】
(3)diffuse(漫反射)——折射
兰伯特光照模型(Lambert) 兰伯特定律:在平面某点漫反射光的光强与该反射点的法向量和入射光角度的余弦值成正比。
// Get the normal in world space fixed3 worldNormal = normalize(i.worldNormal); // Get the light direction in world space fixed3 worldLightDir = normalize(UnityWorldSpaceLightDir(i.worldPos)); // Compute diffuse term fixed3 diffuse = _LightColor0.rgb * _Diffuse.rgb * saturate(dot(worldNormal, worldLightDir)); fixed3 color = ambient + diffuse; return fixed4(color, 1.0); }半兰伯特光照模型(Half Lambert)
// Compute diffuse term fixed halfLambert = dot(worldNormal, worldLightDir) * 0.5 + 0.5; fixed3 diffuse = _LightColor0.rgb * _Diffuse.rgb * halfLambert;(4)specular(高光反射)——反射 反射方向可以由CG提供的函数获得 reflect(入射方向,法线方向)
// Get the reflect direction in world space fixed3 reflectDir = normalize(reflect(-worldLightDir, worldNormal)); // Get the view direction in world space fixed3 viewDir = normalize(UnityWorldSpaceViewDir(i.worldPos)); // Compute specular term fixed3 specular = _LightColor0.rgb * _Specular.rgb * pow(saturate(dot(reflectDir, viewDir)), _Gloss);扩充:Blinn高光光照模型
// Get the view direction in world space fixed3 viewDir = normalize(UnityWorldSpaceViewDir(i.worldPos)); // Get the half direction in world space fixed3 halfDir = normalize(worldLightDir + viewDir); // Compute specular term fixed3 specular = _LightColor0.rgb * _Specular.rgb * pow(max(0, dot(worldNormal, halfDir)), _Gloss);【部分内容摘自冯乐乐】