Efficiently planting multiple nodes

If you are a new Irrlicht Engine user, and have a newbie-question, this is the forum for you. You may also post general programming questions here.
Post Reply
Tumbleweed
Posts: 6
Joined: Sat Dec 01, 2007 3:41 pm

Efficiently planting multiple nodes

Post by Tumbleweed »

I'm sure there's a very simple solution {sighs}... although I'm slowly becoming more familiar with Irrlicht through the API, tutorials, and (much) searching through these forums, the little things are killing me, lol! Doesn't help I'm still working on getting C++ down beyond the very basic code (I'm a transplant from VB6).

At this time, I simply want to "plant" a field of randomly-positioned grass across a flat terrain. A small level was created integrating Irrlicht's Tutorial 12 code (Terrain Rendering) with elvman's Realistic Water node. I needed water, lol! Anyway, the fps with that combination averages around 400+ fps.

Thanks to Acki's loop/nodeID code at http://irrlicht.sourceforge.net/phpBB2/ ... hp?t=24874, this works to plant 2000 instances of grass (one GrassPlane2.x model is simply made of two intersecting planes [4 triangles total] and currently not animated):

Code: Select all

	
// create 2000 nodes with IDs from 1 to 2000:

for(int ID = 1; ID <= 2000; ID++)
{
    scene::IAnimatedMeshSceneNode* arrGrass = smgr->addAnimatedMeshSceneNode(smgr->getMesh("../../media/GrassPlane2.x"), 0, ID);
    arrGrass->setMaterialFlag(video::EMF_LIGHTING, false); 
    arrGrass->setMaterialFlag(video::EMF_BACK_FACE_CULLING, false); 
    arrGrass->getMaterial(0).MaterialTypeParam = 0.01f;  
    arrGrass->setMaterialType(video::EMT_TRANSPARENT_ALPHA_CHANNEL); 
    arrGrass->setPosition(core::vector3df(random_intX,1800,random_intY)); 
    arrGrass->setRotation(core::vector3df (0,random_rot,0));
}

This works fine, but REALLY slows the frame rate down to about 20 fps on an NVIDIA GEForce 8600 card just with this loop. Replacing the random_ variables in setPosition and setRotation (those variables were generated previously) with actual numbers did not appear to change the fps.

Is this loop (and the engine's API behaviour) reloading the model and texture 2000 times, or is the original file being stored in IMeshCache automatically? Is there a better way to tackle this?

Thanks very much for any thoughts!
Starving graphic artist will UV Map for code.
rogerborg
Admin
Posts: 3590
Joined: Mon Oct 09, 2006 9:36 am
Location: Scotland - gonnae no slag aff mah Engleesh
Contact:

Post by rogerborg »

First up, try using EMT_TRANSPARENT_ALPHA_CHANNEL_REF instead of EMT_TRANSPARENT_ALPHA_CHANNEL.

However, without your full source and resources, we can only guess at the bottleneck.
Please upload candidate patches to the tracker.
Need help now? IRC to #irrlicht on irc.freenode.net
How To Ask Questions The Smart Way
Tumbleweed
Posts: 6
Joined: Sat Dec 01, 2007 3:41 pm

Post by Tumbleweed »

I've uploaded my source and resources to here (2 MB):

http://www.fileden.com/files/2007/12/10 ... errain.zip

Please bear in mind it's only a test level (for example, the grass models do not follow the contours of the terrain :oops: ). Just trying to get a grasp of this engine before I try anything "professional looking". ;)

I'm using the 1.4 version of Irrlicht; did some changes on the code today but only gained a little on fps (about 5). I appreciate any thoughts!

BTW, I did try the EMT_TRANSPARENT_ALPHA_CHANNEL_REF, and although the speed picked up a little, it appeared to wash out the grass textures in some way. I'll need to figure that one out.

Thanks again!
Starving graphic artist will UV Map for code.
Acki
Posts: 3496
Joined: Tue Jun 29, 2004 12:04 am
Location: Nobody's Place (Venlo NL)
Contact:

Post by Acki »

the archive is missing RealisticWater.h... ;)

