示例#1
0
void TerrainGeometryManager::configureTerrainDefaults()
{
	OGRE_NEW TerrainGlobalOptions();

	Light *light = gEnv->terrainManager->getMainLight();
	TerrainGlobalOptions *terrainOptions = TerrainGlobalOptions::getSingletonPtr();
	// Configure global
	terrainOptions->setMaxPixelError(IOPT("MaxPixelError", 5));

	// Important to set these so that the terrain knows what to use for derived (non-realtime) data
	if (light)
	{
		terrainOptions->setLightMapDirection(light->getDerivedDirection());
		terrainOptions->setCompositeMapDiffuse(light->getDiffuseColour());
	}
	terrainOptions->setCompositeMapAmbient(gEnv->sceneManager->getAmbientLight());

	// Configure default import settings for if we use imported image
	Ogre::Terrain::ImportData& defaultimp = mTerrainGroup->getDefaultImportSettings();
	defaultimp.terrainSize  = terrainSize; // the heightmap size
	defaultimp.worldSize    = worldSize; // this is the scaled up size, like 12km
	defaultimp.inputScale   = mapsizey;
	defaultimp.minBatchSize = IOPT("minBatchSize", 33);
	defaultimp.maxBatchSize = IOPT("maxBatchSize", 65);

	// optimizations
	TerrainMaterialGeneratorA::SM2Profile* matProfile = static_cast<TerrainMaterialGeneratorA::SM2Profile*>(terrainOptions->getDefaultMaterialGenerator()->getActiveProfile());
	if (matProfile)
	{
		matProfile->setLightmapEnabled(BOPT("LightmapEnabled", false));
		matProfile->setLayerNormalMappingEnabled(BOPT("NormalMappingEnabled", false));
		matProfile->setLayerSpecularMappingEnabled(BOPT("SpecularMappingEnabled", false));
		matProfile->setLayerParallaxMappingEnabled(BOPT("ParallaxMappingEnabled", false));
		matProfile->setGlobalColourMapEnabled(BOPT("GlobalColourMapEnabled", false));
		matProfile->setReceiveDynamicShadowsDepth(BOPT("ReceiveDynamicShadowsDepth", true));
	}

	terrainOptions->setLayerBlendMapSize(IOPT("LayerBlendMapSize", 1024));
	terrainOptions->setCompositeMapSize(IOPT("CompositeMapSize", 1024));
	terrainOptions->setCompositeMapDistance(IOPT("CompositeMapDistance", 4000));
	terrainOptions->setSkirtSize(IOPT("SkirtSize", 30));
	terrainOptions->setLightMapSize(IOPT("LightMapSize", 1024));
	terrainOptions->setCastsDynamicShadows(BOPT("CastsDynamicShadows", true));

	terrainOptions->setUseRayBoxDistanceCalculation(false);

	// load layer basics now
	loadLayers(0, 0, 0);
}
  void configureShadows( bool enabled, bool depthShadows )
  {
    TerrainMaterialGeneratorA::SM2Profile* matProfile =
      static_cast<TerrainMaterialGeneratorA::SM2Profile*>(mTerrainGlobals->getDefaultMaterialGenerator()->getActiveProfile());
    matProfile->setReceiveDynamicShadowsEnabled( enabled );
#ifdef SHADOWS_IN_LOW_LOD_MATERIAL
    matProfile->setReceiveDynamicShadowsLowLod( true );
#else
    matProfile->setReceiveDynamicShadowsLowLod( false );
#endif
    // Default materials
    for( EntityList::iterator i = mHouseList.begin(); i != mHouseList.end(); ++i )
    {
      (*i)->setMaterialName( "Examples/TudorHouse" );
    }
    if( enabled )
    {// General scene setup
      mSceneMgr->setShadowTechnique( SHADOWTYPE_TEXTURE_ADDITIVE_INTEGRATED );
      mSceneMgr->setShadowFarDistance( 3000 );

      // 3 textures per directional light (PSSM)
      mSceneMgr->setShadowTextureCountPerLightType( Ogre::Light::LT_DIRECTIONAL, 3 );
      if( mPSSMSetup.isNull() )
      {// shadow camera setup
        PSSMShadowCameraSetup* pssmSetup = new PSSMShadowCameraSetup();
        pssmSetup->setSplitPadding( mCamera->getNearClipDistance() );
        pssmSetup->calculateSplitPoints( 3, mCamera->getNearClipDistance(), mSceneMgr->getShadowFarDistance() );
        pssmSetup->setOptimalAdjustFactor( 0, 2 );
        pssmSetup->setOptimalAdjustFactor( 1, 1 );
        pssmSetup->setOptimalAdjustFactor( 2, 0.5 );

        mPSSMSetup.bind( pssmSetup );
      }
      mSceneMgr->setShadowCameraSetup( mPSSMSetup );
      if( depthShadows )
      {
        mSceneMgr->setShadowTextureCount( 3 );
        mSceneMgr->setShadowTextureConfig( 0, 2048, 2048, PF_FLOAT32_R );
        mSceneMgr->setShadowTextureConfig( 1, 1024, 1024, PF_FLOAT32_R );
        mSceneMgr->setShadowTextureConfig( 2, 1024, 1024, PF_FLOAT32_R );
        mSceneMgr->setShadowTextureSelfShadow( true );
        mSceneMgr->setShadowCasterRenderBackFaces( true );

        MaterialPtr houseMat = buildDepthShadowMaterial( "fw12b.jpg" );
        for( EntityList::iterator i = mHouseList.begin(); i != mHouseList.end(); ++i )
        {
          (*i)->setMaterial( houseMat );
        }
      }
      else
      {
        mSceneMgr->setShadowTextureCount( 3 );
        mSceneMgr->setShadowTextureConfig( 0, 2048, 2048, PF_X8B8G8R8 );
        mSceneMgr->setShadowTextureConfig( 1, 1024, 1024, PF_X8B8G8R8 );
        mSceneMgr->setShadowTextureConfig( 2, 1024, 1024, PF_X8B8G8R8 );
        mSceneMgr->setShadowTextureSelfShadow( false );
        mSceneMgr->setShadowCasterRenderBackFaces( false );
        mSceneMgr->setShadowTextureCasterMaterial( StringUtil::BLANK );
      }
      matProfile->setReceiveDynamicShadowsDepth( depthShadows );
      matProfile->setReceiveDynamicShadowsPSSM( static_cast<PSSMShadowCameraSetup*>(mPSSMSetup.get()) );
      //addTextureShadowDebugOverlay(TL_RIGHT, 3);
    }
    else
    {
      mSceneMgr->setShadowTechnique( SHADOWTYPE_NONE );
    }
  }