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 #include <QObject>
45
46 #include <OpenFlipper/BasePlugin/BaseInterface.hh>
47 #include <OpenFlipper/BasePlugin/RenderInterface.hh>
48 #include <OpenFlipper/BasePlugin/LoggingInterface.hh>
49
50 #include <ACG/Scenegraph/SceneGraph.hh>
51
52 #include <map>
53
54 class SSAOPlugin : public QObject, BaseInterface, RenderInterface, LoggingInterface
55 {
56 Q_OBJECT
57 Q_INTERFACES(BaseInterface)
58 Q_INTERFACES(RenderInterface)
59 Q_INTERFACES(LoggingInterface)
60
61 Q_PLUGIN_METADATA(IID "org.OpenFlipper.Plugins.Plugin-Render-SSAO")
62
63
64 signals:
65 // LoggingInterface
66 void log(Logtype _type, QString _message);
67 void log(QString _message);
68
69
70 public :
71
72 SSAOPlugin();
73 ~SSAOPlugin();
74
75 QString name() { return (QString("SSAO Plugin")); };
76 QString description( ) { return (QString(tr("Screen Space Ambient Occlusion"))); };
77
78 public slots:
79 QString version() { return QString("1.0"); };
80
81 private slots:
82
83 //BaseInterface
84 void initializePlugin();
85 void exit();
86
87 // RenderInterface
88 void render(ACG::GLState* _glState, Viewer::ViewerProperties& _properties);
89 QString rendererName();
90 void supportedDrawModes(ACG::SceneGraph::DrawModes::DrawMode& _mode);
91 QString checkOpenGL();
92
93 private:
94
96 void destroyResources();
97
99 void destroyResources(int _viewerId);
100
102 void reloadResources(int _viewerId, unsigned int _sceneTexWidth, unsigned int _sceneTexHeight);
103
105 void drawQuadProj(float _x0 = -1.0f, float _y0 = 1.0f,
106 float _w = 2.0f, float _h = 2.0f);
107
109 void traverseLightNodes(BaseNode* _node);
110
112 void generatePeelingShaders(GLSL::StringList* _strVertexShaderOut,
113 GLSL::StringList* _strFragmentShaderOut, bool _textured);
114
116 void drawScenePass(ACG::GLState* _glState, Viewer::ViewerProperties& _properties, BaseNode* _sceneGraphRoot);
117
119 struct ViewerResources;
120 void gaussianBlurPass(const ViewerResources* _pViewer, const float* _texelSize,
121 GLenum _targetAttachement, GLuint _srcTexture);
122
124 void generateSamplingKernel();
125 private:
126
127 struct ViewerResources
128 {
129 ViewerResources() = default;
130
132 unsigned int glWidth_ = 0;
133
135 unsigned int glHeight_ = 0;
136
138 unsigned int rtSceneWidth_ = 0;
140 unsigned int rtSceneHeight_ = 0;
141
143 unsigned int rtWidth_ = 0;
145 unsigned int rtHeight_ = 0;
146
148 unsigned int rtDownWidth_ = 0;
150 unsigned int rtDownHeight_ = 0;
151
153 GLuint depthBufTex_ = 0;
154
157 GLuint sceneNormalTex_ = 0;
158
160 GLuint depthSSAORenderBuf_ = 0;
161
163 GLuint depthSceneRenderBuf_ = 0;
164
166 GLuint sceneBufTex_ = 0;
167
169 GLuint downsampledTex_ = 0;
170
172 GLuint downsampledTmpTex_ = 0;
173
175 GLuint occlusionTex_ = 0;
176
179 GLuint sceneFbo_ = 0;
180
183 GLuint ssaoFbo_ = 0;
184
187 GLuint blurFbo_ = 0;
188 };
189
190 std::map<int, ViewerResources> viewerRes_;
191
193 GLSL::Shader* shaders_[10];
194
195 enum
196 {
197 PROG_INIT = 0, // early Z pass + standard scene rendering
198 PROG_DOWNSAMPLING,
199 PROG_BLUR,
200 PROG_SSAO,
201 PROG_FINAL,
202 PROG_FINAL_MSAA
203 };
204
206 GLSL::Program* programs_[6];
207
209 GLuint randomVecTex_;
210
212 static const unsigned int numSamples_;
213
215 ACG::Vec3f samplingKernel_[128];
216 };
SSAOPlugin::generatePeelingShaders
void generatePeelingShaders(GLSL::StringList *_strVertexShaderOut, GLSL::StringList *_strFragmentShaderOut, bool _textured)
peel shader generator based on lights and texture mode
SSAOPlugin::ViewerResources::glHeight_
unsigned int glHeight_
viewer window height
Definition: SSAO.hh:135
SSAOPlugin::ViewerResources::depthSceneRenderBuf_
GLuint depthSceneRenderBuf_
depth renderbuffer for sceneFbo
Definition: SSAO.hh:163
Viewer::ViewerProperties
Definition: ViewerProperties.hh:107
SSAOPlugin::ViewerResources::blurFbo_
GLuint blurFbo_
Definition: SSAO.hh:187
SSAOPlugin::numSamples_
static const unsigned int numSamples_
number of samples
Definition: SSAO.hh:212
SSAOPlugin::drawScenePass
void drawScenePass(ACG::GLState *_glState, Viewer::ViewerProperties &_properties, BaseNode *_sceneGraphRoot)
draw the current scene
Definition: SSAO.cc:486
SSAOPlugin::ViewerResources
Definition: SSAO.hh:127
ACG::GLState
Definition: GLState.hh:213
SSAOPlugin::ViewerResources::glWidth_
unsigned int glWidth_
viewer window width
Definition: SSAO.hh:132
RenderInterface.hh
SSAOPlugin::ViewerResources::downsampledTex_
GLuint downsampledTex_
downsampled depth render target
Definition: SSAO.hh:169
Logtype
Logtype
Log types for Message Window.
Definition: LoggingInterface.hh:92
SSAOPlugin::ViewerResources::rtDownHeight_
unsigned int rtDownHeight_
downsampled rt height
Definition: SSAO.hh:150
OpenMesh::VectorT
Definition: Vector11T.hh:83
SSAOPlugin::ViewerResources::sceneFbo_
GLuint sceneFbo_
Definition: SSAO.hh:179
SSAOPlugin::ViewerResources::depthBufTex_
GLuint depthBufTex_
depth buffer render target
Definition: SSAO.hh:153
SSAOPlugin::ViewerResources::ssaoFbo_
GLuint ssaoFbo_
Definition: SSAO.hh:183
SSAOPlugin::ViewerResources::downsampledTmpTex_
GLuint downsampledTmpTex_
downsampled temp rt for intermediate results
Definition: SSAO.hh:172
LoggingInterface
Interface for all Plugins which do logging to the logging window of the framework.
Definition: LoggingInterface.hh:112
SSAOPlugin
Definition: SSAO.hh:54
LoggingInterface.hh
SSAOPlugin::traverseLightNodes
void traverseLightNodes(BaseNode *_node)
find all light nodes in the scene
GLSL::Program
GLSL program class.
Definition: GLSLShader.hh:211
SSAOPlugin::samplingKernel_
ACG::Vec3f samplingKernel_[128]
ssao sampling kernel
Definition: SSAO.hh:215
SSAOPlugin::ViewerResources::sceneBufTex_
GLuint sceneBufTex_
standard scene without a render target
Definition: SSAO.hh:166
SSAOPlugin::name
QString name()
Return a name for the plugin.
Definition: SSAO.hh:75
SSAOPlugin::ViewerResources::sceneNormalTex_
GLuint sceneNormalTex_
Definition: SSAO.hh:157
ACG::SceneGraph::BaseNode
Definition: BaseNode.hh:104
SSAOPlugin::ViewerResources::rtWidth_
unsigned int rtWidth_
render target width
Definition: SSAO.hh:143
SSAOPlugin::ViewerResources::depthSSAORenderBuf_
GLuint depthSSAORenderBuf_
depth renderbuffer for ssaoFbo
Definition: SSAO.hh:160
SSAOPlugin::ViewerResources::occlusionTex_
GLuint occlusionTex_
occlusion render target
Definition: SSAO.hh:175
ACG::SceneGraph::DrawModes::DrawMode
Specifies a DrawMode.
Definition: DrawModes.hh:288
SSAOPlugin::description
QString description()
Return a description of what the plugin is doing.
Definition: SSAO.hh:76
SSAOPlugin::ViewerResources::rtSceneHeight_
unsigned int rtSceneHeight_
scene render target height
Definition: SSAO.hh:140
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:467
SSAOPlugin::generateSamplingKernel
void generateSamplingKernel()
computes a hemisphere sampling kernel in [0,1] range
Definition: SSAO.cc:111
SceneGraph.hh
SSAOPlugin::shaders_
GLSL::Shader * shaders_[10]
shader resources
Definition: SSAO.hh:193
GLSL::Shader
A generic shader base class.
Definition: GLSLShader.hh:71
SSAOPlugin::ViewerResources::rtHeight_
unsigned int rtHeight_
render target height
Definition: SSAO.hh:145
SSAOPlugin::randomVecTex_
GLuint randomVecTex_
random vector table for sample offset rotation
Definition: SSAO.hh:209
SSAOPlugin::ViewerResources::rtDownWidth_
unsigned int rtDownWidth_
downsampled rt width
Definition: SSAO.hh:148
SSAOPlugin::destroyResources
void destroyResources()
free all gl resources
Definition: SSAO.cc:418
SSAOPlugin::programs_
GLSL::Program * programs_[6]
shader programs
Definition: SSAO.hh:206
RenderInterface
Interface to add additional rendering functions from within plugins.
Definition: RenderInterface.hh:60
SSAOPlugin::ViewerResources::rtSceneWidth_
unsigned int rtSceneWidth_
scene render target width
Definition: SSAO.hh:138
SSAOPlugin::reloadResources
void reloadResources(int _viewerId, unsigned int _sceneTexWidth, unsigned int _sceneTexHeight)
reload gl resources
Definition: SSAO.cc:161
BaseInterface
Interface class from which all plugins have to be created.
Definition: BaseInterface.hh:65
BaseInterface.hh