Project

General

Profile

SO3Engine
SO3ShadowManager.cpp
Go to the documentation of this file.
1
17
18namespace SO3
19{
20
21SShadowManager::SShadowManager()
22{
23}
24
25SShadowManager::SShadowManager(SScene* parent)
26{
27 currentScene = parent;
29
30 // Initialise to null.
31 currentShadowSystem = 0;
32 currentQuality = SO3_SHADOWS_QUALITY_MEDIUM;
33 textureSize = SO3_SHADOWS_QUALITY_MEDIUM;
34 shadowLightingTechnique = SO3_MODULATIVE_SHADOWS_LIGHTING;
35 textureFadeStart = 0.7f;
36 textureFadeEnd = 0.9f;
37
38 ogreScene->setShadowFarDistance(20);
39 ogreScene->setShadowTextureSize(textureSize);
40 ogreScene->setShadowDirectionalLightExtrusionDistance(50);
41}
42
44{
46 ogreScene->setShadowTechnique(Ogre::SHADOWTYPE_NONE);
47}
48
53
58
59void SShadowManager::SetColour(const int& color)
60{
61 ogreScene->setShadowColour(ConversionTools::ScolToOgreColorRGBA(color));
62}
63
65{
66 return textureSize;
67}
68
69void SShadowManager::SetTextureSize(const int& size)
70{
71 //TODO getCap RSC_HWRENDER_TO_TEXTURE
72 ogreScene->setShadowTextureSize(size);
73 textureSize = size;
74}
75
80
82{
83 assert(technique != SO3_INVALID_SHADOWS_LIGHTING);
84 if (technique == shadowLightingTechnique)
85 return;
86
87 shadowLightingTechnique = technique;
88 if (currentShadowSystem != 0)
89 {
90 currentShadowSystem->UpdateShadowTechnique();
91 }
92}
93
95{
96 if (GetShadowType() == type)
97 {
99 return;
100 }
101
102 //TODO check if there is enable lights in scene
103 SO3_SAFE_DELETE(currentShadowSystem);
104
105 switch (type)
106 {
107 case SO3_SHADOWS_NONE:
108 ogreScene->setShadowTechnique(Ogre::SHADOWTYPE_NONE);
109 break;
111 currentShadowSystem = new SShadowStencil(this);
112 break;
115 currentShadowSystem = new SShadowLiSPSM(this);
116 break;
117 case SO3_SHADOWS_CSM:
119 currentShadowSystem = new SShadowCSM(this);
120 break;
121 case SO3_SHADOWS_PSSM:
123 currentShadowSystem = new SShadowPSSM(this);
124 break;
125#ifdef SO3_BUILD_DEFERRED
127 currentShadowSystem = new SShadowDeferred(this);
128 break;
129#endif
130 }
131
133
134 //force all viewport to resize : hack to prevent black window
135 /* //crash on camera for raycast
136 Ogre::SceneManager::CameraList camList = ogreScene->getCameras();
137 for (Ogre::SceneManager::CameraList::const_iterator iter = camList.begin(); iter != camList.end(); iter++)
138 {
139 Ogre::Viewport* viewport = (iter->second)->getViewport();
140 if (viewport->)
141 viewport->_updateDimensions();
142 }*/
143}
144
146{
147 if (currentShadowSystem != 0)
148 return currentShadowSystem->GetShadowType();
149 else
151}
152
153
155{
156 if (dist <= 0.0f)
157 return;
158
159 ogreScene->setShadowFarDistance(dist);
160
161 //rebuild the shadows
164 SetShadowType(lastType);
165}
166
168{
169 return ogreScene->getShadowFarDistance();
170}
171
173{
174 return ogreScene->getShadowDirectionalLightExtrusionDistance();
175}
176
178{
179 ogreScene->setShadowDirectionalLightExtrusionDistance((value == 0.0) ? ogreScene->getShadowFarDistance() + 50.0f : value);
180
181 //rebuild the shadows
184 SetShadowType(lastType);
185}
186
188{
189 textureFadeStart = fade;
190 ogreScene->setShadowTextureFadeStart(fade);
191}
192
194{
195 return textureFadeStart;
196}
197
198void SShadowManager::SetShadowFadeEnd(const float& fade)
199{
200 textureFadeEnd = fade;
201 ogreScene->setShadowTextureFadeEnd(fade);
202}
203
205{
206 return textureFadeEnd;
207}
208
209void SShadowManager::SetSelfShadow(const bool& state)
210{
211 ogreScene->setShadowTextureSelfShadow(state);
212}
213
215{
216 return ogreScene->getShadowTextureSelfShadow();
217}
218
220{
221 if (quality != currentQuality)
222 {
223 currentQuality = quality;
224
225 //rebuild the shadows
228 SetShadowType(lastType);
229 }
230}
231
236
237void SShadowManager::UpdateShadowMaterial(Ogre::Technique* tech)
238{
239 if (currentShadowSystem != 0)
240 currentShadowSystem->UpdateShadowMaterial(tech);
241}
242
243void SShadowManager::CleanShadowMaterial(Ogre::Technique* tech)
244{
245 if (currentShadowSystem != 0)
246 currentShadowSystem->RemoveMaterialPass(tech);
247}
248
250{
251 if (currentShadowSystem != 0)
252 return currentShadowSystem->IsShadowMaterialPass(pass);
253
254 return false;
255}
256
257}
static Ogre::ColourValue ScolToOgreColorRGBA(const int &scolColor)
static int OgreToScolColorRGBA(const Ogre::ColourValue &ogreColor)
void UpdateLightsShadowParameters()
Definition SO3Scene.cpp:889
Ogre::SceneManager * GetOgreScenePointer()
Definition SO3Scene.cpp:449
static bool CheckSystemCompatibility()
virtual void UpdateShadowTechnique()=0
Definition SO3Shadow.cpp:79
virtual void UpdateShadowMaterial(Ogre::Technique *tech)
Definition SO3Shadow.cpp:83
virtual void RemoveMaterialPass(Ogre::Technique *tech)
Definition SO3Shadow.cpp:87
SShadowManager::ShadowType GetShadowType()
Definition SO3Shadow.cpp:69
virtual bool IsShadowMaterialPass(Ogre::Pass *pass)
Definition SO3Shadow.cpp:91
static bool CheckSystemCompatibility()
void SetShadowFadeStart(const float &fade)
float GetShadowDirectionalLightExtrusionDistance()
void UpdateShadowMaterial(Ogre::Technique *tech)
ShadowLightingType GetLightingTechnique()
void SetShadowType(const ShadowType &type)
void SetColour(const int &color)
void CleanShadowMaterial(Ogre::Technique *tech)
void SetSelfShadow(const bool &state)
void SetShadowFadeEnd(const float &fade)
void SetShadowQuality(ShadowQuality quality)
void SetLightingTechnique(const ShadowLightingType &technique)
void SetShadowFarDistance(const float &dist)
void SetTextureSize(const int &size)
bool IsShadowMaterialPass(Ogre::Pass *pass)
ShadowQuality GetShadowQuality()
void SetShadowDirectionalLightExtrusionDistance(const float &value)
Ogre::SceneManager * ogreScene
static bool CheckSystemCompatibility()