Unity shader各向异性的头发效果

参考 https://www.jianshu.com/p/7dc980ea4c51

Unity shader各向异性的头发效果
hairJit 贴图
Unity shader各向异性的头发效果

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);
...

这样就得出与发丝方向垂直的高光了

上一篇:均分纸牌问题


下一篇:数组名作为函数参数--求数组平均数