SO3Engine
SO3DeferredShadowManager.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
25#ifndef __SO3_DEFERRED_SHADOW_MANAGER_H__
26#define __SO3_DEFERRED_SHADOW_MANAGER_H__
27
28#include <Ogre.h>
29#define SO3_ENABLE_DEFERRED_CUSTOM_SHADOWS 0
30
31namespace SO3
32{
33
34// Material scheme name for shadows generation
35#define SO3_DEFERRED_SHADOWS_SCHEME_NAME "SO3/Deferred/Shadows"
36
37// Shadow caster material name
38#define SO3_DEFERRED_SHADOW_CASTER_NAME "SO3/Deferred/Shadows/Caster"
39
40// Seting up usefull names
41#define SO3_DEFERRED_SHADOWS_STANDARD_BASE_NAME "/Standard"
42#define SO3_DEFERRED_SHADOWS_CUBIC_BASE_NAME "/Cubic"
43#define SO3_DEFERRED_SHADOWS_TEXTURE_NAME "/Texture"
44#define SO3_DEFERRED_SHADOWS_CAMERA_NAME "/Camera"
45#define SO3_DEFERRED_SHADOWS_MATERIAL_NAME "/Material"
46
49class SDeferredShadowManager : public Ogre::Singleton<SDeferredShadowManager>,
50 public Ogre::MaterialManager::Listener
51{
52public:
53protected:
54private:
55 typedef std::set<Ogre::SceneManager*> OgreSceneManagerList;
56 OgreSceneManagerList ogreSceneManagerList;
57 typedef std::map<Ogre::SceneManager*, Ogre::Camera*> StandardTextureCameraByScene;
58 StandardTextureCameraByScene standardTextureCameraByScene;
59 typedef std::map<Ogre::SceneManager*, std::vector<Ogre::Camera*> > CubicTextureCamerasByScene;
60 CubicTextureCamerasByScene cubicTextureCamerasByScene;
61 Ogre::TexturePtr shadowStandardTexture;
62 Ogre::MaterialPtr shadowStandardMaterial;
63 bool standardTextureNeedRebuild;
64 unsigned short standardTextureFsaa;
65 unsigned short standardTextureSize;
66 Ogre::PixelFormat standardTexturePixelFormat;
67 Ogre::TexturePtr shadowCubicTexture;
68 Ogre::MaterialPtr shadowCubicMaterial;
69 bool cubicTextureNeedRebuild;
70 unsigned short cubicTextureFsaa;
71 unsigned short cubicTextureSize;
72 Ogre::PixelFormat cubicTexturePixelFormat;
73 Ogre::Matrix4 PROJECTIONCLIPSPACE2DTOIMAGESPACE_PERSPECTIVE;
74 std::string deferredShadowStandardTextureName;
75 std::string deferredShadowStandardCameraName;
76 std::string deferredShadowStandardMaterialName;
77 std::string deferredShadowCubicTextureName;
78 std::string deferredShadowCubicCameraName;
79 std::string deferredShadowCubicMaterialName;
80 Ogre::ShadowCameraSetup* spotShadowCameraSetup;
81 Ogre::ShadowCameraSetup* pointShadowCameraSetup;
82 Ogre::ShadowCameraSetup* directionalShadowCameraSetup;
83
84public:
89
94
99
104
107 void RegisterSceneManager(Ogre::SceneManager* targetScene);
108
111 void UnregisterSceneManager(Ogre::SceneManager* existingScene);
112
116 void SetShadowTextureSize(unsigned short size);
117
121 void SetShadowTexturePixelFormat(Ogre::PixelFormat fmt);
122
126 void SetShadowTextureFSAA(unsigned short fsaa);
127
130 void SetShadowStandardTextureSize(unsigned short size);
131
134 void SetShadowStandardTexturePixelFormat(Ogre::PixelFormat fmt);
135
138 void SetShadowStandardTextureFSAA(unsigned short fsaa);
139
142 void SetShadowCubicTextureSize(unsigned short size);
143
146 void SetShadowCubicTexturePixelFormat(Ogre::PixelFormat fmt);
147
150 void SetShadowCubicTextureFSAA(unsigned short fsaa);
151
154 Ogre::TexturePtr& PrepareShadowTexture(Ogre::Camera* ogreCamera, Ogre::Viewport* ogreViewport, const Ogre::Light* light, Ogre::Pass* ogrePass);
155
159 virtual Ogre::Technique* handleSchemeNotFound(unsigned short schemeIndex, const Ogre::String& schemeName, Ogre::Material* originalMaterial, unsigned short lodIndex, const Ogre::Renderable* rend);
160protected:
161private:
164 void CreateShadowStandardTexture();
165
168 void CreateShadowCubicTexture();
169
172 void DestroyShadowStandardTexture();
173
176 void DestroyShadowCubicTexture();
177
180 void PrepareShadowTextureImpl(Ogre::SceneManager* ogreTargetScene, Ogre::Camera* ogreCamera, Ogre::Viewport* ogreViewport, const Ogre::Light* ogreLight);
181
184 void PrepareShadowCubicTextureImpl(Ogre::SceneManager* ogreTargetScene, Ogre::Camera* ogreCamera, Ogre::Viewport* ogreViewport, const Ogre::Light* ogreLight);
185};
186
187}
188
189#endif
void RegisterSceneManager(Ogre::SceneManager *targetScene)
static SDeferredShadowManager * getSingletonPtr()
void SetShadowStandardTextureFSAA(unsigned short fsaa)
void SetShadowStandardTextureSize(unsigned short size)
void SetShadowCubicTextureSize(unsigned short size)
static SDeferredShadowManager & getSingleton()
void UnregisterSceneManager(Ogre::SceneManager *existingScene)
void SetShadowStandardTexturePixelFormat(Ogre::PixelFormat fmt)
Ogre::TexturePtr & PrepareShadowTexture(Ogre::Camera *ogreCamera, Ogre::Viewport *ogreViewport, const Ogre::Light *light, Ogre::Pass *ogrePass)
void SetShadowTextureFSAA(unsigned short fsaa)
void SetShadowTextureSize(unsigned short size)
void SetShadowTexturePixelFormat(Ogre::PixelFormat fmt)
void SetShadowCubicTexturePixelFormat(Ogre::PixelFormat fmt)
void SetShadowCubicTextureFSAA(unsigned short fsaa)
virtual Ogre::Technique * handleSchemeNotFound(unsigned short schemeIndex, const Ogre::String &schemeName, Ogre::Material *originalMaterial, unsigned short lodIndex, const Ogre::Renderable *rend)