Skip to content

Commit 4eae451

Browse files
SSR: a few fixes to support reverse depth (#228)
1 parent 2d55ae8 commit 4eae451

File tree

7 files changed

+97
-106
lines changed

7 files changed

+97
-106
lines changed

Hydrogent/src/Tasks/HnPostProcessTask.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2023-2024 Diligent Graphics LLC
2+
* Copyright 2023-2025 Diligent Graphics LLC
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -637,7 +637,10 @@ void HnPostProcessTask::Prepare(pxr::HdTaskContext* TaskCtx,
637637

638638
const TextureDesc& FinalColorDesc = m_FinalColorRTV->GetTexture()->GetDesc();
639639

640-
m_PostFXContext->PrepareResources(pDevice, {pRenderParam->GetFrameNumber(), FinalColorDesc.Width, FinalColorDesc.Height}, PostFXContext::FEATURE_FLAG_NONE);
640+
const PostFXContext::FEATURE_FLAGS PostFXFlags = pRenderParam->GetConfig().UseReverseDepth ?
641+
PostFXContext::FEATURE_FLAG_REVERSED_DEPTH :
642+
PostFXContext::FEATURE_FLAG_NONE;
643+
m_PostFXContext->PrepareResources(pDevice, {pRenderParam->GetFrameNumber(), FinalColorDesc.Width, FinalColorDesc.Height}, PostFXFlags);
641644
m_SSAO->PrepareResources(pDevice, pCtx, m_PostFXContext.get(), m_Params.SSAOFeatureFlags);
642645
m_SSR->PrepareResources(pDevice, pCtx, m_PostFXContext.get(), m_Params.SSRFeatureFlags);
643646
m_TAA->PrepareResources(pDevice, pCtx, m_PostFXContext.get(), m_Params.TAAFeatureFlags);

PostProcess/Common/interface/PostFXContext.hpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2024 Diligent Graphics LLC
2+
* Copyright 2024-2025 Diligent Graphics LLC
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -51,7 +51,7 @@ class PostFXContext
5151
enum FEATURE_FLAGS : Uint32
5252
{
5353
FEATURE_FLAG_NONE = 0u,
54-
FEATURE_FLAG_REVERSED_DEPTH = 1u << 0u, // Not implemented
54+
FEATURE_FLAG_REVERSED_DEPTH = 1u << 0u,
5555
FEATURE_FLAG_HALF_PRECISION_DEPTH = 1u << 1u
5656
};
5757

@@ -154,6 +154,11 @@ class PostFXContext
154154
return m_SupportedFeatures;
155155
}
156156

157+
FEATURE_FLAGS GetFeatureFlags() const
158+
{
159+
return m_FeatureFlags;
160+
}
161+
157162
const FrameDesc& GetFrameDesc() const
158163
{
159164
return m_FrameDesc;

PostProcess/ScreenSpaceReflection/interface/ScreenSpaceReflection.hpp

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -56,17 +56,15 @@ class ScreenSpaceReflection
5656
public:
5757
enum FEATURE_FLAGS : Uint32
5858
{
59-
FEATURE_FLAG_NONE = 0u,
60-
FEATURE_FLAG_REVERSED_DEPTH = 1u << 0u, // Not implemented
61-
FEATURE_FLAG_PACKED_NORMAL = 1u << 1u, // Nor implemented
59+
FEATURE_FLAG_NONE = 0u,
6260

6361
// When using this flag, you only need to pass the color buffer of the previous frame.
6462
// We find the intersection using the depth buffer of the current frame, and when an intersection is found,
6563
// we make the corresponding offset by the velocity vector at the intersection point, for sampling from the color buffer.
66-
FEATURE_FLAG_PREVIOUS_FRAME = 1u << 2u,
64+
FEATURE_FLAG_PREVIOUS_FRAME = 1u << 0u,
6765

6866
// When this flag is used, ray tracing step is executed at half resolution
69-
FEATURE_FLAG_HALF_RESOLUTION = 1u << 3u
67+
FEATURE_FLAG_HALF_RESOLUTION = 1u << 1u
7068
};
7169

7270
struct RenderAttributes

PostProcess/ScreenSpaceReflection/src/ScreenSpaceReflection.cpp

Lines changed: 69 additions & 85 deletions
Large diffs are not rendered by default.

Shaders/PostProcess/ScreenSpaceReflection/private/SSR_Common.fxh

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@
44
#include "PostFX_Common.fxh"
55

66
#if SSR_OPTION_INVERTED_DEPTH
7-
#define MipConvFunc max
7+
#define ClosestDepth max
88
#define DepthFarPlane 0.0
99
#else
10-
#define MipConvFunc min
10+
#define ClosestDepth min
1111
#define DepthFarPlane 1.0
1212
#endif // SSR_OPTION_INVERTED_DEPTH
1313

@@ -48,9 +48,9 @@ float2 MapSquareToDisk(float2 Point)
4848
bool IsBackground(float Depth)
4949
{
5050
#if SSR_OPTION_INVERTED_DEPTH
51-
return Depth < 1.0e-6f;
51+
return Depth < 1.0e-6;
5252
#else
53-
return Depth >= (1.0f - 1.0e-6f);
53+
return Depth >= (1.0 - 1.0e-6);
5454
#endif // SSR_OPTION_INVERTED_DEPTH
5555
}
5656

Shaders/PostProcess/ScreenSpaceReflection/private/SSR_ComputeDownsampledStencilMask.fx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ void ComputeDownsampledStencilMaskPS(in FullScreenTriangleVSOutput VSOut)
4949
for (uint SampleIdx = 0u; SampleIdx < 4u; ++SampleIdx)
5050
{
5151
uint2 Offset = uint2(SampleIdx & 0x01u, SampleIdx >> 1u);
52-
MinDepth = MipConvFunc(MinDepth, SampleDepth(RemappedPosition, Offset, TextureDimension));
52+
MinDepth = ClosestDepth(MinDepth, SampleDepth(RemappedPosition, Offset, TextureDimension));
5353
MaxRoughness = max(MaxRoughness, SampleRoughness(RemappedPosition, Offset, TextureDimension));
5454
}
5555

@@ -61,7 +61,7 @@ void ComputeDownsampledStencilMaskPS(in FullScreenTriangleVSOutput VSOut)
6161
for (uint SampleIdx = 0u; SampleIdx < 2u; ++SampleIdx)
6262
{
6363
uint2 Offset = uint2(2u, SampleIdx);
64-
MinDepth = MipConvFunc(MinDepth, SampleDepth(RemappedPosition, Offset, TextureDimension));
64+
MinDepth = ClosestDepth(MinDepth, SampleDepth(RemappedPosition, Offset, TextureDimension));
6565
MaxRoughness = max(MaxRoughness, SampleRoughness(RemappedPosition, Offset, TextureDimension));
6666
}
6767
}
@@ -71,14 +71,14 @@ void ComputeDownsampledStencilMaskPS(in FullScreenTriangleVSOutput VSOut)
7171
for (uint SampleIdx = 0u; SampleIdx < 2u; ++SampleIdx)
7272
{
7373
uint2 Offset = uint2(SampleIdx, 2);
74-
MinDepth = MipConvFunc(MinDepth, SampleDepth(RemappedPosition, Offset, TextureDimension));
74+
MinDepth = ClosestDepth(MinDepth, SampleDepth(RemappedPosition, Offset, TextureDimension));
7575
MaxRoughness = max(MaxRoughness, SampleRoughness(RemappedPosition, Offset, TextureDimension));
7676
}
7777
}
7878

