forked from GameTechDev/CloudsGPUPro6
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLightSctrPostProcess.h
232 lines (183 loc) · 10.5 KB
/
LightSctrPostProcess.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
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
/////////////////////////////////////////////////////////////////////////////////////////////
// Copyright 2017 Intel Corporation
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or imlied.
// See the License for the specific language governing permissions and
// limitations under the License.
/////////////////////////////////////////////////////////////////////////////////////////////
#pragma once
#include <D3DX11.h>
#include <D3DX10math.h>
#include "RenderTechnique.h"
#include "structures.fxh"
struct SFrameAttribs
{
ID3D11Device *pd3dDevice;
ID3D11DeviceContext *pd3dDeviceContext;
double dElapsedTime;
SLightAttribs *pLightAttribs;
ID3D11Buffer *pcbLightAttribs;
ID3D11Buffer *pcbCameraAttribs;
//SCameraAttribs CameraAttribs;
ID3D11ShaderResourceView *ptex2DSrcColorBufferSRV;
ID3D11RenderTargetView *ptex2DSrcColorBufferRTV;
ID3D11DepthStencilView *ptex2DSrcDepthBufferDSV;
ID3D11ShaderResourceView *ptex2DSrcDepthBufferSRV;
ID3D11ShaderResourceView *ptex2DShadowMapSRV;
ID3D11RenderTargetView *pDstRTV;
ID3D11ShaderResourceView *ptex2DScrSpaceCloudTransparencySRV;
ID3D11ShaderResourceView *ptex2DScrSpaceCloudMinMaxDistSRV;
ID3D11ShaderResourceView *ptex2DScrSpaceCloudColorSRV;
ID3D11ShaderResourceView *ptex2DLiSpCloudTransparencySRV;
ID3D11ShaderResourceView *ptex2DLiSpCloudMinMaxDepthSRV;
};
#undef float4
#undef float3
#undef float2
#include <atlcomcli.h>
class CLightSctrPostProcess
{
public:
CLightSctrPostProcess();
~CLightSctrPostProcess();
HRESULT OnCreateDevice(ID3D11Device* in_pd3dDevice,
ID3D11DeviceContext *in_pd3dDeviceContext);
void OnDestroyDevice();
HRESULT OnResizedSwapChain(ID3D11Device* pd3dDevice, UINT uiBackBufferWidth, UINT uiBackBufferHeight);
void PerformPostProcessing(SFrameAttribs &FrameAttribs,
SPostProcessingAttribs &PPAttribs);
void ComputeSunColor(const D3DXVECTOR3 &vDirectionOnSun,
const D3DXVECTOR4 &f4ExtraterrestrialSunColor,
D3DXVECTOR4 &f4SunColorAtGround,
D3DXVECTOR4 &f4AmbientLight);
void RenderSun(SFrameAttribs &FrameAttribs);
ID3D11Buffer *GetMediaAttribsCB(){return m_pcbMediaAttribs;}
ID3D11ShaderResourceView* GetPrecomputedNetDensitySRV(){return m_ptex2DOccludedNetDensityToAtmTopSRV;}
ID3D11ShaderResourceView* GetAmbientSkyLightSRV(ID3D11Device *pDevice, ID3D11DeviceContext *pContext);
private:
void ReconstructCameraSpaceZ(SFrameAttribs &FrameAttribs);
void RenderSliceEndpoints(SFrameAttribs &FrameAttribs);
void RenderCoordinateTexture(SFrameAttribs &FrameAttribs);
void RenderCoarseUnshadowedInsctr(SFrameAttribs &FrameAttribs);
void RefineSampleLocations(SFrameAttribs &FrameAttribs);
void MarkRayMarchingSamples(SFrameAttribs &FrameAttribs);
void RenderSliceUVDirAndOrig(SFrameAttribs &FrameAttribs);
void Build1DMinMaxMipMap(SFrameAttribs &FrameAttribs, int iCascadeIndex);
void RenderCldDensEpipolarScan(SFrameAttribs &FrameAttribs, int iCascadeIndex);
void DoRayMarching(SFrameAttribs &FrameAttribs, UINT uiMaxStepsAlongRay, const SShadowMapAttribs &SMAttribs, int iCascadeIndex);
void InterpolateInsctrIrradiance(SFrameAttribs &FrameAttribs);
void UnwarpEpipolarScattering(SFrameAttribs &FrameAttribs, bool bRenderLuminance);
void UpdateAverageLuminance(SFrameAttribs &FrameAttribs);
void FixInscatteringAtDepthBreaks(SFrameAttribs &FrameAttribs, UINT uiMaxStepsAlongRay, const SShadowMapAttribs &SMAttribs, bool bRenderLuminance);
void RenderSampleLocations(SFrameAttribs &FrameAttribs);
HRESULT CreatePrecomputedOpticalDepthTexture(ID3D11Device *pDevice, ID3D11DeviceContext *pContext);
HRESULT CreatePrecomputedScatteringLUT(ID3D11Device *pDevice, ID3D11DeviceContext *pContext);
void CreateRandomSphereSamplingTexture(ID3D11Device *pDevice);
void CreateLowResLuminanceTexture(ID3D11Device *pDevice);
void CreateAmbientSkyLightTexture(ID3D11Device *pDevice, ID3D11DeviceContext *pContext);
void DefineMacros(class CD3DShaderMacroHelper &Macros);
SPostProcessingAttribs m_PostProcessingAttribs;
bool m_bUseCombinedMinMaxTexture;
UINT m_uiSampleRefinementCSThreadGroupSize;
UINT m_uiSampleRefinementCSMinimumThreadGroupSize;
CComPtr<ID3D11ShaderResourceView> m_ptex2DSliceEndpointsSRV;
CComPtr<ID3D11RenderTargetView> m_ptex2DSliceEndpointsRTV;
CComPtr<ID3D11ShaderResourceView> m_ptex2DCoordinateTextureSRV;
CComPtr<ID3D11RenderTargetView> m_ptex2DCoordinateTextureRTV;
CComPtr<ID3D11DepthStencilView> m_ptex2DEpipolarImageDSV;
CComPtr<ID3D11ShaderResourceView> m_ptex2DEpipolarCamSpaceZSRV;
CComPtr<ID3D11RenderTargetView> m_ptex2DEpipolarCamSpaceZRTV;
CComPtr<ID3D11ShaderResourceView> m_ptex2DEpipolarCloudTranspSRV;
CComPtr<ID3D11RenderTargetView> m_ptex2DEpipolarCloudTranspRTV;
CComPtr<ID3D11ShaderResourceView> m_ptex2DInterpolationSourcesSRV;
CComPtr<ID3D11UnorderedAccessView> m_ptex2DInterpolationSourcesUAV;
CComPtr<ID3D11ShaderResourceView> m_ptex2DInitialScatteredLightSRV;
CComPtr<ID3D11RenderTargetView> m_ptex2DInitialScatteredLightRTV;
CComPtr<ID3D11ShaderResourceView> m_ptex2DEpipolarInscatteringSRV, m_ptex2DEpipolarExtinctionSRV;
CComPtr<ID3D11RenderTargetView> m_ptex2DEpipolarInscatteringRTV, m_ptex2DEpipolarExtinctionRTV;
CComPtr<ID3D11ShaderResourceView> m_ptex2DCameraSpaceZSRV;
CComPtr<ID3D11RenderTargetView> m_ptex2DCameraSpaceZRTV;
CComPtr<ID3D11ShaderResourceView> m_ptex2DSliceUVDirAndOriginSRV;
CComPtr<ID3D11RenderTargetView> m_ptex2DSliceUVDirAndOriginRTV;
CComPtr<ID3D11ShaderResourceView> m_ptex2DMinMaxShadowMapSRV[2];
CComPtr<ID3D11RenderTargetView> m_ptex2DMinMaxShadowMapRTV[2];
CComPtr<ID3D11ShaderResourceView> m_ptex2DCldDensEpipolarScanSRV[2];
CComPtr<ID3D11RenderTargetView> m_ptex2DCldDensEpipolarScanRTV[2];
static const int sm_iNumPrecomputedHeights = 1024;
static const int sm_iNumPrecomputedAngles = 1024;
CComPtr<ID3D11ShaderResourceView> m_ptex2DOccludedNetDensityToAtmTopSRV;
CComPtr<ID3D11RenderTargetView> m_ptex2DOccludedNetDensityToAtmTopRTV;
static const int sm_iPrecomputedSctrUDim = 32/2;
static const int sm_iPrecomputedSctrVDim = 128;
static const int sm_iPrecomputedSctrWDim = 64/2;
static const int sm_iPrecomputedSctrQDim = 16;
CComPtr<ID3D11ShaderResourceView> m_ptex3DSingleScatteringSRV;
CComPtr<ID3D11ShaderResourceView> m_ptex3DHighOrderScatteringSRV;
CComPtr<ID3D11ShaderResourceView> m_ptex3DMultipleScatteringSRV;
static const int sm_iNumRandomSamplesOnSphere = 128;
CComPtr<ID3D11ShaderResourceView> m_ptex2DSphereRandomSamplingSRV;
HRESULT CreateTextures(ID3D11Device* pd3dDevice);
HRESULT CreateMinMaxShadowMap(ID3D11Device* pd3dDevice);
HRESULT CreateCldDensEpipolarScanTex(ID3D11Device* pd3dDevice);
CComPtr<ID3D11DepthStencilView> m_ptex2DScreenSizeDSV;
static const int sm_iLowResLuminanceMips = 7; // 64x64
CComPtr<ID3D11RenderTargetView> m_ptex2DLowResLuminanceRTV;
CComPtr<ID3D11ShaderResourceView> m_ptex2DLowResLuminanceSRV;
CComPtr<ID3D11RenderTargetView> m_ptex2DAverageLuminanceRTV;
CComPtr<ID3D11ShaderResourceView> m_ptex2DAverageLuminanceSRV;
static const int sm_iAmbientSkyLightTexDim = 1024;
CComPtr<ID3D11RenderTargetView> m_ptex2DAmbientSkyLightRTV;
CComPtr<ID3D11ShaderResourceView> m_ptex2DAmbientSkyLightSRV;
UINT m_uiBackBufferWidth, m_uiBackBufferHeight;
LPCTSTR m_strEffectPath;
CComPtr<ID3D11VertexShader> m_pGenerateScreenSizeQuadVS;
CRenderTechnique m_ReconstrCamSpaceZTech;
CRenderTechnique m_RendedSliceEndpointsTech;
CRenderTechnique m_RendedCoordTexTech;
CRenderTechnique m_RefineSampleLocationsTech;
CRenderTechnique m_RenderCoarseUnshadowedInsctrTech;
CRenderTechnique m_MarkRayMarchingSamplesInStencilTech;
CRenderTechnique m_RenderSliceUVDirInSMTech;
CRenderTechnique m_InitializeMinMaxShadowMapTech;
CRenderTechnique m_ComputeMinMaxSMLevelTech;
CRenderTechnique m_InitializeCldDensEpipolarScanTech;
CRenderTechnique m_ComputeCldDensEpiScanLevelTech;
CRenderTechnique m_DoRayMarchTech[2]; // 0 - min/max optimization disabled; 1 - min/max optimization enabled
CRenderTechnique m_InterpolateIrradianceTech;
CRenderTechnique m_UnwarpEpipolarSctrImgTech;
CRenderTechnique m_UnwarpAndRenderLuminanceTech;
CRenderTechnique m_UpdateAverageLuminanceTech;
CRenderTechnique m_FixInsctrAtDepthBreaksTech[4]; // bit 0: 0 - perform ray marching, 1 - perform ray marching and attenuate background
// bit 1: 0 - perform tone mapping, 1 - render luminance only
CRenderTechnique m_RenderSampleLocationsTech;
CRenderTechnique m_RenderSunTech;
CRenderTechnique m_PrecomputeSingleSctrTech;
CRenderTechnique m_ComputeSctrRadianceTech;
CRenderTechnique m_ComputeScatteringOrderTech;
CRenderTechnique m_AddScatteringOrderTech;
CComPtr<ID3D11SamplerState> m_psamLinearClamp;
CComPtr<ID3D11SamplerState> m_psamLinearBorder0;
CComPtr<ID3D11SamplerState> m_psamComparison;
CComPtr<ID3D11SamplerState> m_psamPointClamp;
CComPtr<ID3D11DepthStencilState> m_pEnableDepthCmpEqDS;
CComPtr<ID3D11DepthStencilState> m_pDisableDepthTestDS;
CComPtr<ID3D11DepthStencilState> m_pDisableDepthTestIncrStencilDS;
CComPtr<ID3D11DepthStencilState> m_pNoDepth_StEqual_IncrStencilDS;
CComPtr<ID3D11DepthStencilState> m_pNoDepth_StEqual_KeepStencilDS;
CComPtr<ID3D11RasterizerState> m_pSolidFillNoCullRS;
CComPtr<ID3D11BlendState> m_pDefaultBS, m_pAdditiveBlendBS, m_pAlphaBlendBS;
void ComputeScatteringCoefficients(ID3D11DeviceContext *pDeviceCtx = NULL);
const float m_fTurbidity;
SAirScatteringAttribs m_MediaParams;
CComPtr<ID3D11Buffer> m_pcbPostProcessingAttribs;
CComPtr<ID3D11Buffer> m_pcbMediaAttribs;
CComPtr<ID3D11Buffer> m_pcbMiscParams;
};