From 96582c94edd3822a2d26ab9264e4bf13ff27807b Mon Sep 17 00:00:00 2001 From: anisunity Date: Wed, 8 Sep 2021 15:03:30 +0200 Subject: [PATCH 01/10] Initial SSR clear coat improvement --- .../Runtime/Material/Lit/Lit.hlsl | 28 +++++++++++++------ .../Runtime/Material/StackLit/StackLit.hlsl | 21 ++++++++++---- 2 files changed, 35 insertions(+), 14 deletions(-) diff --git a/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/Lit.hlsl b/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/Lit.hlsl index f391c7bf599..76a7f3f0bec 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/Lit.hlsl +++ b/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/Lit.hlsl @@ -1822,17 +1822,29 @@ IndirectLighting EvaluateBSDF_ScreenSpaceReflection(PositionInputs posInput, // of a materia feature and the coat mask. float clampedNdotV = ClampNdotV(preLightData.NdotV); float F = F_Schlick(CLEAR_COAT_F0, clampedNdotV); - lighting.specularReflected = ssrLighting.rgb * (HasFlag(bsdfData.materialFeatures, MATERIALFEATUREFLAGS_LIT_CLEAR_COAT) ? - lerp(preLightData.specularFGD, F, bsdfData.coatMask) - : preLightData.specularFGD); + // Set the default weight value - reflectionHierarchyWeight = ssrLighting.a; + reflectionHierarchyWeight = ssrLighting.a; - // In case this is a clear coat material, we only need to add to the reflectionHierarchyWeight the amount of energy that the clear coat has already - // provided to the indirect specular lighting. That would be reflectionHierarchyWeight * F (if has a coat mask). In the environement lighting, - // we do something similar. The base layer coat is multiplied by (1-coatF)^2, but that we cannot do as we have no lighting to provid for the base layer. + // If this material has a clear coat, the behavior is more complex if (HasFlag(bsdfData.materialFeatures, MATERIALFEATUREFLAGS_LIT_CLEAR_COAT)) - reflectionHierarchyWeight = lerp(reflectionHierarchyWeight, reflectionHierarchyWeight * F, bsdfData.coatMask); + { + // We have three possible behaviors in this case: + // - The smoothness is superior or equal to 0.9, we approximate the fact that the clear coat and base layer have the same roughness and use the SSR as the indirect specular signal. + // - The smoothness is inferior to 0.8. We cannot use the SSR for the base layer, but we use the fresnel to lerp between the two lobes. + // - The smooothness is between 0.8 and 0.9, we lerp between the two behaviors. + float blendingFactor = lerp(0.0, 1.0, saturate((bsdfData.perceptualRoughness - 0.1) / 0.2)); + + // Combine the three behaviors for the lighting signal + lighting.specularReflected = ssrLighting.rgb * lerp(preLightData.specularFGD, lerp(preLightData.specularFGD, F, bsdfData.coatMask), blendingFactor); + + // We only need to add to the reflectionHierarchyWeight the amount of energy that the clear coat has already + // provided to the indirect specular lighting. That would be reflectionHierarchyWeight * F (if has a coat mask). In the environement lighting, + // we do something similar. The base layer coat is multiplied by (1-coatF)^2, but that we cannot do as we have no lighting to provid for the base layer. + reflectionHierarchyWeight = lerp(reflectionHierarchyWeight, lerp(reflectionHierarchyWeight, reflectionHierarchyWeight * F, bsdfData.coatMask), blendingFactor); + } + else + lighting.specularReflected = ssrLighting.rgb * preLightData.specularFGD; return lighting; } diff --git a/com.unity.render-pipelines.high-definition/Runtime/Material/StackLit/StackLit.hlsl b/com.unity.render-pipelines.high-definition/Runtime/Material/StackLit/StackLit.hlsl index de18a0d03f0..b90c1bf536e 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/Material/StackLit/StackLit.hlsl +++ b/com.unity.render-pipelines.high-definition/Runtime/Material/StackLit/StackLit.hlsl @@ -4220,18 +4220,27 @@ IndirectLighting EvaluateBSDF_ScreenSpaceReflection(PositionInputs posInput, reflectanceFactorC *= preLightData.energyCompensationFactor[COAT_LOBE_IDX]; float3 reflectanceFactorB = (float3)0.0; - for(int i = 0; i < TOTAL_NB_LOBES; i++) + for(int i = 0; i < BASE_NB_LOBES; i++) { - float3 lobeFactor = preLightData.specularFGD[i]; // note: includes the lobeMix factor, see PreLightData. - lobeFactor *= preLightData.hemiSpecularOcclusion[i]; + float3 lobeFactor = preLightData.specularFGD[i + COAT_NB_LOBES]; // note: includes the lobeMix factor, see PreLightData. + lobeFactor *= preLightData.hemiSpecularOcclusion[i + COAT_NB_LOBES]; // TODOENERGY: If vlayered, should be done in ComputeAdding with FGD formulation for non dirac lights. // Incorrect, but for now: - lobeFactor *= preLightData.energyCompensationFactor[i]; + lobeFactor *= preLightData.energyCompensationFactor[i + COAT_NB_LOBES]; reflectanceFactorB += lobeFactor; } - lighting.specularReflected = ssrLighting.rgb * lerp(reflectanceFactorB, reflectanceFactorC, bsdfData.coatMask); - reflectionHierarchyWeight = lerp(ssrLighting.a, ssrLighting.a * reflectanceFactorC.x, bsdfData.coatMask); + // Given that we have two base lobes, we need to mix them for an appproximated roughness + float mixedPerceptualRougness = lerp(bsdfData.perceptualRoughnessA, bsdfData.perceptualRoughnessB, bsdfData.lobeMix); + + // We have three possible behaviors in this case: + // - The smoothness is superior or equal to 0.9, we approximate the fact that the clear coat and base layer have the same roughness and use the SSR as the indirect specular signal. + // - The smoothness is inferior to 0.8. We cannot use the SSR for the base layer, but we use the fresnel to lerp between the two lobes. + // - The smooothness is between 0.8 and 0.9, we lerp between the two behaviors. + float blendingFactor = lerp(0.0, 1.0, saturate((mixedPerceptualRougness - 0.1) / 0.2)); + + lighting.specularReflected = ssrLighting.rgb * lerp(reflectanceFactorB, lerp(reflectanceFactorB, reflectanceFactorC, bsdfData.coatMask), blendingFactor); + reflectionHierarchyWeight = lerp(ssrLighting.a, lerp(ssrLighting.a, ssrLighting.a * reflectanceFactorC.x, bsdfData.coatMask), blendingFactor); } else { From 60805d41daf4a7095021212be9f6c0318cc95b42 Mon Sep 17 00:00:00 2001 From: anisunity Date: Wed, 8 Sep 2021 16:46:50 +0200 Subject: [PATCH 02/10] Second fix for the coat lobe issue. --- .../Runtime/Material/Lit/Lit.hlsl | 23 +++++++++++++------ .../Runtime/Material/StackLit/StackLit.hlsl | 11 +++++++++ 2 files changed, 27 insertions(+), 7 deletions(-) diff --git a/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/Lit.hlsl b/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/Lit.hlsl index 76a7f3f0bec..fbfc48abed0 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/Lit.hlsl +++ b/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/Lit.hlsl @@ -1083,6 +1083,7 @@ struct PreLightData float coatPartLambdaV; float3 coatIblR; float coatIblF; // Fresnel term for view vector + float clearCoatIndirectSpec; float3x3 ltcTransformCoat; // Inverse transformation for GGX (4x VGPRs) #if HAS_REFRACTION @@ -1144,6 +1145,7 @@ PreLightData GetPreLightData(float3 V, PositionInputs posInput, inout BSDFData b preLightData.coatPartLambdaV = GetSmithJointGGXPartLambdaV(clampedNdotV, CLEAR_COAT_ROUGHNESS); preLightData.coatIblR = reflect(-V, N); preLightData.coatIblF = F_Schlick(CLEAR_COAT_F0, clampedNdotV) * bsdfData.coatMask; + preLightData.clearCoatIndirectSpec = 1.0; } // Handle IBL + area light + multiscattering. @@ -1829,6 +1831,9 @@ IndirectLighting EvaluateBSDF_ScreenSpaceReflection(PositionInputs posInput, // If this material has a clear coat, the behavior is more complex if (HasFlag(bsdfData.materialFeatures, MATERIALFEATUREFLAGS_LIT_CLEAR_COAT)) { + // Because we do not want to have a double contribution, we need to keep track that the clear coat's indirect specular contribution was added + preLightData.clearCoatIndirectSpec = 1.0 - ssrLighting.a; + // We have three possible behaviors in this case: // - The smoothness is superior or equal to 0.9, we approximate the fact that the clear coat and base layer have the same roughness and use the SSR as the indirect specular signal. // - The smoothness is inferior to 0.8. We cannot use the SSR for the base layer, but we use the fresnel to lerp between the two lobes. @@ -2008,15 +2013,19 @@ IndirectLighting EvaluateBSDF_Env( LightLoopContext lightLoopContext, // Evaluate the Clear Coat component if needed if (HasFlag(bsdfData.materialFeatures, MATERIALFEATUREFLAGS_LIT_CLEAR_COAT)) { - // No correction needed for coatR as it is smooth - // Note: coat F is scalar as it is a dieletric - envLighting *= Sq(1.0 - preLightData.coatIblF); + if (preLightData.clearCoatIndirectSpec != 0.0) + { + // No correction needed for coatR as it is smooth + // Note: coat F is scalar as it is a dieletric + envLighting *= Sq(1.0 - preLightData.coatIblF); - // Evaluate the Clear Coat color - float4 preLD = SampleEnv(lightLoopContext, lightData.envIndex, coatR, 0.0, lightData.rangeCompressionFactorCompensation, posInput.positionNDC); - envLighting += preLightData.coatIblF * preLD.rgb; + // Evaluate the Clear Coat color + float4 preLD = SampleEnv(lightLoopContext, lightData.envIndex, coatR, 0.0, lightData.rangeCompressionFactorCompensation, posInput.positionNDC); + envLighting += preLightData.coatIblF * preLD.rgb; - // Can't attenuate diffuse lighting here, may try to apply something on bakeLighting in PostEvaluateBSDF + // Can't attenuate diffuse lighting here, may try to apply something on bakeLighting in PostEvaluateBSDF + } + } } #if HAS_REFRACTION diff --git a/com.unity.render-pipelines.high-definition/Runtime/Material/StackLit/StackLit.hlsl b/com.unity.render-pipelines.high-definition/Runtime/Material/StackLit/StackLit.hlsl index b90c1bf536e..a8157d3ecb9 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/Material/StackLit/StackLit.hlsl +++ b/com.unity.render-pipelines.high-definition/Runtime/Material/StackLit/StackLit.hlsl @@ -1046,6 +1046,9 @@ struct PreLightData float coatIeta; + // TODO write comment + float clearCoatIndirectSpec; + // For IBLs (and analytical lights if approximation is used) float3 vLayerEnergyCoeff[NB_VLAYERS]; @@ -2663,6 +2666,7 @@ PreLightData GetPreLightData(float3 V, PositionInputs posInput, inout BSDFData b // accordingly and are accessed by COAT|BASE_NORMAL_IDX preLightData.coatIeta = 1.0 / GetCoatEta(bsdfData); + preLightData.clearCoatIndirectSpec = 1.0; // First thing we need is compute the energy coefficients and new roughnesses. // Even if configured to do it also per analytical light, we need it for IBLs too. @@ -4239,6 +4243,9 @@ IndirectLighting EvaluateBSDF_ScreenSpaceReflection(PositionInputs posInput, // - The smooothness is between 0.8 and 0.9, we lerp between the two behaviors. float blendingFactor = lerp(0.0, 1.0, saturate((mixedPerceptualRougness - 0.1) / 0.2)); + // Because we do not want to have a double contribution, we need to keep track that the clear coat's indirect specular contribution was added + preLightData.clearCoatIndirectSpec = 1.0 - ssrLighting.a; + lighting.specularReflected = ssrLighting.rgb * lerp(reflectanceFactorB, lerp(reflectanceFactorB, reflectanceFactorC, bsdfData.coatMask), blendingFactor); reflectionHierarchyWeight = lerp(ssrLighting.a, lerp(ssrLighting.a, ssrLighting.a * reflectanceFactorC.x, bsdfData.coatMask), blendingFactor); } @@ -4360,6 +4367,10 @@ IndirectLighting EvaluateBSDF_Env( LightLoopContext lightLoopContext, if( (i == (0 IF_FEATURE_COAT(+1))) && _DebugEnvLobeMask.y == 0.0) continue; if( (i == (1 IF_FEATURE_COAT(+1))) && _DebugEnvLobeMask.z == 0.0) continue; #endif + + // If we are going to process the clear coat and it is flagged as akready processed, skip. + if (i == COAT_LOBE_IDX && COAT_NB_LOBES == 1 && preLightData.clearCoatIndirectSpec == 0.0) continue; + // Compiler will deal with all that: normal = (NB_NORMALS > 1 && i == COAT_NORMAL_IDX) ? bsdfData.coatNormalWS : bsdfData.normalWS; From e647c43a37baf3fc8bf18649896f0df689d3ef71 Mon Sep 17 00:00:00 2001 From: anisunity Date: Wed, 8 Sep 2021 16:47:04 +0200 Subject: [PATCH 03/10] oops --- .../Runtime/Material/Lit/Lit.hlsl | 2 +- .../Runtime/Material/StackLit/StackLit.hlsl | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/Lit.hlsl b/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/Lit.hlsl index fbfc48abed0..0cc586a8429 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/Lit.hlsl +++ b/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/Lit.hlsl @@ -1805,7 +1805,7 @@ DirectLighting EvaluateBSDF_Area(LightLoopContext lightLoopContext, // ---------------------------------------------------------------------------- IndirectLighting EvaluateBSDF_ScreenSpaceReflection(PositionInputs posInput, - PreLightData preLightData, + inout PreLightData preLightData, BSDFData bsdfData, inout float reflectionHierarchyWeight) { diff --git a/com.unity.render-pipelines.high-definition/Runtime/Material/StackLit/StackLit.hlsl b/com.unity.render-pipelines.high-definition/Runtime/Material/StackLit/StackLit.hlsl index a8157d3ecb9..bf44cc26e05 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/Material/StackLit/StackLit.hlsl +++ b/com.unity.render-pipelines.high-definition/Runtime/Material/StackLit/StackLit.hlsl @@ -4189,7 +4189,7 @@ DirectLighting EvaluateBSDF_Area(LightLoopContext lightLoopContext, // ---------------------------------------------------------------------------- IndirectLighting EvaluateBSDF_ScreenSpaceReflection(PositionInputs posInput, - PreLightData preLightData, + inout PreLightData preLightData, BSDFData bsdfData, inout float reflectionHierarchyWeight) { From 73a886ca58ac24ba66c11aba1c2574bc89996522 Mon Sep 17 00:00:00 2001 From: Anis Benyoub Date: Thu, 9 Sep 2021 11:29:42 +0200 Subject: [PATCH 04/10] Fixes --- .../Runtime/Material/Lit/Lit.hlsl | 20 ++++++++----------- .../Runtime/Material/StackLit/StackLit.hlsl | 5 ++++- 2 files changed, 12 insertions(+), 13 deletions(-) diff --git a/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/Lit.hlsl b/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/Lit.hlsl index 0cc586a8429..3d8e8295c23 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/Lit.hlsl +++ b/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/Lit.hlsl @@ -1083,7 +1083,7 @@ struct PreLightData float coatPartLambdaV; float3 coatIblR; float coatIblF; // Fresnel term for view vector - float clearCoatIndirectSpec; + float clearCoatIndirectSpec; // Weight used to support the clear coat's SSR/IBL blending float3x3 ltcTransformCoat; // Inverse transformation for GGX (4x VGPRs) #if HAS_REFRACTION @@ -2013,19 +2013,15 @@ IndirectLighting EvaluateBSDF_Env( LightLoopContext lightLoopContext, // Evaluate the Clear Coat component if needed if (HasFlag(bsdfData.materialFeatures, MATERIALFEATUREFLAGS_LIT_CLEAR_COAT)) { - if (preLightData.clearCoatIndirectSpec != 0.0) - { - // No correction needed for coatR as it is smooth - // Note: coat F is scalar as it is a dieletric - envLighting *= Sq(1.0 - preLightData.coatIblF); + // No correction needed for coatR as it is smooth + // Note: coat F is scalar as it is a dieletric + envLighting *= Sq(1.0 - preLightData.coatIblF); - // Evaluate the Clear Coat color - float4 preLD = SampleEnv(lightLoopContext, lightData.envIndex, coatR, 0.0, lightData.rangeCompressionFactorCompensation, posInput.positionNDC); - envLighting += preLightData.coatIblF * preLD.rgb; + // Evaluate the Clear Coat color + float4 preLD = SampleEnv(lightLoopContext, lightData.envIndex, coatR, 0.0, lightData.rangeCompressionFactorCompensation, posInput.positionNDC); + envLighting += preLightData.coatIblF * preLD.rgb * preLightData.clearCoatIndirectSpec; - // Can't attenuate diffuse lighting here, may try to apply something on bakeLighting in PostEvaluateBSDF - } - + // Can't attenuate diffuse lighting here, may try to apply something on bakeLighting in PostEvaluateBSDF } } #if HAS_REFRACTION diff --git a/com.unity.render-pipelines.high-definition/Runtime/Material/StackLit/StackLit.hlsl b/com.unity.render-pipelines.high-definition/Runtime/Material/StackLit/StackLit.hlsl index bf44cc26e05..b2ad757555a 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/Material/StackLit/StackLit.hlsl +++ b/com.unity.render-pipelines.high-definition/Runtime/Material/StackLit/StackLit.hlsl @@ -1046,7 +1046,7 @@ struct PreLightData float coatIeta; - // TODO write comment + // Weight used to support the clear coat's SSR/IBL blending float clearCoatIndirectSpec; // For IBLs (and analytical lights if approximation is used) @@ -4404,6 +4404,9 @@ IndirectLighting EvaluateBSDF_Env( LightLoopContext lightLoopContext, // Incorrect, but just for now: L *= preLightData.energyCompensationFactor[i]; L *= preLightData.hemiSpecularOcclusion[i]; + + // If we are going to process the clear coat, we need to take into account the coat indirect spec factor + L = (i == COAT_LOBE_IDX && COAT_NB_LOBES == 1) ? preLightData.clearCoatIndirectSpec : 1.0; envLighting += L; } From 2d3f2e6b2e3f53c1c6869fb0de34e62557e26579 Mon Sep 17 00:00:00 2001 From: Anis Benyoub Date: Thu, 9 Sep 2021 11:41:26 +0200 Subject: [PATCH 05/10] Fixed double contribution from the clear coat when having SSR or RTR on the Lit and StackLit shaders (case 1352424). --- com.unity.render-pipelines.high-definition/CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/com.unity.render-pipelines.high-definition/CHANGELOG.md b/com.unity.render-pipelines.high-definition/CHANGELOG.md index 4e5a5b42a19..0bde2ef2357 100644 --- a/com.unity.render-pipelines.high-definition/CHANGELOG.md +++ b/com.unity.render-pipelines.high-definition/CHANGELOG.md @@ -45,6 +45,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. - Fixed sorting for mesh decals. - Fixed a warning when enabling tile/cluster debug. - Fix recursive rendering transmittance over the sky (case 1323945). +- Fixed double contribution from the clear coat when having SSR or RTR on the Lit and StackLit shaders (case 1352424). ### Changed - Visual Environment ambient mode is now Dynamic by default. From 1f5c5953888b7e35ac02465ff0c1cf8ba9b6f69d Mon Sep 17 00:00:00 2001 From: Anis Benyoub Date: Thu, 9 Sep 2021 17:12:37 +0200 Subject: [PATCH 06/10] formatting --- .../Runtime/Material/Lit/Lit.hlsl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/Lit.hlsl b/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/Lit.hlsl index 3d8e8295c23..773e6061f89 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/Lit.hlsl +++ b/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/Lit.hlsl @@ -1839,7 +1839,7 @@ IndirectLighting EvaluateBSDF_ScreenSpaceReflection(PositionInputs posInput, // - The smoothness is inferior to 0.8. We cannot use the SSR for the base layer, but we use the fresnel to lerp between the two lobes. // - The smooothness is between 0.8 and 0.9, we lerp between the two behaviors. float blendingFactor = lerp(0.0, 1.0, saturate((bsdfData.perceptualRoughness - 0.1) / 0.2)); - + // Combine the three behaviors for the lighting signal lighting.specularReflected = ssrLighting.rgb * lerp(preLightData.specularFGD, lerp(preLightData.specularFGD, F, bsdfData.coatMask), blendingFactor); From 38242927993749152e7acf9c40de6a3949acbdd6 Mon Sep 17 00:00:00 2001 From: Anis Benyoub Date: Fri, 10 Sep 2021 11:24:12 +0200 Subject: [PATCH 07/10] woopsie --- .../Runtime/Material/StackLit/StackLit.hlsl | 3 --- 1 file changed, 3 deletions(-) diff --git a/com.unity.render-pipelines.high-definition/Runtime/Material/StackLit/StackLit.hlsl b/com.unity.render-pipelines.high-definition/Runtime/Material/StackLit/StackLit.hlsl index b2ad757555a..b1aaeb2cf1c 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/Material/StackLit/StackLit.hlsl +++ b/com.unity.render-pipelines.high-definition/Runtime/Material/StackLit/StackLit.hlsl @@ -4368,9 +4368,6 @@ IndirectLighting EvaluateBSDF_Env( LightLoopContext lightLoopContext, if( (i == (1 IF_FEATURE_COAT(+1))) && _DebugEnvLobeMask.z == 0.0) continue; #endif - // If we are going to process the clear coat and it is flagged as akready processed, skip. - if (i == COAT_LOBE_IDX && COAT_NB_LOBES == 1 && preLightData.clearCoatIndirectSpec == 0.0) continue; - // Compiler will deal with all that: normal = (NB_NORMALS > 1 && i == COAT_NORMAL_IDX) ? bsdfData.coatNormalWS : bsdfData.normalWS; From 9310f8ed1406402faf035f1191446bbe1b5e75d8 Mon Sep 17 00:00:00 2001 From: sebastienlagarde Date: Sun, 12 Sep 2021 19:51:29 +0200 Subject: [PATCH 08/10] Update Lit.hlsl --- .../Runtime/Material/Lit/Lit.hlsl | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/Lit.hlsl b/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/Lit.hlsl index 773e6061f89..b76dac06b6d 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/Lit.hlsl +++ b/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/Lit.hlsl @@ -1805,6 +1805,7 @@ DirectLighting EvaluateBSDF_Area(LightLoopContext lightLoopContext, // ---------------------------------------------------------------------------- IndirectLighting EvaluateBSDF_ScreenSpaceReflection(PositionInputs posInput, + // Note: We use inout here with PreLightData for a hack we do with clear coat to transfer value of clearCoatIndirectSpec but it should be avoided for other Material inout PreLightData preLightData, BSDFData bsdfData, inout float reflectionHierarchyWeight) @@ -1829,6 +1830,11 @@ IndirectLighting EvaluateBSDF_ScreenSpaceReflection(PositionInputs posInput, reflectionHierarchyWeight = ssrLighting.a; // If this material has a clear coat, the behavior is more complex + // For clear coat we change a bit how reflection hierarchy is handled + // With a regular Material, we do SSR to get lighting then fallback on other method based on reflectionHierarchyWeight + // but for clear coat Material we try to do this mechanism separately for each layer. So clear coat do SSR then fallback but with the weight of clearCoatIndirectSpec + // base layer will get reamining energy of coat layer via reflectionHierarchyWeight with the fallback (i.e the cubemap). + // On top of this above we also add an additional hack to limit the smoothness used on based layer depending on coat layer for SSR application (See below) if (HasFlag(bsdfData.materialFeatures, MATERIALFEATUREFLAGS_LIT_CLEAR_COAT)) { // Because we do not want to have a double contribution, we need to keep track that the clear coat's indirect specular contribution was added From af33e1b7006d16e5fc67ef558e19cd973998d092 Mon Sep 17 00:00:00 2001 From: Anis Benyoub Date: Tue, 14 Sep 2021 10:40:00 +0200 Subject: [PATCH 09/10] woopsie in the code --- .../Runtime/Material/StackLit/StackLit.hlsl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/com.unity.render-pipelines.high-definition/Runtime/Material/StackLit/StackLit.hlsl b/com.unity.render-pipelines.high-definition/Runtime/Material/StackLit/StackLit.hlsl index b1aaeb2cf1c..8db6e9b5612 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/Material/StackLit/StackLit.hlsl +++ b/com.unity.render-pipelines.high-definition/Runtime/Material/StackLit/StackLit.hlsl @@ -2630,6 +2630,7 @@ PreLightData GetPreLightData(float3 V, PositionInputs posInput, inout BSDFData b PreLightData_SetupNormals(bsdfData, preLightData, V, N, NdotV); preLightData.diffuseEnergy = float3(1.0, 1.0, 1.0); + preLightData.clearCoatIndirectSpec = 1.0; // For eval IBL lights, we need: // @@ -2666,7 +2667,6 @@ PreLightData GetPreLightData(float3 V, PositionInputs posInput, inout BSDFData b // accordingly and are accessed by COAT|BASE_NORMAL_IDX preLightData.coatIeta = 1.0 / GetCoatEta(bsdfData); - preLightData.clearCoatIndirectSpec = 1.0; // First thing we need is compute the energy coefficients and new roughnesses. // Even if configured to do it also per analytical light, we need it for IBLs too. @@ -4403,7 +4403,7 @@ IndirectLighting EvaluateBSDF_Env( LightLoopContext lightLoopContext, L *= preLightData.hemiSpecularOcclusion[i]; // If we are going to process the clear coat, we need to take into account the coat indirect spec factor - L = (i == COAT_LOBE_IDX && COAT_NB_LOBES == 1) ? preLightData.clearCoatIndirectSpec : 1.0; + L *= (i == COAT_LOBE_IDX && COAT_NB_LOBES == 1) ? preLightData.clearCoatIndirectSpec : 1.0; envLighting += L; } From a4025598f72e05a1ca3c365373a0e232e88b966e Mon Sep 17 00:00:00 2001 From: Anis Benyoub Date: Mon, 20 Sep 2021 12:45:36 +0200 Subject: [PATCH 10/10] Update all screenshots except linux vulkan --- .../Linear/OSXEditor/Metal/None/1302_StackLitSG_PixarLM.png | 4 ++-- .../ReferenceImages/Linear/OSXEditor/Metal/None/2551_SSR.png | 4 ++-- .../WindowsEditor/Direct3D11/None/1302_StackLitSG_PixarLM.png | 4 ++-- .../Linear/WindowsEditor/Direct3D11/None/2551_SSR.png | 4 ++-- .../WindowsEditor/Direct3D12/None/1302_StackLitSG_PixarLM.png | 4 ++-- .../Linear/WindowsEditor/Direct3D12/None/2551_SSR.png | 4 ++-- .../WindowsEditor/Vulkan/None/1302_StackLitSG_PixarLM.png | 4 ++-- .../Linear/WindowsEditor/Vulkan/None/2551_SSR.png | 4 ++-- 8 files changed, 16 insertions(+), 16 deletions(-) diff --git a/TestProjects/HDRP_Tests/Assets/ReferenceImages/Linear/OSXEditor/Metal/None/1302_StackLitSG_PixarLM.png b/TestProjects/HDRP_Tests/Assets/ReferenceImages/Linear/OSXEditor/Metal/None/1302_StackLitSG_PixarLM.png index a0fe7329cdc..7c52eee5b9e 100644 --- a/TestProjects/HDRP_Tests/Assets/ReferenceImages/Linear/OSXEditor/Metal/None/1302_StackLitSG_PixarLM.png +++ b/TestProjects/HDRP_Tests/Assets/ReferenceImages/Linear/OSXEditor/Metal/None/1302_StackLitSG_PixarLM.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:d9ac0db404cae70b6a83ccdd54f5744a50bbb17294538a44ed1467f6368c69a8 -size 212028 +oid sha256:1aa3a521dae784030a87e20cf347958162e24393d3fd2c85aab197f154e6fe7b +size 212504 diff --git a/TestProjects/HDRP_Tests/Assets/ReferenceImages/Linear/OSXEditor/Metal/None/2551_SSR.png b/TestProjects/HDRP_Tests/Assets/ReferenceImages/Linear/OSXEditor/Metal/None/2551_SSR.png index 6a5146f3c7e..772302cc72d 100644 --- a/TestProjects/HDRP_Tests/Assets/ReferenceImages/Linear/OSXEditor/Metal/None/2551_SSR.png +++ b/TestProjects/HDRP_Tests/Assets/ReferenceImages/Linear/OSXEditor/Metal/None/2551_SSR.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:6e9ffbdaca14b58876d46568ffcdd2e723acdb6bf3008bc652cefd85ef10fce1 -size 142882 +oid sha256:93a55dee752a0bb596c16d6dc6dc59b8f7691622a402dfcac6f477b08c4fc4dc +size 143768 diff --git a/TestProjects/HDRP_Tests/Assets/ReferenceImages/Linear/WindowsEditor/Direct3D11/None/1302_StackLitSG_PixarLM.png b/TestProjects/HDRP_Tests/Assets/ReferenceImages/Linear/WindowsEditor/Direct3D11/None/1302_StackLitSG_PixarLM.png index 4af65a030f5..cdd2c338f3f 100644 --- a/TestProjects/HDRP_Tests/Assets/ReferenceImages/Linear/WindowsEditor/Direct3D11/None/1302_StackLitSG_PixarLM.png +++ b/TestProjects/HDRP_Tests/Assets/ReferenceImages/Linear/WindowsEditor/Direct3D11/None/1302_StackLitSG_PixarLM.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:c024ddcf69509e7b895df1a640c57f4baee061c7814ba600f63408a7c8fa3ac0 -size 211399 +oid sha256:b08295918695965b6797de45177d16c02c5c955421b760094cc1380a3fc691d5 +size 211165 diff --git a/TestProjects/HDRP_Tests/Assets/ReferenceImages/Linear/WindowsEditor/Direct3D11/None/2551_SSR.png b/TestProjects/HDRP_Tests/Assets/ReferenceImages/Linear/WindowsEditor/Direct3D11/None/2551_SSR.png index 2c60f1ff108..9f3aeb7ebb1 100644 --- a/TestProjects/HDRP_Tests/Assets/ReferenceImages/Linear/WindowsEditor/Direct3D11/None/2551_SSR.png +++ b/TestProjects/HDRP_Tests/Assets/ReferenceImages/Linear/WindowsEditor/Direct3D11/None/2551_SSR.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:56c9383462eb4be6e6f5daeb5beb71ccac10086c01e6697d3e5847f411c342fa -size 146961 +oid sha256:efe6a76322ab84ce22ab15abe9a8b17470451f6322682e826dddf6df5cf73bda +size 147625 diff --git a/TestProjects/HDRP_Tests/Assets/ReferenceImages/Linear/WindowsEditor/Direct3D12/None/1302_StackLitSG_PixarLM.png b/TestProjects/HDRP_Tests/Assets/ReferenceImages/Linear/WindowsEditor/Direct3D12/None/1302_StackLitSG_PixarLM.png index c18a8f35c13..36ad7cd5fea 100644 --- a/TestProjects/HDRP_Tests/Assets/ReferenceImages/Linear/WindowsEditor/Direct3D12/None/1302_StackLitSG_PixarLM.png +++ b/TestProjects/HDRP_Tests/Assets/ReferenceImages/Linear/WindowsEditor/Direct3D12/None/1302_StackLitSG_PixarLM.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:94bd417f722ad25d9e00466ecab5c6a94651d4cc4e6fb82d05135bd34a85d949 -size 211597 +oid sha256:3fdc820d09792c28e33d2c5698ef77ea19e91eb89786f5304b0ff23a905583a6 +size 211311 diff --git a/TestProjects/HDRP_Tests/Assets/ReferenceImages/Linear/WindowsEditor/Direct3D12/None/2551_SSR.png b/TestProjects/HDRP_Tests/Assets/ReferenceImages/Linear/WindowsEditor/Direct3D12/None/2551_SSR.png index 97b7ca35706..1eaad192e15 100644 --- a/TestProjects/HDRP_Tests/Assets/ReferenceImages/Linear/WindowsEditor/Direct3D12/None/2551_SSR.png +++ b/TestProjects/HDRP_Tests/Assets/ReferenceImages/Linear/WindowsEditor/Direct3D12/None/2551_SSR.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:b822a08740ddc63dc8dab665b4b5226af66e456e33ad4b45940cc66bbdc9cbd2 -size 146874 +oid sha256:79d6d18d8453b554b4af1a665236a66df28ded3c105b44fb9cab1a1ed5179d18 +size 147515 diff --git a/TestProjects/HDRP_Tests/Assets/ReferenceImages/Linear/WindowsEditor/Vulkan/None/1302_StackLitSG_PixarLM.png b/TestProjects/HDRP_Tests/Assets/ReferenceImages/Linear/WindowsEditor/Vulkan/None/1302_StackLitSG_PixarLM.png index 353e025eba5..9f13563b662 100644 --- a/TestProjects/HDRP_Tests/Assets/ReferenceImages/Linear/WindowsEditor/Vulkan/None/1302_StackLitSG_PixarLM.png +++ b/TestProjects/HDRP_Tests/Assets/ReferenceImages/Linear/WindowsEditor/Vulkan/None/1302_StackLitSG_PixarLM.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:ea9c0b66eda079dde8aa3256fdacf1cf8006f560d01533721f395032c52ab342 -size 207569 +oid sha256:01fcf917577d5f34b672674f5f408229d462bf6bb16b668a0ad9c528316fed43 +size 207417 diff --git a/TestProjects/HDRP_Tests/Assets/ReferenceImages/Linear/WindowsEditor/Vulkan/None/2551_SSR.png b/TestProjects/HDRP_Tests/Assets/ReferenceImages/Linear/WindowsEditor/Vulkan/None/2551_SSR.png index 11cbddaf040..660e27b4426 100644 --- a/TestProjects/HDRP_Tests/Assets/ReferenceImages/Linear/WindowsEditor/Vulkan/None/2551_SSR.png +++ b/TestProjects/HDRP_Tests/Assets/ReferenceImages/Linear/WindowsEditor/Vulkan/None/2551_SSR.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:1b0519cef96a71ddeb7adfe891a9ebab7c9ec6777ec9c6b582755a969b821cfa -size 147890 +oid sha256:21159c1f1e9ac49b8a6472a412e41989bff1e96dfa3f0b9e5f211da54fa9987d +size 148634