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.

BentNormal Oriented SpecularOcclusion of Shadow.

half3 GlobalIlluminationBentOcclusion(BRDFData brdfData, half3 bakedGI, half occlusion, half3 normalWS, half3 viewDirectionWS, half shadow = 1.0, half mainLightNoH = 0.0)
{
    half3 reflectVector = reflect(-viewDirectionWS, normalWS);
    half fresnelTerm = Pow4(1.0 - saturate(dot(normalWS, viewDirectionWS)));
    half3 indirectDiffuse = bakedGI * occlusion;
    half3 indirectSpecular = GlossyEnvironmentReflection(reflectVector, brdfData.perceptualRoughness, occlusion * max(shadow, 1-sqrt(mainLightNoH)));
    return EnvironmentBRDF(brdfData, indirectDiffuse, indirectSpecular, fresnelTerm);
}

BentNormal Oriented SpecularOcclusion of Shadow.

Categories: shader

Tagged as: ,

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s