Tucano  0.1
A library for rapid prototyping with modern OpenGL and GLSL
Tucano::Effects::SSAO Class Reference

#include <ssao.hpp>

Inheritance diagram for Tucano::Effects::SSAO:
Tucano::Effect

Public Member Functions

 SSAO (float rad=1.0)
 Default constructor. More...
 
virtual void initialize (void)
 Initializes the SSAO effects,. More...
 
void createViewSpaceBuffer (Tucano::Mesh &mesh, const Tucano::Camera &camera_trackball, const Tucano::Camera &light_trackball)
 First pass of the SSAO, writes coords, normals and colors to a buffer. More...
 
void computeSSAO (const Tucano::Camera &camera)
 Compute the Ambient Occlusion factor for each pixel. More...
 
void applySSAO (const Tucano::Camera &light_trackball)
 Blur SSAO result and mix with original render. More...
 
virtual void render (Tucano::Mesh &mesh, const Tucano::Camera &camera_trackball, const Tucano::Camera &light_trackball)
 Renders the mesh with the desired effect. More...
 
int getIntensity (void)
 Get intensity value. More...
 
void setIntensity (int value)
 Set intensity value. More...
 
int getRadius (void)
 Get radius value. More...
 
void setRadius (int value)
 Set radius value. More...
 
void setScale (int value)
 Set global scale value. More...
 
void setBlurRange (int value)
 
void toggleAmbientPass (void)
 Toggles the displayAmbientPass flag. More...
 
- Public Member Functions inherited from Tucano::Effect
 Effect (string shadersDir="shaders/")
 Default constructor. More...
 
virtual ShaderloadShader (string shader_name)
 Loads a shader by filename, initializes it, and inserts in shaders list. More...
 
virtual void loadShader (Shader &shader, string shader_name)
 
virtual ShaderloadShader (string shader_name, string vertex_name, string frag_name, string geom_name)
 Loads a shader by complete filenames (with extensions), initializes it, and inserts in shaders list. More...
 
void setShadersDir (string dir)
 
virtual void reloadShaders (void)
 Reloads all shaders needed for effect usage. More...
 

Protected Attributes

Tucano::Texture noise_texture
 Noise texture. More...
 
float radius
 Kernel radius. If the distance between a sample point and the point for which the occlusion is being computed is larger than radius, the occlusion for this sample will be neglected. More...
 
Tucano::Framebuffer fbo
 Framebuffer to store coord/normal buffer. More...
 
Tucano::Shader ssao_shader
 The per pixel AO computation shader. More...
 
Tucano::Shader deferred_shader
 Save coord, normal and color to FBO. More...
 
Tucano::Shader ssao_final_shader
 Join original render with SSAO (blur it first) More...
 
Tucano::Mesh quad
 A quad mesh for framebuffer rendering. More...
 
bool apply_blur = true
 Flag indicating wether blur shall be applied or not. More...
 
bool displayAmbientPass = false
 Flag indicating if the mesh should be rendered only with ambient occlusion pass or with full illumination. If True, mesh will be rendered only with the ambient occlusion pass. More...
 
int blurRange = 3
 Number of neighbour pixels used in blurring. The blur will be applied to a blurRange x blurRange square around the current pixel. It's important to notice that blurRange must be an odd number. More...
 
int depthTextureID = 0
 The ID defining the color attachment to which the depth texture is bound in the framebuffer. More...
 
int normalTextureID = 1
 The ID defining the color attachment to which the normal texture is bound in the framebuffer. More...
 
int colorTextureID = 2
 The ID defining the color attachment to which the color texture is bound in the framebuffer. More...
 
int ssaoTextureID = 3
 The ID of the color attachment holding the SSAO result. More...
 
int blurTextureID = 4
 The ID defining the color attachment to which the blur texture is bound in the framebuffer. More...
 
int intensity = 1
 Global intensity value. More...
 
float global_scale = 1.0
 Global scale. More...
 
- Protected Attributes inherited from Tucano::Effect
std::vector< Shader * > shaders_list
 Vector of pointers to shaders used in this effect, in case the user needs multiple pass rendering. More...
 
string shaders_dir
 Directory in which the shader files are stored. More...
 

Private Member Functions

void initializeShaders (void)
 Creates and loads all shaders. More...
 

Detailed Description

Screen Space Ambient Occlusion effect class. Handles the pre-computations needed in order to use this effect, as well as handles the rendering with this effect.

Based on http://www.gamedev.net/page/resources/_/technical/graphics-programming-and-theory/a-simple-and-practical-approach-to-ssao-r2753

Constructor & Destructor Documentation

Tucano::Effects::SSAO::SSAO ( float  rad = 1.0)
inline

Default constructor.

Parameters
radThe kernel radius. This is used to define the max distance between the current point and the samples that will be considered for occlusion computation.

Member Function Documentation