did you try to change the culling mode to EAC_FRUSTUM_BOX (afair EAC_BOX is default) ???
you also can try to use bilboards instead of meshes...
while(!asleep) sheep++;
IrrExtensions:Image
http://abusoft.g0dsoft.com
try Stendhal a MORPG written in Java
Tumbleweed
Posts: 6
Joined: Sat Dec 01, 2007 3:41 pm

Post by Tumbleweed »

Acki wrote:the archive is missing RealisticWater.h... ;)

did you try to change the culling mode to EAC_FRUSTUM_BOX (afair EAC_BOX is default) ???
you also can try to use bilboards instead of meshes...
Re: RealisticWater.h. Opps :oops: Here it is: http://www.fileden.com/files/2007/12/10 ... ticWater.h

I believe I did try the EAC_FRUSTUM_BOX on the terrain node and it did increase the fps, but I lost visibility of much of the terrain except for higher elevations of it. It looked like Water World {grin}.

If I use billboards, won't the model always turn to face the camera? Or is there a setting to disable that undesirable feature? I'll try that option tonight after work and see what it does.

I guess the thing that bothers me the most with the test level is that the addition of 8000 triangles (2000 nodes * 4 triangles each) would decrease the frame rate so much on a solid pc. I hope the engine isn't reloading the single grass texture over and over, because it *is* a one megabyte .tga. Reducing the size of the file and using a more compressed format such as .jpg is really not an option, as I need the gradient alpha channel and lossless detail of the texture. I can't think that would be the problem though... attempting to store 2000 MB (2 GB) would probably send blue smoke through the case, lol!

Thanks again for the help!
Starving graphic artist will UV Map for code.
vitek
Bug Slayer
Posts: 3919
Joined: Mon Jan 16, 2006 10:52 am
Location: Corvallis, OR

Post by vitek »

guess the thing that bothers me the most with the test level is that the addition of 8000 triangles (2000 nodes * 4 triangles each) would decrease the frame rate so much on a solid pc
.

The scene manager has to setup, cull, and then render every one of these nodes. The larger the number of nodes the worse the performance will be.

You should try using the release version of the Irrlicht library. If that doesn't help enough, then you will get a big gain by making one scene node that has a single mesh for all of the grass quads. You will have to cull the patches that aren't on screen for performance [you can use a quad tree], but it will definitely help.

You might just do a search for grass scene node. I believe bitplane wrote one a while back that is quite good.

Travis
Tumbleweed
Posts: 6
Joined: Sat Dec 01, 2007 3:41 pm

Post by Tumbleweed »

vitek wrote:If that doesn't help enough, then you will get a big gain by making one scene node that has a single mesh for all of the grass quads.
I gave that idea a try; with focusing on triangles previously, I didn't realize that node management might have large demands as well. So last night, I created "plots" of grass (300 grass planes each plot) and reduced my node count to about 30. Just that alone bumped the frame rate to 100+ fps at the most dense areas of grass. :)

vitek wrote: You might just do a search for grass scene node. I believe bitplane wrote one a while back that is quite good.
I tried that with the 1.3 version of the engine a month or so ago. While it displayed properly, I didn't stick with that as my level bogged down quite a bit. Quite honestly, my eyes glazed over at the code :shock: and I didn't dig into much at all at that time. But you're right, the project was very good. I'm just not good enough with the engine or C++ to be able to understand it line-by-line yet.

Thanks again for the help!

---------

Just FYI for other "artists": reducing the tga size from 512x512 (at 1 MB) to 256x256 (at less than 300KB file size) did nothing noticeably to improve frame rate. So many things to learn about this engine, lol!
Starving graphic artist will UV Map for code.
hybrid
Admin
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Post by hybrid »

Just a note on the texture size: Textures are only loaded once to the GPU, after that they are sampled from high-spped GPU RAM. You want to have enough free RAM of this type for the rest of your application. But unless you fill it up completely you won't notice any penalties when using it.
Post Reply