-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSSRComputeHierarchicalDepthBufferCS.hlsl
51 lines (39 loc) · 1.98 KB
/
SSRComputeHierarchicalDepthBufferCS.hlsl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
Texture2D<float> gDepthInput : register(t0);
RWTexture2D<float> gDepthOutput : register(u0);
#define ThreadGroupSize 256
[numthreads(ThreadGroupSize, 1, 1)]
void main(uint3 GroupThreadID : SV_GroupThreadID, uint3 DispatchThreadID : SV_DispatchThreadID)
{
uint2 u_previousLevelDimensions;
gDepthInput.GetDimensions(u_previousLevelDimensions.x, u_previousLevelDimensions.y);
uint2 thisLevelTexelCoord = DispatchThreadID.xy;
uint2 previousLevelBaseTexelCoord = 2 * thisLevelTexelCoord;
float4 depthTexelValues;
depthTexelValues.x = gDepthInput[previousLevelBaseTexelCoord + uint2(0, 0)];
depthTexelValues.y = gDepthInput[previousLevelBaseTexelCoord + uint2(1, 0)];
depthTexelValues.z = gDepthInput[previousLevelBaseTexelCoord + uint2(1, 1)];
depthTexelValues.w = gDepthInput[previousLevelBaseTexelCoord + uint2(0, 1)];
float minDepth = min(min(depthTexelValues.x, depthTexelValues.y), min(depthTexelValues.z, depthTexelValues.w));
bool shouldIncludeExtraColumnFromPreviousLevel = ((u_previousLevelDimensions.x & 1) != 0);
bool shouldIncludeExtraRowFromPreviousLevel = ((u_previousLevelDimensions.y & 1) != 0);
if (shouldIncludeExtraColumnFromPreviousLevel)
{
float2 extraColumnTexelValues;
extraColumnTexelValues.x = gDepthInput[previousLevelBaseTexelCoord + uint2(2, 0)];
extraColumnTexelValues.y = gDepthInput[previousLevelBaseTexelCoord + uint2(2, 1)];
if (shouldIncludeExtraRowFromPreviousLevel)
{
float cornerTexelValue = gDepthInput[previousLevelBaseTexelCoord + uint2(2, 2)];
minDepth = min(minDepth, cornerTexelValue);
}
minDepth = min(minDepth, min(extraColumnTexelValues.x, extraColumnTexelValues.y));
}
if (shouldIncludeExtraRowFromPreviousLevel)
{
float2 extraRowTexelValues;
extraRowTexelValues.x = gDepthInput[previousLevelBaseTexelCoord + uint2(0, 2)];
extraRowTexelValues.y = gDepthInput[previousLevelBaseTexelCoord + uint2(1, 2)];
minDepth = min(minDepth, min(extraRowTexelValues.x, extraRowTexelValues.y));
}
gDepthOutput[DispatchThreadID.xy] = minDepth;
}