Developer Documentation
SSAO.hh
1 /*===========================================================================*\
2 * *
3 * OpenFlipper *
4  * Copyright (c) 2001-2015, RWTH-Aachen University *
5  * Department of Computer Graphics and Multimedia *
6  * All rights reserved. *
7  * www.openflipper.org *
8  * *
9  *---------------------------------------------------------------------------*
10  * This file is part of OpenFlipper. *
11  *---------------------------------------------------------------------------*
12  * *
13  * Redistribution and use in source and binary forms, with or without *
14  * modification, are permitted provided that the following conditions *
15  * are met: *
16  * *
17  * 1. Redistributions of source code must retain the above copyright notice, *
18  * this list of conditions and the following disclaimer. *
19  * *
20  * 2. Redistributions in binary form must reproduce the above copyright *
21  * notice, this list of conditions and the following disclaimer in the *
22  * documentation and/or other materials provided with the distribution. *
23  * *
24  * 3. Neither the name of the copyright holder nor the names of its *
25  * contributors may be used to endorse or promote products derived from *
26  * this software without specific prior written permission. *
27  * *
28  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS *
29  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED *
30  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A *
31  * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER *
32  * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, *
33  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, *
34  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR *
35  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF *
36  * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING *
37  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS *
38  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. *
39 * *
40 \*===========================================================================*/
41 
42 /*===========================================================================*\
43 * *
44 * $Revision$ *
45 * $LastChangedBy$ *
46 * $Date$ *
47 * *
48 \*===========================================================================*/
49 
50 #include <QObject>
51 
55 
57 
58 #include <map>
59 
61 {
62  Q_OBJECT
63  Q_INTERFACES(BaseInterface)
64  Q_INTERFACES(RenderInterface)
65  Q_INTERFACES(LoggingInterface)
66 
67 #if QT_VERSION >= 0x050000
68  Q_PLUGIN_METADATA(IID "org.OpenFlipper.Plugins.Plugin-Render-SSAO")
69 #endif
70 
71 
72 signals:
73  // LoggingInterface
74  void log(Logtype _type, QString _message);
75  void log(QString _message);
76 
77 
78 public :
79 
80  SSAOPlugin();
81  ~SSAOPlugin();
82 
83  QString name() { return (QString("SSAO Plugin")); };
84  QString description( ) { return (QString(tr("Screen Space Ambient Occlusion"))); };
85 
86 public slots:
87  QString version() { return QString("1.0"); };
88 
89 private slots:
90 
91  //BaseInterface
92  void initializePlugin();
93  void exit();
94 
95  // RenderInterface
96  void render(ACG::GLState* _glState, Viewer::ViewerProperties& _properties);
97  QString rendererName();
98  void supportedDrawModes(ACG::SceneGraph::DrawModes::DrawMode& _mode);
99  QString checkOpenGL();
100 
101 private:
102 
104  void destroyResources();
105 
107  void destroyResources(int _viewerId);
108 
110  void reloadResources(int _viewerId, unsigned int _sceneTexWidth, unsigned int _sceneTexHeight);
111 
113  void drawQuadProj(float _x0 = -1.0f, float _y0 = 1.0f,
114  float _w = 2.0f, float _h = 2.0f);
115 
117  void traverseLightNodes(BaseNode* _node);
118 
120  void generatePeelingShaders(GLSL::StringList* _strVertexShaderOut,
121  GLSL::StringList* _strFragmentShaderOut, bool _textured);
122 
124  void drawScenePass(ACG::GLState* _glState, Viewer::ViewerProperties& _properties, BaseNode* _sceneGraphRoot);
125 
127  struct ViewerResources;
128  void gaussianBlurPass(const ViewerResources* _pViewer, const float* _texelSize,
129  GLenum _targetAttachement, GLuint _srcTexture);
130 
132  void generateSamplingKernel();
133 private:
134 
136  {
137  ViewerResources();
138 
140  unsigned int glWidth_;
141 
143  unsigned int glHeight_;
144 
146  unsigned int rtSceneWidth_;
148  unsigned int rtSceneHeight_;
149 
151  unsigned int rtWidth_;
153  unsigned int rtHeight_;
154 
156  unsigned int rtDownWidth_;
158  unsigned int rtDownHeight_;
159 
161  GLuint depthBufTex_;
162 
166 
169 
172 
174  GLuint sceneBufTex_;
175 
178 
181 
184 
187  GLuint sceneFbo_;
188 
191  GLuint ssaoFbo_;
192 
195  GLuint blurFbo_;
196  };
197 
198  std::map<int, ViewerResources> viewerRes_;
199 
202 
203  enum
204  {
205  PROG_INIT = 0, // early Z pass + standard scene rendering
206  PROG_DOWNSAMPLING,
207  PROG_BLUR,
208  PROG_SSAO,
209  PROG_FINAL,
210  PROG_FINAL_MSAA
211  };
212 
215 
218 
220  static const unsigned int numSamples_;
221 
224 };
GLuint randomVecTex_
random vector table for sample offset rotation
Definition: SSAO.hh:217
QString description()
Return a description of what the plugin is doing.
Definition: SSAO.hh:84
unsigned int rtDownWidth_
downsampled rt width
Definition: SSAO.hh:156
Logtype
Log types for Message Window.
unsigned int glHeight_
viewer window height
Definition: SSAO.hh:143
void traverseLightNodes(BaseNode *_node)
find all light nodes in the scene
A generic shader base class.
Definition: GLSLShader.hh:77
GLSL::Program * programs_[6]
shader programs
Definition: SSAO.hh:214
unsigned int rtWidth_
render target width
Definition: SSAO.hh:151
void generatePeelingShaders(GLSL::StringList *_strVertexShaderOut, GLSL::StringList *_strFragmentShaderOut, bool _textured)
peel shader generator based on lights and texture mode
GLuint depthSceneRenderBuf_
depth renderbuffer for sceneFbo
Definition: SSAO.hh:171
unsigned int glWidth_
viewer window width
Definition: SSAO.hh:140
Interface class from which all plugins have to be created.
GLuint downsampledTmpTex_
downsampled temp rt for intermediate results
Definition: SSAO.hh:180
GLuint depthSSAORenderBuf_
depth renderbuffer for ssaoFbo
Definition: SSAO.hh:168
ACG::Vec3f samplingKernel_[128]
ssao sampling kernel
Definition: SSAO.hh:223
Interface for all Plugins which do logging to the logging window of the framework.
unsigned int rtSceneWidth_
scene render target width
Definition: SSAO.hh:146
Interface to add additional rendering functions from within plugins.
void drawScenePass(ACG::GLState *_glState, Viewer::ViewerProperties &_properties, BaseNode *_sceneGraphRoot)
draw the current scene
Definition: SSAO.cc:495
void reloadResources(int _viewerId, unsigned int _sceneTexWidth, unsigned int _sceneTexHeight)
reload gl resources
Definition: SSAO.cc:170
GLuint occlusionTex_
occlusion render target
Definition: SSAO.hh:183
GLuint sceneBufTex_
standard scene without a render target
Definition: SSAO.hh:174
QString name()
Return a name for the plugin.
Definition: SSAO.hh:83
unsigned int rtDownHeight_
downsampled rt height
Definition: SSAO.hh:158
void generateSamplingKernel()
computes a hemisphere sampling kernel in [0,1] range
Definition: SSAO.cc:120
void destroyResources()
free all gl resources
Definition: SSAO.cc:427
unsigned int rtHeight_
render target height
Definition: SSAO.hh:153
GLuint depthBufTex_
depth buffer render target
Definition: SSAO.hh:161
GLSL::Shader * shaders_[10]
shader resources
Definition: SSAO.hh:201
unsigned int rtSceneHeight_
scene render target height
Definition: SSAO.hh:148
GLuint downsampledTex_
downsampled depth render target
Definition: SSAO.hh:177
void drawQuadProj(float _x0=-1.0f, float _y0=1.0f, float _w=2.0f, float _h=2.0f)
draw a quad in projection space (only positions)
Definition: SSAO.cc:476
static const unsigned int numSamples_
number of samples
Definition: SSAO.hh:220
GLSL program class.
Definition: GLSLShader.hh:217