Geogram Version 1.10.2
A programming library of geometric algorithms
Loading...
Searching...
No Matches
ambient_occlusion.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2000-2022 Inria
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 *
8 * * Redistributions of source code must retain the above copyright notice,
9 * this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above copyright notice,
11 * this list of conditions and the following disclaimer in the documentation
12 * and/or other materials provided with the distribution.
13 * * Neither the name of the ALICE Project-Team nor the names of its
14 * contributors may be used to endorse or promote products derived from this
15 * software without specific prior written permission.
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
18 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
21 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27 * POSSIBILITY OF SUCH DAMAGE.
28 *
29 * Contact: Bruno Levy
30 *
31 * https://www.inria.fr/fr/bruno-levy
32 *
33 * Inria,
34 * Domaine de Voluceau,
35 * 78150 Le Chesnay - Rocquencourt
36 * FRANCE
37 *
38 */
39
40#ifndef H_OGF_RENDERER_CONTEXT_AMBIENT_OCCLUSION_H
41#define H_OGF_RENDERER_CONTEXT_AMBIENT_OCCLUSION_H
42
46
51
52namespace GEO {
53
58 public:
59
64
69
73 double required_GLSL_version() const override;
74
78 void pre_render(index_t w, index_t h) override;
79
83 void post_render() override;
84
88 void update() override;
89
96 return lightness_;
97 }
98
105 lightness_ = x;
106 }
107
114 return contrast_;
115 }
116
122 contrast_ = x;
123 }
124
130 return blur_width_;
131 }
132
138 blur_width_ = x;
139 }
140
149 return nb_directions_;
150 }
151
160 nb_directions_ = x;
161 }
162
169 double get_max_radius() const {
170 return max_radius_;
171 }
172
179 void set_max_radius(double x) {
180 max_radius_ = x;
181 geo_clamp(max_radius_, 0.0, 1.0);
182 }
183
189 double get_step_mul() const {
190 return step_mul_;
191 }
192
198 void set_step_mul(double x) {
199 step_mul_ = std::max(x,1.0);
200 }
201
210 return downscale_factor_;
211 }
212
222#ifdef GEO_OS_EMSCRIPTEN
223 geo_argused(x);
224#else
225 if(x > 0 && x != downscale_factor_) {
226 downscale_factor_ = x;
227 resize(width(),height());
228 }
229#endif
230 }
231
232 protected:
236 void initialize(index_t w, index_t h) override;
237
241 void resize(index_t w, index_t h) override;
242
250
257
263
272 void blur();
273
280
281 private:
282 index_t lightness_;
283 index_t contrast_;
284 index_t blur_width_;
285 index_t nb_directions_;
286 double max_radius_;
287 double step_mul_;
288
289 GLint proj_inv_loc_;
290 GLfloat proj_inv_[16];
291
292 GLuint random_tex_;
293 GLuint SSAO_program_;
294
295 // Downscale
296 GLuint downscale_program_;
297 index_t downscale_factor_;
298 FrameBufferObject downscale_Z_;
299 FrameBufferObject downscale_AO_;
300
301 // Blur
302 FrameBufferObject blur_1_;
303 FrameBufferObject blur_2_;
304 GLuint blur_program_;
305 };
306
311
312}
313
314#endif
double get_step_mul() const
Gets the multiplicative factor applied to each step when traversing from a pixel.
void resize(index_t w, index_t h) override
Callback called whenever the rendering context is resized.
index_t get_downscale_factor() const
Gets the downscale factor.
void update() override
Callback called whenever parameters are changed in the GUI.
void set_blur_width(index_t x)
Sets the size of the blurring kernel.
void set_contrast(index_t x)
Sets the contrast.
double required_GLSL_version() const override
Gets the minimum required GLSL version needed to execute the shaders in this FullScreenEffectImpl.
index_t get_contrast() const
Gets the contrast.
void set_downscale_factor(index_t x)
Sets the downscale factor.
void set_lightness(index_t x)
Sets the lightness.
double get_max_radius() const
Gets the maximum radius around a pixel where ambient occlusion is computed.
void get_proj_inv()
Gets the inverse of the projection transform.
void set_max_radius(double x)
Sets the maximum radius around a pixel where ambient occlusion is computed.
void display_final_texture()
Displays the final result.
index_t get_lightness() const
Gets the lightness.
void pre_render(index_t w, index_t h) override
Callback called at the beginning of each frame.
~AmbientOcclusionImpl() override
AmbientOcclusionImpl destructor.
void set_step_mul(double x)
Sets the multiplicative factor applied to each step when traversing from a pixel.
void compute_SSAO()
Computes the ambient occlusion in the blur_1_ FrameBufferObject, from the depth textures.
void set_nb_directions(index_t x)
Sets the number of directions.
void initialize(index_t w, index_t h) override
Callback called the first time this FullScreenEffectImpl is used.
void blur()
Applies a Gaussian blur to the (raw) ambient occlusion computed by apply_shader().
void post_render() override
Callback called at the end of each frame.
AmbientOcclusionImpl()
AmbientOcclusionImpl constructor.
index_t get_nb_directions() const
Gets the number of directions.
index_t get_blur_width() const
Gets the size of the blurring kernel.
void create_random_tex()
Creates a texture with random values in it.
An OpenGL frame buffer object.
FullScreenEffectImpl()
FullScreenEffectImpl constructor.
index_t width() const
Gets the width of the rendering context.
index_t height() const
Gets the height of the rendering context.
A smart pointer with reference-counted copy semantics.
Helper class for manipulating OpenGL frame buffer objects.
Low-level base class for full screen effects.
#define GEOGRAM_GFX_API
Linkage declaration for geogram symbols.
Definition defs.h:55
Common include file, providing basic definitions. Should be included before anything else by all head...
Global Vorpaline namespace.
Definition basic.h:55
void geo_argused(const T &)
Suppresses compiler warnings about unused parameters.
Definition argused.h:60
void geo_clamp(T &x, T min, T max)
Clamps a value to a range.
Definition numeric.h:326
geo_index_t index_t
The type for storing and manipulating indices.
Definition numeric.h:341
SmartPointer< AmbientOcclusionImpl > AmbientOcclusionImpl_var
An automatic reference-counted pointer to an AmbientOcclusionImpl.