void Tucano::Effects::SSAO::applySSAO ( const Tucano::Camera light_trackball)
inline

Blur SSAO result and mix with original render.

Parameters
light_trackballA pointer to the light trackball object.
void Tucano::Effects::SSAO::computeSSAO ( const Tucano::Camera camera)
inline

Compute the Ambient Occlusion factor for each pixel.

void Tucano::Effects::SSAO::createViewSpaceBuffer ( Tucano::Mesh mesh,
const Tucano::Camera camera_trackball,
const Tucano::Camera light_trackball 
)
inline

First pass of the SSAO, writes coords, normals and colors to a buffer.

Parameters
meshMesh to be rendered.
camera_trackballA pointer to the camera trackball object.
light_trackballA pointer to the light trackball object.
int Tucano::Effects::SSAO::getIntensity ( void  )
inline

Get intensity value.

Returns
Intensity value.
int Tucano::Effects::SSAO::getRadius ( void  )
inline

Get radius value.

Returns
Radius value.
virtual void Tucano::Effects::SSAO::initialize ( void  )
inlinevirtual

Initializes the SSAO effects,.

generating the sample kernel, creating and loading the shaders and generating the noise texture.

Implements Tucano::Effect.

void Tucano::Effects::SSAO::initializeShaders ( void  )
inlineprivate

Creates and loads all shaders.

virtual void Tucano::Effects::SSAO::render ( Tucano::Mesh mesh,
const Tucano::Camera camera_trackball,
const Tucano::Camera light_trackball 
)
inlinevirtual

Renders the mesh with the desired effect.

The algorithm has three passes:

  1. compute buffer with coords, normals and color per pixel
  2. compute AO per pixel
  3. blur the final result An option to pass an output buffer is available in case of offline rendering. For example, when taking snapshots of the current result.
    Parameters
    meshMesh to be rendered.
    camera_trackballA pointer to the camera trackball object.
    light_trackballA pointer to the light trackball object.
void Tucano::Effects::SSAO::setBlurRange ( int  value)
inline

Increases blur range.

void Tucano::Effects::SSAO::setIntensity ( int  value)
inline

Set intensity value.

Parameters
valueNew intensity value.
void Tucano::Effects::SSAO::setRadius ( int  value)
inline

Set radius value.

Parameters
valueNew radius value.
void Tucano::Effects::SSAO::setScale ( int  value)
inline

Set global scale value.

Parameters
valueNew scale value.
void Tucano::Effects::SSAO::toggleAmbientPass ( void  )
inline

Toggles the displayAmbientPass flag.

Member Data Documentation

bool Tucano::Effects::SSAO::apply_blur = true
protected

Flag indicating wether blur shall be applied or not.

int Tucano::Effects::SSAO::blurRange = 3
protected

Number of neighbour pixels used in blurring. The blur will be applied to a blurRange x blurRange square around the current pixel. It's important to notice that blurRange must be an odd number.

int Tucano::Effects::SSAO::blurTextureID = 4
protected

The ID defining the color attachment to which the blur texture is bound in the framebuffer.

int Tucano::Effects::SSAO::colorTextureID = 2
protected

The ID defining the color attachment to which the color texture is bound in the framebuffer.

Tucano::Shader Tucano::Effects::SSAO::deferred_shader
protected

Save coord, normal and color to FBO.

int Tucano::Effects::SSAO::depthTextureID = 0
protected

The ID defining the color attachment to which the depth texture is bound in the framebuffer.

bool Tucano::Effects::SSAO::displayAmbientPass = false
protected

Flag indicating if the mesh should be rendered only with ambient occlusion pass or with full illumination. If True, mesh will be rendered only with the ambient occlusion pass.

Tucano::Framebuffer Tucano::Effects::SSAO::fbo
protected

Framebuffer to store coord/normal buffer.

float Tucano::Effects::SSAO::global_scale = 1.0
protected

Global scale.

int Tucano::Effects::SSAO::intensity = 1
protected

Global intensity value.

Tucano::Texture Tucano::Effects::SSAO::noise_texture
protected

Noise texture.

int Tucano::Effects::SSAO::normalTextureID = 1
protected

The ID defining the color attachment to which the normal texture is bound in the framebuffer.

Tucano::Mesh Tucano::Effects::SSAO::quad
protected

A quad mesh for framebuffer rendering.

float Tucano::Effects::SSAO::radius
protected

Kernel radius. If the distance between a sample point and the point for which the occlusion is being computed is larger than radius, the occlusion for this sample will be neglected.

Tucano::Shader Tucano::Effects::SSAO::ssao_final_shader
protected

Join original render with SSAO (blur it first)

Tucano::Shader Tucano::Effects::SSAO::ssao_shader
protected

The per pixel AO computation shader.

int Tucano::Effects::SSAO::ssaoTextureID = 3
protected

The ID of the color attachment holding the SSAO result.


The documentation for this class was generated from the following file: