Skip to content

Fix wobble-like (or tearing-like) SSAO issues when temporal reprojection is enabled. #4895

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

Merged
merged 3 commits into from
Jun 17, 2021
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
1 change: 1 addition & 0 deletions com.unity.render-pipelines.high-definition/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
- Fixed HDRP material upgrade failing when there is a texture inside the builtin resources assigned in the material (case 1339865).
- Fixed custom pass volume not executed in scene view because of the volume culling mask.
- Fixed remapping of depth pyramid debug view
- Fix wobbling/tearing-like artifacts with SSAO.

### Changed
- Changed Window/Render Pipeline/HD Render Pipeline Wizard to Window/Rendering/HDRP Wizard
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,29 +2,29 @@
#include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/NormalBuffer.hlsl"

#pragma kernel TemporalDenoise

#pragma multi_compile HALF_RES FULL_RES

uint PackHistoryData(float AO, float depth, float mvLen)

float4 PackHistoryData(float AO, float depth, float mvLen)
{
uint packedVal = 0;
packedVal = BitFieldInsert(0x000000ff, UnpackInt(AO, 8), packedVal);
packedVal = BitFieldInsert(0x0000ff00, UnpackInt(mvLen, 8) << 8, packedVal);
packedVal = BitFieldInsert(0xffff0000, UnpackInt(depth, 16) << 16, packedVal);
return packedVal;
float4 finalHistory;
finalHistory.xy = PackFloatToR8G8(depth);
finalHistory.z = saturate(AO);
finalHistory.w = saturate(mvLen);
return finalHistory;
}

void UnpackHistoryData(uint historyData, out float AO, out float depth, out float mvLen)
void UnpackHistoryData(float4 historyData, out float AO, out float depth, out float mvLen)
{
AO = UnpackUIntToFloat(historyData, 0, 8);
mvLen = UnpackUIntToFloat(historyData, 8, 8);
depth = UnpackUIntToFloat(historyData, 16, 16);
AO = historyData.z;
mvLen = saturate(historyData.w);
depth = UnpackFloatFromR8G8(historyData.xy);
}

RW_TEXTURE2D_X(uint, _AOOutputHistory);
RW_TEXTURE2D_X(float4, _AOOutputHistory);

TEXTURE2D_X(_AOPackedBlurred);
TEXTURE2D_X_UINT(_AOPackedHistory);
TEXTURE2D_X(_AOPackedHistory);
RW_TEXTURE2D_X(float, _OcclusionTexture);

float3 FindMinMaxAvgAO(float2 centralPos)
Expand Down Expand Up @@ -67,11 +67,12 @@ void TemporalDenoise(uint3 dispatchThreadId : SV_DispatchThreadID)
float2 motionVector;
DecodeMotionVector(LOAD_TEXTURE2D_X(_CameraMotionVectorsTexture, closest), motionVector);
float motionVecLength = length(motionVector);
float4 prevData = 0;

float2 uv = (dispatchThreadId.xy + 0.5) * _AOBufferSize.zw;
float2 uv = ((dispatchThreadId.xy + 0.5) * _AOBufferSize.zw);
float2 prevFrameNDC = uv - motionVector;

uint prevData = asuint(_AOPackedHistory[COORD_TEXTURE2D_X((prevFrameNDC) * _AOHistorySize.xy)].x);
prevData = (SAMPLE_TEXTURE2D_X_LOD(_AOPackedHistory, s_linear_clamp_sampler, (prevFrameNDC) * _RTHandleScaleHistory.zw, 0));
float prevMotionVecLen, prevAO, prevDepth;
UnpackHistoryData(prevData, prevAO, prevDepth, prevMotionVecLen);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ RenderAOParameters PrepareRenderAOParameters(HDCamera camera, Vector2 historySiz
}
else
{
parameters.runningRes = new Vector2(camera.actualWidth, camera.actualHeight) * 0.5f;
cb._AOBufferSize = new Vector4(camera.actualWidth * 0.5f, camera.actualHeight * 0.5f, 2.0f / camera.actualWidth, 2.0f / camera.actualHeight);
parameters.runningRes = new Vector2(Mathf.RoundToInt(camera.actualWidth * 0.5f), Mathf.RoundToInt(camera.actualHeight * 0.5f));
cb._AOBufferSize = new Vector4(parameters.runningRes.x, parameters.runningRes.y, 1.0f / parameters.runningRes.x, 1.0f / parameters.runningRes.y);
}

parameters.temporalAccumulation = settings.temporalAccumulation.value && camera.frameSettings.IsEnabled(FrameSettingsField.MotionVectors);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1296,7 +1296,7 @@ struct AmbientOcclusionAllocator

public RTHandle Allocator(string id, int frameIndex, RTHandleSystem rtHandleSystem)
{
return rtHandleSystem.Alloc(Vector2.one * scaleFactor, TextureXR.slices, filterMode: FilterMode.Point, colorFormat: GraphicsFormat.R32_UInt, dimension: TextureXR.dimension, useDynamicScale: true, enableRandomWrite: true, name: string.Format("{0}_AO Packed history_{1}", id, frameIndex));
return rtHandleSystem.Alloc(Vector2.one * scaleFactor, TextureXR.slices, filterMode: FilterMode.Point, colorFormat: GraphicsFormat.R8G8B8A8_UNorm, dimension: TextureXR.dimension, useDynamicScale: true, enableRandomWrite: true, name: string.Format("{0}_AO Packed history_{1}", id, frameIndex));
}
}

Expand Down