6
$\begingroup$

I am looking for a method of rendering a heightmap from a 3D scene. The scene may consist of a terrain which is in turn generated from another heightmap, but will also have regular 3D objects.

The generated heightmap should, so to speak, indicate the highest point in the "column" of the 3D scene represented by each pixel in the heightmap.

This does not need to be a fast/realtime operation, and it does not really matter what language or library is used, although I'd prefer using Python (perhaps with Panda3D?). Also, I would prefer being able to run it headlessly, from a command-line tool without the need for an actual on-screen rendering.

Is this a common operation for which there are established/canonical methods, either through a library such as Panda3D or through more direct/low-level use of data structures representing the 3D scene?

I should add that I am quite new to the computer graphics field of programming.

$\endgroup$

2 Answers 2

4
$\begingroup$

The easiest way to do this is by rendering the 3D scene the way you usually would through OpenGL, using whatever 3D Python library you already have loading the scene. Instead of the perspective camera you would usually use, render through an orthographic camera looking down on the scene from above (making sure the camera plane is above any part of the scene). Make sure the renderer uses a z (depth) buffer, and if you don't want anything on screen, render it to an off-screen buffer (you don't actually need the colour buffer at all, only the z buffer). Just glReadPixels the z buffer (i.e. read back the pixels from the buffer) after rendering, and save it to a file. Your 3D library will probably have a way to save the buffer to a file directly.

$\endgroup$
4
$\begingroup$

Using OpenGL, or any such library, you could transform your scene with an orthogonal matrix and move your camera view point to be looking above (and parallel to) the scene (in a vertex shader) and then use an empty fragment shader which is going to write to the depth buffer of the current attached framebuffer. Finally retrieving this depth buffer gives you the heightmap of the current view.

If your scene is too big, you could move the camera higher and also move it around taking "chunks" of the map at a time and assembling your heightmap manually by "stitching" these "chunk" heightmaps together.

Hope this helps.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.