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

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

<p>Hope this helps.</p>

CC BY-SA 3.0
2016-12-05T22:04:07.790Z
2016-12-05T22:04:07.790Z
CpCd0y
<p>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 <code>glReadPixels</code> 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.</p>

CC BY-SA 3.0
2016-12-06T09:20:26.703Z
2016-12-06T09:20:26.703Z
Dan Hulme
<p>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.</p>

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

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

<p>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?</p>

<p>I should add that I am quite new to the computer graphics field of programming.</p>

<scene-graph><height-field>
Method for rendering heightmap from a 3D scene
user5314
# Method for rendering heightmap from a 3D scene

(Asked by: username_0 on 2016-12-04)

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.

**Tags:** scene-graph, height-field


---

## 2 answers

### Answer by username_2 on 2016-12-06. Score: 4 | Accepted answer

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.


---

### Answer by username_1 on 2016-12-05. Score: 4

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.


---

