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

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

在这里插入图片描述

其实就是模拟了高频信息
现在粗糙度的那张贴图只需要画低频信息就行了
在这里插入图片描述

代码引用自 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;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值