[SOLVED] [NooB] Tips for 3D in a Heroes Of M&M - like ga

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.
Lideln
Posts: 79
Joined: Sat Jun 24, 2006 11:35 am
Location: Paris, France

[SOLVED] [NooB] Tips for 3D in a Heroes Of M&M - like ga

Post by Lideln »

Hi !

I have sooooooooooo many questions... I've been searching the forums for some answers, and wrote down what I found, but there are still some points I, really big noob, need to be advised on, if someone would like to share his experience :) even for just one question ! :)

Presentation
I would like to create a Heroes of Might and Magic-like game, i.e. with a slightly leveled 3D terrain, many static objects (like trees, mines), some animated objects (like shining gold or item), and several characters (1 to 4 characters per player).

I made some tests, and I'm sure you will laugh at me because I'm a terrible noobie in the 3D world !

What I already have
I made the (complete) UML for the game (but it's no use here... just for info)
I made a tree, but it has 2432 faces, I guess it is a bit too much ?
I made a small map made in Blender, with a texture applied to it (2048x2048)

What I already tried
I tried to display the map, and one tree.
It works, I run at 100fps.

Now I tried to display 100 trees (in one row), and... Patatrac !
4 FPS...
Even if I put the camera where there is nothing at all :shock:

My questions (heheee :lol: )
1)
Why am I at 4 FPS even if I put the camera where there is nothing to display ? Should not the engine compute and draw only what I may see, and only that ? Is there a way to force the engine to do so ?

2)
Is 2432 faces too much for a static mesh ? How much faces should I have with High Poly ? And low poly ?

3)
What technique could I use to display a very large map ? I mean especially to draw the texture on it... I can't figure how to do this ! I searched the forums for that too, and found someone talking about splitting the terrain (and texture) in many parts and draw them seperately, but many people told him it would be terribly slow !


That's it ! Here are my 3 questions... I just hope someone will kindly help me at my very beginning :)

Thanks a lot, and have a nice evening ! :)

Lideln
Last edited by Lideln on Mon Nov 06, 2006 7:50 am, edited 1 time in total.
--
Lideln, France
CodeDog
Posts: 106
Joined: Sat Oct 07, 2006 8:00 pm
Location: CA. USA
Contact:

Post by CodeDog »

Look into Level of Detail.
Sometimes referred to LOD.
What this means it that you use the high poly model for up close, a low poly model for medium distances and a billboard for far away.
Lideln
Posts: 79
Joined: Sat Jun 24, 2006 11:35 am
Location: Paris, France

Post by Lideln »

Hi CodeDog, thanks for your answer !

I'll look for Level Of Detail, and try to learn things about that.
For me the main issue here is that irrlicht seems to draw the objects even if they are not visible, that's why I run at 4 FPS, and I would like to know how to force Irrlicht to draw ONLY what is visible.

(the 2 other questions are still hammering my head :) )

Thanks again,

Lideln
--
Lideln, France
hybrid
Admin
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Post by hybrid »

Irrlicht culls those meshes which are not in the view frustrum. So your problem might be somewhere else (although the heavy drop is strange). There is for example some management overhead per scene node which also has an impact on FPS.
CodeDog
Posts: 106
Joined: Sat Oct 07, 2006 8:00 pm
Location: CA. USA
Contact:

Post by CodeDog »

The node overhead shouldn't have that kind of effect unless he had thousands of separate nodes or he’s creating and destroying nodes with every render loop.


I think at this point we need to see the code he is using.
Lideln
Posts: 79
Joined: Sat Jun 24, 2006 11:35 am
Location: Paris, France

Post by Lideln »

Thanks Hybrid and CodeDog

I'm surely making a big mistake somewhere, but my noobieness prevents me from seeing it ! :wink:

Here is my code :

Code: Select all

/**
 * Init a typical In-Game screen, called only once, of course !
 */
void CInGameScreen::initScreen()
{
	// Temporary variables
	scene::IAnimatedMesh* mesh = NULL;
	scene::ISceneNode* node = NULL;
	
	// Create a (global) camera
	camera = hotp->scene->addCameraSceneNode();

	// Create the map
	// (at the moment it is only a small terrain with a 2048 texture...
	// Will become a far larger map with many textures when I've found how to do that :D)
	mesh = hotp->scene->getMesh("data/levels/level1.3ds");
	node = hotp->scene->addAnimatedMeshSceneNode(mesh);
	node->setScale(vector3df(2.0f, 2.0f, 2.0f));//(2.0f,0.8f,2.0f));
	node->setMaterialFlag(video::EMF_NORMALIZE_NORMALS, true);
	node->setMaterialFlag(video::EMF_LIGHTING, false);
	// The export in 3DS from blender does not take the UVMap into account,
	// so I have to set a texture to it (but the rendered whole thing is ugly :) )
	node->setMaterialTexture(0, hotp->driver->getTexture("data/levels/map1.jpg"));
	
	// Place the camera 
	camera->setPosition(vector3df(0, 30, -20));
	cameraMove = 0.0;
	totalCameraMove = 0.0;
	
	// Place 100 nodes of this object
	mesh = hotp->scene->getMesh("data/objects/arbre.obj");
	for (int i = 0; i < 100; ++i)
	{
		// Add another copy
		ptiga = hotp->scene->addMeshSceneNode(mesh->getMesh(0));
		// What is it for... ? oO
		ptiga->setMaterialFlag(video::EMF_NORMALIZE_NORMALS, true);
		// No global light, so...
		ptiga->setMaterialFlag(video::EMF_LIGHTING, false);
		// Align the copies in a row
		ptiga->setPosition(vector3df(0 + 4 * i, 10, -10));
	}
}
As you can see, the code is quite simple, at the moment this is my very beginning in Irrlicht (and in 3D in general) so I took this code in the terrain tutorial.

