Create height bitmap from mesh I know there are a lot of tutorials out there that tell you how to create a mesh from a height map. E.g. to create some terrain. I wish to know how I can do the reverse. So I have a mesh with a surface going from 0 to 10mm in height for example, and map the 0-10mm range to a grayscale 8bit grayscale bitmap (so 0 to 256). Is this possible with Blender? I do know a way how to convert it to a bitmap by exporting the mesh to *.dae and read the coordinates of the vertices in a script, and create the bitmap myself. But maybe there is an easier way.
The reason I want to do this is the following: A DLP UV light 3D resin printer has an uneven spread of light. There is intensity fall of to the sides. For this one can correct using a mask. But of course, you have to create that mask yourself. So I used a LDR, did some calibration measurements to be able to know what values represents what light intensities.
The box below represents the build area of the printer (X and Y), the Z axis represents relative light intensity (just from 0 to 100%). The plane with the 9 vertices represents the relative light intensity measured. So I have done 9 measurements on the build plate, a the same locations as those of the vertices.

Then the plane was subdivided once (simple) and the additional edges slided to the outer of the plane, so that the catmull clark subdivision leaves the rectangular shape of the plane as is, but does smooth out the rest. This is seen in the image below (slighty different angle than the previous image).

Then the mask for the printer requires it to be inverted. So the least light intensity from the measurement should be 100% white, and the center with the most light should be filtered the most. This is seen in the image below, which is a Z mirror of the subdivided plane.

Now of this smoothed out, inverted plane I wish to make a relative height mask. Where 0 is black (pixel value of 0), and the point touching the wire cube at the top is absolutely white (pixel value of 256). (Pixel values consider 8-bit grayscale image).
If this is for a terrain (I mean the heights are considered from a base plane), you can use a bake to the texture:



This is done using Cycles.

You can see the material nodes settings above:


Input is the location (the location is given from the object's origin, here for simplicity, the object origin is at its baseline)
Only keep the Z value
Divide by the real height of your object (in order to have a resulting value between 0 and 1)
Then put it in a diffuse shader as color
(the texture node have to be present and be the selected node for the bake described below)


To bake:


Go to the render panel and the bake section
Choose diffuse and keep only the "color" option (deselect "direct" and "indirect" as we here want the color only with no environment or other effects)




As indicated in the comments, the previous setting leads to a sharp cutout (visible in the image above: the surrounding is suddenly black).

To avoid that, a possibility is to use another function than just dividing by the object height. What I propose here is to use a sigmoid:


the output is between 0 and 1
the output limits slowly tend to 0 on left and 1 on right


That leads to this kind of result which you can compare to the image above:



In the blend file below, the higher the value for the multiply node is, the more limit rendered values will be sharp.