Developer Documentation
Loading...
Searching...
No Matches
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
49
51
52#include <map>
53
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
64signals:
65 // LoggingInterface
66 void log(Logtype _type, QString _message);
67 void log(QString _message);
68
69
70public :
71
72 SSAOPlugin();
74
75 QString name() { return (QString("SSAO Plugin")); };
76 QString description( ) { return (QString(tr("Screen Space Ambient Occlusion"))); };
77
78public slots:
79 QString version() { return QString("1.0"); };
80
81private 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
93private:
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
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
125private:
126
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
161
164
166 GLuint sceneBufTex_ = 0;
167
169 GLuint downsampledTex_ = 0;
170
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
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
207
210
212 static const unsigned int numSamples_;
213
216};
Logtype
Log types for Message Window.
Interface class from which all plugins have to be created.
GLSL program class.
A generic shader base class.
Definition GLSLShader.hh:71
Interface for all Plugins which do logging to the logging window of the framework.
Interface to add additional rendering functions from within plugins.
static const unsigned int numSamples_
number of samples
Definition SSAO.hh:212
GLuint randomVecTex_
random vector table for sample offset rotation
Definition SSAO.hh:209
void generatePeelingShaders(GLSL::StringList *_strVertexShaderOut, GLSL::StringList *_strFragmentShaderOut, bool _textured)
peel shader generator based on lights and texture mode
QString description()
Return a description of what the plugin is doing.
Definition SSAO.hh:76
void drawScenePass(ACG::GLState *_glState, Viewer::ViewerProperties &_properties, BaseNode *_sceneGraphRoot)
draw the current scene
Definition SSAO.cc:486
void destroyResources()
free all gl resources
Definition SSAO.cc:418
void reloadResources(int _viewerId, unsigned int _sceneTexWidth, unsigned int _sceneTexHeight)
reload gl resources
Definition SSAO.cc:161
ACG::Vec3f samplingKernel_[128]
ssao sampling kernel
Definition SSAO.hh:215
GLSL::Shader * shaders_[10]
shader resources
Definition SSAO.hh:193
void generateSamplingKernel()
computes a hemisphere sampling kernel in [0,1] range
Definition SSAO.cc:111
QString name()
Return a name for the plugin.
Definition SSAO.hh:75
GLSL::Program * programs_[6]
shader programs
Definition SSAO.hh:206
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
void traverseLightNodes(BaseNode *_node)
find all light nodes in the scene
GLuint depthSceneRenderBuf_
depth renderbuffer for sceneFbo
Definition SSAO.hh:163
GLuint depthBufTex_
depth buffer render target
Definition SSAO.hh:153
unsigned int rtHeight_
render target height
Definition SSAO.hh:145
GLuint downsampledTex_
downsampled depth render target
Definition SSAO.hh:169
unsigned int rtDownWidth_
downsampled rt width
Definition SSAO.hh:148
unsigned int rtSceneWidth_
scene render target width
Definition SSAO.hh:138
unsigned int rtDownHeight_
downsampled rt height
Definition SSAO.hh:150
unsigned int rtSceneHeight_
scene render target height
Definition SSAO.hh:140
GLuint downsampledTmpTex_
downsampled temp rt for intermediate results
Definition SSAO.hh:172
GLuint occlusionTex_
occlusion render target
Definition SSAO.hh:175
GLuint depthSSAORenderBuf_
depth renderbuffer for ssaoFbo
Definition SSAO.hh:160
GLuint sceneBufTex_
standard scene without a render target
Definition SSAO.hh:166
unsigned int glWidth_
viewer window width
Definition SSAO.hh:132
unsigned int glHeight_
viewer window height
Definition SSAO.hh:135
unsigned int rtWidth_
render target width
Definition SSAO.hh:143