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..59ac92fbdab 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 }; + /// + /// Add a bias distance to sampled depth in AO to reduce self-shadowing aliasing artifacts. + /// + [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 /// 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..f4cab26091b 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) @@ -249,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