forked from microsoft/Xbox-ATG-Samples
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBokehEffect12.h
162 lines (133 loc) · 4.82 KB
/
BokehEffect12.h
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
//--------------------------------------------------------------------------------------
// BokehEffect12.h
//
// Demonstrates how to render depth of field using point sprites.
//
// Advanced Technology Group (ATG)
// Copyright (C) Microsoft Corporation. All rights reserved.
//--------------------------------------------------------------------------------------
#pragma once
#include "DeviceResources.h"
namespace ATG
{
class BokehEffect
{
public:
struct Parameters
{
// CoC
float focusLength;
float FNumber;
float focalPlane;
// performance
float maxCoCSizeNear;
float maxCoCSizeFar;
float switchover1[2];
float switchover2[2];
// quality
float initialEnergyScale;
bool useFastShader;
};
BokehEffect(
ID3D12Device* device,
DXGI_FORMAT format,
DirectX::GraphicsMemory* graphicsMemory,
DirectX::ResourceUploadBatch& batch);
void ResizeResources(ID3D12Device* device, int width, int height);
void Render(
ID3D12GraphicsCommandList* cmdList,
ID3D12Resource* sceneTexture,
D3D12_CPU_DESCRIPTOR_HANDLE srcColorSRV,
D3D12_CPU_DESCRIPTOR_HANDLE srcDepthSRV,
D3D12_CPU_DESCRIPTOR_HANDLE dstRTV,
const DirectX::XMMATRIX& matInvProj,
const Parameters& params,
bool useDebugShader);
private:
void CreateResources(ID3D12Device* device, DirectX::ResourceUploadBatch& batch);
void CreatePSO(ID3D12Device* device, DXGI_FORMAT format);
void StartRendering(ID3D12GraphicsCommandList* cmdList, const DirectX::XMMATRIX& matInvProj, const Parameters& params);
enum RootParameters
{
e_rootParameterPS0 = 0,
e_rootParameterGS4,
e_rootParameterVS0,
e_rootParameterGS0,
e_rootParameterCB0,
e_rootParameterCB1,
e_rootParameterCB2,
e_numRootParameters
};
enum DescriptorHeapIndex
{
e_iSRVSrcColor = 0,
e_iSRVIris,
e_iSRVSrcDepth,
e_iSRVDOFColor,
e_iSRVSrcDepth2 = 5,
e_iSRVSourceColorRGBZCopy,
e_iSRVSourceColorRGBZHalfCopy,
e_iSRVEnergies,
e_iUAVScratch,
e_iUAVEnergies,
e_iSRVHeapEnd
};
enum RTVDescriptorHeapIndex
{
e_iRTVDOFColor = 0,
e_iRTVSourceColorRGBZCopy,
e_iRTVSourceColorRGBZHalfCopy,
e_iRTVDst,
e_iRTVHeapEnd
};
struct BokehCB
{
float maxCoCDiameterNear;
float focusLength;
float focalPlane;
float FNumber;
float depthBufferSize[2];
float dofTexSize[2];
float srcScreenSize[2];
float maxCoCDiameterFar;
float irisTextureOffset;
float viewports[6][4];
float switchover1[2];
float switchover2[2];
float initialEnergyScale;
float pad[3];
float mInvProj[16];
};
private:
template <typename T>
using ComPtr = Microsoft::WRL::ComPtr<T>;
DirectX::GraphicsMemory* m_graphicsMemory;
DirectX::DescriptorPile m_srvHeap; // Descriptor heap for SRVs
DirectX::DescriptorPile m_rtvHeap; // Descriptor heap for RTVs
// weights texture
ComPtr<ID3D12Resource> m_energiesTex;
ComPtr<ID3D12Resource> m_scratchTex;
// the texture that takes front and back blur of the source texture
ComPtr<ID3D12Resource> m_DOFColorTexture;
// in focus copy
ComPtr<ID3D12Resource> m_sourceColorTextureRGBZCopy;
ComPtr<ID3D12Resource> m_sourceColorTextureRGBZHalfCopy;
// iris texture
ComPtr<ID3D12Resource> m_irisTex;
// Root signature and PSO
ComPtr<ID3D12RootSignature> m_commonRS;
ComPtr<ID3D12PipelineState> m_recombinePSO;
ComPtr<ID3D12PipelineState> m_recombinePSODebug;
ComPtr<ID3D12PipelineState> m_createRGBZPSO;
ComPtr<ID3D12PipelineState> m_downsampleRGBZPSO;
ComPtr<ID3D12PipelineState> m_quadPointPSO;
ComPtr<ID3D12PipelineState> m_quadPointFastPSO;
ComPtr<ID3D12RootSignature> m_createEnergyTexRS;
ComPtr<ID3D12PipelineState> m_createEnergyTexPSO;
int m_width;
int m_height;
DXGI_FORMAT m_format;
D3D12_VIEWPORT m_vpSplitOutput[6];
D3D12_RECT m_scissorSplitOutput[6];
};
}