/// @brief Configure the shadow system. This should be the *FIRST* thing in the scene setup, because the shadow technique can alter the way meshes are loaded. void SceneSetup::setupShadowSystem (void) { #if SHADOW_METHOD == 1 /**** Stencil shadowing. No shaders necessary. ****/ GameCore::mSceneMgr->setShadowTechnique(Ogre::SHADOWTYPE_STENCIL_ADDITIVE); GameCore::mSceneMgr->setShadowFarDistance(150); GameCore::mSceneMgr->setShadowDirectionalLightExtrusionDistance(1000); #elif SHADOW_METHOD == 2 /**** Texture shadowmapping. Uses LiSPSM projection to enhance quality. ****/ GameCore::mSceneMgr->setShadowTechnique(Ogre::SHADOWTYPE_TEXTURE_ADDITIVE); GameCore::mSceneMgr->setShadowFarDistance(SHADOW_FAR_DISTANCE); GameCore::mSceneMgr->setShadowDirectionalLightExtrusionDistance(1000); GameCore::mSceneMgr->setShadowDirLightTextureOffset(0.9f); GameCore::mSceneMgr->setShadowTextureCount(1); GameCore::mSceneMgr->setShadowTextureSize(SHADOW_TEXTURE_SIZE); Ogre::LiSPSMShadowCameraSetup* shadowSetup = new Ogre::LiSPSMShadowCameraSetup(); shadowSetup->setOptimalAdjustFactor(1); GameCore::mSceneMgr->setShadowCameraSetup(Ogre::ShadowCameraSetupPtr(shadowSetup)); #elif SHADOW_METHOD == 3 /**** Depth Shadowmapping with PCF filtering and LiSPSM projection. Ensure materials are correctly setup. ****/ GameCore::mSceneMgr->setShadowTechnique(Ogre::SHADOWTYPE_TEXTURE_ADDITIVE); GameCore::mSceneMgr->setShadowFarDistance(150); GameCore::mSceneMgr->setShadowDirectionalLightExtrusionDistance(1000); GameCore::mSceneMgr->setShadowDirLightTextureOffset(0.9f); GameCore::mSceneMgr->setShadowTextureCount(1); GameCore::mSceneMgr->setShadowTextureConfig(0, 4096, 4096, Ogre::PF_FLOAT32_R); GameCore::mSceneMgr->setShadowTextureCasterMaterial("Ogre/DepthShadowmap/Caster/Float"); // Set the caster material. GameCore::mSceneMgr->setShadowTextureReceiverMaterial("Ogre/DepthShadowmap/Receiver/Float/PCF"); // Set the receiver material (remove /PCF to disable). GameCore::mSceneMgr->setShadowTextureSelfShadow(true); GameCore::mSceneMgr->setShadowCasterRenderBackFaces(true); Ogre::LiSPSMShadowCameraSetup* shadowSetup = new Ogre::LiSPSMShadowCameraSetup(); shadowSetup->setOptimalAdjustFactor(1); GameCore::mSceneMgr->setShadowCameraSetup(Ogre::ShadowCameraSetupPtr(shadowSetup)); #elif SHADOW_METHOD == 4 /**** Depth Shadowmapping with PSSM projection and LiSPSM filtering and split resolution. Ensure materials are correctly setup. ****/ GameCore::mSceneMgr->setShadowTechnique(Ogre::SHADOWTYPE_TEXTURE_ADDITIVE_INTEGRATED); GameCore::mSceneMgr->setShadowFarDistance(150); GameCore::mSceneMgr->setShadowDirectionalLightExtrusionDistance(500); GameCore::mSceneMgr->setShadowDirLightTextureOffset(0.7f); GameCore::mSceneMgr->setShadowTextureCountPerLightType(Ogre::Light::LT_DIRECTIONAL, 3); GameCore::mSceneMgr->setShadowTextureCount(3); GameCore::mSceneMgr->setShadowTextureConfig(0, 1024, 1024, Ogre::PF_FLOAT32_RGB); GameCore::mSceneMgr->setShadowTextureConfig(1, 1024, 1024, Ogre::PF_FLOAT32_RGB); GameCore::mSceneMgr->setShadowTextureConfig(2, 512, 512, Ogre::PF_FLOAT32_RGB); GameCore::mSceneMgr->setShadowTextureSelfShadow(true); GameCore::mSceneMgr->setShadowTextureCasterMaterial("PSSM/shadow_caster"); GameCore::mSceneMgr->setShadowCasterRenderBackFaces(false); GameCore::mSceneMgr->setShadowColour(Ogre::ColourValue(0.0f, 0.0f, 0.0f)); Ogre::PSSMShadowCameraSetup* shadowSetup = new Ogre::PSSMShadowCameraSetup(); shadowSetup->calculateSplitPoints(3, mCamera->getNearClipDistance() * 0.5, mCamera->getFarClipDistance()); char str[64]; sprintf(str, "\nnearClip=%.1f, farClip=%.1f\n\n", mCamera->getNearClipDistance(), mCamera->getFarClipDistance()); OutputDebugString(str); shadowSetup->setSplitPadding(1); shadowSetup->setOptimalAdjustFactor(0, 5); shadowSetup->setOptimalAdjustFactor(1, 1); shadowSetup->setOptimalAdjustFactor(2, 0); GameCore::mSceneMgr->setShadowCameraSetup(Ogre::ShadowCameraSetupPtr(shadowSetup)); #endif }
// ------------------------------------------------------------------------- void OgreBulletListener::init(Ogre::Root *root, Ogre::RenderWindow *win, OgreBulletApplication *application) { mRoot = root; mWindow = win; mApplication = application; mCameraTrans = Ogre::Vector3::ZERO; mGuiListener = new OgreBulletGuiListener(this, win); mInputListener = new OgreBulletInputListener(this, win); /******************* CREATESHADOWS ***************************/ #ifndef _DEBUG mCurrentShadowTechnique = convertShadowTechniqueToInt(SHADOWTYPE_TEXTURE_ADDITIVE); mSceneMgr->setShadowColour(ColourValue(0.5, 0.5, 0.5)); Ogre::PixelFormat pxlFmt = Ogre::PF_L8; if (mRoot->getRenderSystem()->getCapabilities()->hasCapability(RSC_TEXTURE_FLOAT)) { const bool isOpenGL = (Ogre::Root::getSingleton().getRenderSystem()->getName().find("GL") != Ogre::String::npos); if (isOpenGL)// GL performs much better if you pick half-float format pxlFmt = Ogre::PF_FLOAT16_R; else pxlFmt = Ogre::PF_FLOAT32_R;// D3D is the opposite - if you ask for PF_FLOAT16_R you // get an integer format instead! You can ask for PF_FLOAT16_GR // but the precision doesn't work well } if (pxlFmt != Ogre::PF_L8) { String CUSTOM_CASTER_MATERIAL("Ogre/DepthShadowmap/Caster/Float"); String CUSTOM_RECEIVER_MATERIAL("Ogre/DepthShadowmap/Receiver/Float"); mSceneMgr->setShadowTextureSelfShadow(true); mSceneMgr->setShadowTextureCasterMaterial(CUSTOM_CASTER_MATERIAL); mSceneMgr->setShadowTextureReceiverMaterial(CUSTOM_RECEIVER_MATERIAL + "/PCF"); //mSceneMgr->setShadowTextureReceiverMaterial(CUSTOM_RECEIVER_MATERIAL); } Ogre::LiSPSMShadowCameraSetup *mLiSPSMSetup = new Ogre::LiSPSMShadowCameraSetup(); mLiSPSMSetup->setUseAggressiveFocusRegion(true); //mLiSPSMSetup->setUseSimpleOptimalAdjust(true); mLiSPSMSetup->setOptimalAdjustFactor(1.1f); mSceneMgr->setShadowCameraSetup(Ogre::ShadowCameraSetupPtr(mLiSPSMSetup)); mSceneMgr->setShadowTechnique(convertToShadowTechnique(mCurrentShadowTechnique)); if (mRoot->getRenderSystem()->getCapabilities()->hasCapability(RSC_HWRENDER_TO_TEXTURE)) { // In D3D, use a 1024x1024 shadow texture mSceneMgr->setShadowTextureSettings(2048, 2, pxlFmt); } else { // Use 512x512 texture in GL since we can't go higher than the window res mSceneMgr->setShadowTextureSettings(512, 2, pxlFmt); } #endif // _DEBUG /******************* CREATE Queries ***************************/ mRayQuery = mSceneMgr->createRayQuery(Ray()); mRayQuery->setQueryMask (GEOMETRY_QUERY_MASK); mRayQuery->setQueryTypeMask(SceneManager::ENTITY_TYPE_MASK); MovableObject::setDefaultQueryFlags (ANY_QUERY_MASK); // mQuit = false; mPaused = false; mActivationBool = false; mPickConstraint = 0; mWireFrame = false; mDrawAabb = false; mDrawFeaturesText = false; mDrawContactPoints = false; mNoDeactivation = false; mNoHelpText = false; mDrawText = false; mProfileTimings = false; mEnableSatComparison = false; mDisableBulletLCP = false; mEnableCCD = false; }