28 #include <Terrain/OgreTerrain.h>
29 #include <Overlay/OgreOverlayManager.h>
30 #include <Overlay/OgreOverlayContainer.h>
31 #include <Overlay/OgreOverlay.h>
32 #include <OgreMaterialManager.h>
37 ShadowManager::ShadowManager()
39 PSSM_Shadows.mPSSMSetup.setNull();
40 PSSM_Shadows.mDepthShadows =
false;
41 PSSM_Shadows.ShadowsTextureNum = 3;
45 ShadowManager::~ShadowManager()
49 void ShadowManager::loadConfiguration()
51 this->updateShadowTechnique();
54 int ShadowManager::updateShadowTechnique()
67 OverlayManager& mgr = Ogre::OverlayManager::getSingleton();
68 Overlay* overlay = mgr.create(
"DebugOverlay");
70 for (
int i = 0; i < PSSM_Shadows.ShadowsTextureNum; ++i)
75 MaterialPtr debugMat = MaterialManager::getSingleton().create(
"Ogre/DebugTexture" + StringConverter::toString(i), ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME);
76 debugMat->getTechnique(0)->getPass(0)->setLightingEnabled(
false);
77 TextureUnitState* t = debugMat->getTechnique(0)->getPass(0)->createTextureUnitState(tex->getName());
78 t->setTextureAddressingMode(TextureUnitState::TAM_CLAMP);
80 OverlayContainer* debugPanel = (OverlayContainer*)(OverlayManager::getSingleton().createOverlayElement(
"Panel",
"Ogre/DebugTexPanel" + StringConverter::toString(i)));
81 debugPanel->_setPosition(0.8, i * 0.25);
82 debugPanel->_setDimensions(0.2, 0.24);
83 debugPanel->setMaterialName(debugMat->getName());
84 debugPanel->setEnabled(
true);
85 overlay->add2D(debugPanel);
93 void ShadowManager::processPSSM()
106 MaterialPtr shadowMat = MaterialManager::getSingleton().getByName(
"Ogre/shadow/depth/caster");
109 if (PSSM_Shadows.Quality == 3)
114 PSSM_Shadows.lambda = 0.965f;
116 else if (PSSM_Shadows.Quality == 2)
121 PSSM_Shadows.lambda = 0.97f;
123 else if (PSSM_Shadows.Quality == 1)
128 PSSM_Shadows.lambda = 0.975f;
135 PSSM_Shadows.lambda = 0.98f;
138 if (PSSM_Shadows.mPSSMSetup.isNull())
141 Ogre::PSSMShadowCameraSetup* pssmSetup =
new Ogre::PSSMShadowCameraSetup();
146 pssmSetup->setOptimalAdjustFactor(0, -1);
147 pssmSetup->setOptimalAdjustFactor(1, -1);
148 pssmSetup->setOptimalAdjustFactor(2, -1);
150 PSSM_Shadows.mPSSMSetup.bind(pssmSetup);
153 setManagedMaterialSplitPoints(pssmSetup->getSplitPoints());
158 void ShadowManager::updatePSSM()
160 if (!PSSM_Shadows.mPSSMSetup.get())
169 Ogre::PSSMShadowCameraSetup* pssmSetup =
static_cast<Ogre::PSSMShadowCameraSetup*
>(PSSM_Shadows.mPSSMSetup.get());
178 void ShadowManager::setManagedMaterialSplitPoints(Ogre::PSSMShadowCameraSetup::SplitPointList splitPointList)
180 Ogre::Vector4 splitPoints;
182 for (
int i = 0; i < 3; ++i)
183 splitPoints[i] = splitPointList[i];
185 GpuSharedParametersPtr p = GpuProgramManager::getSingleton().getSharedParameters(
"pssm_params");
186 p->setNamedConstant(
"pssmSplitPoints", splitPoints);