I do not create/delete anything each frame, that's why I'm as surprised as you to see 4FPS even when there is nothing to display in the camera field of view.

If you need another part of code... Please feel free to ask !

Thanks again :)

Have a nice day,

Lideln
--
Lideln, France
Lideln
Posts: 79
Joined: Sat Jun 24, 2006 11:35 am
Location: Paris, France

Post by Lideln »

Hi !

So, no idea why I'm at 4FPS with nothing at all in the camera FOV ?
If, instead of the tree with 2432 faces I use a cube with only 96 faces, the FPS increase to 70, but it's still not normal since I do not have anything visible on the screen.... :(

Irrlicht-gurus, do you have any idea ? :D

(and for my little 2 other questions as well :) )

Thanks a lot,

Kind regards,

Lideln
--
Lideln, France
AmigaIrr
Posts: 94
Joined: Mon Jan 10, 2005 7:55 am
Location: France, Alsace

Post by AmigaIrr »

Lideln wrote:Thanks Hybrid and CodeDog

I'm surely making a big mistake somewhere, but my noobieness prevents me from seeing it ! :wink:

Here is my code :

Code: Select all

/**
 * Init a typical In-Game screen, called only once, of course !
 */
void CInGameScreen::initScreen()
{
	// Temporary variables
	scene::IAnimatedMesh* mesh = NULL;
	scene::ISceneNode* node = NULL;
	
	// Create a (global) camera
	camera = hotp->scene->addCameraSceneNode();

	// Create the map
	// (at the moment it is only a small terrain with a 2048 texture...
	// Will become a far larger map with many textures when I've found how to do that :D)
	mesh = hotp->scene->getMesh("data/levels/level1.3ds");
	node = hotp->scene->addAnimatedMeshSceneNode(mesh);
	node->setScale(vector3df(2.0f, 2.0f, 2.0f));//(2.0f,0.8f,2.0f));
	node->setMaterialFlag(video::EMF_NORMALIZE_NORMALS, true);
	node->setMaterialFlag(video::EMF_LIGHTING, false);
	// The export in 3DS from blender does not take the UVMap into account,
	// so I have to set a texture to it (but the rendered whole thing is ugly :) )
	node->setMaterialTexture(0, hotp->driver->getTexture("data/levels/map1.jpg"));
	
	// Place the camera 
	camera->setPosition(vector3df(0, 30, -20));
	cameraMove = 0.0;
	totalCameraMove = 0.0;
	
	// Place 100 nodes of this object
	mesh = hotp->scene->getMesh("data/objects/arbre.obj");
	for (int i = 0; i < 100; ++i)
	{
		// Add another copy
		ptiga = hotp->scene->addMeshSceneNode(mesh->getMesh(0));
		// What is it for... ? oO
		ptiga->setMaterialFlag(video::EMF_NORMALIZE_NORMALS, true);
		// No global light, so...
		ptiga->setMaterialFlag(video::EMF_LIGHTING, false);
		// Align the copies in a row
		ptiga->setPosition(vector3df(0 + 4 * i, 10, -10));
	}
}
As you can see, the code is quite simple, at the moment this is my very beginning in Irrlicht (and in 3D in general) so I took this code in the terrain tutorial.

I do not create/delete anything each frame, that's why I'm as surprised as you to see 4FPS even when there is nothing to display in the camera field of view.

If you need another part of code... Please feel free to ask !

Thanks again :)

Have a nice day,

Lideln


nice !

have you a executable to download ?
L'eternité c'est long, surtout vers la fin...

Q6600 triton 79, 4 GO, 2* RAPTOR 150GO of ARECA 256 RAID 0, 3870 Zalmann, P5K. 24" Samsung. Antec nine hundred
Lideln
Posts: 79
Joined: Sat Jun 24, 2006 11:35 am
Location: Paris, France

Post by Lideln »

Hi !

Sorry I was absent for some days...
Thanks for replying, Im really obsessed by this issue !

Im under linux, but I created an archive in zip format in case you are under Windows, and I included sources so you can compile (there is a precompiled binary for linux).

http://www.filefactory.com/file/4a517a/

