Simple Terrain Class

Post those lines of code you feel like sharing or find what you require for your project here; or simply use them as tutorials.
Valmond
Posts: 308
Joined: Thu Apr 12, 2007 3:26 pm

Simple Terrain Class

Post by Valmond »

Hi

My game went all slow so I did some simple profiling and well, it's really CPU bound
and it seemed that the Terrain node ate most of the CPU (I have several terrains visible ingame).

First I tried (stupidly) to use VBO but as the terrain optimizes itself each frame that was no good so I wrote a 'fixed' (as in 'not changing')
terrain class that works about the same as the original one (but with VBO) so I though I'd share it here.

BTW my game went from ~15fps to 150+ so for me it was the right thing to do :-)

MSVC project (Windows exe included that shows original and new terrain).
Brainsaw
Posts: 1176
Joined: Wed Jan 07, 2004 12:57 pm
Location: Bavaria

Post by Brainsaw »

This is cool. Nice work. I just testes the demo, haven't yet looked at the code. Is it easy to replace an original terrainscenenode by yours?
Dustbin::Games on the web: https://www.dustbin-online.de/

Dustbin::Games on facebook: https://www.facebook.com/dustbingames/
Dustbin::Games on twitter: https://twitter.com/dustbingames
vinjn
Posts: 27
Joined: Tue May 20, 2008 4:45 am

Post by vinjn »

nice example

I am wondering could the default ITerrainSceneNode has the ability to be a static terrain officially?
I mean some additional function like

Code: Select all

 bool setStaticTerrain(bool isStatic);
serengeor
Posts: 1712
Joined: Tue Jan 13, 2009 7:34 pm
Location: Lithuania

Post by serengeor »

like WTF!!!, from 800~ to 2000~+ fps
:shock:
Good job :wink:
Working on game: Marrbles (Currently stopped).
ACE247
Posts: 704
Joined: Tue Mar 16, 2010 12:31 am

Post by ACE247 »

I'm speechless....
I used to use some Terrain pager class to render large terrains, but this is just awesome. +-3800FPS!! :D
Valmond
Posts: 308
Joined: Thu Apr 12, 2007 3:26 pm

Post by Valmond »

Thanks for the nice comments :-)

@Brainsaw

It's not Exactly the same but switching shouldn't bee too hard, if you use
32-bits floating point maps you only need to change the creation call.

Well, the example uses a shader and IIRC the original has some sort of
'base texture' + 'detail map', don't know if that works with a 'normal' mesh.
Feel free to use the shader bundled though.


@vinjn

Or just add this code to Irrlicht (with loaders for 8 & 16 bits and surely some tweaking)?
Brainsaw
Posts: 1176
Joined: Wed Jan 07, 2004 12:57 pm
Location: Bavaria

Post by Brainsaw »

OK, I'm now back from my vacation and I think I'll take a closer look within the next days, I think I'll try to create an IrrEdit plugin using the terrain (because I always create IrrEdit plugins ;) ). I just try to do put as much of the necessary code into a plugin so that I don't have to code much specific stuff inside my programs but let the loadscene method do the necessary.
Dustbin::Games on the web: https://www.dustbin-online.de/

Dustbin::Games on facebook: https://www.facebook.com/dustbingames/
Dustbin::Games on twitter: https://twitter.com/dustbingames
Virion
Competition winner
Posts: 2148
Joined: Mon Dec 18, 2006 5:04 am

Post by Virion »

this is superb!
shadowslair
Posts: 758
Joined: Mon Mar 31, 2008 3:32 pm
Location: Bulgaria

Post by shadowslair »

In both versions I get black terrain. I guess it is not supposed to be black. :)
I get "Could not create hlsl shader" and "Shader number = -1" in the console window. Well, shader version 3.0 on my Radeon 9550... :D
"Although we walk on the ground and step in the mud... our dreams and endeavors reach the immense skies..."
Valmond
Posts: 308
Joined: Thu Apr 12, 2007 3:26 pm

Post by Valmond »

@shadowslair

Is there any errors (or warnings) around that output?

Tested it on a recent ATI a while ago but since then I might have changed something I shouldn't have (nVidia accepts small errors in the code like wrong casts, ATI don't).
Valmond
Posts: 308
Joined: Thu Apr 12, 2007 3:26 pm

Post by Valmond »

@Brainsaw

Nice!
Tell me if there are any special functionalities you need ported from the original terrain class to the new one.
ACE247
Posts: 704
Joined: Tue Mar 16, 2010 12:31 am

Post by ACE247 »

I see you used a .raw file for storing the heightmap. Now seeing that I know nothing about raw for storing a heightmap, how can i make one and how can i use it?
Valmond
Posts: 308
Joined: Thu Apr 12, 2007 3:26 pm

Post by Valmond »

.raw is just a bunch of bytes, here it is 32bit floats (IIRC) but it could be 8bit ints or whatever.

I generate it with a script (just flushes all the floats into a file) and the data comes from Unity3D which I use to model my terrains.
kidhr
Posts: 9
Joined: Fri Oct 01, 2010 5:04 pm

Post by kidhr »

Hello 8)

Great job !!!
Thanks for your sharing

Unfortunately, I have the same issue than Shadowslair when i try to compile your sample.
The two versions are black
Radeon 5700
Your exe file + your irrlicht dll => ok

msvc 2005 + irrlichit 1.7.1
0 => black
1 => crash on m_MeshNode=smgr->addMeshSceneNode(m_Mesh,parent,-1,core::vector3df(0,0,0));

msvc express 2010 + irrlichit 1.7.1
0 => black
1 => crash on m_MeshNode=smgr->addMeshSceneNode(m_Mesh,parent,-1,core::vector3df(0,0,0));

msvc express 2010 + irrlichit 1.8.0 alpha
0 => black
1 => black
Run with no errors on console

I have missed something ?

Thanks in advance
Valmond
Posts: 308
Joined: Thu Apr 12, 2007 3:26 pm

Post by Valmond »

Does it work with the original exe?

I'm using a modified Irrlicht (1.7.1), can you link with the Irrlicht in the rar file to see if the problem doesn't come from that?
Post Reply