Ramp Texture

 

以光照与目视点夹角(0,1)值为uv值,取ramp texture的颜色点改变光照颜色。最终效果是不同光照角度看起来有不同的颜色。

 

inline float4 LightingBasicDiffuse (SurfaceOutput s, fixed3 lightDir, fixed atten)
{
    float difLight = dot(s.Normal,lightDir);
    float hLambert = difLight * 0.5 + 0.5;
    float3 ramp = tex2D(_RampTex,float2(hLambert)).rgb;
    float4 col;
    col.rgb = s.Albedo * _LightColor0.rgb * (ramp);
    col.a = s.Alpha;
    return col;
}

 

 

可利用Ramp Texture模拟BRDF(Bidirectional reflectance distribution function,双向反射分布函数)效果。方法是在光照模型中加入视点观察角度,viewDir,与lightDir分别计算出物体表面的夹角作为二维的uv值在Ramp Texutre取色:

inline float4 LightingBasicDiffuse (SurfaceOutput s, fixed3 lightDir, half3 viewDir, fixed atten)
{
    float difLight = dot(s.Normal,lightDir);
    float rimLight = dot(s.Normal,viewDir);
    float hLambert = difLight * 0.5 + 0.5;
    float3 ramp = tex2D(_RampTex,float2(hLambert,rimLight)).rgb;
    float4 col;
    col.rgb = s.Albedo * _LightColor0.rgb * (ramp);
    col.a = s.Alpha;
    return col;
}

Ramp Texture 的颜色分布可以应对二维取值:

posted on 2013-12-10 09:56  0x9801  阅读(1101)  评论(0)    收藏  举报

导航