Resources on heightmaps?

Started by
6 comments, last by TheChubu 11 years, 3 months ago

Hi! Could somebody point me to some information dealing with heightmaps? (best image format to store them, load them, how to convert them to polygonal geometry and viceversa, etc). Specific OpenGL oriented implementation details would also appreciated!

While I'm looking for details on how to implement them myself, most articles I found deal with already existing tools so they're not useful to me : /

"I AM ZE EMPRAH OPENGL 3.3 THE CORE, I DEMAND FROM THEE ZE SHADERZ AND MATRIXEZ"

My journals: dustArtemis ECS framework and Making a Terrain Generator

Advertisement

This has been discussed several times. I'll do a quick recap of heightmaps and terrain algorithms.

Terrain algorithms: dead. Just brute force. Caveat: perhaps using pixel-based tracing might make sense.

Heightmaps: they are 2D array of values.

Format to use: everything lossless will fit. I like PNG 16-bit grayscale. A raw dump might be more appropriate in some cases. Multichannel recomposition (value = red + (green << 8) + (blue << 16)) is hard to work with but at least it won't get garbled if some processing program does not support it. Floating-point based formats are to be taken with extra super special care.

How to convert them: they are a bunch of triangles! In the past, several methods have been proposed. In the end, they're not really required unless going for AAA quality, and even in this case, you'll find out many games triangolate trivially.

OpenGL implementation: there are plenty.

You're better with a specific question.

Previously "Krohm"

Great, I already have a PNG loader.

Now, as for specific question. Well, what pixels in a heightmap represent? Vertices of a triangle? Quads?

I was thinking that maybe I could draw one with triangle strips, considering each pixel as a vertex, and using the (X,Y) positions as indexes for indexed drawing, though I'm not so sure since I can't picture it on my head yet. Got set up the loader and a PNG file made up of random noise. I'm trying to code it right now.

I'm using LWJGL by the way.

"I AM ZE EMPRAH OPENGL 3.3 THE CORE, I DEMAND FROM THEE ZE SHADERZ AND MATRIXEZ"

My journals: dustArtemis ECS framework and Making a Terrain Generator

Generally the pixels are consodered to be the vertices, and you draw triangles betwwen them.

There are different ways to draw the triangles though.

4 triangles with an imaginary middle vertex that is the average of the 4 pixel vertices in the corners

2 triangles

2 triangles with alternating direction for diagonal (to make the tiling not so obvious?)

o3o

Thanks! Thats useful information.

Anyway, I did ended up rendering something out of a grayscale image, though I just set up GL_TRIANGLE_STRIP and that's it, so the vertices have no coherence at all. I have no idea what is going on the upper side of the pic (all those horizontal lines).

Now I'll try to correct the vertices...

"I AM ZE EMPRAH OPENGL 3.3 THE CORE, I DEMAND FROM THEE ZE SHADERZ AND MATRIXEZ"

My journals: dustArtemis ECS framework and Making a Terrain Generator

Yes! Got it! Though there is something terribly wrong with my depth test I think.


GL11.glEnable(GL11.GL_CULL_FACE);
GL11.glCullFace(GL11.GL_BACK);
GL11.glFrontFace(GL11.GL_CW);
GL11.glEnable(GL11.GL_DEPTH_TEST);
GL11.glDepthMask(true);
GL11.glDepthFunc(GL11.GL_GEQUAL);
GL11.glDepthRange(0.0f, 1.0f);

If i change it to GL_LEQUAL seems like every depth test fails and I see nothing. Probably there is something wrong with the data or my perspective matrix, maybe I'm not drawing in the correct order.

"I AM ZE EMPRAH OPENGL 3.3 THE CORE, I DEMAND FROM THEE ZE SHADERZ AND MATRIXEZ"

My journals: dustArtemis ECS framework and Making a Terrain Generator

Terrain algorithms: dead. Just brute force.

Though I kind of agree with that, "dead" is not 100% right. It still makes sense to use some kind of LOD in many situations, for two reasons.

1. Brute force is OK for small to medium view ranges but simply impossible otherwise, unless your resolution is extremely poor. If you have, say, a resolution of 1 meter and you brute force with a 2 kilometer visible range (which is about half of what you see in real life), that's a ... huge ... budget. Now if you think 1 meter is too coarse, you might want to add tesselation, which further increases the number of vertices.

2. Brute force creates a lot of small triangles in the distance. Small triangles are fragment shader poison. One does not normally want to have too many triangles that are "too small", in particular one does not want triangles that are hardly larger than a fragment (or, worse, smaller).

Insofar I would word it as "terrain algorithms are not THAT important any more, and may be unnecessary in some cases, while in other cases something very coarse is totally sufficient".

Yes, perhaps I've been too bold.

Previously "Krohm"

Hi! Well, I got it working. I wasn't clearing the depth buffer so It added up after each frame and I wasn't seeing anything biggrin.png

I load the image and get the (x,y,z) coords like this: The x is the X of the pixel in the image, the y is the avg of the red green and blue colors at that pixel (pointless to avg in grayscale though) and the z is the Y coordinate of the pixel of the image. Color of the vertex is the color of the pixel.

Got some rotations/translations working too, so here are the views from above and below the mesh (from below it looks like some crazy cloudy thing).

Now I need to implement a proper camera.

Thanks for the help guys!

"I AM ZE EMPRAH OPENGL 3.3 THE CORE, I DEMAND FROM THEE ZE SHADERZ AND MATRIXEZ"

My journals: dustArtemis ECS framework and Making a Terrain Generator

This topic is closed to new replies.

Advertisement