Geogram  Version 1.9.1-rc
A programming library of geometric algorithms
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 
52 namespace 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 
202  protected:
206  void initialize(index_t w, index_t h) override;
207 
211  void resize(index_t w, index_t h) override;
212 
220 
227 
232  void compute_SSAO();
233 
242  void blur();
243 
249  void get_proj_inv();
250 
251  private:
252  index_t lightness_;
253  index_t contrast_;
254  index_t blur_width_;
255  index_t nb_directions_;
256  double max_radius_;
257  double step_mul_;
258 
259  GLint proj_inv_loc_;
260  GLfloat proj_inv_[16];
261 
262  GLuint random_tex_;
263  GLuint SSAO_program_;
264 
265  // Blur
266  FrameBufferObject blur_1_;
267  FrameBufferObject blur_2_;
268  GLuint blur_program_;
269  };
270 
275 
276 }
277 
278 #endif
Implementation of AmbientOcclusion full screen effect.
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.
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_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.
Implementation of full screen effects.
A smart pointer with reference-counted copy semantics.
Definition: smart_pointer.h:76
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_clamp(T &x, T min, T max)
Clamps a value to a range.
Definition: numeric.h:314
geo_index_t index_t
The type for storing and manipulating indices.
Definition: numeric.h:329
SmartPointer< AmbientOcclusionImpl > AmbientOcclusionImpl_var
An automatic reference-counted pointer to an AmbientOcclusionImpl.