-
Notifications
You must be signed in to change notification settings - Fork 99
Expand file tree
/
Copy pathDoFPass1CS.hlsl
More file actions
60 lines (51 loc) · 2.01 KB
/
DoFPass1CS.hlsl
File metadata and controls
60 lines (51 loc) · 2.01 KB
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
52
53
54
55
56
57
58
59
60
//
// Copyright (c) Microsoft. All rights reserved.
// This code is licensed under the MIT License (MIT).
// THIS CODE IS PROVIDED *AS IS* WITHOUT WARRANTY OF
// ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING ANY
// IMPLIED WARRANTIES OF FITNESS FOR A PARTICULAR
// PURPOSE, MERCHANTABILITY, OR NON-INFRINGEMENT.
//
// Developed by Minigraph
//
// Author: James Stanard
//
#include "DoFCommon.hlsli"
Texture2D<float> LNDepthBuffer : register(t0); // Linear/normalized depth buffer
RWTexture2D<float3> TileClass : register(u0);
groupshared float gs_ClosestDepthSearch[64];
groupshared float gs_FarthestDepthSearch[64];
groupshared float gs_MaximumCoC[64];
float MaxCoC( float4 Depths )
{
float MaxDepthRelativeToFocus = Max4(abs(Depths - FocusCenter.xxxx));
return max(1.0 / sqrt(MATH_CONST_PI), MAX_COC_RADIUS * saturate( MaxDepthRelativeToFocus * FocalSpread ));
}
[RootSignature(DoF_RootSig)]
[numthreads( 8, 8, 1 )]
void main( uint3 Gid : SV_GroupID, uint GI : SV_GroupIndex, uint3 GTid : SV_GroupThreadID, uint3 DTid : SV_DispatchThreadID )
{
float2 uv = (DTid.xy * 2 + 1) * RcpBufferDim;
float4 Depths = LNDepthBuffer.Gather(ClampSampler, uv);
float TileMinDepth = Min4(Depths);
float TileMaxDepth = Max4(Depths);
float TileMaxCoC = MaxCoC(Depths);
// Write and sync
gs_ClosestDepthSearch[GI] = TileMinDepth;
gs_FarthestDepthSearch[GI] = TileMaxDepth;
gs_MaximumCoC[GI] = TileMaxCoC;
GroupMemoryBarrierWithGroupSync();
for (uint i = 32; i > 0; i >>= 1)
{
// Read and sync
if (GI < i)
{
gs_ClosestDepthSearch[i] = min(gs_ClosestDepthSearch[i], gs_ClosestDepthSearch[GI + i]);
gs_FarthestDepthSearch[i] = max(gs_FarthestDepthSearch[i], gs_FarthestDepthSearch[GI + i]);
gs_MaximumCoC[i] = max(gs_MaximumCoC[i], gs_MaximumCoC[GI + i]);
}
GroupMemoryBarrierWithGroupSync();
}
if (GI == 0)
TileClass[Gid.xy] = float3(gs_MaximumCoC[0], gs_FarthestDepthSearch[0], gs_FarthestDepthSearch[0]);
}