-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathTiledSplatBlur.h
325 lines (256 loc) · 10 KB
/
TiledSplatBlur.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
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
#pragma once
////////////////////////////////////////////////////////////////////////////////
// Headers
////////////////////////////////////////////////////////////////////////////////
#include "PCH.h"
#include "Common.h"
#include "WavefrontAberration.h"
////////////////////////////////////////////////////////////////////////////////
/// TILED SPLATTING BLUR FUNCTIONS
////////////////////////////////////////////////////////////////////////////////
namespace TiledSplatBlur
{
////////////////////////////////////////////////////////////////////////////////
/** Component and display name. */
static constexpr const char* COMPONENT_NAME = "TiledSplatBlur";
static constexpr const char* DISPLAY_NAME = "Tiled Splat Blur";
static constexpr const char* CATEGORY = "Aberration";
////////////////////////////////////////////////////////////////////////////////
/** A compute-based tile splat depth of field component. */
struct TiledSplatBlurComponent
{
// Input dynamic range
meta_enum(InputDynamicRange, int, HDR, LDR);
// The various output modes available, mainly for debugging
meta_enum(OutputMode, int, Convolution, MergedColor, MergedDepth, FragmentSize, PsfId, LerpFactor, BlurRadius, BlurRadiusFract, BlurRadiusCont, TileBufferSize, Alpha, IncidentAngle);
// The various overlay modes avaiable, entirely for debugging purposes
meta_enum(OverlayMode, int, None, PsfBorder, BlurRadiusBorder, TileBorder, ObjectDepthBorder);
// The various accumulation methods
meta_enum(AccumulationMethod, int, Sum, BackToFront, FrontToBack);
// Type of shader to use
meta_enum(CoefficientLerpMethod, int, Lerp, Trigonometric);
// The various PSF texture formats
meta_enum(PsfTextureFormat, int, F11, F16, F32);
// PSF texture layouts
meta_enum(PsfTextureDepthLayout, int, RadiusBased, DiopterBased);
meta_enum(PsfTextureAngleLayout, int, LayerBased, PsfBased);
// PSF axis handling method
meta_enum(PsfAxisMethod, int, OnAxis, OffAxis);
// The various weight scaling methods (for fragment size)
meta_enum(WeightScaleMethod, int, One, Linear, AreaCircle, AreaSquare);
// The various weight rescaling methods
meta_enum(WeightRescaleMethod, int, LinearRescale, AlphaBlend);
// Type of shader to use
meta_enum(ShaderType, int, Debug, Release, Auto);
// Eye aberration description
Aberration::WavefrontAberration m_aberration;
// Whether the aberration cache should be cleared or not after computation
bool m_clearAberrationCache = false;
// Type of input to use
InputDynamicRange m_inputDynamicRange;
// Output mode
OutputMode m_outputMode;
// Overlay mode
OverlayMode m_overlayMode;
// Accumulation method.
AccumulationMethod m_accumulationMethod;
// Resolution at which to render
int m_renderResolutionId;
// Size of a tile, in pixels
int m_tileSize;
// Max CoC radius
int m_maxCoC;
// Number of wavelengths to consider
int m_numWavelengths;
/** Various group sizes*/
struct GroupSizes
{
// Batch size for the PSF interpolation step.
int m_interpolation;
// Batch size for the fragment merge step.
int m_merge;
// Batch size for the tile splatting step.
int m_splat;
// Batch size for the sorting step.
int m_sort;
// Batch size for the sorting step.
int m_convolution;
} m_groupSizes;
// Number of fragment merge steps to take
int m_fragmentMergeSteps;
// Max sort elements
int m_maxSortElements;
// Fragment merge parameters
struct MergePreset
{
int m_blockSize;
float m_colorSimilarityThreshold;
float m_colorContrastThreshold;
float m_depthSimilarityThreshold;
float m_minBlurRadiusThreshold;
};
// Thresholds for fragment merging
std::vector<MergePreset> m_mergePresets;
// Alpha threshold for early accumulation stop.
float m_alphaThreshold;
// Whether sorting should be applied to the tile buffer or not.
bool m_sortTileBuffer;
// Whether the result is to be normalized or not
bool m_normalizeResult;
// The PSF texture format
PsfTextureFormat m_psfTextureFormat;
// The PSF texture layout
PsfTextureDepthLayout m_psfTextureDepthLayout;
PsfTextureAngleLayout m_psfTextureAngleLayout;
// PSF axis management
PsfAxisMethod m_psfAxisMethod;
// Fragment size weight scaling method
WeightScaleMethod m_weightScaleMethod;
// Fragment rescale method
WeightRescaleMethod m_weightRescaleMethod;
// What type of shader to use
ShaderType m_shaderType;
// Coefficient lerping method
CoefficientLerpMethod m_coeffLerpMethod;
// Reduction terms for the PSF layers
glm::vec3 m_psfLayersS{ 0.0f };
glm::vec3 m_psfLayersP{ 0.0f };
bool m_clearPsfTexture = false;
// Scale factors for the constant and scaled sort depth offsets
float m_sortDepthOffset;
float m_sortDepthScale;
// Depth offset used for debugging, to simulate movement.
float m_depthOffset;
// ---- Private members
// All the aberration presets available.
Aberration::WavefrontAberrationPresets m_aberrationPresets;
// List of derived PSF parameters
struct DerivedPsfParameters
{
size_t m_minBlurRadius;
size_t m_maxBlurRadius;
size_t m_numPsfWeights;
float m_blurRadiusDeg;
};
std::vector<DerivedPsfParameters> m_derivedPsfParameters;
};
////////////////////////////////////////////////////////////////////////////////
/** Tiled splat blur common parameters. */
struct UniformDataCommon
{
// Common, pre-computed values
glm::uvec2 m_numTiles;
glm::ivec2 m_renderResolution;
glm::ivec2 m_paddedResolution;
glm::vec2 m_cameraFov;
GLuint m_fragmentBufferSubentries;
GLuint m_tileBufferCenterSubentries;
GLuint m_tileBufferTotalSubentries;
GLuint m_numSortIterations;
// Run modes
GLuint m_psfAxisMethod;
GLuint m_psfTextureFormat;
GLuint m_psfTextureDepthLayout;
GLuint m_psfTextureAngleLayout;
GLuint m_weightScaleMethod;
GLuint m_weightRescaleMethod;
GLuint m_outputMode;
GLuint m_overlayMode;
GLuint m_accumulationMethod;
// PSF texture settings
alignas(sizeof(glm::vec4)) glm::vec4 m_psfLayersS;
alignas(sizeof(glm::vec4)) glm::vec4 m_psfLayersP;
// Merge settings
GLuint m_numMergeSteps;
GLuint m_mergedFragmentSize;
// Sort settings
GLfloat m_sortOffsetConstant;
GLfloat m_sortOffsetScale;
// Convolution settings
GLuint m_renderChannels;
GLuint m_renderLayers;
GLfloat m_depthOffset;
GLfloat m_alphaThreshold;
GLfloat m_normalizeResult;
// PSF properties
GLuint m_minBlurRadiusCurrent;
GLuint m_maxBlurRadiusCurrent;
GLuint m_minBlurRadiusGlobal;
GLuint m_maxBlurRadiusGlobal;
GLuint m_numDefocuses;
GLuint m_numHorizontalAngles;
GLuint m_numVerticalAngles;
GLuint m_numChannels;
GLuint m_numApertures;
GLuint m_numFocuses;
GLfloat m_objectDistancesMin;
GLfloat m_objectDistancesMax;
GLfloat m_objectDistancesStep;
GLfloat m_apertureMin;
GLfloat m_apertureMax;
GLfloat m_apertureStep;
GLfloat m_focusDistanceMin;
GLfloat m_focusDistanceMax;
GLfloat m_focusDistanceStep;
GLfloat m_incidentAnglesHorMin;
GLfloat m_incidentAnglesHorMax;
GLfloat m_incidentAnglesHorStep;
GLfloat m_incidentAnglesVertMin;
GLfloat m_incidentAnglesVertMax;
GLfloat m_incidentAnglesVertStep;
};
////////////////////////////////////////////////////////////////////////////////
/** Tiled splat blur PSF interpolation parameters. */
struct UniformDataPsfInterpolation
{
GLuint m_radius;
GLuint m_diameter;
};
////////////////////////////////////////////////////////////////////////////////
/** Tiled splat blur fragment merge parameters. */
struct UniformDataFragmentMerge
{
GLuint m_blockSize;
GLfloat m_colorSimilarityThreshold;
GLfloat m_colorContrastThreshold;
GLfloat m_depthSimilarityThreshold;
GLfloat m_minBlurRadiusThreshold;
};
////////////////////////////////////////////////////////////////////////////////
/** Tiled splat blur sort parameters. */
struct UniformDataSort
{
GLuint m_groupId;
GLuint m_groupSize;
GLuint m_compareDistance;
};
////////////////////////////////////////////////////////////////////////////////
/** Tiled splat blur psf parameters. */
struct UniformDataPsfParam
{
GLuint m_minBlurRadius;
GLuint m_maxBlurRadius;
GLuint m_weightStartId;
GLfloat m_blurRadiusDeg;
};
////////////////////////////////////////////////////////////////////////////////
void initObject(Scene::Scene& scene, Scene::Object& object);
////////////////////////////////////////////////////////////////////////////////
void releaseObject(Scene::Scene& scene, Scene::Object& object);
////////////////////////////////////////////////////////////////////////////////
void updateObject(Scene::Scene& scene, Scene::Object* simulationSettings, Scene::Object* object);
////////////////////////////////////////////////////////////////////////////////
bool renderObjectPreconditionLDROpenGL(Scene::Scene& scene, Scene::Object* simulationSettings, Scene::Object* renderSettings, Scene::Object* camera, std::string const& functionName, Scene::Object* object);
////////////////////////////////////////////////////////////////////////////////
bool renderObjectPreconditionHDROpenGL(Scene::Scene& scene, Scene::Object* simulationSettings, Scene::Object* renderSettings, Scene::Object* camera, std::string const& functionName, Scene::Object* object);
////////////////////////////////////////////////////////////////////////////////
void renderObjectOpenGL(Scene::Scene& scene, Scene::Object* simulationSettings, Scene::Object* renderSettings, Scene::Object* camera, std::string const& functionName, Scene::Object* object);
////////////////////////////////////////////////////////////////////////////////
void generateGui(Scene::Scene& scene, Scene::Object* guiSettings, Scene::Object* object);
////////////////////////////////////////////////////////////////////////////////
void demoSetup(Scene::Scene& scene);
}
////////////////////////////////////////////////////////////////////////////////
// Component declaration
DECLARE_COMPONENT(TILED_SPLAT_BLUR, TiledSplatBlurComponent, TiledSplatBlur::TiledSplatBlurComponent)
DECLARE_OBJECT(TILED_SPLAT_BLUR, COMPONENT_ID_TILED_SPLAT_BLUR, COMPONENT_ID_EDITOR_SETTINGS)