From 1f7270f889ee0859d5257a3606c604073aa0cdb9 Mon Sep 17 00:00:00 2001 From: Adrien de Tocqueville Date: Tue, 27 Jul 2021 16:02:24 +0200 Subject: [PATCH 1/7] Add two methods for specular occlusion based on spherical gaussians --- .../ShaderLibrary/CommonLighting.hlsl | 69 ++++++++++++++++++- .../Editor/Material/Lit/LitGUI.cs | 2 + .../Runtime/Material/Lit/Lit.shader | 4 +- .../Runtime/Material/Lit/LitData.hlsl | 15 ++-- .../Runtime/Material/Lit/LitProperties.hlsl | 2 + 5 files changed, 81 insertions(+), 11 deletions(-) diff --git a/com.unity.render-pipelines.core/ShaderLibrary/CommonLighting.hlsl b/com.unity.render-pipelines.core/ShaderLibrary/CommonLighting.hlsl index 05617ac44f4..e571d96b324 100644 --- a/com.unity.render-pipelines.core/ShaderLibrary/CommonLighting.hlsl +++ b/com.unity.render-pipelines.core/ShaderLibrary/CommonLighting.hlsl @@ -245,7 +245,7 @@ real3 GTAOMultiBounce(real visibility, real3 albedo) return max(x, ((x * a + b) * x + c) * x); } -// Based on Oat and Sander's 2008 technique +// Based on Oat and Sander's 2007 technique // Area/solidAngle of intersection of two cone real SphericalCapIntersectionSolidArea(real cosC1, real cosC2, real cosB) { @@ -290,6 +290,73 @@ real GetSpecularOcclusionFromBentAO(real3 V, real3 bentNormalWS, real3 normalWS, return SphericalCapIntersectionSolidArea(cosAv, cosAs, cosB) / (TWO_PI * (1.0 - cosAs)); } +float Square(float x) +{ + return x * x; +} + +real GetSpecularOcclusionFromBentAO_ASG(real3 V, real3 bentNormalWS, real3 normalWS, real ambientOcclusion, real roughness) +{ + //AnisotropicSphericalGaussian NDF = WarpedGGXDistributionASG(normalWS, roughness, V); + //SphericalGaussian Visibility = VisibilityConeSG(bentNormalWS, ambientOcclusion); + //SphericalGaussian UpperHemisphere = UpperHemisphereSG(normalWS); + //return saturate( InnerProduct(NDF, Visibility) / InnerProduct(NDF, UpperHemisphere) ); + + // Approximation of the operation above: + + // 1. Approximate visibility cone with a spherical gaussian of amplitude A=1 + // For a cone angle X, we can determine sharpness so that all point inside the cone have a value > Y + // sharpness = (log(Y) - log(A)) / (cos(X) - 1) + // For AO cone, cos(X) = sqrt(1 - ambientOcclusion) + // -> for Y = 0.1, sharpness = -1.0 / (sqrt(1-ao) - 1) + + const float nu1 = -0.5f / (sqrt(1.0f - ambientOcclusion) - 1.0f); + + // 2. Approximate upper hemisphere with sharpness = 0.8 and amplitude = 1 + const float nu2 = 0.5f * 0.8f; + + // 3. Compute warped Anisotropic SG of GGX distribution + // Ref: http://cg.cs.tsinghua.edu.cn/people/~kun/asg/paper_asg.pdf + // https://therealmjp.github.io/posts/sg-series-part-4-specular-lighting-from-an-sg-light-source/#going-anisotropic + // use same sharpness for X and Y because it simplifies a lot and it doesn't change much + float NoV = dot(V, normalWS); + float3 R = 2 * NoV * normalWS - V; + float NDFSharpnessInv = 4.0f * roughness * roughness * NoV; + float3 NDFAxisX = cross(V, normalWS); + float3 NDFAxisY = cross(R, NDFAxisX); + + //float amplitude = sqrt( ((nu1 + NDF.SharpnessX) * (nu1 + NDF.SharpnessY)) / ((nu2 + NDF.SharpnessX) * (nu2 + NDF.SharpnessY)) ); + float amplitude = nu1 * NDFSharpnessInv + 1; // Assuming sharpnessX == sharpnessY and nu2 << sharpness + float sharpness = nu1 / max(amplitude, 0.001f); // == (nu1 * NDF.SharpnessX) / (nu1 + NDF.SharpnessX); + + // Ignore L2 cause it's mostly 0 + float NDFAxisYNorm = 1.0f / dot(NDFAxisY, NDFAxisY); + float u1 = Square(dot(NDFAxisY, bentNormalWS)) * NDFAxisYNorm; + float u2 = Square(dot(NDFAxisY, normalWS)) * NDFAxisYNorm; + float L1 = Square(dot(NDFAxisX, bentNormalWS)) / dot(NDFAxisX, NDFAxisX); + float expFactor = exp(nu2 * u2 - sharpness * (L1 + u1)); + + // put expFactor 2 times because it looks nicer + return saturate(amplitude * expFactor * expFactor); +} + +real GetSpecularOcclusionFromBentAO_SG(real3 V, real3 bentNormalWS, real3 normalWS, real ambientOcclusion, real roughness) +{ + // Same as GetSpecularOcclusionFromBentAO_ASG but with non anisotropic SG for GGX + float us = 0.81f; + float vs = 1.0f / (sqrt(1.0f - ambientOcclusion) - 1.0f); + float3 NDFAxis = reflect(-V, normalWS) * (0.5f / max(roughness * roughness * dot(normalWS, V), 0.001)); + + float umLength1 = length(NDFAxis - vs * bentNormalWS); + float umLength2 = length(NDFAxis + us * normalWS); + float d1 = 1 - exp(-2 * umLength1); + float d2 = 1 - exp(-2 * umLength2); + + float expFactor1 = exp(umLength1 - umLength2 + us + vs); + + return saturate(expFactor1 * (d1 * umLength2) / (d2 * umLength1)); +} + // Ref: Steve McAuley - Energy-Conserving Wrapped Diffuse real ComputeWrappedDiffuseLighting(real NdotL, real w) { diff --git a/com.unity.render-pipelines.high-definition/Editor/Material/Lit/LitGUI.cs b/com.unity.render-pipelines.high-definition/Editor/Material/Lit/LitGUI.cs index 83983ad1c2b..e448d5345cc 100644 --- a/com.unity.render-pipelines.high-definition/Editor/Material/Lit/LitGUI.cs +++ b/com.unity.render-pipelines.high-definition/Editor/Material/Lit/LitGUI.cs @@ -130,6 +130,8 @@ static public void SetupLitKeywordsAndPass(Material material) int specOcclusionMode = material.GetInt(kSpecularOcclusionMode); CoreUtils.SetKeyword(material, "_SPECULAR_OCCLUSION_NONE", specOcclusionMode == 0); CoreUtils.SetKeyword(material, "_SPECULAR_OCCLUSION_FROM_BENT_NORMAL_MAP", specOcclusionMode == 2); + CoreUtils.SetKeyword(material, "_SPECULAR_OCCLUSION_FROM_BENT_NORMAL_MAP_SG", specOcclusionMode == 3); + CoreUtils.SetKeyword(material, "_SPECULAR_OCCLUSION_FROM_BENT_NORMAL_MAP_ASG", specOcclusionMode == 4); } if (material.HasProperty(kHeightMap)) CoreUtils.SetKeyword(material, "_HEIGHTMAP", material.GetTexture(kHeightMap)); diff --git a/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/Lit.shader b/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/Lit.shader index 7d72c2a71dc..615c393908e 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/Lit.shader +++ b/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/Lit.shader @@ -77,7 +77,7 @@ Shader "HDRP/Lit" // Following options are for the GUI inspector and different from the input parameters above // These option below will cause different compilation flag. - [Enum(Off, 0, From Ambient Occlusion, 1, From Bent Normals, 2)] _SpecularOcclusionMode("Specular Occlusion Mode", Int) = 1 + [Enum(Off, 0, From Ambient Occlusion, 1, From Bent Normals, 2, From Spherical Gaussians, 3, From Anisotropic Spherical Gaussians, 4)] _SpecularOcclusionMode("Specular Occlusion Mode", Int) = 1 [HDR] _EmissiveColor("EmissiveColor", Color) = (0, 0, 0) // Used only to serialize the LDR and HDR emissive color in the material UI, @@ -257,7 +257,7 @@ Shader "HDRP/Lit" // _ENABLESPECULAROCCLUSION and _SPECULAR_OCCLUSION_X can't exist at the same time (the new _SPECULAR_OCCLUSION replace it) // When _ENABLESPECULAROCCLUSION is found we define _SPECULAR_OCCLUSION_X so new code to work #pragma shader_feature_local_fragment _ENABLESPECULAROCCLUSION - #pragma shader_feature_local_fragment _ _SPECULAR_OCCLUSION_NONE _SPECULAR_OCCLUSION_FROM_BENT_NORMAL_MAP + #pragma shader_feature_local_fragment _ _SPECULAR_OCCLUSION_NONE _SPECULAR_OCCLUSION_FROM_BENT_NORMAL_MAP _SPECULAR_OCCLUSION_FROM_BENT_NORMAL_MAP_SG _SPECULAR_OCCLUSION_FROM_BENT_NORMAL_MAP_ASG #pragma shader_feature_local_raytracing _ENABLESPECULAROCCLUSION #pragma shader_feature_local_raytracing _ _SPECULAR_OCCLUSION_NONE _SPECULAR_OCCLUSION_FROM_BENT_NORMAL_MAP diff --git a/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/LitData.hlsl b/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/LitData.hlsl index 31cef50350c..397b1f5ec7e 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/LitData.hlsl +++ b/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/LitData.hlsl @@ -17,9 +17,6 @@ #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/LitDecalData.hlsl" #endif -//#include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/SphericalCapPivot/SPTDistribution.hlsl" -//#define SPECULAR_OCCLUSION_USE_SPTD - //#define PROJECTED_SPACE_NDF_FILTERING // Struct that gather UVMapping info of all layers + common calculation @@ -284,13 +281,15 @@ void GetSurfaceAndBuiltinData(FragInputs input, float3 V, inout PositionInputs p // By default we use the ambient occlusion with Tri-ace trick (apply outside) for specular occlusion. // If user provide bent normal then we process a better term -#if defined(_BENTNORMALMAP) && defined(_SPECULAR_OCCLUSION_FROM_BENT_NORMAL_MAP) +#if defined(_BENTNORMALMAP) && (defined(_SPECULAR_OCCLUSION_FROM_BENT_NORMAL_MAP) || defined(_SPECULAR_OCCLUSION_FROM_BENT_NORMAL_MAP_SG) || defined(_SPECULAR_OCCLUSION_FROM_BENT_NORMAL_MAP_ASG)) // If we have bent normal and ambient occlusion, process a specular occlusion - #ifdef SPECULAR_OCCLUSION_USE_SPTD - surfaceData.specularOcclusion = GetSpecularOcclusionFromBentAOPivot(V, bentNormalWS, surfaceData.normalWS, surfaceData.ambientOcclusion, PerceptualSmoothnessToPerceptualRoughness(surfaceData.perceptualSmoothness)); - #else + #ifdef _SPECULAR_OCCLUSION_FROM_BENT_NORMAL_MAP surfaceData.specularOcclusion = GetSpecularOcclusionFromBentAO(V, bentNormalWS, surfaceData.normalWS, surfaceData.ambientOcclusion, PerceptualSmoothnessToRoughness(surfaceData.perceptualSmoothness)); -#endif + #elif defined(_SPECULAR_OCCLUSION_FROM_BENT_NORMAL_MAP_SG) + surfaceData.specularOcclusion = GetSpecularOcclusionFromBentAO_SG(V, bentNormalWS, surfaceData.normalWS, surfaceData.ambientOcclusion, PerceptualSmoothnessToRoughness(surfaceData.perceptualSmoothness)); + #elif defined(_SPECULAR_OCCLUSION_FROM_BENT_NORMAL_MAP_ASG) + surfaceData.specularOcclusion = GetSpecularOcclusionFromBentAO_ASG(V, bentNormalWS, surfaceData.normalWS, surfaceData.ambientOcclusion, PerceptualSmoothnessToRoughness(surfaceData.perceptualSmoothness)); + #endif // Don't do spec occ from Ambient if there is no mask mask #elif defined(_MASKMAP) && !defined(_SPECULAR_OCCLUSION_NONE) surfaceData.specularOcclusion = GetSpecularOcclusionFromAmbientOcclusion(ClampNdotV(dot(surfaceData.normalWS, V)), surfaceData.ambientOcclusion, PerceptualSmoothnessToRoughness(surfaceData.perceptualSmoothness)); diff --git a/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/LitProperties.hlsl b/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/LitProperties.hlsl index d20882376c4..9eed7799baf 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/LitProperties.hlsl +++ b/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/LitProperties.hlsl @@ -22,6 +22,8 @@ TEXTURE2D(_MaskMap); SAMPLER(sampler_MaskMap); TEXTURE2D(_BentNormalMap); // Reuse sampler from normal map SAMPLER(sampler_BentNormalMap); +TEXTURE2D(_BentNormalMapOS); +SAMPLER(sampler_BentNormalMapOS); TEXTURE2D(_NormalMap); SAMPLER(sampler_NormalMap); From 2bbce333412a5009401f4040bef21f8227bc384e Mon Sep 17 00:00:00 2001 From: Adrien de Tocqueville Date: Thu, 5 Aug 2021 20:35:54 +0200 Subject: [PATCH 2/7] Add to all lit shaders --- .../Runtime/Material/LayeredLit/LayeredLit.shader | 4 ++-- .../Runtime/Material/LayeredLit/LayeredLitTessellation.shader | 4 ++-- .../Runtime/Material/Lit/Lit.shader | 2 +- .../Runtime/Material/Lit/LitTessellation.shader | 4 ++-- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/com.unity.render-pipelines.high-definition/Runtime/Material/LayeredLit/LayeredLit.shader b/com.unity.render-pipelines.high-definition/Runtime/Material/LayeredLit/LayeredLit.shader index b54c1e7aa98..71f339499f8 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/Material/LayeredLit/LayeredLit.shader +++ b/com.unity.render-pipelines.high-definition/Runtime/Material/LayeredLit/LayeredLit.shader @@ -244,7 +244,7 @@ Shader "HDRP/LayeredLit" // Following are builtin properties - [Enum(Off, 0, From Ambient Occlusion, 1, From Bent Normals, 2)] _SpecularOcclusionMode("Specular Occlusion Mode", Int) = 1 + [Enum(Off, 0, From Ambient Occlusion, 1, From AO and Bent Normals, 2, From AO and Bent Normals (SG), 3, From AO and Bent Normals (ASG), 4)] _SpecularOcclusionMode("Specular Occlusion Mode", Int) = 1 [HDR] _EmissiveColor("EmissiveColor", Color) = (0, 0, 0) // Used only to serialize the LDR and HDR emissive color in the material UI, @@ -451,7 +451,7 @@ Shader "HDRP/LayeredLit" // _ENABLESPECULAROCCLUSION and _SPECULAR_OCCLUSION_X can't exist at the same time (the new _SPECULAR_OCCLUSION replace it) // When _ENABLESPECULAROCCLUSION is found we define _SPECULAR_OCCLUSION_X so new code to work #pragma shader_feature_fragment _ENABLESPECULAROCCLUSION // Non-local - #pragma shader_feature_fragment _ _SPECULAR_OCCLUSION_NONE _SPECULAR_OCCLUSION_FROM_BENT_NORMAL_MAP // Non-local + #pragma shader_feature_fragment _ _SPECULAR_OCCLUSION_NONE _SPECULAR_OCCLUSION_FROM_BENT_NORMAL_MAP _SPECULAR_OCCLUSION_FROM_BENT_NORMAL_MAP_SG _SPECULAR_OCCLUSION_FROM_BENT_NORMAL_MAP_ASG // Non-local #pragma shader_feature_raytracing _ENABLESPECULAROCCLUSION // Non-local #pragma shader_feature_raytracing _ SPECULAR_OCCLUSION_NONE _SPECULAR_OCCLUSION_FROM_BENT_NORMAL_MAP // Non-local diff --git a/com.unity.render-pipelines.high-definition/Runtime/Material/LayeredLit/LayeredLitTessellation.shader b/com.unity.render-pipelines.high-definition/Runtime/Material/LayeredLit/LayeredLitTessellation.shader index a9c9fa29f9b..4b2c8501a08 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/Material/LayeredLit/LayeredLitTessellation.shader +++ b/com.unity.render-pipelines.high-definition/Runtime/Material/LayeredLit/LayeredLitTessellation.shader @@ -244,7 +244,7 @@ Shader "HDRP/LayeredLitTessellation" // Following are builtin properties - [Enum(Off, 0, From Ambient Occlusion, 1, From Bent Normals, 2)] _SpecularOcclusionMode("Specular Occlusion Mode", Int) = 1 + [Enum(Off, 0, From Ambient Occlusion, 1, From AO and Bent Normals, 2, From AO and Bent Normals (SG), 3, From AO and Bent Normals (ASG), 4)] _SpecularOcclusionMode("Specular Occlusion Mode", Int) = 1 [HDR] _EmissiveColor("EmissiveColor", Color) = (0, 0, 0) // Used only to serialize the LDR and HDR emissive color in the material UI, @@ -461,7 +461,7 @@ Shader "HDRP/LayeredLitTessellation" // _ENABLESPECULAROCCLUSION and _SPECULAR_OCCLUSION_X can't exist at the same time (the new _SPECULAR_OCCLUSION replace it) // When _ENABLESPECULAROCCLUSION is found we define _SPECULAR_OCCLUSION_X so new code to work #pragma shader_feature _ENABLESPECULAROCCLUSION // Non-local - #pragma shader_feature _ _SPECULAR_OCCLUSION_NONE _SPECULAR_OCCLUSION_FROM_BENT_NORMAL_MAP // Non-local + #pragma shader_feature_fragment _ _SPECULAR_OCCLUSION_NONE _SPECULAR_OCCLUSION_FROM_BENT_NORMAL_MAP _SPECULAR_OCCLUSION_FROM_BENT_NORMAL_MAP_SG _SPECULAR_OCCLUSION_FROM_BENT_NORMAL_MAP_ASG // Non-local #ifdef _ENABLESPECULAROCCLUSION #define _SPECULAR_OCCLUSION_FROM_BENT_NORMAL_MAP #endif diff --git a/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/Lit.shader b/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/Lit.shader index 615c393908e..96a4800908a 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/Lit.shader +++ b/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/Lit.shader @@ -77,7 +77,7 @@ Shader "HDRP/Lit" // Following options are for the GUI inspector and different from the input parameters above // These option below will cause different compilation flag. - [Enum(Off, 0, From Ambient Occlusion, 1, From Bent Normals, 2, From Spherical Gaussians, 3, From Anisotropic Spherical Gaussians, 4)] _SpecularOcclusionMode("Specular Occlusion Mode", Int) = 1 + [Enum(Off, 0, From Ambient Occlusion, 1, From AO and Bent Normals, 2, From AO and Bent Normals (SG), 3, From AO and Bent Normals (ASG), 4)] _SpecularOcclusionMode("Specular Occlusion Mode", Int) = 1 [HDR] _EmissiveColor("EmissiveColor", Color) = (0, 0, 0) // Used only to serialize the LDR and HDR emissive color in the material UI, diff --git a/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/LitTessellation.shader b/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/LitTessellation.shader index 3da0a6e2762..cc3eaed5586 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/LitTessellation.shader +++ b/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/LitTessellation.shader @@ -77,7 +77,7 @@ Shader "HDRP/LitTessellation" // Following options are for the GUI inspector and different from the input parameters above // These option below will cause different compilation flag. - [Enum(Off, 0, From Ambient Occlusion, 1, From Bent Normals, 2)] _SpecularOcclusionMode("Specular Occlusion Mode", Int) = 1 + [Enum(Off, 0, From Ambient Occlusion, 1, From AO and Bent Normals, 2, From AO and Bent Normals (SG), 3, From AO and Bent Normals (ASG), 4)] _SpecularOcclusionMode("Specular Occlusion Mode", Int) = 1 [HDR] _EmissiveColor("EmissiveColor", Color) = (0, 0, 0) // Used only to serialize the LDR and HDR emissive color in the material UI, @@ -268,7 +268,7 @@ Shader "HDRP/LitTessellation" // _ENABLESPECULAROCCLUSION and _SPECULAR_OCCLUSION_X can't exist at the same time (the new _SPECULAR_OCCLUSION replace it) // When _ENABLESPECULAROCCLUSION is found we define _SPECULAR_OCCLUSION_X so new code to work #pragma shader_feature_local_fragment _ENABLESPECULAROCCLUSION - #pragma shader_feature_local_fragment _ _SPECULAR_OCCLUSION_NONE _SPECULAR_OCCLUSION_FROM_BENT_NORMAL_MAP + #pragma shader_feature_local_fragment _ _SPECULAR_OCCLUSION_NONE _SPECULAR_OCCLUSION_FROM_BENT_NORMAL_MAP _SPECULAR_OCCLUSION_FROM_BENT_NORMAL_MAP_SG _SPECULAR_OCCLUSION_FROM_BENT_NORMAL_MAP_ASG #pragma shader_feature_local_raytracing _ENABLESPECULAROCCLUSION #pragma shader_feature_local_raytracing _ _SPECULAR_OCCLUSION_NONE _SPECULAR_OCCLUSION_FROM_BENT_NORMAL_MAP From c42c4e32b3bbe3906046f9d0cdc1ac25314c1d0d Mon Sep 17 00:00:00 2001 From: Adrien de Tocqueville Date: Tue, 31 Aug 2021 18:09:02 +0200 Subject: [PATCH 3/7] Set SG version as default --- .../ShaderLibrary/CommonLighting.hlsl | 54 ++++--------------- .../CHANGELOG.md | 1 + .../Editor/Material/Lit/LitGUI.cs | 2 - .../ShaderGraph/TargetData/LightingData.cs | 2 +- .../Material/LayeredLit/LayeredLit.shader | 6 +-- .../LayeredLit/LayeredLitTessellation.shader | 4 +- .../Runtime/Material/Lit/Lit.shader | 4 +- .../Runtime/Material/Lit/LitData.hlsl | 8 +-- .../Material/Lit/LitTessellation.shader | 4 +- 9 files changed, 23 insertions(+), 62 deletions(-) diff --git a/com.unity.render-pipelines.core/ShaderLibrary/CommonLighting.hlsl b/com.unity.render-pipelines.core/ShaderLibrary/CommonLighting.hlsl index e571d96b324..504ff0e1fc3 100644 --- a/com.unity.render-pipelines.core/ShaderLibrary/CommonLighting.hlsl +++ b/com.unity.render-pipelines.core/ShaderLibrary/CommonLighting.hlsl @@ -279,7 +279,7 @@ real SphericalCapIntersectionSolidArea(real cosC1, real cosC2, real cosB) // ref: Practical Realtime Strategies for Accurate Indirect Occlusion // http://blog.selfshadow.com/publications/s2016-shading-course/#course_content // Original Cone-Cone method with cosine weighted assumption (p129 s2016_pbs_activision_occlusion) -real GetSpecularOcclusionFromBentAO(real3 V, real3 bentNormalWS, real3 normalWS, real ambientOcclusion, real roughness) +real GetSpecularOcclusionFromBentAO_ConeCone(real3 V, real3 bentNormalWS, real3 normalWS, real ambientOcclusion, real roughness) { // Retrieve cone angle // Ambient occlusion is cosine weighted, thus use following equation. See slide 129 @@ -290,14 +290,9 @@ real GetSpecularOcclusionFromBentAO(real3 V, real3 bentNormalWS, real3 normalWS, return SphericalCapIntersectionSolidArea(cosAv, cosAs, cosB) / (TWO_PI * (1.0 - cosAs)); } -float Square(float x) -{ - return x * x; -} - -real GetSpecularOcclusionFromBentAO_ASG(real3 V, real3 bentNormalWS, real3 normalWS, real ambientOcclusion, real roughness) +real GetSpecularOcclusionFromBentAO(real3 V, real3 bentNormalWS, real3 normalWS, real ambientOcclusion, real roughness) { - //AnisotropicSphericalGaussian NDF = WarpedGGXDistributionASG(normalWS, roughness, V); + //SphericalGaussian NDF = WarpedGGXDistribution(normalWS, roughness, V); //SphericalGaussian Visibility = VisibilityConeSG(bentNormalWS, ambientOcclusion); //SphericalGaussian UpperHemisphere = UpperHemisphereSG(normalWS); //return saturate( InnerProduct(NDF, Visibility) / InnerProduct(NDF, UpperHemisphere) ); @@ -309,50 +304,23 @@ real GetSpecularOcclusionFromBentAO_ASG(real3 V, real3 bentNormalWS, real3 norma // sharpness = (log(Y) - log(A)) / (cos(X) - 1) // For AO cone, cos(X) = sqrt(1 - ambientOcclusion) // -> for Y = 0.1, sharpness = -1.0 / (sqrt(1-ao) - 1) - - const float nu1 = -0.5f / (sqrt(1.0f - ambientOcclusion) - 1.0f); + float vs = -1.0f / (sqrt(1.0f - ambientOcclusion) - 1.0f); // 2. Approximate upper hemisphere with sharpness = 0.8 and amplitude = 1 - const float nu2 = 0.5f * 0.8f; + float us = 0.8f; - // 3. Compute warped Anisotropic SG of GGX distribution - // Ref: http://cg.cs.tsinghua.edu.cn/people/~kun/asg/paper_asg.pdf - // https://therealmjp.github.io/posts/sg-series-part-4-specular-lighting-from-an-sg-light-source/#going-anisotropic - // use same sharpness for X and Y because it simplifies a lot and it doesn't change much + // 3. Compute warped SG Axis of GGX distribution + // Ref: All-Frequency Rendering of Dynamic, Spatially-Varying Reflectance + // https://www.microsoft.com/en-us/research/wp-content/uploads/2009/12/sg.pdf float NoV = dot(V, normalWS); - float3 R = 2 * NoV * normalWS - V; - float NDFSharpnessInv = 4.0f * roughness * roughness * NoV; - float3 NDFAxisX = cross(V, normalWS); - float3 NDFAxisY = cross(R, NDFAxisX); - - //float amplitude = sqrt( ((nu1 + NDF.SharpnessX) * (nu1 + NDF.SharpnessY)) / ((nu2 + NDF.SharpnessX) * (nu2 + NDF.SharpnessY)) ); - float amplitude = nu1 * NDFSharpnessInv + 1; // Assuming sharpnessX == sharpnessY and nu2 << sharpness - float sharpness = nu1 / max(amplitude, 0.001f); // == (nu1 * NDF.SharpnessX) / (nu1 + NDF.SharpnessX); - - // Ignore L2 cause it's mostly 0 - float NDFAxisYNorm = 1.0f / dot(NDFAxisY, NDFAxisY); - float u1 = Square(dot(NDFAxisY, bentNormalWS)) * NDFAxisYNorm; - float u2 = Square(dot(NDFAxisY, normalWS)) * NDFAxisYNorm; - float L1 = Square(dot(NDFAxisX, bentNormalWS)) / dot(NDFAxisX, NDFAxisX); - float expFactor = exp(nu2 * u2 - sharpness * (L1 + u1)); - - // put expFactor 2 times because it looks nicer - return saturate(amplitude * expFactor * expFactor); -} - -real GetSpecularOcclusionFromBentAO_SG(real3 V, real3 bentNormalWS, real3 normalWS, real ambientOcclusion, real roughness) -{ - // Same as GetSpecularOcclusionFromBentAO_ASG but with non anisotropic SG for GGX - float us = 0.81f; - float vs = 1.0f / (sqrt(1.0f - ambientOcclusion) - 1.0f); - float3 NDFAxis = reflect(-V, normalWS) * (0.5f / max(roughness * roughness * dot(normalWS, V), 0.001)); + float3 NDFAxis = (2 * NoV * normalWS - V) * (0.5f / max(roughness * roughness * NoV, 0.001f)); - float umLength1 = length(NDFAxis - vs * bentNormalWS); + float umLength1 = length(NDFAxis + vs * bentNormalWS); float umLength2 = length(NDFAxis + us * normalWS); float d1 = 1 - exp(-2 * umLength1); float d2 = 1 - exp(-2 * umLength2); - float expFactor1 = exp(umLength1 - umLength2 + us + vs); + float expFactor1 = exp(umLength1 - umLength2 + us - vs); return saturate(expFactor1 * (d1 * umLength2) / (d2 * umLength1)); } diff --git a/com.unity.render-pipelines.high-definition/CHANGELOG.md b/com.unity.render-pipelines.high-definition/CHANGELOG.md index 2971190cdb1..d2ced209e23 100644 --- a/com.unity.render-pipelines.high-definition/CHANGELOG.md +++ b/com.unity.render-pipelines.high-definition/CHANGELOG.md @@ -378,6 +378,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. - Fixed case where the SceneView don't refresh when using LightExplorer with a running and Paused game (1354129) - Fixed wrong ordering in FrameSettings (Normalize Reflection Probes) - Allow negative wind speed parameter. +- Fixed specular occlusion sharpness and over darkening at grazing angles. ### Changed - Changed Window/Render Pipeline/HD Render Pipeline Wizard to Window/Rendering/HDRP Wizard diff --git a/com.unity.render-pipelines.high-definition/Editor/Material/Lit/LitGUI.cs b/com.unity.render-pipelines.high-definition/Editor/Material/Lit/LitGUI.cs index e448d5345cc..83983ad1c2b 100644 --- a/com.unity.render-pipelines.high-definition/Editor/Material/Lit/LitGUI.cs +++ b/com.unity.render-pipelines.high-definition/Editor/Material/Lit/LitGUI.cs @@ -130,8 +130,6 @@ static public void SetupLitKeywordsAndPass(Material material) int specOcclusionMode = material.GetInt(kSpecularOcclusionMode); CoreUtils.SetKeyword(material, "_SPECULAR_OCCLUSION_NONE", specOcclusionMode == 0); CoreUtils.SetKeyword(material, "_SPECULAR_OCCLUSION_FROM_BENT_NORMAL_MAP", specOcclusionMode == 2); - CoreUtils.SetKeyword(material, "_SPECULAR_OCCLUSION_FROM_BENT_NORMAL_MAP_SG", specOcclusionMode == 3); - CoreUtils.SetKeyword(material, "_SPECULAR_OCCLUSION_FROM_BENT_NORMAL_MAP_ASG", specOcclusionMode == 4); } if (material.HasProperty(kHeightMap)) CoreUtils.SetKeyword(material, "_HEIGHTMAP", material.GetTexture(kHeightMap)); diff --git a/com.unity.render-pipelines.high-definition/Editor/Material/ShaderGraph/TargetData/LightingData.cs b/com.unity.render-pipelines.high-definition/Editor/Material/ShaderGraph/TargetData/LightingData.cs index cd4b56e5a72..0a3878e4caf 100644 --- a/com.unity.render-pipelines.high-definition/Editor/Material/ShaderGraph/TargetData/LightingData.cs +++ b/com.unity.render-pipelines.high-definition/Editor/Material/ShaderGraph/TargetData/LightingData.cs @@ -74,7 +74,7 @@ public bool specularAA // } [SerializeField] - SpecularOcclusionMode m_SpecularOcclusionMode; + SpecularOcclusionMode m_SpecularOcclusionMode = SpecularOcclusionMode.FromAO; public SpecularOcclusionMode specularOcclusionMode { get => m_SpecularOcclusionMode; diff --git a/com.unity.render-pipelines.high-definition/Runtime/Material/LayeredLit/LayeredLit.shader b/com.unity.render-pipelines.high-definition/Runtime/Material/LayeredLit/LayeredLit.shader index 6ae2f8463e2..a28294fda2b 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/Material/LayeredLit/LayeredLit.shader +++ b/com.unity.render-pipelines.high-definition/Runtime/Material/LayeredLit/LayeredLit.shader @@ -244,7 +244,7 @@ Shader "HDRP/LayeredLit" // Following are builtin properties - [Enum(Off, 0, From Ambient Occlusion, 1, From AO and Bent Normals, 2, From AO and Bent Normals (SG), 3, From AO and Bent Normals (ASG), 4)] _SpecularOcclusionMode("Specular Occlusion Mode", Int) = 1 + [Enum(Off, 0, From Ambient Occlusion, 1, From AO and Bent Normals, 2)] _SpecularOcclusionMode("Specular Occlusion Mode", Int) = 1 [HDR] _EmissiveColor("EmissiveColor", Color) = (0, 0, 0) // Used only to serialize the LDR and HDR emissive color in the material UI, @@ -451,9 +451,9 @@ Shader "HDRP/LayeredLit" // _ENABLESPECULAROCCLUSION and _SPECULAR_OCCLUSION_X can't exist at the same time (the new _SPECULAR_OCCLUSION replace it) // When _ENABLESPECULAROCCLUSION is found we define _SPECULAR_OCCLUSION_X so new code to work #pragma shader_feature_fragment _ENABLESPECULAROCCLUSION // Non-local - #pragma shader_feature_fragment _ _SPECULAR_OCCLUSION_NONE _SPECULAR_OCCLUSION_FROM_BENT_NORMAL_MAP _SPECULAR_OCCLUSION_FROM_BENT_NORMAL_MAP_SG _SPECULAR_OCCLUSION_FROM_BENT_NORMAL_MAP_ASG // Non-local + #pragma shader_feature_fragment _ _SPECULAR_OCCLUSION_NONE _SPECULAR_OCCLUSION_FROM_BENT_NORMAL_MAP // Non-local #pragma shader_feature_raytracing _ENABLESPECULAROCCLUSION // Non-local - #pragma shader_feature_raytracing _ SPECULAR_OCCLUSION_NONE _SPECULAR_OCCLUSION_FROM_BENT_NORMAL_MAP // Non-local + #pragma shader_feature_raytracing _ _SPECULAR_OCCLUSION_NONE _SPECULAR_OCCLUSION_FROM_BENT_NORMAL_MAP // Non-local #ifdef _ENABLESPECULAROCCLUSION #define _SPECULAR_OCCLUSION_FROM_BENT_NORMAL_MAP diff --git a/com.unity.render-pipelines.high-definition/Runtime/Material/LayeredLit/LayeredLitTessellation.shader b/com.unity.render-pipelines.high-definition/Runtime/Material/LayeredLit/LayeredLitTessellation.shader index f936751854a..d79b23c3be1 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/Material/LayeredLit/LayeredLitTessellation.shader +++ b/com.unity.render-pipelines.high-definition/Runtime/Material/LayeredLit/LayeredLitTessellation.shader @@ -244,7 +244,7 @@ Shader "HDRP/LayeredLitTessellation" // Following are builtin properties - [Enum(Off, 0, From Ambient Occlusion, 1, From AO and Bent Normals, 2, From AO and Bent Normals (SG), 3, From AO and Bent Normals (ASG), 4)] _SpecularOcclusionMode("Specular Occlusion Mode", Int) = 1 + [Enum(Off, 0, From Ambient Occlusion, 1, From AO and Bent Normals, 2)] _SpecularOcclusionMode("Specular Occlusion Mode", Int) = 1 [HDR] _EmissiveColor("EmissiveColor", Color) = (0, 0, 0) // Used only to serialize the LDR and HDR emissive color in the material UI, @@ -461,7 +461,7 @@ Shader "HDRP/LayeredLitTessellation" // _ENABLESPECULAROCCLUSION and _SPECULAR_OCCLUSION_X can't exist at the same time (the new _SPECULAR_OCCLUSION replace it) // When _ENABLESPECULAROCCLUSION is found we define _SPECULAR_OCCLUSION_X so new code to work #pragma shader_feature _ENABLESPECULAROCCLUSION // Non-local - #pragma shader_feature_fragment _ _SPECULAR_OCCLUSION_NONE _SPECULAR_OCCLUSION_FROM_BENT_NORMAL_MAP _SPECULAR_OCCLUSION_FROM_BENT_NORMAL_MAP_SG _SPECULAR_OCCLUSION_FROM_BENT_NORMAL_MAP_ASG // Non-local + #pragma shader_feature _ _SPECULAR_OCCLUSION_NONE _SPECULAR_OCCLUSION_FROM_BENT_NORMAL_MAP // Non-local #ifdef _ENABLESPECULAROCCLUSION #define _SPECULAR_OCCLUSION_FROM_BENT_NORMAL_MAP #endif diff --git a/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/Lit.shader b/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/Lit.shader index 82f7fc719ea..5501967ffcf 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/Lit.shader +++ b/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/Lit.shader @@ -77,7 +77,7 @@ Shader "HDRP/Lit" // Following options are for the GUI inspector and different from the input parameters above // These option below will cause different compilation flag. - [Enum(Off, 0, From Ambient Occlusion, 1, From AO and Bent Normals, 2, From AO and Bent Normals (SG), 3, From AO and Bent Normals (ASG), 4)] _SpecularOcclusionMode("Specular Occlusion Mode", Int) = 1 + [Enum(Off, 0, From Ambient Occlusion, 1, From AO and Bent Normals, 2)] _SpecularOcclusionMode("Specular Occlusion Mode", Int) = 1 [HDR] _EmissiveColor("EmissiveColor", Color) = (0, 0, 0) // Used only to serialize the LDR and HDR emissive color in the material UI, @@ -257,7 +257,7 @@ Shader "HDRP/Lit" // _ENABLESPECULAROCCLUSION and _SPECULAR_OCCLUSION_X can't exist at the same time (the new _SPECULAR_OCCLUSION replace it) // When _ENABLESPECULAROCCLUSION is found we define _SPECULAR_OCCLUSION_X so new code to work #pragma shader_feature_local_fragment _ENABLESPECULAROCCLUSION - #pragma shader_feature_local_fragment _ _SPECULAR_OCCLUSION_NONE _SPECULAR_OCCLUSION_FROM_BENT_NORMAL_MAP _SPECULAR_OCCLUSION_FROM_BENT_NORMAL_MAP_SG _SPECULAR_OCCLUSION_FROM_BENT_NORMAL_MAP_ASG + #pragma shader_feature_local_fragment _ _SPECULAR_OCCLUSION_NONE _SPECULAR_OCCLUSION_FROM_BENT_NORMAL_MAP #pragma shader_feature_local_raytracing _ENABLESPECULAROCCLUSION #pragma shader_feature_local_raytracing _ _SPECULAR_OCCLUSION_NONE _SPECULAR_OCCLUSION_FROM_BENT_NORMAL_MAP diff --git a/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/LitData.hlsl b/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/LitData.hlsl index 397b1f5ec7e..729fa81e0b2 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/LitData.hlsl +++ b/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/LitData.hlsl @@ -281,15 +281,9 @@ void GetSurfaceAndBuiltinData(FragInputs input, float3 V, inout PositionInputs p // By default we use the ambient occlusion with Tri-ace trick (apply outside) for specular occlusion. // If user provide bent normal then we process a better term -#if defined(_BENTNORMALMAP) && (defined(_SPECULAR_OCCLUSION_FROM_BENT_NORMAL_MAP) || defined(_SPECULAR_OCCLUSION_FROM_BENT_NORMAL_MAP_SG) || defined(_SPECULAR_OCCLUSION_FROM_BENT_NORMAL_MAP_ASG)) +#if defined(_BENTNORMALMAP) && defined(_SPECULAR_OCCLUSION_FROM_BENT_NORMAL_MAP) // If we have bent normal and ambient occlusion, process a specular occlusion - #ifdef _SPECULAR_OCCLUSION_FROM_BENT_NORMAL_MAP surfaceData.specularOcclusion = GetSpecularOcclusionFromBentAO(V, bentNormalWS, surfaceData.normalWS, surfaceData.ambientOcclusion, PerceptualSmoothnessToRoughness(surfaceData.perceptualSmoothness)); - #elif defined(_SPECULAR_OCCLUSION_FROM_BENT_NORMAL_MAP_SG) - surfaceData.specularOcclusion = GetSpecularOcclusionFromBentAO_SG(V, bentNormalWS, surfaceData.normalWS, surfaceData.ambientOcclusion, PerceptualSmoothnessToRoughness(surfaceData.perceptualSmoothness)); - #elif defined(_SPECULAR_OCCLUSION_FROM_BENT_NORMAL_MAP_ASG) - surfaceData.specularOcclusion = GetSpecularOcclusionFromBentAO_ASG(V, bentNormalWS, surfaceData.normalWS, surfaceData.ambientOcclusion, PerceptualSmoothnessToRoughness(surfaceData.perceptualSmoothness)); - #endif // Don't do spec occ from Ambient if there is no mask mask #elif defined(_MASKMAP) && !defined(_SPECULAR_OCCLUSION_NONE) surfaceData.specularOcclusion = GetSpecularOcclusionFromAmbientOcclusion(ClampNdotV(dot(surfaceData.normalWS, V)), surfaceData.ambientOcclusion, PerceptualSmoothnessToRoughness(surfaceData.perceptualSmoothness)); diff --git a/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/LitTessellation.shader b/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/LitTessellation.shader index 4e2a5cf3ada..ce88d3f398f 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/LitTessellation.shader +++ b/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/LitTessellation.shader @@ -77,7 +77,7 @@ Shader "HDRP/LitTessellation" // Following options are for the GUI inspector and different from the input parameters above // These option below will cause different compilation flag. - [Enum(Off, 0, From Ambient Occlusion, 1, From AO and Bent Normals, 2, From AO and Bent Normals (SG), 3, From AO and Bent Normals (ASG), 4)] _SpecularOcclusionMode("Specular Occlusion Mode", Int) = 1 + [Enum(Off, 0, From Ambient Occlusion, 1, From AO and Bent Normals, 2)] _SpecularOcclusionMode("Specular Occlusion Mode", Int) = 1 [HDR] _EmissiveColor("EmissiveColor", Color) = (0, 0, 0) // Used only to serialize the LDR and HDR emissive color in the material UI, @@ -268,7 +268,7 @@ Shader "HDRP/LitTessellation" // _ENABLESPECULAROCCLUSION and _SPECULAR_OCCLUSION_X can't exist at the same time (the new _SPECULAR_OCCLUSION replace it) // When _ENABLESPECULAROCCLUSION is found we define _SPECULAR_OCCLUSION_X so new code to work #pragma shader_feature_local_fragment _ENABLESPECULAROCCLUSION - #pragma shader_feature_local_fragment _ _SPECULAR_OCCLUSION_NONE _SPECULAR_OCCLUSION_FROM_BENT_NORMAL_MAP _SPECULAR_OCCLUSION_FROM_BENT_NORMAL_MAP_SG _SPECULAR_OCCLUSION_FROM_BENT_NORMAL_MAP_ASG + #pragma shader_feature_local_fragment _ _SPECULAR_OCCLUSION_NONE _SPECULAR_OCCLUSION_FROM_BENT_NORMAL_MAP #pragma shader_feature_local_raytracing _ENABLESPECULAROCCLUSION #pragma shader_feature_local_raytracing _ _SPECULAR_OCCLUSION_NONE _SPECULAR_OCCLUSION_FROM_BENT_NORMAL_MAP From 4fe1bb77f5ba372c35fe759cbb7b638f39edc530 Mon Sep 17 00:00:00 2001 From: Adrien de Tocqueville Date: Wed, 1 Sep 2021 11:12:43 +0200 Subject: [PATCH 4/7] Update screenshots --- .../Linear/LinuxEditor/Vulkan/None/1210_Lit_BentNormal.png | 4 ++-- .../Linear/OSXEditor/Metal/None/1210_Lit_BentNormal.png | 4 ++-- .../WindowsEditor/Direct3D11/None/1210_Lit_BentNormal.png | 4 ++-- .../Linear/WindowsEditor/Vulkan/None/1210_Lit_BentNormal.png | 4 ++-- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/TestProjects/HDRP_Tests/Assets/ReferenceImages/Linear/LinuxEditor/Vulkan/None/1210_Lit_BentNormal.png b/TestProjects/HDRP_Tests/Assets/ReferenceImages/Linear/LinuxEditor/Vulkan/None/1210_Lit_BentNormal.png index 51d7c1faaa8..427e89e5b72 100644 --- a/TestProjects/HDRP_Tests/Assets/ReferenceImages/Linear/LinuxEditor/Vulkan/None/1210_Lit_BentNormal.png +++ b/TestProjects/HDRP_Tests/Assets/ReferenceImages/Linear/LinuxEditor/Vulkan/None/1210_Lit_BentNormal.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:bdaa894b3cd3a8a6ae48d3cfc20d2068920db6aefc00f40621149647cfc4a9ee -size 174564 +oid sha256:ef77d89a884c94e69c0981c576f7538b8305e69ac0e6d3e33a548207f38ac82c +size 153225 diff --git a/TestProjects/HDRP_Tests/Assets/ReferenceImages/Linear/OSXEditor/Metal/None/1210_Lit_BentNormal.png b/TestProjects/HDRP_Tests/Assets/ReferenceImages/Linear/OSXEditor/Metal/None/1210_Lit_BentNormal.png index a4789b62f38..d5c04b086da 100644 --- a/TestProjects/HDRP_Tests/Assets/ReferenceImages/Linear/OSXEditor/Metal/None/1210_Lit_BentNormal.png +++ b/TestProjects/HDRP_Tests/Assets/ReferenceImages/Linear/OSXEditor/Metal/None/1210_Lit_BentNormal.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:43d968134620179d1a0998174fe208aff8922959dad93d77538cdebb2fbc63db -size 152713 +oid sha256:2a277bafebf1d50f506144f0c18a4448dd3eca2215cf092ba1eb61ff61ee7aff +size 152947 diff --git a/TestProjects/HDRP_Tests/Assets/ReferenceImages/Linear/WindowsEditor/Direct3D11/None/1210_Lit_BentNormal.png b/TestProjects/HDRP_Tests/Assets/ReferenceImages/Linear/WindowsEditor/Direct3D11/None/1210_Lit_BentNormal.png index 0bd6dcb3171..0802ee6697b 100644 --- a/TestProjects/HDRP_Tests/Assets/ReferenceImages/Linear/WindowsEditor/Direct3D11/None/1210_Lit_BentNormal.png +++ b/TestProjects/HDRP_Tests/Assets/ReferenceImages/Linear/WindowsEditor/Direct3D11/None/1210_Lit_BentNormal.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:22a865a7db80ef101242ce4f23cf3d846ec542cac7422810ed7424a7351c7f7c -size 153072 +oid sha256:255b0c7bb1445a57659c17f3d7bcc4a05bd5970f19aadaa6c73b0da7e9e83096 +size 153148 diff --git a/TestProjects/HDRP_Tests/Assets/ReferenceImages/Linear/WindowsEditor/Vulkan/None/1210_Lit_BentNormal.png b/TestProjects/HDRP_Tests/Assets/ReferenceImages/Linear/WindowsEditor/Vulkan/None/1210_Lit_BentNormal.png index 8cb522aeaf4..427e89e5b72 100644 --- a/TestProjects/HDRP_Tests/Assets/ReferenceImages/Linear/WindowsEditor/Vulkan/None/1210_Lit_BentNormal.png +++ b/TestProjects/HDRP_Tests/Assets/ReferenceImages/Linear/WindowsEditor/Vulkan/None/1210_Lit_BentNormal.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:7deb071c27433c51b50c915065817b466252555d2e3b9428593eb2acf3183e55 -size 152903 +oid sha256:ef77d89a884c94e69c0981c576f7538b8305e69ac0e6d3e33a548207f38ac82c +size 153225 From 83b754678441dc98bcf3130688d29fcc7016a6a5 Mon Sep 17 00:00:00 2001 From: Adrien de Tocqueville Date: Thu, 2 Sep 2021 13:23:32 +0200 Subject: [PATCH 5/7] dx12 screenshot test --- .../WindowsEditor/Direct3D12/None/1210_Lit_BentNormal.png | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/TestProjects/HDRP_Tests/Assets/ReferenceImages/Linear/WindowsEditor/Direct3D12/None/1210_Lit_BentNormal.png b/TestProjects/HDRP_Tests/Assets/ReferenceImages/Linear/WindowsEditor/Direct3D12/None/1210_Lit_BentNormal.png index 7e770153d4a..5a33a60d264 100644 --- a/TestProjects/HDRP_Tests/Assets/ReferenceImages/Linear/WindowsEditor/Direct3D12/None/1210_Lit_BentNormal.png +++ b/TestProjects/HDRP_Tests/Assets/ReferenceImages/Linear/WindowsEditor/Direct3D12/None/1210_Lit_BentNormal.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:638dbedea46a9b053d04bf35f5269631246ab215a606c091f2720e9a1f2867a8 -size 153160 +oid sha256:2d0d5bc5d1f072eafa1d031d45d37c420e92c716e6eb4e1164f48325a2c8b7ec +size 138653 From ae41cc8fe95e66695092f4d4741047e74bb7432c Mon Sep 17 00:00:00 2001 From: Adrien de Tocqueville Date: Thu, 2 Sep 2021 15:11:06 +0200 Subject: [PATCH 6/7] real screenshot --- .../WindowsEditor/Direct3D12/None/1210_Lit_BentNormal.png | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/TestProjects/HDRP_Tests/Assets/ReferenceImages/Linear/WindowsEditor/Direct3D12/None/1210_Lit_BentNormal.png b/TestProjects/HDRP_Tests/Assets/ReferenceImages/Linear/WindowsEditor/Direct3D12/None/1210_Lit_BentNormal.png index 5a33a60d264..6b320949612 100644 --- a/TestProjects/HDRP_Tests/Assets/ReferenceImages/Linear/WindowsEditor/Direct3D12/None/1210_Lit_BentNormal.png +++ b/TestProjects/HDRP_Tests/Assets/ReferenceImages/Linear/WindowsEditor/Direct3D12/None/1210_Lit_BentNormal.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:2d0d5bc5d1f072eafa1d031d45d37c420e92c716e6eb4e1164f48325a2c8b7ec -size 138653 +oid sha256:f60718ffd796662561b9ac0a3d48fa55d3943b09c2ca942e420c6ece8882e9b7 +size 153158 From 207a5a30647e468e0d6a0c590af8422160a819b7 Mon Sep 17 00:00:00 2001 From: Adrien de Tocqueville Date: Fri, 3 Sep 2021 14:35:01 +0200 Subject: [PATCH 7/7] review --- .../ShaderLibrary/CommonLighting.hlsl | 3 +-- .../Documentation~/Upgrading-from-2021.1-to-2021.2.md | 5 +++++ 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/com.unity.render-pipelines.core/ShaderLibrary/CommonLighting.hlsl b/com.unity.render-pipelines.core/ShaderLibrary/CommonLighting.hlsl index 504ff0e1fc3..c9dbf658d2f 100644 --- a/com.unity.render-pipelines.core/ShaderLibrary/CommonLighting.hlsl +++ b/com.unity.render-pipelines.core/ShaderLibrary/CommonLighting.hlsl @@ -292,13 +292,12 @@ real GetSpecularOcclusionFromBentAO_ConeCone(real3 V, real3 bentNormalWS, real3 real GetSpecularOcclusionFromBentAO(real3 V, real3 bentNormalWS, real3 normalWS, real ambientOcclusion, real roughness) { + // Pseudo code: //SphericalGaussian NDF = WarpedGGXDistribution(normalWS, roughness, V); //SphericalGaussian Visibility = VisibilityConeSG(bentNormalWS, ambientOcclusion); //SphericalGaussian UpperHemisphere = UpperHemisphereSG(normalWS); //return saturate( InnerProduct(NDF, Visibility) / InnerProduct(NDF, UpperHemisphere) ); - // Approximation of the operation above: - // 1. Approximate visibility cone with a spherical gaussian of amplitude A=1 // For a cone angle X, we can determine sharpness so that all point inside the cone have a value > Y // sharpness = (log(Y) - log(A)) / (cos(X) - 1) diff --git a/com.unity.render-pipelines.high-definition/Documentation~/Upgrading-from-2021.1-to-2021.2.md b/com.unity.render-pipelines.high-definition/Documentation~/Upgrading-from-2021.1-to-2021.2.md index e40182b802d..0fa05b8584e 100644 --- a/com.unity.render-pipelines.high-definition/Documentation~/Upgrading-from-2021.1-to-2021.2.md +++ b/com.unity.render-pipelines.high-definition/Documentation~/Upgrading-from-2021.1-to-2021.2.md @@ -39,6 +39,11 @@ HDRP 2021.2 has various tessellation shader code to enable tessellation support * HDRP has improved support of motion vectors for tessellation. Only `previousPositionRWS` is part of the varyings. HDRP also added the `MotionVectorTessellation()` function. For more information, see the `MotionVectorVertexShaderCommon.hlsl` file. * HDRP now evaluates the `tessellationFactor` in the vertex shader and passes it to the hull shader as an interpolator. For more information, see the `VaryingMesh.hlsl` and `VertMesh.hlsl` files. +### Specular Occlusion + +The algorithm for computing specular occlusion from bent normals and ambient occlusion has been changed to improve visual results. +To use the old algorithm, function calls to `GetSpecularOcclusionFromBentAO` should be replaced by calls to `GetSpecularOcclusionFromBentAO_ConeCone` + ## Density Volumes Density Volumes are now known as **Local Volumetric Fog**.