Sign in to follow this  
deadstar

Jagged terrain

Recommended Posts

Hi all, My terrain looks jagged, and I'm at my wits end trying to figure out why. The heightmap is loaded from a PNG image, and I organise the data into vertices and a face list, and calculate vertex normals. Here is the relevant code:
//Load in vertices
		for (int x = 0; x < Width; x++)
		{
			for (int z = 0; z < Height; z++)
			{
				TempVertex->x = static_cast<float> (x) * Scale; 
				TempVertex->y =	static_cast<float> (SDL_GetPixel(Surface, x, z)) * Scale * HeightScale;
				TempVertex->z = static_cast<float> (z) * Scale;

				TempVertex->UVCoord.u = static_cast<float> (x) / Width;
				TempVertex->UVCoord.v = static_cast<float> (z) / Height;

				Vertex.push_back(*TempVertex);
			}
		}

//Calculate faces
		for (int x = 0; x < Width - 1; x++)
		{
			for (int z = 0; z < Height - 1; z++)
			{
				//First triangle
				TempFace->a = x	* Width + z;
				TempFace->b = x	* Width + (z + 1);
				TempFace->c = (x + 1) * Width + z;

				Faces.push_back(*TempFace);

				//Second triangle
				TempFace->a = (x + 1) * Width + (z + 1);
				TempFace->b = (x + 1) * Width + z;
				TempFace->c = x * Width + (z + 1);

				Faces.push_back(*TempFace);
			}
		}

And here is a shot of what it currently looks like: The heightmap was generated with EarthSculptor, which outputs a 1bpp PNG image. I've experimented with adding a 'resolution' variable, and changing the vertex winding whilst calculating the normals, nothing seems to make a difference. I'm not asking anyone to *fix it* for me, just point me in the right direction.

Share this post


Link to post
Share on other sites
If "1bpp" means 1 byte per pixel, that's the problem right there.
You won't have more than 256 different elevations in your terrain, causing the unevenness.

Share this post


Link to post
Share on other sites
maybe your should use smooth algorithm for vertices.
this is code from Irrlicht.


//! smooth the terrain
void CTerrainSceneNode::smoothTerrain(SMeshBufferLightMap* mb, s32 smoothFactor=5)
{
for (s32 run = 0; run < smoothFactor; ++run)
{
s32 yd = TerrainData.Size;
for (s32 y = 1; y < TerrainData.Size - 1; ++y)
{
for (s32 x = 1; x < TerrainData.Size - 1; ++x)
{
mb->Vertices[x + yd].Pos.Y =
(mb->Vertices[x-1 + yd].Pos.Y +
mb->Vertices[x+1 + yd].Pos.Y +
mb->Vertices[x + yd - TerrainData.Size].Pos.Y +
mb->Vertices[x + yd - TerrainData.Size].Pos.Y) * 0.25f;
}
yd += TerrainData.Size;
}
}
}



Share this post


Link to post
Share on other sites
Quote:
Original post by polymorphed
If "1bpp" means 1 byte per pixel, that's the problem right there.
You won't have more than 256 different elevations in your terrain, causing the unevenness.


'1BPP' according to SDL_image's Surface->format->BytesPerPixel. I use the GetPixel() function from the SDL wiki to retrieve the height value, which returns the 1BPP pixel as a Uint32.

32BPP according to The Gimp and Photoshop.

I'd appreciate if someone could elaborate on this for me.

Share this post


Link to post
Share on other sites
Is the heightmap in greyscale when you view it, or does it have variations of red, green and blue?

If it's greyscale, that means that you have no more than 256 elevations.
If it's non-greyscale, that probably means that the program you're using encodes it in a special way to take advantage of all the available channels (red, green, blue and alpha) to create somewhere between 256 and 2^32 elevations.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this