1
$\begingroup$

I found this old question by "omuverde" on blenderartists[1]

It's there a way to export a ANT Landscape generated terrain from Blender to a heightmap? I saw a tutorial that did it by positioning the camera above the terrain and rendering the heightmap but i'd like a more elegant way of doing this.

So, is there a way or am I going to have to write a script to sort verts from the mesh in the right order?

I repost it here because the question was never answered, and the suggested method (render the heightmap as an image) may have issues with the choice of lightsource. Also It is preferred that the image is exported in linear colorspace.

[1] http://blenderartists.org/forum/showthread.php?115406-ANT-Landscape-to-Heightmap

$\endgroup$
4
$\begingroup$

It can be achieved by baking the height of a mesh.

Before you start, make sure that the origin of the object is beneath or at the lowest point of the mesh, preferably the latter. Negative values do not go well with images. Go to the UV/Image Editor and create a new image

enter image description here

Go to the 3D view, select your mesh, go to edit mode, select all vertices with A, go to orthographic view by pressing numpad 5 and top view by pressing numpad 7. Press U and click Project From View (Bounds)

enter image description here

Go back to Object Mode, go to the node editor add a new material for the mesh. Add a Texture Coordinate node, a Separate XYZ node and a Math node. Connect the Object output from the Texture Coordinate node to the Vector input of the Separate XYZ node, the Z output of the Separate XYZ node to the upper input of the Math node and the output of the Math node to the Color input of the Diffuse node. Change the operation mode of the Math node to Power and the bottom value to 2.

Add an Image Texture node, select the just created image in it, but do not connect it to any other node.

The Node Editor should look like this: enter image description here

Make sure you have the Image Texture node selected, go in the Properties Panel to the Render tab. Go to the Bake options, change Bake Type to Diffuse Color and click Bake.

enter image description here

You can now find the height map in the UV/Image Editor by selecting the image you created at the start. Do not forget to save the height map by pressing F3.

enter image description here

Note that this method is not perfect, a mesh created using this height map will not be completely identical to the original mesh.

$\endgroup$
  • $\begingroup$ Why taking the square? $\endgroup$ – user877329 May 5 '16 at 18:05
  • $\begingroup$ The square of the height. Has that to do with gamma correction? $\endgroup$ – user877329 May 6 '16 at 9:24
  • $\begingroup$ It has something to do with the way color data is stored. Minutephysics explains it a bit in this video: youtube.com/watch?v=LKnqECcg6Gw. I tested multiple methods, and taking the square gets the best result. I am not sure why, but it works. Compare these two pictures: snapr.pw/i/0b9059b0e5.png (without taking the square) and snapr.pw/i/bbc94fb546.png (with taking the square) $\endgroup$ – Ezra May 6 '16 at 9:36
  • $\begingroup$ Ok so it has to do with gamma correction. Then squaring is not precisely correct. I need to know if I can save a linear image from blender or not. See also wiki.blender.org/index.php/Dev:Ref/Release_Notes/2.64/… $\endgroup$ – user877329 May 6 '16 at 9:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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