來源:
float StrandSpecular (float3 T, float3 V, float3 L, float exponent)
{
float3 H = normalize(L + V);
float dotTH = dot(T, H);
float sinTH = sqrt(1.0 - dotTH*dotTH);
float dirAtten = smoothstep(-1.0, 0.0, dot(T, H));
return dirAtten * pow(sinTH, exponent);
}
smoothstep函數:
smoothstep(a, b, x)
{
x<a, 返回0;
x>b,返回1;
a<x<b,返回 w=(x-a)/(b-a), ww(3-2*w)
}
當dot(T,H)小於-1,生成0;
當dot(T,H)大於0,生成1;
當-1<dot(T,H)<0,返回smoothstep的值。
smoothstep函數裏w=x+1。如圖:
橫座標爲dot(T,H)