Connecting terrein nodes
Connecting terrein nodes
Hello everyone,
I have a question regarding multiple terrain nodes. I have 4 terrain nodes with each a part of a heightmap that should connect to each other. Sadly when I render it, the different terrains dont connect and there are height differences.
Does someone know a solution to this problem?
-Diho
I have a question regarding multiple terrain nodes. I have 4 terrain nodes with each a part of a heightmap that should connect to each other. Sadly when I render it, the different terrains dont connect and there are height differences.
Does someone know a solution to this problem?
-Diho
Re: Connecting terrein nodes
Use the addTerrainMesh method instead. The geomipmap terrain nodes are currently sort of almost a legacy feature, as the terrain meshes are the same fast and can be stored statically on the video card with a very small impact on performance, and use less memory, compared to the terrain nodes. If you're going to use a large terrain, the terrain node goes well, if you're using smaller terrains from textures, go for the terrain meshes instead, and set them to be static meshes
"There is nothing truly useless, it always serves as a bad example". Arthur A. Schmitt
Re: Connecting terrein nodes
also, the terrain scenenode has some requirements for creation that are not obvious.
if the bitmap size does not match up with the patch size then, when trying to align nodes together, there will be some error.
Code: Select all
//! A scene node for displaying terrain using the geo mip map algorithm.
/** The code for the TerrainSceneNode is based on the Terrain renderer by Soconne and
* the GeoMipMapSceneNode developed by Spintz. They made their code available for Irrlicht
* and allowed it to be distributed under this licence. I only modified some parts.
* A lot of thanks go to them.
*
* This scene node is capable of very quickly loading
* terrains and updating the indices at runtime to enable viewing very large terrains. It uses a
* CLOD (Continuous Level of Detail) algorithm which updates the indices for each patch based on
* a LOD (Level of Detail) which is determined based on a patch's distance from the camera.
*
* The Patch Size of the terrain must always be a size of ( 2^N+1, i.e. 8+1(9), 16+1(17), etc. ).
* The MaxLOD available is directly dependent on the patch size of the terrain. LOD 0 contains all
* of the indices to draw all the triangles at the max detail for a patch. As each LOD goes up by 1
* the step taken, in generating indices increases by - 2^LOD, so for LOD 1, the step taken is 2, for
* LOD 2, the step taken is 4, LOD 3 - 8, etc. The step can be no larger than the size of the patch,
* so having a LOD of 8, with a patch size of 17, is asking the algoritm to generate indices every
* 2^8 ( 256 ) vertices, which is not possible with a patch size of 17. The maximum LOD for a patch
* size of 17 is 2^4 ( 16 ). So, with a MaxLOD of 5, you'll have LOD 0 ( full detail ), LOD 1 ( every
* 2 vertices ), LOD 2 ( every 4 vertices ), LOD 3 ( every 8 vertices ) and LOD 4 ( every 16 vertices ).
**/
if the bitmap size does not match up with the patch size then, when trying to align nodes together, there will be some error.
Re: Connecting terrein nodes
@Mel, @Seven, Thanks for your replies!
Re: Connecting terrein nodes
I successfully managed to connect multiple terrain nodes to each other, but at a certain distance from the seam, you can see a few gaps between the two connecting terrain nodes.
Here you can see the gaps
But when I move closer, they are gone.
Does anyone know how to fix this? I have already played a bit with different LOD and smoothing levels but that doesn't seem to solve it.
-Diho
Here you can see the gaps
But when I move closer, they are gone.
Does anyone know how to fix this? I have already played a bit with different LOD and smoothing levels but that doesn't seem to solve it.
-Diho
Re: Connecting terrein nodes
You're asking for their LODs at the seam to be the same. I don't think it has logic for that, it's intended to contain the entire terrain; I'd look into alternative solutions, like static terrain meshes.
Re: Connecting terrein nodes
There has to be a better solution than using static terrain meshes. In the comment of Spintz http://irrlicht.sourceforge.net/forum/v ... 29#p114529 he describes that a possible solution is to make sure that every terrain scene node has the same lod level at it's edges/borders.
Does anyone know where to start? My guess is that I have to look at the preRenderLODCalculations function inside the CTerrainSceneNode.cpp file.
Does anyone know where to start? My guess is that I have to look at the preRenderLODCalculations function inside the CTerrainSceneNode.cpp file.
Re: Connecting terrein nodes
I found the solution, it's quite simple to be honest.
in CTerrainSceneNode.cpp around line 640 you can find this piece of code:
The only thing you need to add are two single lines of code:
resulting in the following piece of code:
These two lines make sure that ever patch at the border of a terrain node keep the same lod level (0 at the moment). I hope someone finds this useful
in CTerrainSceneNode.cpp around line 640 you can find this piece of code:
Code: Select all
for (s32 j = 0; j < count; ++j)
{
if (frustum->getBoundingBox().intersectsWithBox(TerrainData.Patches[j].BoundingBox))
{
const f32 distance = cameraPosition.getDistanceFromSQ(TerrainData.Patches[j].Center);
TerrainData.Patches[j].CurrentLOD = 0;
for (s32 i = TerrainData.MaxLOD - 1; i>0; --i)
{
if (distance >= TerrainData.LODDistanceThreshold[i])
{
TerrainData.Patches[j].CurrentLOD = i;
break;
}
}
}
else
{
TerrainData.Patches[j].CurrentLOD = -1;
}
}
Code: Select all
if (j < 16 || j > (count - 16) || j % 16 == 0 || (j % 15) == (floor(j / 15) - 1))
continue;
Code: Select all
for (s32 j = 0; j < count; ++j)
{
if (frustum->getBoundingBox().intersectsWithBox(TerrainData.Patches[j].BoundingBox))
{
const f32 distance = cameraPosition.getDistanceFromSQ(TerrainData.Patches[j].Center);
TerrainData.Patches[j].CurrentLOD = 0;
//border patches should be the same
if (j < 16 || j > (count - 16) || j % 16 == 0 || (j % 15) == (floor(j / 15) - 1))
continue;
for (s32 i = TerrainData.MaxLOD - 1; i>0; --i)
{
if (distance >= TerrainData.LODDistanceThreshold[i])
{
TerrainData.Patches[j].CurrentLOD = i;
break;
}
}
}
else
{
TerrainData.Patches[j].CurrentLOD = -1;
}
}
Re: Connecting terrein nodes
Thanks for the info. Do you have maybe already written a small test-application which shows exactly this problem? In that case it would be cool if you could post that one as well.
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
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
Re: Connecting terrein nodes
Sure, I will add an example, as soon as I have some time, to the code snippet board and leave a link here.
Re: Connecting terrein nodes
Thank you! All discussion continuing in the http://irrlicht.sourceforge.net/forum/v ... =9&t=51220 thread. Locking this one.
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
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm