• Brute Force (HeightMap) For Terrain Rendering


    Triangle Num:32768

    FPS < 30

    Environment: 6G-ddr3, i5-480m

    Brute Force not very userful for nowadays game, due to its poor fps. I'm a novice for terrain rendering, maybe the "LOD" could increase the fps. 

    How to do : Here is the principle and below is the code(yes, I use Ogre O>_<O).

    void createScene()
    	{
    		// load terrain map
    		if(myTerrain.LoadHeightMap("height.dat", TERRAIN_SIZE))
    		{
    			myTerrain.SetHeightScale(0.25f);
    		}
    		else
    		{
    			return;
    		}
    
    		//config the light
    		/*Ogre::Light* light = mSceneMgr->createLight("Light1");
    		light->setType(Ogre::Light::LT_DIRECTIONAL);
    		light->setDirection(Ogre::Vector3(1,-1,0));*/
    
    		Ogre::MaterialPtr mat = Ogre::MaterialManager::getSingleton().create("myMaterialWithNoCulling",
    			Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME);
    		mat->setCullingMode(Ogre::CULL_NONE );
    		mat->setSceneBlending(Ogre::SBT_ADD); 
    
    		Ogre::ManualObject* manual = mSceneMgr->createManualObject("MyTerrain");
    		manual->begin("myMaterialWithNoCulling", RenderOperation::OT_TRIANGLE_LIST);
    		float fColor;
    		for(int iz = 0; iz < TERRAIN_SIZE - 1; ++iz)
    		{
    			for(int ix = 0; ix < TERRAIN_SIZE - 1 ; ++ix)
    			{
    
    				fColor = myTerrain.GetTrueHeightAtPoint(ix, iz);
    				manual->position(ix, myTerrain.GetScaledHeightAtPoint(ix,iz), iz);
    				manual->colour(fColor, fColor, fColor);
    
    				fColor = myTerrain.GetTrueHeightAtPoint(ix + 1, iz);
    				manual->position(ix + 1, myTerrain.GetScaledHeightAtPoint(ix + 1,iz), iz);
    				manual->colour(fColor, fColor, fColor);
    
    				fColor = myTerrain.GetTrueHeightAtPoint(ix, iz + 1);
    				manual->position(ix, myTerrain.GetScaledHeightAtPoint(ix,iz + 1), iz + 1);
    				manual->colour(fColor, fColor, fColor);
    
    				fColor = myTerrain.GetTrueHeightAtPoint(ix, iz + 1);
    				manual->position(ix, myTerrain.GetScaledHeightAtPoint(ix,iz + 1), iz + 1);
    				manual->colour(fColor, fColor, fColor);
    
    				fColor = myTerrain.GetTrueHeightAtPoint(ix + 1, iz);
    				manual->position(ix + 1, myTerrain.GetScaledHeightAtPoint(ix + 1,iz), iz);
    				manual->colour(fColor, fColor, fColor);
    
    				fColor = myTerrain.GetTrueHeightAtPoint(ix + 1, iz + 1);
    				manual->position(ix + 1, myTerrain.GetScaledHeightAtPoint(ix + 1,iz + 1), iz + 1);
    				manual->colour(fColor, fColor, fColor);
    			}
    		}
    
    		manual->end();
    
    		/*manual->convertToMesh("bruteForceTerrain");
    
    		Ogre::Entity* terrainMesh = mSceneMgr->createEntity("bruteForceTerrain");*/
    
    		mSceneMgr->getRootSceneNode()->createChildSceneNode()->attachObject(manual);
    	}
    

      

  • 相关阅读:
    SharePoint Server 2007 Beta2 Technical Refresh 安装提示
    SharePoint Server安全工具:Forefront for SharePoint
    7月6日,深圳OTEC成员会议
    数据字典存储事件实例
    C#学习:事件
    发布符合 .NET Framework 准则的事件
    ASP.NET缓存:用户控件缓存
    C#中用ToString方法格式化时间
    C#学习:委托
    实现接口事件
  • 原文地址:https://www.cnblogs.com/Baesky/p/Ogre_Brute_Terrain.html
Copyright © 2020-2023  润新知