# Linear grayscale heightmap from plane mesh

**URL:** <https://blenderartists.org/t/linear-grayscale-heightmap-from-plane-mesh/578915>\
**Category:** Materials and Textures\
**Created:** [June 24, 2013, 9:15am UTC](https://blenderartists.org/t/linear-grayscale-heightmap-from-plane-mesh/578915 "2013-06-24T09:15:50Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![eliel](https://blenderartists.org/letter_avatar_proxy/v4/letter/e/fbc32d/32.png) [@eliel](https://blenderartists.org/u/eliel)\
**Post date:** [June 24, 2013, 9:15am UTC](https://blenderartists.org/t/linear-grayscale-heightmap-from-plane-mesh/578915/1 "2013-06-24T09:15:50Z")

</div>

Hello Blender gurus,

for a hobby game project I’m working on, I’ve been trying to export a linear grayscale heightmap according to a Z-deformed\* plane mesh, referring mainly to the now obsolete wiki article [http://wiki.blender.org/index.php/Doc:2.4/Tutorials/Textures/Maps/Creating\_a\_Heightmap\_from\_a\_Plane](http://wiki.blender.org/index.php/Doc:2.4/Tutorials/Textures/Maps/Creating_a_Heightmap_from_a_Plane) and a YouTube Blender 2.6 tut ([http://www.youtube.com/watch?v=EnrrsVzkqnc](http://www.youtube.com/watch?v=EnrrsVzkqnc)), but with undesired results. What my game engine expects from these heightmaps is only the following:

- lowest point of the (heavily subdivided) plane mesh corresponds to a pixel with value 0 (black), and the highest point to 255, with absolutely linear mapping for everything in between (eg. 0.5\*(Z[SUB]max[/SUB] + Z[SUB]min[/SUB]) -\> “127.5”).

What I’m doing now is this:

1. create plane, scale by 8, apply that scale, subdivide a healthy number of times, and manually deform plane as desired
2. add material and enable Shadeless. Add texture, select Blend as type, enable Ramp (linear, RGBA(0,0,0,1) to RGBA(1,1,1,1)), mapping Z,Z,Z. Mapping = Generated, Projection = Flat.
3. move camera on top, pointing downwards, orthographic, scale 16.000
4. select appropriate output image dimensions, format, bit depth and all that stuff
5. render, save to image

However, just by looking at a height map generated using this method in the UV/Image editor view there are no _exactly_ zero or white pixels to be found, which is not what I was aiming for. Also, I’m not entirely convinced of the actual linearity of this mapping, based on my tests on the game engine and the fact that the gradient texture preview looks rather obviously not linear (see picture below)

![](https://blenderartists.org/uploads/default/original/3X/9/3/93bf1f1a2ae1c045d30b7c43e62274ad25742ab0.png)

I’ve successfully done this the other way around, ie. deformed a subdivided plane mesh according to a height map generated with GIMP, but wasn’t quite proficient enough to create natural looking landscapes that way. :o

So now, what am I missing? Is there a way to generate a perfectly linear, (Z[SUB]min [/SUB]-\> 0; Z[SUB]max[/SUB] -\> 255) heightmap directly from Blender? Thanks.

- by Z-deformed I mean only Z-displacement is ever applied; the top-orthographic projection of my meshes is always square.

---

<div class="post-metadata">

**Author:** ![norvman](https://blenderartists.org/user_avatar/blenderartists.org/norvman/32/13306_2.png) [@norvman](https://blenderartists.org/u/norvman)\
**Post date:** [June 25, 2013, 7:25am UTC](https://blenderartists.org/t/linear-grayscale-heightmap-from-plane-mesh/578915/2 "2013-06-25T07:25:30Z")

</div>

this might be a good place to start…

[http://www.blenderartists.org/forum/showthread.php?273033-Sculpting-with-UVs-and-displacements](http://www.blenderartists.org/forum/showthread.php?273033-Sculpting-with-UVs-and-displacements)

---

<div class="post-metadata">

**Author:** ![PyroGXPilot](https://blenderartists.org/user_avatar/blenderartists.org/pyrogxpilot/32/18257_2.png) [@PyroGXPilot](https://blenderartists.org/u/PyroGXPilot)\
**Post date:** [June 25, 2013, 10:47am UTC](https://blenderartists.org/t/linear-grayscale-heightmap-from-plane-mesh/578915/3 "2013-06-25T10:47:25Z")

</div>

Do you have a blend file?

---

<div class="post-metadata">

**Author:** ![eliel](https://blenderartists.org/letter_avatar_proxy/v4/letter/e/fbc32d/32.png) [@eliel](https://blenderartists.org/u/eliel)\
**Post date:** [June 26, 2013, 4:02am UTC](https://blenderartists.org/t/linear-grayscale-heightmap-from-plane-mesh/578915/4 "2013-06-26T04:02:07Z")

</div>

Fantastic! Using _Displacement Bake_ I managed to do exactly what I wanted.

Basically what I did was to add a second plane of similar _xy_-dimensions on top of my manually displaced terrain mesh, UV-unwrapped it and provided a blank 1024-by-1024 image (from the UV/Image editor view -\> _New_) for baking.

Then I switched to _Object mode_ and first selected the displaced mesh and then the baking plane (in that order!), went to the Render-\>Bake submenu, selected _Displacement_ from the Bake Mode-dropdown, enabled _Selected to Active_ (this is why the order was important) and pressed Bake. And voilà, we have a perfectly linear height map, with Z[SUB]min [/SUB]mapped to 0 and Z[SUB]max [/SUB]to 255 (or 65535 if using 16-bit color depth).

There are also a couple of unmentioned manual parameter-tweaking steps involved (such as finding the correct value for the maximum distance param in the bake menu), but I would guess those, along with the rest of the procedure, can just be scripted later on. 🆒

So: thanks all y’all!

Here’s a screenshot for those interested:

 ![](https://blenderartists.org/uploads/default/original/3X/d/9/d927fc45feb8ed5ffce40ce840ca8db5c0420002.jpg)  

Btw, just realized it’s a bit misleading to be calling it a _plane_ mesh, since it’s not really _planar_ after the deformation part has been done 😉

---

<div class="post-metadata">

**Author:** ![norvman](https://blenderartists.org/user_avatar/blenderartists.org/norvman/32/13306_2.png) [@norvman](https://blenderartists.org/u/norvman)\
**Post date:** [June 26, 2013, 2:40pm UTC](https://blenderartists.org/t/linear-grayscale-heightmap-from-plane-mesh/578915/5 "2013-06-26T14:40:37Z")

</div>

Very cool guy… also thanks for your explaination on what you did there… it always helps to share… I’m still learning cycles and textureing and baking myself in Blender…

---

<div class="post-metadata">

**Author:** ![Anathema](https://blenderartists.org/user_avatar/blenderartists.org/anathema/32/1083188_2.png) [@Anathema](https://blenderartists.org/u/Anathema)\
**Post date:** [June 26, 2013, 4:15pm UTC](https://blenderartists.org/t/linear-grayscale-heightmap-from-plane-mesh/578915/6 "2013-06-26T16:15:11Z")

</div>

What a nice find, I’ll be sure to bookmark this in case I ever need heightmaps (more of a voxel person myself)

---

<div class="post-metadata">

**Author:** ![norvman](https://blenderartists.org/user_avatar/blenderartists.org/norvman/32/13306_2.png) [@norvman](https://blenderartists.org/u/norvman)\
**Post date:** [July 2, 2013, 5:51am UTC](https://blenderartists.org/t/linear-grayscale-heightmap-from-plane-mesh/578915/7 "2013-07-02T05:51:20Z")

</div>

Yah I need to spend more time with particals and voxels and all that stuff… just not enough time in the day…

---

<div class="post-metadata">

**Author:** ![JollyRoger](https://blenderartists.org/letter_avatar_proxy/v4/letter/j/c57346/32.png) [@JollyRoger](https://blenderartists.org/u/JollyRoger)\
**Post date:** [March 17, 2014, 5:28pm UTC](https://blenderartists.org/t/linear-grayscale-heightmap-from-plane-mesh/578915/8 "2014-03-17T17:28:44Z")

</div>

AWESOME! Thanks!  
I used this guys tut: no second plane, and no baking.

Made this on my laser, (the whole point of this exercise) after exporting the height map.

 ![](https://blenderartists.org/uploads/default/original/4X/6/2/2/62220e71340e3cda4d18191af6c7fe1ad0b87652.jpg)  
 ![](https://blenderartists.org/uploads/default/original/4X/5/c/1/5c1cb7b941c559f8afa5772ce4b8fb97596dbcd5.jpg)  
 ![](https://blenderartists.org/uploads/default/original/4X/b/d/d/bddeb67851356a27d49a12d8876b14a31264a200.jpg)  
  
I used some crappy particle board, but it came out ok. I will use acrylic next time. Worked good for a test.
