Getting the patch associated with LOD in getCurrentLODOfPatches()

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
n00bc0de
Posts: 55
Joined: Tue Oct 04, 2022 1:21 am

Getting the patch associated with LOD in getCurrentLODOfPatches()

Post by n00bc0de »

I am trying to figure out how to get the patch associated with the LOD returned by getCurrentLODOfPatches() in a terrain node.

For instance, how would I set an LOD to 1 if it is 0, etc.
CuteAlien
Admin
Posts: 9734
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Re: Getting the patch associated with LOD in getCurrentLODOfPatches()

Post by CuteAlien »

Not code I'm really familiar with. But on a quick check - getCurrentLODOfPatches returns indices to an array which is always square. So in theory setLODOfPatch could be used to set another LOD and the maximal patchX and patchZ you can set should be the sqrt(of the array size returned by getCurrentLODOfPatches) minus one.
But as docs do warn - whatever value you set there will be changed again when the camera changes (and that happens in OnRegisterSceneNode).

So I guess usually it's better to work with overrideLODDistance if you want different LOD's.

If you try to work with custom value it's probably better to rework this node a bit. For example allowing to suppress recalculations. And allow triggering calculation outside of OnRegisterSceneNode. Or maybe your LOD is different for other reasons, like you don't want fixed distances (don't know what you really need right now).

Anyway - if you have any ideas to improve this node you can always send me patches. If they make sense I can apply them.
IRC: #irrlicht on irc.libera.chat
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
n00bc0de
Posts: 55
Joined: Tue Oct 04, 2022 1:21 am

Re: Getting the patch associated with LOD in getCurrentLODOfPatches()

Post by n00bc0de »

Thanks. I can play around with it a bit more. It already works really well so if overrideLODDistance works for what I need I probably won't have a change to submit. If LODs are not currently available for other nodes I might submit a patch for that since that would be extremely useful for high poly scenes.
CuteAlien
Admin
Posts: 9734
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Re: Getting the patch associated with LOD in getCurrentLODOfPatches()

Post by CuteAlien »

Not sure if other nodes are patched that easily for that, terrain is somewhat special. For the general case it's probably easier to have application code which switches out the mesh (or node) at a certain distance.

Also I noticed that with newer GPU's you can go really high with polygons before those become the bottleneck (with RTX 3060 and a typical static scene I can go to around 16 millions in Irrlicht before poly-numbers have any effect on speed). At least with static meshes (for animated meshes it's still expensive as Irrlicht does animation on CPU). Generally I run into material switches becoming the problem way before that.
IRC: #irrlicht on irc.libera.chat
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
n00bc0de
Posts: 55
Joined: Tue Oct 04, 2022 1:21 am

Re: Getting the patch associated with LOD in getCurrentLODOfPatches()

Post by n00bc0de »

I did figure out how to read the LOD of a patch. I wrote this function to do it.

Code: Select all

irr::s32 getLODOfPatch(irr::scene::ITerrainSceneNode* terrain, irr::s32 patchX, irr::s32 patchZ)
{
	irr::core::array<irr::s32> lod;
	irr::s32 lodp_size = terrain->getCurrentLODOfPatches(lod);
	irr::s32 dim_size = irr::core::squareroot(lodp_size);
	return lod[patchX * dim_size + patchZ];
}
Post Reply