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 2012-02-12 23:11 Meta.Grfx 阅读(1789) 评论(0) 编辑 收藏 举报
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 如何编写易于单元测试的代码
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
· 周边上新:园子的第一款马克杯温暖上架
· Open-Sora 2.0 重磅开源!
· 分享 3 个 .NET 开源的文件压缩处理库,助力快速实现文件压缩解压功能!
· Ollama——大语言模型本地部署的极速利器
· DeepSeek如何颠覆传统软件测试?测试工程师会被淘汰吗?