当前位置:   article > 正文

Unity shader各向异性的头发效果_unity羊毛效果

unity羊毛效果

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

在这里插入图片描述
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);
}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14

片元着色器(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);
...
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10

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

各向异性逐顶点的问题

在这里插入图片描述
这个是因为模型面数太低了,需要提高模型精度,或者增加一个高精度的法线贴图
才行,而且还与 UV有关的

在这里插入图片描述

为0变亮的问题

加上个step控制一下(避免用if)

 strandSpecular = strandSpecular * color.rgb * step(0.002, _StrandShiness);
  • 1
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/知新_RL/article/detail/233306
推荐阅读
相关标签
  

闽ICP备14008679号