最近在学习Unity的着色器编程,发现和GLSL的原理差不多,现在立个贴记录一下学习的心得。
Half Lambert是在Diffuse光照模型的基础之上进行改进的,将Diffuse光照计算后产生的光照值 x * 0.5 + 0.5,从而将Diffuse光照模型的值从(0--1)映射到(0.5--1),将物体处于低光照区域的表面也显示出来,改善了视觉效果。
Diffuse Shading:
inline float4 LightingBasicDiffuse (SurfaceOutput s, fixed3 lightDir, fixed atten)
{
float difLight = max(0, dot (s.Normal, lightDir));
float4 col;
col.rgb = s.Albedo * _LightColor0.rgb * (difLight * atten * 2);
col.a = s.Alpha;
return col;
}
inline float4 LightingBasicDiffuse (SurfaceOutput s, fixed3 lightDir, fixed atten)
{
float difLight = max(0, dot (s.Normal, lightDir));
float hLambert = difLight * 0.5f + 0.5f;
float4 col;
col.rgb = s.Albedo * _LightColor0.rgb * (hLambert * atten * 2);
col.a = s.Alpha;
return col;
}