Unity 关于双叶高光(Dual lobe Specular)

Next-Generation Character Rendering
https://leegoonz.blog/2020/08/24/dual-lobe-for-skin-shader-by-urp/

Unity 关于双叶高光(Dual lobe Specular)_第1张图片

其实就是模拟了高频信息
现在粗糙度的那张贴图只需要画低频信息就行了
Unity 关于双叶高光(Dual lobe Specular)_第2张图片

代码引用自 leegoonz

完整实现UE4里也有, leegoonz大佬应该是做了优化
这里我也做了些修改

half3 DirectBDRF_DualLobeSpecular(BRDFData brdfData, half3 normalWS, half3 lightDirectionWS, half3 viewDirectionWS,half mask, half lobeWeight)
{
    float3 halfDir = SafeNormalize(float3(lightDirectionWS) + float3(viewDirectionWS));
 
    float NoH = saturate(dot(normalWS, halfDir));
    half LoH = saturate(dot(lightDirectionWS, halfDir));
 
    float d = NoH * NoH * brdfData.roughness2MinusOne + 1.00001f;
    half nv = saturate(dot(normalWS,lightDirectionWS));
    half LoH2 = LoH * LoH;
    float sAO = saturate(-0.3f + nv * nv);
    sAO =  lerp(pow(0.75, 8.00f), 1.0f, sAO);
    half SpecularOcclusion = sAO;
    half specularTermGGX = brdfData.roughness2 / ((d * d) * max(0.1h, LoH2) * brdfData.normalizationTerm);
    half specularTermBeckMann =
        (2.0 * (brdfData.roughness2) /
        ((d * d) * max(0.1h, LoH2) * brdfData.normalizationTerm)) * lobeWeight * mask;
    half specularTerm = (specularTermGGX / 2 + specularTermBeckMann) * SpecularOcclusion ;
 
    // On platforms where half actually means something, the denominator has a risk of overflow
    // clamp below was added specifically to "fix" that, but dx compiler (we convert bytecode to metal/gles)
    // sees that specularTerm have only non-negative terms, so it skips max(0,..) in clamp (leaving only min(100,...))
    #if defined (SHADER_API_MOBILE) || defined (SHADER_API_SWITCH)
    specularTerm = specularTerm - HALF_MIN;
    specularTerm = clamp(specularTerm, 0.0, 100.0); // Prevent FP16 overflow on mobiles
    #endif
 
    half3 color = specularTerm * brdfData.specular;
    return color;
}

你可能感兴趣的:(shader,Unreal,计算机图形学,图形学)