hairJit 贴图
float StrandSpecular(float3 T, float3 V, float3 L, float exponent, float strenth)
{
float3 H = normalize(L + V);
float dotTH = dot(T, H);
float sinTH = sqrt(1.0 - dotTH * dotTH);
float dirAtten = smoothstep(-1.0, 0.0, dotTH);
return dirAtten * pow(sinTH, exponent) * strenth;
}
float3 ShiftTangent(float3 T, float3 N, float shift)
{
float3 shiftedT = T + shift * N;
return normalize(shiftedT);
}
片元着色器(fragment shader)
...
binormal = cross(normal, tangent) // 次法线可以由法线和切线算出
...
fixed spec = dot(worldNormal, worldHalfDir);
tangent = ShiftTangent(binormal, worldNormal, hairJit + _AnisoOffset);
fixed3 specular1 = _LightSpecColor.rgb *
StrandSpecular(tangent, worldViewDir, worldLightDir, _Shininess1 * 20, _SpecIntensity1);
fixed3 specular2 = _LightSpecColor.rgb *
StrandSpecular(tangent, worldViewDir, worldLightDir, _Shininess2 * 20, _SpecIntensity2);
...
这样就得出与发丝方向垂直的高光了