Page 1 of 1

Opimising Irrlicht water scene node

Posted: Sun Jan 22, 2006 5:00 pm
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.

Posted: Mon Jan 23, 2006 3:26 pm
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.

Posted: Mon Jan 23, 2006 8:22 pm
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
	}
}

Posted: Mon Jan 23, 2006 8:32 pm
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.

Posted: Mon Jan 23, 2006 11:18 pm
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.

Posted: Tue Jan 24, 2006 2:49 am
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.

Posted: Tue Jan 24, 2006 3:26 am
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.

Posted: Tue Jan 24, 2006 11:37 am
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