This repository was archived by the owner on Apr 19, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 21
/
Copy pathCloudySky.h
234 lines (189 loc) · 7.56 KB
/
CloudySky.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
233
234
/////////////////////////////////////////////////////////////////////////////////////////////
// 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 <d3dx9math.h>
#include "Structures.fxh"
// Temporary:
#undef float2
#undef float3
#undef float4
#include <stdio.h>
#include "CPUT_DX11.h"
#include "CPUTMaterial.h"
#include <D3D11.h> // for D3D11_BUFFER_DESC
#include <xnamath.h> // for XMFLOAT
#include <time.h> // for srand(time)
#include "EarthHemisphere.h"
#include "ElevationDataSource.h"
struct FrameConstantBuffer
{
XMFLOAT4 Eye;
XMFLOAT4 LookAt;
XMFLOAT4 Up;
XMFLOAT4 LightDirection;
XMMATRIX worldMatrix;
XMMATRIX viewMatrix;
XMMATRIX projectionMatrix;
};
static const CPUTControlID ID_MAIN_PANEL = 10;
static const CPUTControlID ID_SCATTERING_ATTRIBS_PANEL = 20;
static const CPUTControlID ID_ADDITIONAL_ATTRIBS_PANEL = 30;
static const CPUTControlID ID_TONE_MAPPING_ATTRIBS_PANEL = 40;
static const CPUTControlID ID_HELP_TEXT_PANEL = 50;
static const CPUTControlID ID_IGNORE_CONTROL_ID = -1;
static const CPUTControlID CONTROL_PANEL_IDS[] = {ID_MAIN_PANEL, ID_SCATTERING_ATTRIBS_PANEL, ID_ADDITIONAL_ATTRIBS_PANEL, ID_TONE_MAPPING_ATTRIBS_PANEL};
enum CONTROL_IDS
{
ID_SELECT_PANEL_COMBO = 100,
ID_FULLSCREEN_BUTTON,
ID_ENABLE_VSYNC,
ID_ENABLE_LIGHT_SCATTERING,
ID_ENABLE_LIGHT_SHAFTS,
ID_ENABLE_CLOUDS,
ID_SHAFTS_FROM_CLOUDS_MODE,
ID_ANIMATE_SUN,
ID_LIGHT_SCTR_TECHNIQUE,
ID_NUM_INTEGRATION_STEPS,
ID_NUM_EPIPOLAR_SLICES,
ID_NUM_SAMPLES_IN_EPIPOLAR_SLICE,
ID_INITIAL_SAMPLE_STEP_IN_EPIPOLAR_SLICE,
ID_EPIPOLE_SAMPLING_DENSITY_FACTOR,
ID_REFINEMENT_THRESHOLD,
ID_SHOW_SAMPLING,
ID_MIN_MAX_SHADOW_MAP_OPTIMIZATION,
ID_OPTIMIZE_SAMPLE_LOCATIONS,
ID_CORRECT_SCATTERING_AT_DEPTH_BREAKS,
ID_SCATTERING_SCALE,
ID_MIDDLE_GRAY,
ID_WHITE_POINT,
ID_LUM_SATURATION,
ID_AUTO_EXPOSURE,
ID_TONE_MAPPING_MODE,
ID_LIGHT_ADAPTATION,
ID_SHOW_DEPTH_BREAKS,
ID_SHOW_LIGHTING_ONLY_CHECK,
ID_SHADOW_MAP_RESOLUTION,
ID_CLOUD_DENSITY_MAP_RESOLUTION,
ID_CLOUD_DOWNSCALE_FACTOR_DROPDOWN,
ID_CLOUDINESS_SLIDER,
ID_CLOUD_ALTITUDE_SLIDER,
ID_CLOUD_THICKNESS_SLIDER,
ID_CLOUD_SPEED_SLIDER,
ID_NUM_PARTICLE_RINGS_SLIDER,
ID_PARTICLE_RING_DIM_SLIDER,
ID_MAX_PARTICLE_LAYERS_SLIDER,
ID_CLOUD_TYPE_DROPDOWN,
ID_VOLUMERTIC_BLENDING_CHECK,
ID_PARTICLE_RENDERING_DISTANCE_SLIDER,
ID_USE_CUSTOM_SCTR_COEFFS_CHECK,
ID_RLGH_COLOR_BTN,
ID_MIE_COLOR_BTN,
ID_SINGLE_SCTR_MODE_DROPDOWN,
ID_MULTIPLE_SCTR_MODE_DROPDOWN,
ID_NUM_CASCADES_DROPDOWN,
ID_SHOW_CASCADES_CHECK,
ID_SMOOTH_SHADOWS_CHECK,
ID_BEST_CASCADE_SEARCH_CHECK,
ID_CASCADE_PARTITIONING_SLIDER,
ID_CASCADE_PROCESSING_MODE_DROPDOWN,
ID_FIRST_CASCADE_TO_RAY_MARCH_DROPDOWN,
ID_REFINEMENT_CRITERION_DROPDOWN,
ID_EXTINCTION_EVAL_MODE_DROPDOWN,
ID_MIN_MAX_MIP_FORMAT_DROPDOWN,
ID_AEROSOL_DENSITY_SCALE_SLIDER,
ID_AEROSOL_ABSORBTION_SCALE_SLIDER,
ID_TEXTLINES = 1000
};
// DirectX 11 Sample
//-----------------------------------------------------------------------------
class CCloudySkySample:public CPUT_DX11
{
public:
CCloudySkySample();
virtual ~CCloudySkySample();
// Event handling
virtual CPUTEventHandledCode HandleKeyboardEvent(CPUTKey key);
virtual CPUTEventHandledCode HandleMouseEvent(int x, int y, int wheel, CPUTMouseState state);
virtual void HandleCallbackEvent( CPUTEventID Event, CPUTControlID ControlID, CPUTControl* pControl );
// 'callback' handlers for rendering events. Derived from CPUT_DX11
virtual void Create();
virtual void Render(double deltaSeconds);
virtual void Update(double deltaSeconds);
virtual void ResizeWindow(UINT width, UINT height);
void Shutdown();
HRESULT ParseConfigurationFile( LPCWSTR ConfigFilePath );
private:
HRESULT CreateShadowMap(ID3D11Device* pd3dDevice);
void ReleaseShadowMap();
HRESULT CreateCloudDensityMap(ID3D11Device* pd3dDevice);
void ReleaseCloudDensityMap();
HRESULT CreateTmpBackBuffAndDepthBuff(ID3D11Device* pd3dDevice);
void ReleaseTmpBackBuffAndDepthBuff();
void RenderShadowMap(ID3D11DeviceContext *pContext,
SLightAttribs &LightAttribs,
float fTime);
void Destroy();
float GetSceneExtent();
class CLightSctrPostProcess *m_pLightSctrPP;
class CCloudsController *m_pCloudsController;
CComPtr<ID3D11Buffer> m_pcbCameraAttribs;
UINT m_uiShadowMapResolution, m_uiCloudDensityMapResolution;
float m_fCascadePartitioningFactor;
bool m_bEnableLightScattering;
bool m_bAnimateSun;
static const int m_iMinEpipolarSlices = 32;
static const int m_iMaxEpipolarSlices = 2048;
static const int m_iMinSamplesInEpipolarSlice = 32;
static const int m_iMaxSamplesInEpipolarSlice = 2048;
static const int m_iMaxEpipoleSamplingDensityFactor = 32;
static const int m_iMinInitialSamplesInEpipolarSlice = 8;
SPostProcessingAttribs m_PPAttribs;
SGlobalCloudAttribs m_CloudAttribs;
float m_fScatteringScale;
std::vector< CComPtr<ID3D11DepthStencilView> > m_pShadowMapDSVs;
CComPtr<ID3D11ShaderResourceView> m_pShadowMapSRV;
std::vector< CComPtr<ID3D11RenderTargetView> > m_pLiSpCloudTransparencyRTVs, m_pLiSpCloudMinMaxDepthRTVs;
CComPtr<ID3D11ShaderResourceView> m_pLiSpCloudTransparencySRV, m_pLiSpCloudMinMaxDepthSRV;
CPUTRenderTargetColor* m_pOffscreenRenderTarget;
CPUTRenderTargetDepth* m_pOffscreenDepth;
CPUTCamera* m_pDirectionalLightCamera;
CPUTCamera* m_pDirLightOrienationCamera;
CPUTCameraController* mpCameraController;
CPUTCameraController* m_pLightController;
CPUTTimerWin m_Timer;
float m_fElapsedTime;
float m_fCloudTime;
float m_fCloudTimeScale;
D3DXVECTOR4 m_f4LightColor;
int m_iGUIMode;
SRenderingParams m_TerrainRenderParams;
std::wstring m_strRawDEMDataFile;
std::wstring m_strMtrlMaskFile;
std::wstring m_strTileTexPaths[CEarthHemsiphere::NUM_TILE_TEXTURES];
std::wstring m_strNormalMapTexPaths[CEarthHemsiphere::NUM_TILE_TEXTURES];
std::auto_ptr<CElevationDataSource> m_pElevDataSource;
CEarthHemsiphere m_EarthHemisphere;
D3DXMATRIX m_CameraViewMatrix;
D3DXVECTOR3 m_CameraPos;
CComPtr<ID3D11Buffer> m_pcbLightAttribs;
UINT m_uiBackBufferWidth, m_uiBackBufferHeight;
CPUTDropdown* m_pSelectPanelDropDowns[_countof(CONTROL_PANEL_IDS)];
UINT m_uiSelectedPanelInd;
float m_fMinElevation, m_fMaxElevation;
private:
CCloudySkySample(const CCloudySkySample&);
const CCloudySkySample& operator = (const CCloudySkySample&);
};