Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix aliasing artifact in MultiScaleVolumetricObscurance (AmbientOcclusion) #7489

Merged
merged 3 commits into from
Nov 30, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions com.unity.postprocessing/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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. |
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also plz update the wording in the doc .md file.

| 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. |
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ internal sealed class AmbientOcclusionEditor : PostProcessEffectEditor<AmbientOc
SerializedParameterOverride m_Color;
SerializedParameterOverride m_AmbientOnly;
SerializedParameterOverride m_ThicknessModifier;
SerializedParameterOverride m_ZBias;
SerializedParameterOverride m_DirectLightingStrength;
SerializedParameterOverride m_Quality;
SerializedParameterOverride m_Radius;
Expand All @@ -22,6 +23,7 @@ public override void OnEnable()
m_Color = FindParameterOverride(x => 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);
Expand Down Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 };

/// <summary>
/// Add a bias distance to sampled depth in AO to reduce self-shadowing aliasing artifacts.
/// </summary>
[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

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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

Expand Down