콘텐츠로 건너뛰기

Extra technique for Skin shader by URP

Dual Lobe BeckMann

half3 DirectBDRFXD(BRDFData brdfData, BRDFDataXD brdfDataXD, half3 normalWS, half3 lightDirectionWS, half3 viewDirectionWS,half mask)
{
    #ifndef _SPECULARHIGHLIGHTS_OFF
    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);
    #if _USESKIN
    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 + brdfData.diffuse;
    return color;
    #endif
    #else
    return brdfData.diffuse;
    #endif
}

Dual Lobe BeckMann


Custom HDR Reflection for More Metallic.

half3 GlossyEnvironmentReflectionSkin(half3 reflectVector, half perceptualRoughness, half occlusion , half mask)
{
    #if !defined(_ENVIRONMENTREFLECTIONS_OFF)
    half mip = PerceptualRoughnessToMipmapLevel(perceptualRoughness);
    half4 customIrradiance = SAMPLE_TEXTURECUBE_LOD(_cubemap , sampler_cubemap, reflectVector, mip);
    half4 encodedIrradiance = SAMPLE_TEXTURECUBE_LOD(unity_SpecCube0, samplerunity_SpecCube0, reflectVector, mip);
    half4 blendIrraciance = lerp(encodedIrradiance , customIrradiance , mask);

    #if !defined(UNITY_USE_NATIVE_HDR)
    half3 irradiance = DecodeHDREnvironment(blendIrraciance, unity_SpecCube0_HDR);
    #else
    half3 irradiance = blendIrraciance.rgb;
    #endif
    return irradiance * occlusion;
    #endif // GLOSSY_REFLECTIONS

    return _GlossyEnvironmentColor.rgb * occlusion;
}

Custom HDR Reflection for More Metallic.

태그:

댓글 남기기

%d 블로거가 이것을 좋아합니다: