- Home /
Understanding heightmap RAW imports
I have a real-world rectangular chunk of area (411m by 280m in real world units) whose heightmap I created using the following process (using python):
I queried the individual elevation of each coordinate in the area I want by iterating from the starting latitude and longitude and increasing first the latitude by 0.0001 (I converted the floating points to integers first so although I increase the value by 1 the effect is that of varying the coordinate by 0.0001) and then the longitude in a basic nested for loop fashion. The dimensions of the matrix of elevation points I create is 38 by 36 since there are 38 different latitudes and 36 different corresponding longitudes.
Once I have the elevation for each bounded coordinate, I divide the range (max elevation - min elevation) into 65536 (2^16) parts. For each elevation data point I find a numerical value between 0 and 65536 and color it accordingly, using shades of grey. As I understand, white represents higher elevation and black represents lower elevation. For example if lowest = 270 and highest = 285, I have a possible elevation array of the form [270, 270.00022, 270.00044.....] since 15/65536 ≈ 0.00022
I export it as a PNG but I changed the extension to RAW since according to my understanding this is exactly how RAW files are encoded. Now I understand the image should be a power of 2 + 1 but I don't get how I can convert my 38 by 36 matrix into such an image while still preserving my goal of mapping real world elevation onto the terrain.
I tried importing the heightmap in Unity on a terrain of size 411 by 280, 38 by 36, 380 by 360 and nothing gave me the effect I wanted.
I looked at the other answers but Im still not sure if my understanding of the process is correct. Could somebody point out the flaw in my process and give me any leads at all? My team and I have been stuck on this for a while and I don't see a solution in sight haha.
Answer by kaarloew · Jan 24, 2019 at 07:41 AM
RAW and PNG are different things. And file extensions are mostly for just people (actual code usually reads FourCC to determine the format of file).
Maybe https://unity3d.college/2017/07/17/importing-real-world-terrain-unity-free-terrain-party/ maybe that one helps with your project
AFAIK Unity doesn't support PNG files that have more that 8 bits per channel. https://forum.unity.com/threads/16-bit-png-shows-considerable-banding.527522/
I did check that website out, I guess my use case is a little too specific haha. Thanks for the clarification! The python module I use only supports PNG, I guess I need to look elsewhere. Thanks again!