Developer Documentation

- Main Page
- Related Pages
- Modules
- Namespaces
- Classes
- Files

- File List
- File Members

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
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
52 #include <OpenFlipper/BasePlugin/BaseInterface.hh>
53 #include <OpenFlipper/BasePlugin/RenderInterface.hh>
54 #include <OpenFlipper/BasePlugin/LoggingInterface.hh>
55
56 #include <ACG/Scenegraph/SceneGraph.hh>
57
58 #include <map>
59
60 class SSAOPlugin : public QObject, BaseInterface, RenderInterface, LoggingInterface
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
135 struct ViewerResources
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
165 GLuint sceneNormalTex_;
166
168 GLuint depthSSAORenderBuf_;
169
171 GLuint depthSceneRenderBuf_;
172
174 GLuint sceneBufTex_;
175
177 GLuint downsampledTex_;
178
180 GLuint downsampledTmpTex_;
181
183 GLuint occlusionTex_;
184
187 GLuint sceneFbo_;
188
191 GLuint ssaoFbo_;
192
195 GLuint blurFbo_;
196 };
197
198 std::map<int, ViewerResources> viewerRes_;
199
201 GLSL::Shader* shaders_[10];
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
214 GLSL::Program* programs_[6];
215
217 GLuint randomVecTex_;
218
220 static const unsigned int numSamples_;
221
223 ACG::Vec3f samplingKernel_[128];
224 };
SSAOPlugin::destroyResources
void destroyResources()
free all gl resources
Definition: SSAO.cc:427
SSAOPlugin::reloadResources
void reloadResources(int _viewerId, unsigned int _sceneTexWidth, unsigned int _sceneTexHeight)
reload gl resources
Definition: SSAO.cc:170
Viewer::ViewerProperties
Definition: ViewerProperties.hh:119
BaseInterface
Interface class from which all plugins have to be created.
Definition: BaseInterface.hh:76
SSAOPlugin::ViewerResources::depthSceneRenderBuf_
GLuint depthSceneRenderBuf_
depth renderbuffer for sceneFbo
Definition: SSAO.hh:171
SSAOPlugin::ViewerResources::blurFbo_
GLuint blurFbo_
Definition: SSAO.hh:195
ACG::SceneGraph::BaseNode
Definition: BaseNode.hh:135
Logtype
Logtype
Log types for Message Window.
Definition: LoggingInterface.hh:103
RenderInterface
Interface to add additional rendering functions from within plugins.
Definition: RenderInterface.hh:70
SSAOPlugin::numSamples_
static const unsigned int numSamples_
number of samples
Definition: SSAO.hh:220
SSAOPlugin::ViewerResources::rtDownHeight_
unsigned int rtDownHeight_
downsampled rt height
Definition: SSAO.hh:158
SSAOPlugin::samplingKernel_
ACG::Vec3f samplingKernel_[128]
ssao sampling kernel
Definition: SSAO.hh:223
SSAOPlugin::ViewerResources::downsampledTex_
GLuint downsampledTex_
downsampled depth render target
Definition: SSAO.hh:177
SSAOPlugin::ViewerResources::downsampledTmpTex_
GLuint downsampledTmpTex_
downsampled temp rt for intermediate results
Definition: SSAO.hh:180
SSAOPlugin::ViewerResources::ssaoFbo_
GLuint ssaoFbo_
Definition: SSAO.hh:191
LoggingInterface.hh
LoggingInterface
Interface for all Plugins which do logging to the logging window of the framework.
Definition: LoggingInterface.hh:123
SSAOPlugin::ViewerResources::rtSceneHeight_
unsigned int rtSceneHeight_
scene render target height
Definition: SSAO.hh:148
ACG::GLState
Definition: GLState.hh:220
SSAOPlugin::drawScenePass
void drawScenePass(ACG::GLState *_glState, Viewer::ViewerProperties &_properties, BaseNode *_sceneGraphRoot)
draw the current scene
Definition: SSAO.cc:495
SSAOPlugin::ViewerResources::sceneNormalTex_
GLuint sceneNormalTex_
Definition: SSAO.hh:165
SSAOPlugin::randomVecTex_
GLuint randomVecTex_
random vector table for sample offset rotation
Definition: SSAO.hh:217
SSAOPlugin::drawQuadProj
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
GLSL::Shader
A generic shader base class.
Definition: GLSLShader.hh:77
ACG::SceneGraph::DrawModes::DrawMode
Specifies a DrawMode.
Definition: DrawModes.hh:294
SSAOPlugin::traverseLightNodes
void traverseLightNodes(BaseNode *_node)
find all light nodes in the scene
SSAOPlugin::ViewerResources::depthBufTex_
GLuint depthBufTex_
depth buffer render target
Definition: SSAO.hh:161
SSAOPlugin::shaders_
GLSL::Shader * shaders_[10]
shader resources
Definition: SSAO.hh:201
SSAOPlugin::ViewerResources::rtSceneWidth_
unsigned int rtSceneWidth_
scene render target width
Definition: SSAO.hh:146
SSAOPlugin::ViewerResources::sceneBufTex_
GLuint sceneBufTex_
standard scene without a render target
Definition: SSAO.hh:174
SSAOPlugin::ViewerResources::rtHeight_
unsigned int rtHeight_
render target height
Definition: SSAO.hh:153
SSAOPlugin::ViewerResources::glHeight_
unsigned int glHeight_
viewer window height
Definition: SSAO.hh:143
SSAOPlugin::generateSamplingKernel
void generateSamplingKernel()
computes a hemisphere sampling kernel in [0,1] range
Definition: SSAO.cc:120
OpenMesh::VectorT
Definition: Vector11T.hh:83
SceneGraph.hh
SSAOPlugin::name
QString name()
Return a name for the plugin.
Definition: SSAO.hh:83
SSAOPlugin
Definition: SSAO.hh:60
SSAOPlugin::ViewerResources::depthSSAORenderBuf_
GLuint depthSSAORenderBuf_
depth renderbuffer for ssaoFbo
Definition: SSAO.hh:168
SSAOPlugin::description
QString description()
Return a description of what the plugin is doing.
Definition: SSAO.hh:84
GLSL::Program
GLSL program class.
Definition: GLSLShader.hh:217
SSAOPlugin::ViewerResources::occlusionTex_
GLuint occlusionTex_
occlusion render target
Definition: SSAO.hh:183
SSAOPlugin::ViewerResources::sceneFbo_
GLuint sceneFbo_
Definition: SSAO.hh:187
BaseInterface.hh
SSAOPlugin::ViewerResources
Definition: SSAO.hh:135
SSAOPlugin::programs_
GLSL::Program * programs_[6]
shader programs
Definition: SSAO.hh:214
SSAOPlugin::ViewerResources::rtWidth_
unsigned int rtWidth_
render target width
Definition: SSAO.hh:151
SSAOPlugin::ViewerResources::glWidth_
unsigned int glWidth_
viewer window width
Definition: SSAO.hh:140
RenderInterface.hh
SSAOPlugin::generatePeelingShaders
void generatePeelingShaders(GLSL::StringList *_strVertexShaderOut, GLSL::StringList *_strFragmentShaderOut, bool _textured)
peel shader generator based on lights and texture mode
SSAOPlugin::ViewerResources::rtDownWidth_
unsigned int rtDownWidth_
downsampled rt width
Definition: SSAO.hh:156