7979
if (IsWidthOdd && IsHeightOdd)
8080
{
81-
MinDepth = MipConvFunc(MinDepth, SampleDepth(RemappedPosition, uint2(2, 2), TextureDimension));
81+
MinDepth = ClosestDepth(MinDepth, SampleDepth(RemappedPosition, uint2(2, 2), TextureDimension));
8282
MaxRoughness = max(MaxRoughness, SampleRoughness(RemappedPosition, uint2(2, 2), TextureDimension));
8383
}
8484

Shaders/PostProcess/ScreenSpaceReflection/private/SSR_ComputeHierarchicalDepthBuffer.fx

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,8 @@ float ComputeHierarchicalDepthBufferPS(in FullScreenTriangleVSOutput VSOut) : SV
4343
SampledPixels.z = SampleDepth(RemappedPosition, int2(1, 0), LastMipDimension);
4444
SampledPixels.w = SampleDepth(RemappedPosition, int2(1, 1), LastMipDimension);
4545

46-
float MinDepth = MipConvFunc(MipConvFunc(SampledPixels.x, SampledPixels.y), MipConvFunc(SampledPixels.z, SampledPixels.w));
46+
float MinDepth = ClosestDepth(ClosestDepth(SampledPixels.x, SampledPixels.y),
47+
ClosestDepth(SampledPixels.z, SampledPixels.w));
4748

4849
bool IsWidthOdd = (LastMipDimension.x & 1) != 0;
4950
bool IsHeightOdd = (LastMipDimension.y & 1) != 0;
@@ -52,19 +53,19 @@ float ComputeHierarchicalDepthBufferPS(in FullScreenTriangleVSOutput VSOut) : SV
5253
{
5354
SampledPixels.x = SampleDepth(RemappedPosition, int2(2, 0), LastMipDimension);
5455
SampledPixels.y = SampleDepth(RemappedPosition, int2(2, 1), LastMipDimension);
55-
MinDepth = MipConvFunc(MinDepth, MipConvFunc(SampledPixels.x, SampledPixels.y));
56+
MinDepth = ClosestDepth(MinDepth, ClosestDepth(SampledPixels.x, SampledPixels.y));
5657
}
5758

5859
if (IsHeightOdd)
5960
{
6061
SampledPixels.x = SampleDepth(RemappedPosition, int2(0, 2), LastMipDimension);
6162
SampledPixels.y = SampleDepth(RemappedPosition, int2(1, 2), LastMipDimension);
62-
MinDepth = MipConvFunc(MinDepth, MipConvFunc(SampledPixels.x, SampledPixels.y));
63+
MinDepth = ClosestDepth(MinDepth, ClosestDepth(SampledPixels.x, SampledPixels.y));
6364
}
6465

6566
if (IsWidthOdd && IsHeightOdd)
6667
{
67-
MinDepth = MipConvFunc(MinDepth, SampleDepth(RemappedPosition, int2(2, 2), LastMipDimension));
68+
MinDepth = ClosestDepth(MinDepth, SampleDepth(RemappedPosition, int2(2, 2), LastMipDimension));
6869
}
6970

7071
return MinDepth;

0 commit comments

Comments
 (0)