Пример #1
0
void initShadows()
{
    GlbVar.ogreSmgr->setShadowTechnique(Ogre::SHADOWTYPE_TEXTURE_MODULATIVE_INTEGRATED);

    //3 textures per directional light.
    GlbVar.ogreSmgr->setShadowTextureCountPerLightType(Ogre::Light::LT_DIRECTIONAL, 3);
    GlbVar.ogreSmgr->setShadowTextureCount(3);
    GlbVar.ogreSmgr->setShadowTextureConfig(0, 2048, 2048, Ogre::PF_FLOAT32_R);
    GlbVar.ogreSmgr->setShadowTextureConfig(1, 2048, 2048, Ogre::PF_FLOAT32_R);
    GlbVar.ogreSmgr->setShadowTextureConfig(2, 1024, 1024, Ogre::PF_FLOAT32_R);
    GlbVar.ogreSmgr->setShadowTextureSelfShadow(true);
    GlbVar.ogreSmgr->setShadowCasterRenderBackFaces(true);

    //Caster material.
    GlbVar.ogreSmgr->setShadowTextureCasterMaterial("BaseShadowCaster");

    //Shadow camera setup.
    Ogre::PSSMShadowCameraSetup::SplitPointList splits;
    splits.push_back(0.1f);
    splits.push_back(18.7167f);
    splits.push_back(77.4301f);
    splits.push_back(1000.0f);

    Ogre::PSSMShadowCameraSetup* pssmSetup = new Ogre::PSSMShadowCameraSetup();
    pssmSetup->setSplitPoints(splits);
    pssmSetup->setSplitPadding(10);
    pssmSetup->setOptimalAdjustFactor(0, 5);
    pssmSetup->setOptimalAdjustFactor(1, 3);
    pssmSetup->setOptimalAdjustFactor(2, 0.1);
    GlbVar.ogreSmgr->setShadowCameraSetup(Ogre::ShadowCameraSetupPtr(pssmSetup));
}
Пример #2
0
void ShadowManager::updatePSSM(Ogre::Terrain* terrain)
{
	if (!PSSM_Shadows.mPSSMSetup.get())  return;

	Ogre::TerrainMaterialGeneratorA::SM2Profile *matProfile = 0;
	if (Ogre::TerrainGlobalOptions::getSingletonPtr())
	{
		matProfile = static_cast<Ogre::TerrainMaterialGeneratorA::SM2Profile*>(Ogre::TerrainGlobalOptions::getSingleton().getDefaultMaterialGenerator()->getActiveProfile());
		matProfile->setReceiveDynamicShadowsEnabled(true);
		matProfile->setReceiveDynamicShadowsLowLod(true);
		matProfile->setGlobalColourMapEnabled(true);
	}


	Ogre::PSSMShadowCameraSetup* pssmSetup = static_cast<Ogre::PSSMShadowCameraSetup*>(PSSM_Shadows.mPSSMSetup.get());
	Ogre::PSSMShadowCameraSetup::SplitPointList splitPointList = pssmSetup->getSplitPoints();

	
	splitPointList[0] = 1.0;
	splitPointList[1] = 95.0;
	splitPointList[2] = 255.0;
	splitPointList[3] = 512.0;
	pssmSetup->setSplitPoints(splitPointList);
	
	
	Ogre::Vector4 splitPoints;
	for (int i = 0; i < PSSM_Shadows.ShadowsTextureNum; ++i)
		splitPoints[i] = splitPointList[i];

	MaterialPtr mat = MaterialManager::getSingleton().getByName("RoR/Managed_Mats/Base");
	mat->getTechnique("ShadowTechnique")->getPass(0)->getFragmentProgramParameters()->setNamedConstant("pssmSplitPoints", splitPoints);

	// TODO: fix this
/*	setMaterialSplitPoints("road", splitPoints);
	setMaterialSplitPoints("road2", splitPoints);
	*/

	if (matProfile && terrain)
	{
		matProfile->generateForCompositeMap(terrain);
		matProfile->setReceiveDynamicShadowsDepth(PSSM_Shadows.mDepthShadows);
		matProfile->setReceiveDynamicShadowsPSSM(static_cast<Ogre::PSSMShadowCameraSetup*>(PSSM_Shadows.mPSSMSetup.get()));
	}
}