When I import a RAW grayscale heightmap for a terrain layer I am facing the issue that only the lowest and highest points of the terrain have the expected height, but heights in between are off.
I tested this by placing little cubes according to the geospatial data that I am working with. There I saw that there always is a big difference between the cubes and the actual terrain.
My workflow is the following:
I open the ASC-File containing the terrain data in QGIS (tool for geospatial data)
→ I export a rendered grayscale TIF file from QGIS
→ opened in Photoshop
→ changed image size to 4097x4097 and set the mode to 16-bit grayscale
→ exported as RAW file
→ imported as terrain heightmap in Unity
→ set y coordinate of the terrain to the lowest height of the terrain which is shown in “QGIS” and for the terrain height I used the difference of the highest and the lowest elevation
You can find the relevant files on my googledrive as they were to large for upload on the
https://drive.google.com/file/d/1zjwLPxe7jT5SNuT-iwUBSIiWoqT5FKXO/view?usp=sharingforum.
I also tried directly creating the RAW file from the ASC file using the tool “GDAL” but this resulted in a completely flat terrain.
I would really appreciate it if someone could help me. I am struggling with this for quiet a while and I really must solve this as it is very important for my bachelor thesis.
I theorize it might be non-linear colorspace when you make your TIF file.
You might want to make a test grayscale with a series of height areas, such as 0%, 10%, 20%, up to 100%, then import it, and from within your Unity scene you can see how that imports and reason if something along the way is applying a non-linear function.
Thank you a lot for your reply! @Kurt-Dekker
I really appreciate it that you are trying to help 
I created two 33x33px raw files in photoshop. One with 100%, 80%, 60%, 40%,20% and 0% gray and a second one with a linear gradient from 100% to 0%.
You can see the results in the attached image.
With the second gradient you can clearly see that there is some non-linear function applied.
I am wondering what I could now do to solve the issue and I am surprised that I am nearly the only one who is struggling with this. Maybe it’s due to the fact that you only notice the issue when you are doing measurements like I do…
Any further ideas what I could do?
There was already someone who experienced the same issue back in 2016 but no one replied.
https://answers.unity.com/questions/1188501/terrain-heightmap-non-linear-mapping-issue.html
Perhaps try correcting it the way you would correct gamma?
https://en.wikipedia.org/wiki/Gamma_correction
You might even be able to find the actual terms used in your TIF step (or wherever the gamma is being introduced) and back it out perfectly.
This is interesting.
My thoughts are if Unity terrain reads aren’t working in IEEE 754 format 32-bit floats on the raw data OR, are not using height/width ratios to support the human perception of mountains.
then the Y vertical calculations is using a perfect cube for the “volume bounds”
i know from experimenting a long time ago with the brushes, the resolution and density wasn’t always accurate to the unity given in the brush. unless the terrain was at a certain width.
1 Like