I was just playing a bit with heightmaps and I realized something :
Let's take a look at the example 12, Terrain Rendering.
When looking at the terrain, everything is smoothed and looks nice and if we look to the heightmap (see below), there are only 3 or 4 hills on the heightmap... It's a 256*256 very basic and very small heightmap which doesn't need to be scaled a lot :
But what if we try to make a huge terrain with twenty hills or more and we try to use only a 256*256 bitmap :
As you can see, the heightmap does not look very nice and it's normal because we have only very small hills and it looks a bit chaotic...
Now if we try to render our heightmap with Irrlicht, we shall need to scale it a lot more than the older one because each hill has to seem as big as in the first one.
But here's what happens (the texture is a false one, that's not what I'm talking about) :
As you can see... It's quite ugly... Looks like our hills were turned into stairs and the expected effect is not that at all...
I thought that the problem was in the core, because Irrlicht loads a vertex buffer which has the same size as our heightmap (256*256 in both case) and then scales this buffer. Thus, a simple heightmap, not much scaled, is rendered perfectly but when you scale this heightmap, the distance between each vertex is scaled and then it's not well rendered.
I'm now wondering if anyone ever tried to solve this problem (I searched a bit on the forum and found nothing related) and if so, how he did.
I actually added a little code on Irrlicht's terrain generator to smooth the terrain loaded :
Code: Select all
for(s32 i = 0; i < 5; i++)
{
for(int index = 2; index < (TerrainData.Size * TerrainData.Size - 2); index++)
{
pMeshBuffer->Vertices[index].Pos.Y =
(pMeshBuffer->Vertices[index - 2].Pos.Y + pMeshBuffer->Vertices[index - 1].Pos.Y +
pMeshBuffer->Vertices[index + 1].Pos.Y + pMeshBuffer->Vertices[index + 2].Pos.Y) / 4.0f;
}
}
for(s32 i = 0; i < 5; i++)
{
for(int index = TerrainData.Size; index < (TerrainData.Size * (TerrainData.Size - 1)); index++)
{
pMeshBuffer->Vertices[index].Pos.Y =
(pMeshBuffer->Vertices[index - TerrainData.Size].Pos.Y +
pMeshBuffer->Vertices[index + TerrainData.Size].Pos.Y ) / 2.0f;
}
}
As you can see, it is really simple because it just changes each vertex's Y position according to the near vertices but the result surprised me :
Thanks to that code, I can create quite big terrains on small heightmaps.
The terrain is foggy but it looks like this :
I know such a code could not be used for every heightmap because it *normalizes* the height of our terrain and modifies it a lot but I was wondering if anyone had already worked on such a thing.