Opimising Irrlicht water scene node

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
MikeR
Posts: 767
Joined: Sun Dec 26, 2004 4:03 pm
Location: Northern California USA
Contact:

Opimising Irrlicht water scene node

Post by MikeR »

I'm using the following code in my app:

Code: Select all

//MY LAVA USING IRRLICHT WATER. NEEDS WORK *****************************************

	q3levelmesh = smgr->addHillPlaneMesh("myHill",

		core::dimension2d<f32>(20,20),
		
		core::dimension2d<s32>(80,80), 0, 0,
	
		core::dimension2d<f32>(90,0),
	
		core::dimension2d<f32>(5,5));
		
scene::ISceneNode* node = 0;
node = smgr->addAnimatedMeshSceneNode(q3levelmesh);
//waveHeight=2.0f,  waveSpeed=300.0f,  waveLenght=10.0f
    node= smgr->addWaterSurfaceSceneNode(q3levelmesh->getMesh(0), 10.0f, 2300.0f, 40.0f);
	node->setPosition(core::vector3df(1700,-1550,-440));

	node->setMaterialTexture(0,	driver->getTexture("lava.jpg"));
	node->setMaterialTexture(1,	driver->getTexture("LavaRed.jpg"));
	node->setMaterialType(video::EMT_REFLECTION_2_LAYER);
My fps drops from 75 to 60 when I enter the room where this is. The reason is becouse the water scene node is a square.

Code: Select all

core::dimension2d<s32>(80,80), 0, 0,
Almost half of this is below the floor. If I change the size to 40, 80, it squashes the waves so that they look like thin lines.
Does anyone know how to make this scene node smaller without killing the look? I've tried playing with the wave height and length, but need a "wave width" to make those work properly.

This is the only thing left in this world that's causing an fps drop.
Thanks for any help.
If it exists in the real world, it can be created in 3d

Sys specs:
AMD 3700+ 64 processor
1.0 gb ram
e-Geforce 6600 graphics 256 mb onboard ram
bearSoft
Posts: 165
Joined: Fri Apr 01, 2005 9:55 pm
Location: Denmark

Post by bearSoft »

Mike i fear that it is a real problem
In the FX-demo i have 11.. fps
Just by commenting the waterscenenode out of the file i get 57 fps.
Irr's 'animated textures as water' is simply -very- resourse demanding.
Regards.
Tech: win98se| 320mb ram| abitbe6| 433mhzceleron| atiRadeon7000.64mb| soundblaster125| dx9.0b | devCPP | IRR 0.12.0 |
vitek
Bug Slayer
Posts: 3919
Joined: Mon Jan 16, 2006 10:52 am
Location: Corvallis, OR

Post by vitek »

Are you guys running debug builds?

I cut down the SpecialFX example to just the water and the camera. With a release build of Irrlicht I get 590fps [nVidia 6200 TC]. With a debug version, I get 135fps. That's a pretty healthy difference.

For those who don't know this, the water does a sin & cos for every vertex on the water mesh every render. On top of that, it recalculates the normals for every face every render. That stuff is kinda expensive. Especially when your water mesh has lots of verticies/faces.

I was able to get the debug to run at 200fps by changing the implementation of recalculateNormalsT just a little bit.

Code: Select all

template<class VTXTYPE>
inline void recalculateNormalsT(VTXTYPE* v, int vtxcnt,
								u16* idx, int idxcnt)
{
#define _FASTER
#ifdef _FASTER
	core::vector3df Normal;
#endif // _FASTER

	for (int i=0; i<idxcnt; i+=3)
	{
#ifdef _FASTER
		VTXTYPE& vertex1 = v[idx[i+0]];
		VTXTYPE& vertex2 = v[idx[i+1]];
		VTXTYPE& vertex3 = v[idx[i+2]];

		Normal = (vertex2.Pos - vertex1.Pos).crossProduct(vertex3.Pos - vertex1.Pos);
		Normal.normalize();

		vertex1.Normal = Normal;
		vertex2.Normal = Normal;
		vertex3.Normal = Normal;
#else // _FASTER
		core::plane3d<f32> p(v[idx[i+0]].Pos, v[idx[i+1]].Pos, v[idx[i+2]].Pos);
		p.Normal.normalize();

		v[idx[i+0]].Normal = p.Normal;
		v[idx[i+1]].Normal = p.Normal;
		v[idx[i+2]].Normal = p.Normal;
#endif // _FASTER
	}
}
Last edited by vitek on Mon Jan 23, 2006 8:34 pm, edited 1 time in total.
vitek
Bug Slayer
Posts: 3919
Joined: Mon Jan 16, 2006 10:52 am
Location: Corvallis, OR

Post by vitek »

it squashes the waves so that they look like thin lines
Instead of changing the 3rd parameter to addHillPlaneMesh, try adjusting the second. I think that will come closer to doing what you want.
MikeR
Posts: 767
Joined: Sun Dec 26, 2004 4:03 pm
Location: Northern California USA
Contact:

Post by MikeR »

vitek wrote:
it squashes the waves so that they look like thin lines
Instead of changing the 3rd parameter to addHillPlaneMesh, try adjusting the second. I think that will come closer to doing what you want.
hmm, ok. I'll give that a try.

And no. I'm running my own build of the dll. I didn't know until recently that the one that comes precompiled is a debug build.
If it exists in the real world, it can be created in 3d

Sys specs:
AMD 3700+ 64 processor
1.0 gb ram
e-Geforce 6600 graphics 256 mb onboard ram
vitek
Bug Slayer
Posts: 3919
Joined: Mon Jan 16, 2006 10:52 am
Location: Corvallis, OR

Post by vitek »

I didn't know until recently that the one that comes precompiled is a debug build.
the one that is in the bin/win32-visualstudio directory is a release build.
MikeR
Posts: 767
Joined: Sun Dec 26, 2004 4:03 pm
Location: Northern California USA
Contact:

Post by MikeR »

Code: Select all

 core::dimension2d<s32>(80,80), 0, 0, 
is the one I have been editing. I need it to be 40, 80 to actually fit correctly, but it won't work. I'm just oging to leave it for now.

I use Dev-cpp. I need cross platform, and vs doesn't play nice with the standard lib.
If it exists in the real world, it can be created in 3d

Sys specs:
AMD 3700+ 64 processor
1.0 gb ram
e-Geforce 6600 graphics 256 mb onboard ram
bearSoft
Posts: 165
Joined: Fri Apr 01, 2005 9:55 pm
Location: Denmark

Post by bearSoft »

:o i did not know about the release/debug difference of the dll's..
That is something i must look at and understand..
Thank U!
@Vitek: in context of:

..able to get the debug to run at 200fps by changing the implementation of recalculateNormalsT just a little bit.
Should NIKO be told that u have an optimated method for that snippet?
Any alteration that could improve fps would be valuable
-btw, my general low fps is ofcause directly related to low hardware prestanda, but the -relative- changes is valid, in respect to usage of different codes
Regards.
Tech: win98se| 320mb ram| abitbe6| 433mhzceleron| atiRadeon7000.64mb| soundblaster125| dx9.0b | devCPP | IRR 0.12.0 |
Post Reply