Page 1 of 1

Getting the patch associated with LOD in getCurrentLODOfPatches()

Posted: Sat Aug 17, 2024 11:42 pm
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.

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

Posted: Sun Aug 18, 2024 10:53 am
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.

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

Posted: Sun Aug 18, 2024 1:44 pm
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.

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

Posted: Sun Aug 18, 2024 3:15 pm
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.

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

Posted: Sun Aug 18, 2024 11:36 pm
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];
}