Project

General

Profile

SO3Engine
SO3SsaoHandler.h
Go to the documentation of this file.
1/*
2-----------------------------------------------------------------------------
3This source file is part of OpenSpace3D
4For the latest info, see http://www.openspace3d.com
5
6Copyright (c) 2012 I-maginer
7
8This program is free software; you can redistribute it and/or modify it under
9the terms of the GNU Lesser General Public License as published by the Free Software
10Foundation; either version 2 of the License, or (at your option) any later
11version.
12
13This program is distributed in the hope that it will be useful, but WITHOUT
14ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
15FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
16
17You should have received a copy of the GNU Lesser General Public License along with
18this program; if not, write to the Free Software Foundation, Inc., 59 Temple
19Place - Suite 330, Boston, MA 02111-1307, USA, or go to
20http://www.gnu.org/copyleft/lesser.txt
21
22-----------------------------------------------------------------------------
23*/
24
28#ifndef __SO3_SSAO_HANDLER_H__
29#define __SO3_SSAO_HANDLER_H__
30
32
33namespace SO3
34{
35
39class SSsaoHandler : public Ogre::MaterialManager::Listener //, Ogre::RenderTargetListener
40{
41public:
66 typedef std::pair<float, float> SsaoTechniqueParameterRange;
68 {
69 const std::string displayName;
71 float value;
72 SsaoTechniqueParameter(const std::string& parameterDisplayName, const SsaoTechniqueParameterRange& parameterRange, const float& parameterValue) : displayName(parameterDisplayName),
73 range(parameterRange)
74 {
75 value = parameterValue;
76 }
77 };
78 typedef std::map<std::string, SsaoTechniqueParameter> SsaoTechniqueParameters;
79
80 static void Reset();
81protected:
82private:
83 enum SsaoGBufferLayout
84 {
85 SO3_SSAO_GBUFFER_NONE,
86 SO3_SSAO_GBUFFER_DEPTH_ONLY,
87 SO3_SSAO_GBUFFER_NORMAL_POSITION,
88 SO3_SSAO_GBUFFER_MAX
89 };
90
91 static bool compositorCreated;
92 bool isEnable;
93 bool isSupported;
94 SViewPort* targetViewport;
95 Ogre::String targetViewportScheme;
96 Ogre::CompositorManager* ogreCompositorManager;
97 Ogre::MaterialManager* ogreMaterialManager;
98 Ogre::GpuProgramManager* ogreProgramManager;
99
100 Ogre::CompositorInstance* inputCompositorInstance;
101 Ogre::CompositorInstance* normalCompositorInstance;
102 Ogre::MaterialPtr normalPositionMaterial;
103 Ogre::MaterialPtr normalPositionAlphaRejectionMaterial;
104 Ogre::MaterialPtr normalPositionMaterialTransparent;
105 Ogre::MaterialPtr crytekSsaoMaterial;
106 Ogre::MaterialPtr hemisphericSsaoMaterial;
107 Ogre::MaterialPtr creaseShadingSsaoMaterial;
108 Ogre::GpuProgramPtr ssaoRenderQuadVp;
109 Ogre::GpuProgramPtr ssaoDepthDebugCompositorFp;
110 Ogre::GpuProgramPtr normalPositionGeneratorVp;
111 Ogre::GpuProgramPtr normalPositionGeneratorFp;
112 Ogre::GpuProgramPtr normalPositionAlphaRejectionGeneratorVp;
113 Ogre::GpuProgramPtr normalPositionAlphaRejectionGeneratorFp;
114 Ogre::GpuProgramPtr ssaoNormalDebugCompositorFp;
115 Ogre::GpuProgramPtr ssaoPositionDebugCompositorFp;
116 Ogre::GpuProgramPtr ssaoDepth2DebugCompositorFp;
117 Ogre::GpuProgramPtr ssaoCrytekCompositorFp;
118 Ogre::GpuProgramPtr ssaoHemiCompositorFp;
119 Ogre::GpuProgramPtr ssaoCreaseCompositorFp;
120 Ogre::GpuProgramPtr filterBoxCompositorFp;
121 Ogre::GpuProgramPtr filterBoxSmartCompositorFp;
122 Ogre::GpuProgramPtr filterBoxSmart2CompositorFp;
123 Ogre::GpuProgramPtr ssaoDebugCompositorFp;
124 Ogre::GpuProgramPtr ssaoMergingCompositorFp;
125
126 SsaoGBufferLayout currentSsaoGbufferLayout;
127 SsaoTechnique currentSsaoTechnique;
128 SsaoFilter currentSsaoFilter;
129 SsaoDebugMode currentSsaoDebugMode;
130 typedef std::map<SsaoTechnique, SsaoTechniqueParameters> SsaoTechniqueParametersByTechnique;
131 static SsaoTechniqueParametersByTechnique ssaoTechniquesParameters;
132 bool mSupportGbuffer;
133
134public:
138 SSsaoHandler(SViewPort* targetViewportInstance);
139
144
147 bool GetEnable();
148
151 void SetEnable(bool enable);
152
156
159 void SetTechnique(SsaoTechnique newTechnique);
160
164
167 void SetFilter(const SsaoFilter& newFilter);
168
172
175 void SetDebugMode(const SsaoDebugMode& newDebugMode);
176
179 float GetTechniqueParameterValue(const SsaoTechnique& technique, const std::string& parameterName) const;
180
183 void SetTechniqueParameterValue(const SsaoTechnique& technique, const std::string& parameterName, const float& parameterValue);
184
188
191 void SetTechniqueParameters(const SsaoTechnique& technique, const SsaoTechniqueParameters& parameters);
192
197 virtual Ogre::Technique* handleSchemeNotFound(unsigned short schemeIndex, const Ogre::String& schemeName, Ogre::Material* originalMaterial, unsigned short lodIndex, const Ogre::Renderable* rend);
198
199 /*
200 virtual void preRenderTargetUpdate(const Ogre::RenderTargetEvent& evt);
201 virtual void postRenderTargetUpdate(const Ogre::RenderTargetEvent& evt);
202 */
203private:
207 SSsaoHandler();
208
211 Ogre::GpuProgramPtr createGpuProgram(const Ogre::String &Name, const bool& fragment, const Ogre::String& Data);
212
216 void GenerateRenderQuadVertexShader();
217
221 void CreateCompositors();
222
226 void GenerateSsaoCompositor();
227
231 void GenerateDepthDebugCompositor();
232
239 void GenerateNormalPositionCompositor();
240
244 void GenerateNormalDebugCompositor();
245
249 void GenerateViewPositionDebugCompositor();
250
254 void GenerateDepthDebugCompositor2();
255
259 void GenerateSsaoCrytekCompositor();
260
264 void GenerateSsaoHemisphericCompositor();
265
281 void GenerateSsaoCreaseShadingCompositor();
282
291 void GenerateFilterBoxCompositor();
292
301 void GenerateFilterBoxSmartCompositor();
302
311 void GenerateFilterBoxSmartCompositor2();
312
316 void GenerateSsaoDebugCompositor();
317
321 void GenerateMergingCompositor();
322
326 SsaoGBufferLayout GetGBufferLayout(const SsaoTechnique& technique);
327};
328
329}
330
331#endif
librairies include
std::pair< float, float > SsaoTechniqueParameterRange
float GetTechniqueParameterValue(const SsaoTechnique &technique, const std::string &parameterName) const
virtual Ogre::Technique * handleSchemeNotFound(unsigned short schemeIndex, const Ogre::String &schemeName, Ogre::Material *originalMaterial, unsigned short lodIndex, const Ogre::Renderable *rend)
void SetTechniqueParameterValue(const SsaoTechnique &technique, const std::string &parameterName, const float &parameterValue)
SsaoDebugMode GetDebugMode()
void SetDebugMode(const SsaoDebugMode &newDebugMode)
SsaoTechnique GetTechnique()
void SetEnable(bool enable)
SsaoTechniqueParameters GetTechniqueParameters(const SsaoTechnique &technique) const
std::map< std::string, SsaoTechniqueParameter > SsaoTechniqueParameters
static void Reset()
void SetFilter(const SsaoFilter &newFilter)
void SetTechniqueParameters(const SsaoTechnique &technique, const SsaoTechniqueParameters &parameters)
void SetTechnique(SsaoTechnique newTechnique)
SsaoTechniqueParameter(const std::string &parameterDisplayName, const SsaoTechniqueParameterRange &parameterRange, const float &parameterValue)
const SsaoTechniqueParameterRange range