Jump to content

  • Log In with Google      Sign In   
  • Create Account


Resources on heightmaps?


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
8 replies to this topic

#1 TheChubu   Crossbones+   -  Reputation: 4118

Like
0Likes
Like

Posted 26 December 2012 - 05:53 AM

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


Sponsor:

#2 Krohm   Crossbones+   -  Reputation: 3052

Like
1Likes
Like

Posted 27 December 2012 - 03:14 AM

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.



#3 TheChubu   Crossbones+   -  Reputation: 4118

Like
0Likes
Like

Posted 27 December 2012 - 04:53 PM

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.


Edited by TheChubu, 27 December 2012 - 04:54 PM.

"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


#4 Waterlimon   Crossbones+   -  Reputation: 2482

Like
1Likes
Like

Posted 27 December 2012 - 05:32 PM

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


#5 TheChubu   Crossbones+   -  Reputation: 4118

Like
0Likes
Like

Posted 28 December 2012 - 06:29 AM

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...

 

 

Attached Thumbnails

  • landscape.jpg

"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


#6 TheChubu   Crossbones+   -  Reputation: 4118

Like
0Likes
Like

Posted 28 December 2012 - 09:30 AM

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.

Attached Thumbnails

  • landscape2.jpg

"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


#7 samoth   Crossbones+   -  Reputation: 4684

Like
1Likes
Like

Posted 28 December 2012 - 10:53 AM

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".



#8 Krohm   Crossbones+   -  Reputation: 3052

Like
0Likes
Like

Posted 29 December 2012 - 07:45 AM

Yes, perhaps I've been too bold.



#9 TheChubu   Crossbones+   -  Reputation: 4118

Like
0Likes
Like

Posted 03 January 2013 - 01:49 PM

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!

Attached Thumbnails

  • Landscape_1.jpg
  • Landscape_2.jpg

"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





Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS