Project

General

Profile

SO3Engine
SO3ShadowCSM.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
31#ifndef __SO3SHADOW_CSM_H__
32#define __SO3SHADOW_CSM_H__
33
35
36namespace SO3
37{
38
39/* CSM Camera Setup from Matthew Paul Reid sample code
40 https://bitbucket.org/ScaleRender/ogrecascadedshadows/downloads
41*/
42class CSMGpuConstants : public Ogre::Singleton<CSMGpuConstants>
43{
44public:
46 virtual ~CSMGpuConstants();
47 void updateCascade(const Ogre::Camera &texCam, size_t index);
48
53
54 /*
55 @copydoc Ogre::Singleton::getSingletonPtr
56 */
58private:
59 Ogre::GpuSharedParametersPtr mParamsScaleBias;
60 Ogre::GpuSharedParametersPtr mParamsShadowMatrix;
61
62 Ogre::Matrix4 mFirstCascadeViewMatrix;
63 Ogre::Real mFirstCascadeCamWidth;
64 Ogre::Real mViewRange;
65 Ogre::Matrix4 hack;
66 size_t mCascadeCount;
67};
68
69class CSMGpuConstants;
70
71class StableCSMShadowCameraSetup : public Ogre::LiSPSMShadowCameraSetup
72{
73public:
74 typedef std::vector<Ogre::Real> SplitPointList;
75
76public:
77 StableCSMShadowCameraSetup(Ogre::SceneManager* ogreScene, CSMGpuConstants* constants);
79
86 void calculateSplitPoints(size_t cascadeCount, Ogre::Real firstSplitDist, Ogre::Real farDist, Ogre::Real lambda = 0.95);
87
94 void setSplitPoints(const SplitPointList& newSplitPoints);
95
96 void setSplitPadding(Ogre::Real pad) { mSplitPadding = pad; }
97
101 Ogre::Real getSplitPadding() const { return mSplitPadding; }
103 size_t getCascadeCount() const { return mCascadeCount; }
104
106 virtual void getShadowCamera(const Ogre::SceneManager *sm, const Ogre::Camera *cam,
107 const Ogre::Viewport *vp, const Ogre::Light *light, Ogre::Camera *texCam, size_t iteration) const;
108
110 inline const SplitPointList& getSplitPoints() const
111 { return mSplitPoints; }
112
113protected:
114 void getShadowCameraForCascade(const Ogre::SceneManager *sm, const Ogre::Camera *cam,
115 const Ogre::Viewport *vp, const Ogre::Light *light, Ogre::Camera *texCam, size_t iteration,
116 Ogre::Real nearSplit, Ogre::Real farSplit) const;
117
118protected:
121 Ogre::Real mSplitPadding;
122
123 mutable size_t mCurrentIteration;
124
125private:
126 CSMGpuConstants* mGpuConstants;
127
128};
129
132class SShadowViewportCSM : public SShadowViewport, Ogre::MaterialManager::Listener
133{
134public:
135protected:
136private:
137 Ogre::TexturePtr mSpTexture;
138 Ogre::RenderTexture* mSpRenderTexture;
139 Ogre::Viewport* mSpViewport;
140
141 Ogre::Overlay* mDebugOverlay;
142 Ogre::OverlayContainer* mDebugOverlayPanel;
143 Ogre::MaterialPtr mOverlayMaterial;
144public:
148 SShadowViewportCSM(Ogre::Viewport* viewport);
149
154
155 virtual void UpdateCamera(Ogre::Camera* cam);
156
161 virtual Ogre::Technique* handleSchemeNotFound(unsigned short schemeIndex, const Ogre::String& schemeName, Ogre::Material* originalMaterial, unsigned short lodIndex, const Ogre::Renderable* rend);
162protected:
163private:
164};
165
168class SShadowCSM : public SShadow
169{
170public:
171protected:
172private:
173
174public:
175 static bool CheckSystemCompatibility();
176
180 SShadowCSM(SShadowManager* sManager);
181
185 ~SShadowCSM();
186protected:
189 virtual void UpdateShadowTechnique();
190
193 virtual void UpdateShadowMaterial(Ogre::Technique* tech);
194
197 virtual void RemoveMaterialPass(Ogre::Technique* tech);
198
201 virtual bool IsShadowMaterialPass(Ogre::Pass* pass);
202private:
206 SShadowCSM();
207
208 void CreateMaterialsPass();
209
210 void CleanMaterials();
211};
212
213}
214
215#endif
static CSMGpuConstants & getSingleton()
static CSMGpuConstants * getSingletonPtr()
void updateCascade(const Ogre::Camera &texCam, size_t index)
virtual void RemoveMaterialPass(Ogre::Technique *tech)
static bool CheckSystemCompatibility()
virtual bool IsShadowMaterialPass(Ogre::Pass *pass)
virtual void UpdateShadowMaterial(Ogre::Technique *tech)
virtual void UpdateShadowTechnique()
virtual Ogre::Technique * handleSchemeNotFound(unsigned short schemeIndex, const Ogre::String &schemeName, Ogre::Material *originalMaterial, unsigned short lodIndex, const Ogre::Renderable *rend)
virtual void UpdateCamera(Ogre::Camera *cam)
SShadowViewportCSM(Ogre::Viewport *viewport)
void calculateSplitPoints(size_t cascadeCount, Ogre::Real firstSplitDist, Ogre::Real farDist, Ogre::Real lambda=0.95)
Ogre::Real getSplitPadding() const
virtual void getShadowCamera(const Ogre::SceneManager *sm, const Ogre::Camera *cam, const Ogre::Viewport *vp, const Ogre::Light *light, Ogre::Camera *texCam, size_t iteration) const
Returns a stable CSM shadow camera for the given iteration.
void setSplitPadding(Ogre::Real pad)
void setSplitPoints(const SplitPointList &newSplitPoints)
void getShadowCameraForCascade(const Ogre::SceneManager *sm, const Ogre::Camera *cam, const Ogre::Viewport *vp, const Ogre::Light *light, Ogre::Camera *texCam, size_t iteration, Ogre::Real nearSplit, Ogre::Real farSplit) const
const SplitPointList & getSplitPoints() const
Returns the calculated split points.
size_t getCascadeCount() const
Get the number of splits.
std::vector< Ogre::Real > SplitPointList