I hope it will help you find what I'm doing wrong, because I can't really progress with this issue...

(And a little UP for the 2 other questions :) Thank you all !)
--
Lideln, France
Dibalo
Posts: 30
Joined: Sat Aug 12, 2006 2:31 pm
Location: Finland
Contact:

Post by Dibalo »

First I´ll give you a very good advice: comment your code! I tried to solve your performance poblem... I didn´t undestand it because I had no idea, what those all pointers are supposed to do and where can I find all those class method declarations.. :D

But I think you could use octree for your maps. It calculates and optimizes your map rendering and thats why it´s a little bit faster than animated maps.
Dattebayo!!
Lideln
Posts: 79
Joined: Sat Jun 24, 2006 11:35 am
Location: Paris, France

Post by Lideln »

Hi Dibalo

Thanks for having had a look at my issue.
I just would like to confirm you that my code is commented, check the sources, you will see doxygen comments about what is used for what purpose (and I actually not have a lot of code, so it must be easy to read).

But anyway, I'll try to find an octree example, but Im also wondering why Irrlicht does not optimize the rendering automatically, and if it is my fault, why.

Nobody seems to have an answer at the moment, but I would really love to get rid of that issue, because it is painful to progress with 4fps :)

Thanks for the tip about the octree, I'll have a look at it :)

Regards,
--
Lideln, France
sgt_pinky
Posts: 149
Joined: Sat Oct 14, 2006 11:20 am
Location: Melbourne, Australia

Post by sgt_pinky »

Meh, I disagree with Dibalo's commenting advice. Your code is fine. First, name your variables so that they are readable (which you have done well), and then someone can just read your code without comments - only use comments for parts that are hard to understand what's happening. That's my policy anyway. When I download tutorials, etc, first thing I do is delete all the comments so I can actually see the code, lol. ;)

I had a look at your render loop and couldn't see anything out of the ordinary that would cause such an FPS drop. A few calls to empty routines that you haven't filled in yet, and the normal scene->drawAll(), etc. Your initScreen() call is clearly outside the render loop, so no problem there.

By the way, this bit:

Code: Select all

// What is it for... ? oO
ptiga->setMaterialFlag(video::EMF_NORMALIZE_NORMALS, true);
A 'normal' is a vector pointing away from each vertex. It is used for lighting calculations. In the next line you turn lighting off, so quite clearly you don't need to normalise your normals, hehe.
Intellectuals solve problems - geniuses prevent them. -- Einstein
#irrlicht on irc.freenode.net
Lideln
Posts: 79
Joined: Sat Jun 24, 2006 11:35 am
Location: Paris, France

Post by Lideln »

Hi Sergeant Pinky !

Thanks for having had a look at this (strange) issue ! :)

On one hand, its good to see that I made no big mistakes, but on the other one, that's what makes this issue a bit more weird.

I haven't has the time to try the octree thing yet, but as soon as I come back from the work day, I'll try it !

Thanks again,

Lideln

PS : tips for the 2 other questions (max advised faces amount for an object, and tips for making a very large terrain) are still welcome :)
For the terrain, I thought it could be good to apply a base texture on *almost* all the faces, and then apply specific texture to faces that represent roads, etc. ? So it would no need an UVmap I guess ?

Thank you all
--
Lideln, France
Lideln
Posts: 79
Joined: Sat Jun 24, 2006 11:35 am
Location: Paris, France

Post by Lideln »

Good evening everybody !

I just came back from the office, and tried the Octree thing.

Here are the results, depending on where I place the camera :
- where there is nothing, including no map : 250 fps
- where there is the map, but no mesh : 105 fps
- where there are 37 meshes : 90 fps

Its far far far better than the older code, so many thanks to Dibalo ! :)

But I have still some unanswered questions : :D

1) If I have a standard map like in HOMM (Heroes Of Might and Magic), I'll have something like 100 or 200 static meshes PLUS an average 10 animated meshes... The fps will drasticaly fall, don't you think ? (I haven't tried atm, but it seems it will happen) Any idea on how to optimize it ? (for example, is putting all the static objects directly in the map a good idea, or should I keep them separate ?)

2) How many faces do you advise me to have for a mesh ?

3) Any idea on how to model a LARGE map ? (and getting rid of the max of 2048px for the UVmap texture, etc.)

Thanks a lot ! Have a nice evening,
--
Lideln, France
Dibalo
Posts: 30
Joined: Sat Aug 12, 2006 2:31 pm
Location: Finland
Contact:

Post by Dibalo »

1) You could use fog effect because your games genre allow it (imho). I mean that fog gets tighter the further you look at. With that, you can render only near meshes and far meshes won´t be rendered. That should optimize your code, and allow you to make much more meshes. 100-200 shoudn´t be a problem. (I assume that Irrlicht fog works similar to OGREs fog.)

2) Under 2000 could be enought, especially if you use normal mapping. It depends, how many nodes you have on the screen at the same time.

3) Heightmaps?
Dattebayo!!
Post Reply