void ShadowManager::updatePSSM(Ogre::Terrain* terrain)
{
	if (!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(false);
	}


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

	Ogre::Vector4 splitPoints;
	for (size_t i = 0; i < /*3*/splitPointList.size(); ++i)
		splitPoints[i] = splitPointList[i];

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


	if (matProfile && terrain)
	{
		matProfile->generateForCompositeMap(terrain);
		matProfile->setReceiveDynamicShadowsDepth(mDepthShadows);
		matProfile->setReceiveDynamicShadowsPSSM(static_cast<Ogre::PSSMShadowCameraSetup*>(mPSSMSetup.get()));
	}
}
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()));
	}
}
Beispiel #3
0
void ShadowManager::processPSSM()
{
    gEnv->sceneManager->setShadowTechnique(Ogre::SHADOWTYPE_TEXTURE_ADDITIVE_INTEGRATED);

    gEnv->sceneManager->setShadowDirectionalLightExtrusionDistance(299.0f);
    gEnv->sceneManager->setShadowFarDistance(350.0f);
    gEnv->sceneManager->setShadowTextureCountPerLightType(Ogre::Light::LT_DIRECTIONAL, PSSM_Shadows.ShadowsTextureNum);
    gEnv->sceneManager->setShadowTextureCount(PSSM_Shadows.ShadowsTextureNum);

    gEnv->sceneManager->setShadowTextureSelfShadow(true);
    gEnv->sceneManager->setShadowCasterRenderBackFaces(true);

    //Caster is set via materials
    gEnv->sceneManager->setShadowTextureCasterMaterial("Ogre/shadow/depth/caster");

    if (PSSM_Shadows.Quality == 3)
    {
        gEnv->sceneManager->setShadowTextureConfig(0, 4096, 4096, PF_FLOAT32_R);
        gEnv->sceneManager->setShadowTextureConfig(1, 3072, 3072, PF_FLOAT32_R);
        gEnv->sceneManager->setShadowTextureConfig(2, 2048, 2048, PF_FLOAT32_R);
        PSSM_Shadows.lambda = 0.965f;
    }
    else if (PSSM_Shadows.Quality == 2)
    {
        gEnv->sceneManager->setShadowTextureConfig(0, 3072, 3072, PF_FLOAT32_R);
        gEnv->sceneManager->setShadowTextureConfig(1, 2048, 2048, PF_FLOAT32_R);
        gEnv->sceneManager->setShadowTextureConfig(2, 2048, 2048, PF_FLOAT32_R);
        PSSM_Shadows.lambda = 0.97f;
    }
    else if (PSSM_Shadows.Quality == 1)
    {
        gEnv->sceneManager->setShadowTextureConfig(0, 2048, 2048, PF_FLOAT32_R);
        gEnv->sceneManager->setShadowTextureConfig(1, 1024, 1024, PF_FLOAT32_R);
        gEnv->sceneManager->setShadowTextureConfig(2, 1024, 1024, PF_FLOAT32_R);
        PSSM_Shadows.lambda = 0.975f;
    }
    else
    {
        gEnv->sceneManager->setShadowTextureConfig(0, 1024, 1024, PF_FLOAT32_R);
        gEnv->sceneManager->setShadowTextureConfig(1, 1024, 1024, PF_FLOAT32_R);
        gEnv->sceneManager->setShadowTextureConfig(2, 512, 512, PF_FLOAT32_R);
        PSSM_Shadows.lambda = 0.98f;
    }

    if (PSSM_Shadows.mPSSMSetup.isNull())
    {
        // shadow camera setup
        Ogre::PSSMShadowCameraSetup* pssmSetup = new Ogre::PSSMShadowCameraSetup();

        pssmSetup->calculateSplitPoints(3, gEnv->mainCamera->getNearClipDistance(), gEnv->sceneManager->getShadowFarDistance(), PSSM_Shadows.lambda);
        pssmSetup->setSplitPadding(gEnv->mainCamera->getNearClipDistance());

        pssmSetup->setOptimalAdjustFactor(0, -1);
        pssmSetup->setOptimalAdjustFactor(1, -1);
        pssmSetup->setOptimalAdjustFactor(2, -1);

        PSSM_Shadows.mPSSMSetup.bind(pssmSetup);

        //Send split info to managed materials
        setManagedMaterialSplitPoints(pssmSetup->getSplitPoints());
    }
    gEnv->sceneManager->setShadowCameraSetup(PSSM_Shadows.mPSSMSetup);
}
	void Main::initScene()
	{
		Ogre::LogManager::getSingleton().logMessage("Main initScene");

		Ice::MessageSystem::Instance().CreateNewsgroup(GlobalMessageIDs::UPDATE_PER_FRAME);
		Ice::MessageSystem::Instance().CreateNewsgroup(GlobalMessageIDs::RENDERING_BEGIN);

		Ice::MessageSystem::Instance().CreateNewsgroup(GlobalMessageIDs::PHYSICS_BEGIN);
		Ice::MessageSystem::Instance().CreateNewsgroup(GlobalMessageIDs::PHYSICS_SUBSTEP);
		Ice::MessageSystem::Instance().CreateNewsgroup(GlobalMessageIDs::PHYSICS_END);

		Ice::MessageSystem::Instance().CreateNewsgroup(GlobalMessageIDs::UPDATE_INDEPENDANT);

		Ice::MessageSystem::Instance().CreateNewsgroup(GlobalMessageIDs::KEY_DOWN);
		Ice::MessageSystem::Instance().CreateNewsgroup(GlobalMessageIDs::KEY_UP);
		Ice::MessageSystem::Instance().CreateNewsgroup(GlobalMessageIDs::MOUSE_DOWN);
		Ice::MessageSystem::Instance().CreateNewsgroup(GlobalMessageIDs::MOUSE_UP);
		Ice::MessageSystem::Instance().CreateNewsgroup(GlobalMessageIDs::MOUSE_MOVE);

		Ice::MessageSystem::Instance().CreateNewsgroup(GlobalMessageIDs::GAMESTATE_ENTER);
		Ice::MessageSystem::Instance().CreateNewsgroup(GlobalMessageIDs::GAMESTATE_LEAVE);

		Ice::MessageSystem::Instance().CreateNewsgroup(GlobalMessageIDs::CONSOLE_INGAME);

		Ice::MessageSystem::Instance().CreateNewsgroup(GlobalMessageIDs::LOADLEVEL_BEGIN);
		Ice::MessageSystem::Instance().CreateNewsgroup(GlobalMessageIDs::LOADLEVEL_END);
		Ice::MessageSystem::Instance().CreateNewsgroup(GlobalMessageIDs::SAVELEVEL_BEGIN);
		Ice::MessageSystem::Instance().CreateNewsgroup(GlobalMessageIDs::SAVELEVEL_END);

		Ice::MessageSystem::Instance().CreateNewsgroup(GlobalMessageIDs::ACTOR_ONSLEEP);
		Ice::MessageSystem::Instance().CreateNewsgroup(GlobalMessageIDs::ACTOR_ONWAKE);
		Ice::MessageSystem::Instance().CreateNewsgroup(GlobalMessageIDs::MATERIAL_ONCONTACT);

		Ice::MessageSystem::Instance().CreateNewsgroup(GlobalMessageIDs::REPARSE_SCRIPTS_PRE);
		Ice::MessageSystem::Instance().CreateNewsgroup(GlobalMessageIDs::REPARSE_SCRIPTS_POST);

		MessageSystem::Instance().CreateNewsgroup(GlobalMessageIDs::ENABLE_GAME_CLOCK);

		Ogre::LogManager::getSingleton().logMessage("Starting PhysX");

		//Start up OgrePhysX
		OgrePhysX::World::getSingleton().init();

		mSceneMgr = mRoot->createSceneManager(Ogre::ST_GENERIC, "Esgaroth");
		mCamera = mSceneMgr->createCamera("MainCamera");
		mCamera->lookAt(Ogre::Vector3(0,0,1));
		mCamera->setNearClipDistance(0.4f);
		mCamera->setFarClipDistance(50000);

		mViewport = mWindow->addViewport(mCamera);
		mViewport->setBackgroundColour(Ogre::ColourValue::Black);
		mCamera->setAspectRatio(Ogre::Real(mViewport->getActualWidth()) / Ogre::Real(mViewport->getActualHeight()));

		//Create PhysX Scene
		PxSceneDesc sceneDesc(OgrePhysX::getPxPhysics()->getTolerancesScale());
		sceneDesc.gravity = PxVec3(0, -9.81f, 0);
		sceneDesc.filterShader = &PhysXSimulationFilterShader;
		mPhysXSimulationCallback = ICE_NEW PhysXSimulationEventCallback();
		sceneDesc.simulationEventCallback = mPhysXSimulationCallback;
		mPhysXScene = OgrePhysX::World::getSingleton().addScene("Main", mSceneMgr, sceneDesc);

		mPreviewSceneMgr = mRoot->createSceneManager(Ogre::ST_GENERIC, "Esgaroth_Preview");

		InitOgreResources();

		Ogre::TextureManager::getSingleton().setDefaultNumMipmaps(5);
		Ogre::MaterialManager::getSingleton().setDefaultTextureFiltering(Ogre::TFO_ANISOTROPIC);
		Ogre::MaterialManager::getSingleton().setDefaultAnisotropy(8); 

		Ogre::MaterialManager::getSingleton().addListener(new DepthSchemeHandler(), "depth");

		//mPreviewSceneMgr->setSkyBox(true, "Sky/ClubTropicana", 2000);
		mPreviewSceneMgr->setAmbientLight(Ogre::ColourValue(0.8f, 0.8f, 0.8f));
		Ogre::Light *ambientlight = mPreviewSceneMgr->createLight("SkyLight");
		ambientlight->setType(Ogre::Light::LightTypes::LT_DIRECTIONAL);
		ambientlight->setDirection(Ogre::Vector3(0,-1,0.4f).normalisedCopy());
		ambientlight->setDiffuseColour(Ogre::ColourValue(1,1,1));
		ambientlight->setSpecularColour(Ogre::ColourValue(1,1,1));

		mSceneMgr->setAmbientLight(Ogre::ColourValue(0.3f,0.2f,0.2f));
		//mSceneMgr->setFog(Ogre::FOG_LINEAR, Ogre::ColourValue::Blue, 0.015);

		mCameraController = ICE_NEW FreeFlightCameraController();
		SceneManager::Instance().AcquireCamera(mCameraController);

		//init scripting stuff
		ScriptSystem::GetInstance();
		LuaScript::SetLoader(OgreFileLoader);
		LuaScript::SetLogFn(ScriptLogFn);
		/*	GUISystem::GetInstance();
		MusicSystem::GetInstance();
		ScriptedControls::GetInstance();*/

		//sound
		mSoundManager = OgreOggSound::OgreOggSoundManager::getSingletonPtr();
		mSoundManager->init("");
		mSoundManager->setSceneManager(mSceneMgr);
		mSoundManager->setDistanceModel(AL_LINEAR_DISTANCE);
		//mCamera->getParentSceneNode()->attachObject(mSoundManager->getListener());

		InitCompositor();

		Ogre::MovableObject::setDefaultVisibilityFlags( Ice::VisibilityFlags::V_DEFAULT);

		/*mCollisionCallback = ICE_NEW ScriptedCollisionCallback();
		NxOgre::ActorGroup *dynamicbodies = mScene->createActorGroup("DynamicBody");
		mScene->addMaterialPair(
		dynamicbodies->((NxOgre::GroupCallback::InheritedCallback*)(mCollisionCallback));
		dynamicbodies->setCollisionCallback(dynamicbodies, NX_NOTIFY_ALL, false);*/

		mSceneMgr->setShadowTechnique(Ogre::SHADOWTYPE_TEXTURE_ADDITIVE_INTEGRATED);

		mSceneMgr->setShadowTextureCountPerLightType(Ogre::Light::LT_DIRECTIONAL, 3);
		mSceneMgr->setShadowTextureCountPerLightType(Ogre::Light::LT_SPOTLIGHT, 1);
		mSceneMgr->setShadowTextureCount(3);
		mSceneMgr->setShadowTextureConfig(0, 2048, 2048, Ogre::PF_FLOAT32_R);
		mSceneMgr->setShadowTextureConfig(1, 2048, 2048, Ogre::PF_FLOAT32_R);
		mSceneMgr->setShadowTextureConfig(2, 2048, 2048, Ogre::PF_FLOAT32_R);
		/*mSceneMgr->setShadowTextureConfig(3, 1024, 1024, Ogre::PF_FLOAT32_R);
		mSceneMgr->setShadowTextureConfig(4, 1024, 1024, Ogre::PF_FLOAT32_R);
		mSceneMgr->setShadowTextureConfig(5, 1024, 1024, Ogre::PF_FLOAT32_R);
		mSceneMgr->setShadowTextureConfig(6, 1024, 1024, Ogre::PF_FLOAT32_R);
		mSceneMgr->setShadowTextureConfig(7, 1024, 1024, Ogre::PF_FLOAT32_R);*/
		/*mSceneMgr->setShadowTextureSelfShadow(true);*/
		mSceneMgr->setShadowTextureCasterMaterial("shadow_caster");

		mSceneMgr->getShadowTexture(0)->getBuffer()->getRenderTarget()->getViewport(0)->setBackgroundColour(Ogre::ColourValue::White);
		mSceneMgr->getShadowTexture(0)->getBuffer()->getRenderTarget()->getViewport(0)->setClearEveryFrame(true);
		mSceneMgr->getShadowTexture(1)->getBuffer()->getRenderTarget()->getViewport(0)->setBackgroundColour(Ogre::ColourValue::White);
		mSceneMgr->getShadowTexture(1)->getBuffer()->getRenderTarget()->getViewport(0)->setClearEveryFrame(true);
		mSceneMgr->getShadowTexture(2)->getBuffer()->getRenderTarget()->getViewport(0)->setBackgroundColour(Ogre::ColourValue::White);
		mSceneMgr->getShadowTexture(2)->getBuffer()->getRenderTarget()->getViewport(0)->setClearEveryFrame(true);

		mSceneMgr->setShadowCasterRenderBackFaces(false);

		// shadow camera setup
		Ogre::FocusedShadowCameraSetup* spotSetup = ICE_NEW Ogre::FocusedShadowCameraSetup();
		mSpotShadowCameraSetup = Ogre::ShadowCameraSetupPtr(spotSetup);

		Ogre::PSSMShadowCameraSetup* pssmSetup = ICE_NEW Ogre::PSSMShadowCameraSetup();
		pssmSetup->calculateSplitPoints(3, 0.4f, 300, 0.95f);
		pssmSetup->setSplitPadding(1);
		pssmSetup->setOptimalAdjustFactor(0, 2);
		pssmSetup->setOptimalAdjustFactor(1, 0.6f);
		pssmSetup->setOptimalAdjustFactor(2, 0.3f);//0.4f);//2, 0.5);
		mDirectionalShadowCameraSetup = Ogre::ShadowCameraSetupPtr(pssmSetup);
		mSceneMgr->setShadowCameraSetup(mDirectionalShadowCameraSetup);
		const Ogre::PSSMShadowCameraSetup::SplitPointList& splitPointList = pssmSetup->getSplitPoints();
		Ogre::Vector4 PSSMSplitPoints;
		for (int i = 0; i < 3; ++i)
		{
			PSSMSplitPoints[i] = splitPointList[i];
		}

		IceNote("PSSMSplitPoints: " + Ogre::StringConverter::toString(PSSMSplitPoints));

		SceneManager::Instance().Init();

		//Load save initialisation
		RegisterStandardAtoms();
		LoadSave::LoadSave::Instance().SetLogFunction(LogMessage);

		LoadSave::LoadSave::Instance().RegisterObject(&DataMap::Register);
		LoadSave::LoadSave::Instance().RegisterObject(&DataMap::Item::Register);
		LoadSave::LoadSave::Instance().RegisterObject(&GenericProperty::Register);
		LoadSave::LoadSave::Instance().RegisterObject(&GameObject::Register);
		LoadSave::LoadSave::Instance().RegisterObject(&ObjectReference::Register);
		LoadSave::LoadSave::Instance().RegisterObject(&LoadSave::SaveableDummy::Register);

		LoadSave::LoadSave::Instance().RegisterObject(&NavigationMesh::Register);

		LoadSave::LoadSave::Instance().RegisterAtom((LoadSave::AtomHandler*)new SaveableVectorHandler<GameObject>("vector<GameObjectPtr>"));
		LoadSave::LoadSave::Instance().RegisterAtom((LoadSave::AtomHandler*)new SaveableVectorHandler<ObjectReference>("vector<ObjectReferencePtr>"));
		LoadSave::LoadSave::Instance().RegisterAtom((LoadSave::AtomHandler*)new SaveableVectorHandler<GOComponent>("vector<GOComponentPtr>"));
		LoadSave::LoadSave::Instance().RegisterAtom((LoadSave::AtomHandler*)new SaveableVectorHandler<NavigationMesh::PathNodeTree>("vector<PathNodeTreePtr>"));
		LoadSave::LoadSave::Instance().RegisterAtom((LoadSave::AtomHandler*)new SaveableVectorHandler<DataMap::Item>("vector<DataMapItemPtr>"));

		//Init script functions
		InitCoreLuaFunctions();

		//Load Plugins
		LoadPlugins();
		//initialize scripts
		ScriptSystem::GetInstance().CreateInstance("StartEngine.lua");
		ScriptSystem::GetInstance().CreateInstance("InitEngine.lua");

		MaterialTable::Instance().InitBindingsFromCfg("OgreMaterialSoundBindings.cfg");

		SceneManager::Instance().PostInit();

		/*Ogre::TexturePtr t_depth = Ogre::TextureManager::getSingleton().createManual("rt_SceneDepth",
		Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, Ogre::TEX_TYPE_2D, 512, 512, 0, Ogre::PF_FLOAT16_RGB, Ogre::TU_RENDERTARGET);
		Ogre::RenderTarget* depth_rtt = t_depth->getBuffer()->getRenderTarget();
		depth_rtt->addViewport(mCamera)->setOverlaysEnabled(false);
		depth_rtt->getViewport(0)->setShadowsEnabled(false);
		depth_rtt->getViewport(0)->setAutoUpdated(true);
		depth_rtt->getViewport(0)->setBackgroundColour(Ogre::ColourValue::Black);
		depth_rtt->getViewport(0)->setClearEveryFrame(true);
		depth_rtt->getViewport(0)->setVisibilityMask(4294967281);
		depth_rtt->getViewport(0)->setMaterialScheme("depth");

		Ogre::TexturePtr t_volumetrics = Ogre::TextureManager::getSingleton().createManual("rt_VolumetricObjects",
		Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, Ogre::TEX_TYPE_2D, 512, 512, 0, Ogre::PF_FLOAT16_RGB, Ogre::TU_RENDERTARGET);
		Ogre::RenderTarget* volumetrics_rtt = t_volumetrics->getBuffer()->getRenderTarget();
		volumetrics_rtt->addViewport(mCamera)->setOverlaysEnabled(false);
		volumetrics_rtt->getViewport(0)->setAutoUpdated(true);
		volumetrics_rtt->getViewport(0)->setShadowsEnabled(false);
		volumetrics_rtt->getViewport(0)->setClearEveryFrame(true);
		volumetrics_rtt->getViewport(0)->setVisibilityMask(2);
		volumetrics_rtt->getViewport(0)->setMaterialScheme("Volumetrics");*/


	};