Terrain Data Visualization
Paul Molnar, March 2022
Terrain data visualization in Unity is easy! Unity has a built in terrain object that has lots of different properties which make it very simple to import data and display it as a terrain. The only constraint is that you need your data in a 2D .raw file which means it cannot model caves or other functions that have more than one point for each XY value. The other thing that can be tricky is turning you .png or .jpg into a raw file. This page will walk you through how to turn a normal image file into a beautiful Unity terrain. This tutorial does not include instructions on how to generate cave terrains where each (x, y) tuple can have more than one y value. If you are interested in cave generation check out this subpage instead: 3D Cave Generation.
Conversion to .raw File:
There are several applications out there which allow for converting from normal image types such as .png or .jpg into .raw files. One free and easy app to use is called Fiji ImageJ which you can download from this link: Fiji Download. You can simply draw an image into Fiji and select "File -> Save As -> Raw Data". Since Fiji is free it is also buggy sometimes so you may have to perform this saving step more than once before it gets saved as a .raw file. One thing to be weary of is that Unity only supports raw files with maximum resolution of 4097 x 4097. If you image is bigger than that you will need to crop it or scale it down before you can use it in Unity. If you decide to scale it down you should scale it down to 4099 x 4099. Then crop one pixel off of each edge as the edges will be black due to the interpolation scaling algorithm which can lead to a distortion of your terrain since the value is based on relative weights.
Getting your .raw File onto a Unity Terrain:
Once you have a .raw file that is less than or equal to a resolution of 4097 x 4097 you can go ahead and create a new terrain in the unity hierarchy. In the inspector click on the terrain settings and scroll down to texture resolutions. From here click the "Import Raw" button and select your raw file from earlier. Select the resolution of your heightmap in the "Heightmap Resolution" setting. You also may want to edit the width, length, and height of the terrain. If you know the real life width, length, and height range of the terrain you chose you can scale the width and length to be whatever you want and then choose the height according to the original proportions. One last setting you may want to change is the material of the terrain. You can change this by adjusting the material in the "Basic Terrain" section to any material including one you have made.
Example Data to Try This With:
Here is a link to Mars elevation data taken by satellites: Mars Elevation Data. To get this data as a .png file you need to click on the "Process" button on the right side of the screen and click "Send Anyway" when it tries to stop you. From there you can fill out each section with the most important ones being the "Projection" tab and the "Download File Format" tab. For the projection try and choose something small such as a 15 x 15 degree latitude/longitude section. From there select "Add Job" and then refresh for updates until it allows you to download a folder containing you .png file.
Example Visualization with Data/Method:
Here is a link to the subpage of this page: Mars Data Visualization (Collaborative) . It is a tutorial on how to get the visualization of Mars pulled up and running on your machine through Virtual Desktop.