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

Expose bilateral blur aggressiveness for spatial SSAO blur when temporal accumulation #1569

Merged
merged 3 commits into from
Sep 8, 2020
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ For information on how to use a Texture to specify ambient occlusion caused by d
| **Full Resolution** | Enable the checkbox to process the ambient occlusion algorithm in full resolution. This improves quality significantly but is a resource-intensive operation and has an impact on performance. Disable the checkbox to process the ambient occlusion algorithm at half the resolution your application runs at. This setting is disabled by default. |
| **Temporal Accumulation** | Enable the checkbox to accumulate the result of AO over time. This will lead to better quality, but it might result in artifacts like non instant convergence and ghosting. **Note:** This mode will not lead to good results if motion vectors are not available. |
| **Ghosting Reduction** | This is only available when Temporal Accumulation is enabled.<br />Moving this factor closer to 0 will increase the amount of accepted samples during temporal accumulation, increasing the ghosting, but reducing the temporal noise. Moving the value closer to 1 will reduce the ghosting, at expense of more visible temporal noise. |
| **Bilateral Aggressiveness** | This is only available when Temporal Accumulation is enabled.<br />Higher this value, the less lenient with depth differences the spatial filter is and therefore more likely is to reject samples that are at different depth values. Increasing this for could reduce white halos where AO should be around objects. |
| **Bilateral Upsample** | Enable the checkbox to upsample the low resolution AO through bilateral upsampling. This preserves sharp edges better, however it is slightly more expensive and might result is more visible aliasing. **Note:** This mode is available only when Full Resolution is set to false. |
| **Direction Count** | Determines how many directions are searched for occlusion, increasing this will impact performance considerably. **Note:** This mode is available only when Temporal Accumulation is set to false. |
| **Blur sharpness** | Determines the sharpness of the non-temporal blur. Higher values preserve sharp features better (with higher risk of noise), lower values have a softer look. **Note:** This mode is available only when Temporal Accumulation is set to false. |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ class AmbientOcclusionEditor : VolumeComponentWithQualityEditor
SerializedDataParameter m_FullResolution;
SerializedDataParameter m_MaximumRadiusInPixels;
SerializedDataParameter m_DirectLightingStrength;
SerializedDataParameter m_SpatialBilateralAggressiveness;

// Temporal only parameters
SerializedDataParameter m_TemporalAccumulation;
Expand Down Expand Up @@ -52,6 +53,7 @@ public override void OnEnable()
m_DirectLightingStrength = Unpack(o.Find(x => x.directLightingStrength));
m_GhostingAdjustement = Unpack(o.Find(x => x.ghostingReduction));
m_BilateralUpsample = Unpack(o.Find("m_BilateralUpsample"));
m_SpatialBilateralAggressiveness = Unpack(o.Find(x => x.spatialBilateralAggressiveness));

m_RayTracing = Unpack(o.Find(x => x.rayTracing));
m_LayerMask = Unpack(o.Find(x => x.layerMask));
Expand Down Expand Up @@ -124,6 +126,7 @@ public override void OnInspectorGUI()
}
else
{
PropertyField(m_SpatialBilateralAggressiveness, EditorGUIUtility.TrTextContent("Bilateral Aggressiveness", "Higher this value, the less lenient with depth differences the spatial filter is. Increase if for example noticing white halos where AO should be."));
PropertyField(m_GhostingAdjustement, EditorGUIUtility.TrTextContent("Ghosting reduction", "Moving this factor closer to 0 will increase the amount of accepted samples during temporal accumulation, increasing the ghosting, but reducing the temporal noise."));
if (isInAdvancedMode && !m_FullResolution.value.boolValue)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,13 @@ public sealed class AmbientOcclusion : VolumeComponentWithQuality
/// Sampling radius. Bigger the radius, wider AO will be achieved, risking to lose fine details and increasing cost of the effect due to increasing cache misses.
/// </summary>
public ClampedFloatParameter radius = new ClampedFloatParameter(2.0f, 0.25f, 5.0f);

/// <summary>
/// Moving this factor closer to 0 will increase the amount of accepted samples during temporal accumulation, increasing the ghosting, but reducing the temporal noise.
/// </summary>
public ClampedFloatParameter spatialBilateralAggressiveness = new ClampedFloatParameter(0.15f, 0.0f, 1.0f);


/// <summary>
/// Whether the results are accumulated over time or not. This can get higher quality results at a cheaper cost, but it can lead to temporal artifacts such as ghosting.
/// </summary>
Expand Down Expand Up @@ -432,7 +439,7 @@ RenderAOParameters PrepareRenderAOParameters(HDCamera camera, Vector2 historySiz
settings.directionCount,
upperNudgeFactor,
minUpperNudgeLimit,
0
settings.spatialBilateralAggressiveness.value * 15.0f
);

cb._FirstTwoDepthMipOffsets = new Vector4(depthMipInfo.mipLevelOffsets[1].x, depthMipInfo.mipLevelOffsets[1].y, depthMipInfo.mipLevelOffsets[2].x, depthMipInfo.mipLevelOffsets[2].y);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
#define _StepSize _AOParams3.w
#define _AOTemporalUpperNudgeLimit _AOParams4.y
#define _AOTemporalLowerNudgeLimit _AOParams4.z
#define _AOSpatialBilateralAggressiveness _AOParams4.w


// If this is set to 0 best quality is achieved when full res, but performance is significantly lower.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,13 @@ RW_TEXTURE2D_X(float, _OcclusionTexture);

#define DEBUG_VISUALIZE_BILATERAL_WEIGHTS 0

#define DEPTH_SCALE 1
#define BILATERAL_EPSILON 0.01

float BilateralWeight(float sampleDepth, float linearCentralDepth)
{
float linearSample = LinearEyeDepth(sampleDepth, _ZBufferParams);
float delta = abs(linearSample - linearCentralDepth);
float w = saturate(1.0f - (DEPTH_SCALE * delta + BILATERAL_EPSILON));
float w = saturate(1.0f - (_AOSpatialBilateralAggressiveness * delta + BILATERAL_EPSILON));

return w;
}
Expand Down