From eda53d6dae8fcfdde66ffcb500a1ef00a9dfc2d5 Mon Sep 17 00:00:00 2001 From: Beini Gu Date: Tue, 14 Jun 2022 16:11:34 -0700 Subject: [PATCH 1/3] fix msvo aliasing artifact --- com.unity.postprocessing/CHANGELOG.md | 1 + .../Documentation~/Ambient-Occlusion.md | 1 + .../Editor/Effects/AmbientOcclusionEditor.cs | 3 +++ .../Runtime/Effects/AmbientOcclusion.cs | 6 ++++++ .../PostProcessing/Runtime/Effects/MultiScaleVO.cs | 2 +- .../Shaders/Builtins/MultiScaleVORender.compute | 11 ++++++----- 6 files changed, 18 insertions(+), 6 deletions(-) diff --git a/com.unity.postprocessing/CHANGELOG.md b/com.unity.postprocessing/CHANGELOG.md index 50f076e64bb..5ad4a728b0a 100644 --- a/com.unity.postprocessing/CHANGELOG.md +++ b/com.unity.postprocessing/CHANGELOG.md @@ -8,6 +8,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. ### Fixed - Fixed FXAA artefact when trying to preserve alpha channel output. +- Fixed MSVO aliasing artifact by using a z-Bias parameter. (case 1375337) ## [3.2.1] - 2022-01-12 diff --git a/com.unity.postprocessing/Documentation~/Ambient-Occlusion.md b/com.unity.postprocessing/Documentation~/Ambient-Occlusion.md index 47698972caf..d14b59943f4 100644 --- a/com.unity.postprocessing/Documentation~/Ambient-Occlusion.md +++ b/com.unity.postprocessing/Documentation~/Ambient-Occlusion.md @@ -63,5 +63,6 @@ This mode is optimized for consoles and desktop platforms. It has better graphic | Mode | Select the type of **Ambient Occlusion** to use. | | Intensity | Adjust the degree of darkness **Ambient Occlusion** produces. | | Thickness Modifier | Modify the thickness of occluders. This increases dark areas but can introduce dark halos around objects. | +| Z Bias | Modifies the z-bias to the depth buffer. This eliminates the banding aliasing artifact for MSVO. | | Color | Set the tint color of the ambient occlusion. | | Ambient Only | Enable this checkbox to make the **Ambient Occlusion** effect only affect ambient lighting. This option is only available with the Deferred rendering path and HDR rendering. | diff --git a/com.unity.postprocessing/PostProcessing/Editor/Effects/AmbientOcclusionEditor.cs b/com.unity.postprocessing/PostProcessing/Editor/Effects/AmbientOcclusionEditor.cs index c943252277d..c200d59d962 100644 --- a/com.unity.postprocessing/PostProcessing/Editor/Effects/AmbientOcclusionEditor.cs +++ b/com.unity.postprocessing/PostProcessing/Editor/Effects/AmbientOcclusionEditor.cs @@ -11,6 +11,7 @@ internal sealed class AmbientOcclusionEditor : PostProcessEffectEditor x.color); m_AmbientOnly = FindParameterOverride(x => x.ambientOnly); m_ThicknessModifier = FindParameterOverride(x => x.thicknessModifier); + m_ZBias = FindParameterOverride(x => x.zBias); m_DirectLightingStrength = FindParameterOverride(x => x.directLightingStrength); m_Quality = FindParameterOverride(x => x.quality); m_Radius = FindParameterOverride(x => x.radius); @@ -51,6 +53,7 @@ public override void OnInspectorGUI() EditorGUILayout.HelpBox("Multi-scale volumetric obscurance requires compute shader support.", MessageType.Warning); PropertyField(m_ThicknessModifier); + PropertyField(m_ZBias); if (RuntimeUtilities.scriptableRenderPipelineActive) PropertyField(m_DirectLightingStrength); diff --git a/com.unity.postprocessing/PostProcessing/Runtime/Effects/AmbientOcclusion.cs b/com.unity.postprocessing/PostProcessing/Runtime/Effects/AmbientOcclusion.cs index a6c87aa489b..6fdd7b595d9 100644 --- a/com.unity.postprocessing/PostProcessing/Runtime/Effects/AmbientOcclusion.cs +++ b/com.unity.postprocessing/PostProcessing/Runtime/Effects/AmbientOcclusion.cs @@ -127,6 +127,12 @@ public sealed class AmbientOcclusion : PostProcessEffectSettings [Range(1f, 10f), Tooltip("This modifies the thickness of occluders. It increases the size of dark areas and also introduces a dark halo around objects.")] public FloatParameter thicknessModifier = new FloatParameter { value = 1f }; + /// + /// Modifies the z-bias to the depth buffer. This eliminates the banding aliasing artifact for MSVO. + /// + [Range(0f, 0.5f), Tooltip("Modifies the bias to the depth buffer for reducing aliasing artifact.")] + public FloatParameter zBias = new FloatParameter { value = 0.01f }; + // HDRP-only parameters /// diff --git a/com.unity.postprocessing/PostProcessing/Runtime/Effects/MultiScaleVO.cs b/com.unity.postprocessing/PostProcessing/Runtime/Effects/MultiScaleVO.cs index 986d3daa8e3..2974251a9b9 100644 --- a/com.unity.postprocessing/PostProcessing/Runtime/Effects/MultiScaleVO.cs +++ b/com.unity.postprocessing/PostProcessing/Runtime/Effects/MultiScaleVO.cs @@ -388,7 +388,7 @@ void PushRenderCommands(CommandBuffer cmd, int source, int destination, Vector3 cmd.SetComputeFloatParams(cs, "gInvThicknessTable", m_InvThicknessTable); cmd.SetComputeFloatParams(cs, "gSampleWeightTable", m_SampleWeightTable); cmd.SetComputeVectorParam(cs, "gInvSliceDimension", new Vector2(1f / sourceSize.x, 1f / sourceSize.y)); - cmd.SetComputeVectorParam(cs, "AdditionalParams", new Vector2(-1f / m_Settings.thicknessModifier.value, m_Settings.intensity.value)); + cmd.SetComputeVectorParam(cs, "AdditionalParams", new Vector3(-1f / m_Settings.thicknessModifier.value, m_Settings.intensity.value, m_Settings.zBias.value)); cmd.SetComputeTextureParam(cs, kernel, "DepthTex", source); cmd.SetComputeTextureParam(cs, kernel, "Occlusion", destination); diff --git a/com.unity.postprocessing/PostProcessing/Shaders/Builtins/MultiScaleVORender.compute b/com.unity.postprocessing/PostProcessing/Shaders/Builtins/MultiScaleVORender.compute index 486d7e31c1c..2e606506046 100644 --- a/com.unity.postprocessing/PostProcessing/Shaders/Builtins/MultiScaleVORender.compute +++ b/com.unity.postprocessing/PostProcessing/Shaders/Builtins/MultiScaleVORender.compute @@ -80,11 +80,12 @@ CBUFFER_START(CB1) float4 gInvThicknessTable[3]; float4 gSampleWeightTable[3]; float4 gInvSliceDimension; - float2 AdditionalParams; + float3 AdditionalParams; CBUFFER_END #define gRejectFadeoff AdditionalParams.x #define gIntensity AdditionalParams.y +#define zBias AdditionalParams.z #ifdef MSAA float2 TestSamplePair(float frontDepth, float2 invRange, uint base, int offset) @@ -92,8 +93,8 @@ float2 TestSamplePair(float frontDepth, float2 invRange, uint base, int offset) // "Disocclusion" measures the penetration distance of the depth sample within the sphere. // Disocclusion < 0 (full occlusion) -> the sample fell in front of the sphere // Disocclusion > 1 (no occlusion) -> the sample fell behind the sphere - float2 disocclusion1 = DepthSamples[base + offset] * invRange - frontDepth; - float2 disocclusion2 = DepthSamples[base - offset] * invRange - frontDepth; + float2 disocclusion1 = DepthSamples[base + offset] * invRange - (frontDepth - zBias); + float2 disocclusion2 = DepthSamples[base - offset] * invRange - (frontDepth - zBias); float2 pseudoDisocclusion1 = saturate(gRejectFadeoff * disocclusion1); float2 pseudoDisocclusion2 = saturate(gRejectFadeoff * disocclusion2); @@ -147,8 +148,8 @@ float TestSamplePair(float frontDepth, float invRange, uint base, int offset) // "Disocclusion" measures the penetration distance of the depth sample within the sphere. // Disocclusion < 0 (full occlusion) -> the sample fell in front of the sphere // Disocclusion > 1 (no occlusion) -> the sample fell behind the sphere - float disocclusion1 = DepthSamples[base + offset] * invRange - frontDepth; - float disocclusion2 = DepthSamples[base - offset] * invRange - frontDepth; + float disocclusion1 = DepthSamples[base + offset] * invRange - (frontDepth - zBias); + float disocclusion2 = DepthSamples[base - offset] * invRange - (frontDepth - zBias); float pseudoDisocclusion1 = saturate(gRejectFadeoff * disocclusion1); float pseudoDisocclusion2 = saturate(gRejectFadeoff * disocclusion2); From 5b1f2b56d3613ca8ad68492ff9f18bf4784fa57f Mon Sep 17 00:00:00 2001 From: Beini Gu Date: Tue, 14 Jun 2022 17:17:03 -0700 Subject: [PATCH 2/3] fix zBias offseting wrong depth buffer --- .../Runtime/Effects/AmbientOcclusion.cs | 4 ++-- .../Shaders/Builtins/MultiScaleVORender.compute | 12 ++++++------ 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/com.unity.postprocessing/PostProcessing/Runtime/Effects/AmbientOcclusion.cs b/com.unity.postprocessing/PostProcessing/Runtime/Effects/AmbientOcclusion.cs index 6fdd7b595d9..a67f665a09d 100644 --- a/com.unity.postprocessing/PostProcessing/Runtime/Effects/AmbientOcclusion.cs +++ b/com.unity.postprocessing/PostProcessing/Runtime/Effects/AmbientOcclusion.cs @@ -130,8 +130,8 @@ public sealed class AmbientOcclusion : PostProcessEffectSettings /// /// Modifies the z-bias to the depth buffer. This eliminates the banding aliasing artifact for MSVO. /// - [Range(0f, 0.5f), Tooltip("Modifies the bias to the depth buffer for reducing aliasing artifact.")] - public FloatParameter zBias = new FloatParameter { value = 0.01f }; + [Range(0f, 0.001f), Tooltip("Modifies the bias to the depth buffer for reducing aliasing artifact.")] + public FloatParameter zBias = new FloatParameter { value = 0.0001f }; // HDRP-only parameters diff --git a/com.unity.postprocessing/PostProcessing/Shaders/Builtins/MultiScaleVORender.compute b/com.unity.postprocessing/PostProcessing/Shaders/Builtins/MultiScaleVORender.compute index 2e606506046..f4cab26091b 100644 --- a/com.unity.postprocessing/PostProcessing/Shaders/Builtins/MultiScaleVORender.compute +++ b/com.unity.postprocessing/PostProcessing/Shaders/Builtins/MultiScaleVORender.compute @@ -93,8 +93,8 @@ float2 TestSamplePair(float frontDepth, float2 invRange, uint base, int offset) // "Disocclusion" measures the penetration distance of the depth sample within the sphere. // Disocclusion < 0 (full occlusion) -> the sample fell in front of the sphere // Disocclusion > 1 (no occlusion) -> the sample fell behind the sphere - float2 disocclusion1 = DepthSamples[base + offset] * invRange - (frontDepth - zBias); - float2 disocclusion2 = DepthSamples[base - offset] * invRange - (frontDepth - zBias); + float2 disocclusion1 = DepthSamples[base + offset] * invRange - frontDepth; + float2 disocclusion2 = DepthSamples[base - offset] * invRange - frontDepth; float2 pseudoDisocclusion1 = saturate(gRejectFadeoff * disocclusion1); float2 pseudoDisocclusion2 = saturate(gRejectFadeoff * disocclusion2); @@ -148,8 +148,8 @@ float TestSamplePair(float frontDepth, float invRange, uint base, int offset) // "Disocclusion" measures the penetration distance of the depth sample within the sphere. // Disocclusion < 0 (full occlusion) -> the sample fell in front of the sphere // Disocclusion > 1 (no occlusion) -> the sample fell behind the sphere - float disocclusion1 = DepthSamples[base + offset] * invRange - (frontDepth - zBias); - float disocclusion2 = DepthSamples[base - offset] * invRange - (frontDepth - zBias); + float disocclusion1 = DepthSamples[base + offset] * invRange - frontDepth; + float disocclusion2 = DepthSamples[base - offset] * invRange - frontDepth; float pseudoDisocclusion1 = saturate(gRejectFadeoff * disocclusion1); float pseudoDisocclusion2 = saturate(gRejectFadeoff * disocclusion2); @@ -250,10 +250,10 @@ void MAIN(uint3 Gid : SV_GroupID, uint GI : SV_GroupIndex, uint3 GTid : SV_Group #endif #ifdef MSAA - const float2 invThisDepth = float2(1.0 / DepthSamples[thisIdx].x, 1.0 / DepthSamples[thisIdx].y); + const float2 invThisDepth = float2(1.0 / (DepthSamples[thisIdx].x - zBias), 1.0 / (DepthSamples[thisIdx].y - zBias)); float2 ao = 0.0; #else - const float invThisDepth = 1.0 / DepthSamples[thisIdx]; + const float invThisDepth = 1.0 / (DepthSamples[thisIdx] - zBias); float ao = 0.0; #endif From 844efaf0e930a35da827014cdc4d19dfde380d38 Mon Sep 17 00:00:00 2001 From: Beini Gu Date: Wed, 15 Jun 2022 17:45:14 -0700 Subject: [PATCH 3/3] change wording --- .../PostProcessing/Runtime/Effects/AmbientOcclusion.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/com.unity.postprocessing/PostProcessing/Runtime/Effects/AmbientOcclusion.cs b/com.unity.postprocessing/PostProcessing/Runtime/Effects/AmbientOcclusion.cs index a67f665a09d..59ac92fbdab 100644 --- a/com.unity.postprocessing/PostProcessing/Runtime/Effects/AmbientOcclusion.cs +++ b/com.unity.postprocessing/PostProcessing/Runtime/Effects/AmbientOcclusion.cs @@ -128,9 +128,9 @@ public sealed class AmbientOcclusion : PostProcessEffectSettings public FloatParameter thicknessModifier = new FloatParameter { value = 1f }; /// - /// Modifies the z-bias to the depth buffer. This eliminates the banding aliasing artifact for MSVO. + /// Add a bias distance to sampled depth in AO to reduce self-shadowing aliasing artifacts. /// - [Range(0f, 0.001f), Tooltip("Modifies the bias to the depth buffer for reducing aliasing artifact.")] + [Range(0f, 0.001f), Tooltip("Add a bias distance to sampled depth in AO to reduce self-shadowing aliasing artifacts. ")] public FloatParameter zBias = new FloatParameter { value = 0.0001f }; // HDRP-only parameters