Unravel Engine C++ Reference
Loading...
Searching...
No Matches
assao_pass.h
Go to the documentation of this file.
1#pragma once
2
6
7namespace unravel
8{
9
11{
12public:
13
14 struct settings
15 {
16 // clang-format off
17
22 float radius{1.2f};
23
28 float shadow_multiplier{1.0f};
29
34 float shadow_power{1.0f};
35
40 float shadow_clamp{0.98f};
41
48
53 float fade_out_from{50.0f};
54
59 float fade_out_to{200.0f};
60
71 int32_t quality_level{3};
72
78
84 int32_t blur_pass_count{2};
85
93 float sharpness{0.98f};
94
102
109
116
121 bool generate_normals{false};
122
123 // clang-format on
124 };
125
134
135
136 assao_pass() = default;
138 {
139 shutdown();
140 }
141
142 auto init(rtti::context& ctx) -> bool;
143 void run(const camera& camera, gfx::render_view& rview, const run_params& params);
144 auto shutdown() -> int32_t;
145
146private:
147 void create_frame_buffers();
148 void destroy_frame_buffers();
149 void update_uniforms(int32_t _pass, const float* view, const float* proj);
150
151 struct uniforms
152 {
153 enum
154 {
155 NumVec4 = 19
156 };
157
158 void init()
159 {
160 u_params = bgfx::createUniform("u_params", bgfx::UniformType::Vec4, NumVec4);
161 }
162
163 void submit()
164 {
165 bgfx::setUniform(u_params, m_params, NumVec4);
166 }
167
168 void destroy()
169 {
170 bgfx::destroy(u_params);
171 }
172
173 // clang-format off
174 union
175 {
176 struct
177 {
178 /* 0 */ struct { float m_viewportPixelSize[2]; float m_halfViewportPixelSize[2]; };
179 /* 1 */ struct { float m_depthUnpackConsts[2]; float m_unused0[2]; };
180 /* 2 */ struct { float m_ndcToViewMul[2]; float m_ndcToViewAdd[2]; };
181 /* 3 */ struct { float m_perPassFullResCoordOffset[2]; float m_perPassFullResUVOffset[2]; };
182 /* 4 */ struct { float m_viewport2xPixelSize[2]; float m_viewport2xPixelSize_x_025[2]; };
183 /* 5 */ struct { float m_effectRadius; float m_effectShadowStrength; float m_effectShadowPow; float m_effectShadowClamp; };
184 /* 6 */ struct { float m_effectFadeOutMul; float m_effectFadeOutAdd; float m_effectHorizonAngleThreshold; float m_effectSamplingRadiusNearLimitRec; };
185 /* 7 */ struct { float m_depthPrecisionOffsetMod; float m_negRecEffectRadius; float m_loadCounterAvgDiv; float m_adaptiveSampleCountLimit; };
186 /* 8 */ struct { float m_invSharpness; float m_passIndex; float m_quarterResPixelSize[2]; };
187 /* 9-13 */ struct { float m_patternRotScaleMatrices[5][4]; };
188 /* 14 */ struct { float m_normalsUnpackMul; float m_normalsUnpackAdd; float m_detailAOStrength; float m_layer; };
189 /* 15-18 */ struct { float m_normalsWorldToViewspaceMatrix[16]; };
190 };
191
192 float m_params[NumVec4 * 4];
193 };
194 // clang-format on
195
196 bgfx::UniformHandle u_params{bgfx::kInvalidHandle};
197 };
198
199 // Resource handles
200
201 bgfx::ProgramHandle m_prepareDepthsProgram{bgfx::kInvalidHandle};
202 bgfx::ProgramHandle m_prepareDepthsAndNormalsProgram{bgfx::kInvalidHandle};
203 bgfx::ProgramHandle m_prepareDepthsHalfProgram{bgfx::kInvalidHandle};
204 bgfx::ProgramHandle m_prepareDepthsAndNormalsHalfProgram{bgfx::kInvalidHandle};
205 bgfx::ProgramHandle m_prepareDepthMipProgram{bgfx::kInvalidHandle};
206 bgfx::ProgramHandle m_generateQ0Program{bgfx::kInvalidHandle};
207 bgfx::ProgramHandle m_generateQ1Program{bgfx::kInvalidHandle};
208 bgfx::ProgramHandle m_generateQ2Program{bgfx::kInvalidHandle};
209 bgfx::ProgramHandle m_generateQ3Program{bgfx::kInvalidHandle};
210 bgfx::ProgramHandle m_generateQ3BaseProgram{bgfx::kInvalidHandle};
211
212 bgfx::ProgramHandle m_generateQ0ProgramRgba16f{bgfx::kInvalidHandle};
213 bgfx::ProgramHandle m_generateQ1ProgramRgba16f{bgfx::kInvalidHandle};
214 bgfx::ProgramHandle m_generateQ2ProgramRgba16f{bgfx::kInvalidHandle};
215 bgfx::ProgramHandle m_generateQ3ProgramRgba16f{bgfx::kInvalidHandle};
216 bgfx::ProgramHandle m_generateQ3BaseProgramRgba16f{bgfx::kInvalidHandle};
217
218 bgfx::ProgramHandle m_smartBlurProgram{bgfx::kInvalidHandle};
219 bgfx::ProgramHandle m_smartBlurWideProgram{bgfx::kInvalidHandle};
220 bgfx::ProgramHandle m_nonSmartBlurProgram{bgfx::kInvalidHandle};
221 bgfx::ProgramHandle m_applyProgram{bgfx::kInvalidHandle};
222 bgfx::ProgramHandle m_nonSmartApplyProgram{bgfx::kInvalidHandle};
223 bgfx::ProgramHandle m_nonSmartHalfApplyProgram{bgfx::kInvalidHandle};
224 bgfx::ProgramHandle m_generateImportanceMapProgram{bgfx::kInvalidHandle};
225 bgfx::ProgramHandle m_postprocessImportanceMapAProgram{bgfx::kInvalidHandle};
226 bgfx::ProgramHandle m_postprocessImportanceMapBProgram{bgfx::kInvalidHandle};
227 bgfx::ProgramHandle m_loadCounterClearProgram{bgfx::kInvalidHandle};
228
229 bgfx::ProgramHandle m_updateGBufferProgram{bgfx::kInvalidHandle};
230
231 // Shader uniforms
232 bgfx::UniformHandle u_rect{bgfx::kInvalidHandle};
233
234 // Uniforms to identify texture samples
235 bgfx::UniformHandle s_normal{bgfx::kInvalidHandle};
236 bgfx::UniformHandle s_depth{bgfx::kInvalidHandle};
237 bgfx::UniformHandle s_ao{bgfx::kInvalidHandle};
238 bgfx::UniformHandle s_blurInput{bgfx::kInvalidHandle};
239 bgfx::UniformHandle s_finalSSAO{bgfx::kInvalidHandle};
240 bgfx::UniformHandle s_depthSource{bgfx::kInvalidHandle};
241 bgfx::UniformHandle s_viewspaceDepthSource{bgfx::kInvalidHandle};
242 bgfx::UniformHandle s_viewspaceDepthSourceMirror{bgfx::kInvalidHandle};
243 bgfx::UniformHandle s_importanceMap{bgfx::kInvalidHandle};
244
245 // Various render targets
246 bgfx::TextureHandle m_halfDepths[4]{{bgfx::kInvalidHandle},
247 {bgfx::kInvalidHandle},
248 {bgfx::kInvalidHandle},
249 {bgfx::kInvalidHandle}};
250 bgfx::TextureHandle m_pingPongHalfResultA{bgfx::kInvalidHandle};
251 bgfx::TextureHandle m_pingPongHalfResultB{bgfx::kInvalidHandle};
252 bgfx::TextureHandle m_finalResults{bgfx::kInvalidHandle};
253 bgfx::TextureHandle m_aoMap{bgfx::kInvalidHandle};
254 bgfx::TextureHandle m_normals{bgfx::kInvalidHandle};
255
256 // Only needed for quality level 3 (adaptive quality)
257 bgfx::TextureHandle m_importanceMap{bgfx::kInvalidHandle};
258 bgfx::TextureHandle m_importanceMapPong{bgfx::kInvalidHandle};
259 bgfx::DynamicIndexBufferHandle m_loadCounter{bgfx::kInvalidHandle};
260
261 settings m_settings{};
262 uniforms m_uniforms{};
263
264 uint32_t m_width{};
265 uint32_t m_height{};
266
267 int32_t m_size[2]{};
268 int32_t m_halfSize[2]{};
269 int32_t m_quarterSize[2]{};
270 int32_t m_fullResOutScissorRect[4]{};
271 int32_t m_halfResOutScissorRect[4]{};
272 int32_t m_border{};
273
274 std::vector<gpu_program::ptr> m_programs;
275};
276} // namespace unravel
auto init(rtti::context &ctx) -> bool
void run(const camera &camera, gfx::render_view &rview, const run_params &params)
auto shutdown() -> int32_t
Class representing a camera. Contains functionality for manipulating and updating a camera....
Definition camera.h:35