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);
    }

  

posted on   Meta.Grfx  阅读(1789)  评论(0编辑  收藏  举报

编辑推荐:
· 如何编写易于单元测试的代码
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
阅读排行:
· 周边上新:园子的第一款马克杯温暖上架
· Open-Sora 2.0 重磅开源!
· 分享 3 个 .NET 开源的文件压缩处理库,助力快速实现文件压缩解压功能!
· Ollama——大语言模型本地部署的极速利器
· DeepSeek如何颠覆传统软件测试?测试工程师会被淘汰吗?
点击右上角即可分享
微信分享提示