This tutorial replaces my tutorial from five years ago, “Shaded Relief with BlenderGIS” tutorial. At this point (March 2020) I am using Blender 2.82 and the most recent BlenderGIS addon. Daniel Huffman’s tutorial, which uses a different technique, has also been updated.
It’s rather an understatement to say that Blender is complex. To keep things from getting out of hand, I’m going to take a straight path, right through the centre of the software, with a focus on getting out the other side with a completed render of shaded relief. But at the end, I will return and explore some of the interesting side trails that lead to the features that make the Blender hillshades so interesting.
Here’s the basic procedure I will follow to create a hillshade, once Blender is installed with the BlenderGIS addon. This can function as a checklist once you’ve become familiar with the process:
- Prepare your DEM
- Read the DEM into Blender as DEM raw data build
- Adjust Z scaling (vertical exaggeration)
- Create and adjust a georef camera
- Correct the final pixel dimensions of the output image to match the DEM
- Set final image type to be TIFF
- Turn the light into a Sun, and adjust its properties
- Do a test render
- Do a full render
Before you experiment with using Blender to make shaded relief, you will want to try the relatively simpler step of producing your own shaded relief in GIS software like QGIS. Consequently, this tutorial won’t explain a host of things that you would learn in that process: what digital elevation models (DEMs) are, the importance of cell sizes, nodata values and projections, or the art of combining shaded relief with other layers, stretching histograms and adjusting brightness and contrast. I will assume that you already know that, at its most basic level, creating shaded relief involves specifying a sun elevation and azimuth, and selecting a vertical exaggeration for your terrain.
I use the free GDAL command-line tools gdal_translate and gdalwarp to do re-projection and re-sampling, as well as produce world files. If the command line makes you queasy, QGIS offers a graphical front-end to these tools as well. (Processing>Toolbox, and search on “translate” or “warp.”)
Your first step will be to go to https://www.blender.org/ and obtained the free animation software Blender 2.8.
Installation of BlenderGIS
You only have to do this once, and then Blender is prepared to accept geographic data.
The BlenderGIS addon has installation instructions in its wiki at https://github.com/domlysz/BlenderGIS/wiki/Install-and-usage. Basically, they go as follows.
Go to the BlenderGIS site on github and hit the Clone or Download button, and then Download ZIP. You will receive a file called BlenderGIS-master.zip which you can store pretty much anywhere. Once you’ve installed BlenderGIS, you won’t need this file any more.
Within Blender, go Edit>Preferences, and select the Addons tab. Click Install…, select the BlenderGIS-master.zip file, and click Install Add-on from File.
Once it is installed, be sure to check the box next to 3D view: BlenderGIS to enable it.
Note that a new menu appears in Blender: the GIS menu.
Two more tweaks will make Blender easier to use.
- Note the default cube that is always there in a new workspace. To delete it, hover the mouse over the cube and hit the Delete key.
- Find the Render tab on the right, and set Render Engine to Cycles. (If you have a good graphics card, you might also want to set Device to GPU compute)
Now go File>Defaults>Save Startup File. This means that in the future, Blender will open with no cube, and with Cycles as the render engine.
Preparing your DEM
- Note down the dimensions of your DEM
- Convert (re-project) to a metric projection
- Create a world file
First I will note down the pixel dimensions of my DEM, whcih in this case are 839 x 702. I will use these numbers later to tell Blender what size image to produce.
Now, the most important principle of making hillshades is that your vertical and horizontal units should be the same. If the DEM data came projected in degrees, you need to convert that to a projection measured in metres.
You’ll notice later that BlenderGIS claims that it can read a DEM projected in “WGS84 latlon” —in other words, EPSG 4326. I have found this works only when you are reading that DEM into a Blender scene already georeferenced in a metric projection. You have to do a kind of complicated head-stand to make this occur, so we’ll take the simpler route and feed to BlenderGIS a DEM that is projected in metres. Typically for me (in northern British Columbia) this would be UTM Zone 9 North/WGS84 (EPSG 32609) or the BC Albers Equal-Area projection/WGS84 (EPSG 3005).
I will use gdalwarp to re-project, and (optionally) re-sample. In the following example, I am re-projecting out of lat/long/WGS84 (EPSG code 4326) into UTM Zone 9 north/WGS84 (EPSG code 32609), and re-sampling to 16 metre square cells. I will assume your DEM is a geotiff file.
gdalwarp -s_srs EPSG:4326 -t_srs EPSG:32609 -r bilinear -tr 16 16 -of GTiff -co "TFW=YES" myDEM.tif myDEM_32609_16x16.tif
- the Spatial Reference System (projection & datum) of the original (the “source”)
- the SRS of the result (the “target”)
- resampling method (bilinear, cubic, etc.)
- resolution, in metres (give two values, one for X and one for Y)
- output format
- additional creation options (TFW=YES means create a world file)
The terms “projection/datum,” SRS (Spatial Reference System), and CRS (Coordinate Reference System) are interchangeable for our purposes.
[I’m not going to suggest converting your DEM to Float32 data type. This makes a difference only with large scale mapping (e.g., 1:25.000 or larger), where you might actually see “steps” in your hillshade where the elevations change by whole metres. If you are doing such mapping, consider floating your DEM first.]
Finally, you will want a world file for the DEM, so you can georeference the hillshade Blender produces. World files used to be pretty common, but now that raster data so often comes with its georeferencing built in, I will explain what they are.
The world file was a clever invention: a six-line text file that contained the cell dimensions and the coordinates of the image origin (upper left corner). It was paired with the image file by having the exact same filename, but with a TFW extension (for TIFF images). For example, you could have myDEM.tif and its associated world file myDEM.tfw. This allowed the georeferencing information to be held externally to the image file.
When an image file has no georeferencing (i.e., it is an ordinary TIFF image, not a GeoTiff), the world file is all your GIS software needs to correctly place and scale the image. The only additional piece that it will have to ask you for is the projection of the image, in order to make sense of the world file.
For JPG and PNG images, the world file extensions are JGW and PNW, respectively.
To make a world file I use gdal_translate as follows:
gdal_translate -co "TFW=YES" myDEM.tif deleteme.tif
This copies myDEM.tif to a dummy file called deleteme.tif (which I will immediately delete), and in the process makes a world file called deleteme.tfw. For now I’ll rename this to myDEM.tfw. Later I’ll change its name again to match the image created by Blender.
So at the end of this preparation step I have three things:
- a DEM in a metric projection (e.g., myDEM_32609_16x16.tif)
- a corresponding world file (e.g., myDEM_32609_16x16.tfw)
- I know the EPSG projection code for the projection the DEM is in (e.g., 32609)
Read the DEM into Blender as Raw DEM
On the GIS menu, go Import>Georeferenced raster, and navigate to your DEM file.
In the right margin, set Mode to DEM raw data build (slow). (If you do not check the Build faces box, you will get a point cloud.)
You also have the option here of selecting the correct CRS (coordinate reference system) for your DEM. You need to do this only if you plan on bringing other georeferenced data into Blender to lay atop your DEM. If not, you can leave this at the default value (WGS84 latlon) even though that is incorrect.
[If the CRS you want to use is not on the dropdown menu, you can add it by clicking the “+” button, checking the Search box, typing in the EPSG code for your CRS into the Query box, and hitting Enter. It should appear in the Results box, and then you just check Save to addon preferences and click OK.]
After a pause, during which Blender builds a plane mesh out of your DEM, you will see a grey, 3D rendering of your terrain, floating in a coordinate space.
A quick tour of Blender
Let’s take a brief detour here and learn some of the the language of Blender, as well as some of its controls and unexpected behaviours.
Blender, being 3D animation software, is a world of vertices (points in space), edges (which connect vertices) and faces (which fill in between edges). In this case, the cells of the DEM have been translated into a square array of vertices, each with the appropriate height for the DEM cell it represents. These vertices have been connected with edges that form a square lattice like the cells of the DEM. Each square of four edges has a face.
The whole set of vertices, etc. is a mesh, specifically in this case a plane mesh.
In the lower right corner, you will notice a status bar:
This tells us that we have 588,978 vertices and 587,438 faces. My DEM is 839 columns by 702 rows, and 839 x 702 = 588,978, so I could have predicted the number of vertices. This is useful to know so you can estimate before reading in a DEM, how much RAM it will require. On average (and this varies as the size of the DEM increases), every 3,500,000 vertices requires 1GB of RAM.
The number of faces is slightly less because no faces are generated by the final row and final column (839 + 702 = 1541, minus 1 face which would be generated by both the final row and final column, hence 1540 fewer faces than vertices.)
The status bar also tells us we are presently using 291MB of RAM. This will go up during the final render. Near as I can tell, available RAM is the only limit to the size of DEMs that Blender can handle.
You can see the vertices, edges and faces of your plane mesh if you zoom in and press TAB to toggle into Edit mode.
Don’t worry if you can’t figure out how to do this just yet. If you do though, be sure to press TAB again to leave Edit mode before continuing on.
The upper right corner of Blender has a panel called an outliner that shows a tree of objects in the Blender world. At present it looks like this.
Notice that the plane (called “Thomlinson 32609 16m clip” in my case) is selected. (In the 3D view this is reflected by the fact that the plane is outlined in orange.) In addition there is a camera and a light.
Below the outliner is a Properties panel. On its left margin you will see a series of tabs identified by these icons. Hovering over them reveals their names.
We won’t have anything to do with some of these (Particles, Physics, etc.) The important ones for our purposes are Render, Output, Object and Object Data.
Note: sometimes the collection of tabs changes, depending on what object in the Blender world is selected. At this moment the plane is selected, but if the light were selected some of these tabs would disappear, and the Object Data tab would display a green light bulb icon.
The rest of the screen is taken up by the large 3D Viewport panel. Navigating in this is similar to using Google Earth, but a little different.
- Rolling the mouse wheel zooms you in and out.
- Holding down the mouse wheel button while moving the mouse in this panel allows you to rotate around objects.
- To pan, hold down Shift and the mouse wheel button while moving the mouse to either side.
The other thing to know about Blender is that some keys work only when the cursor is over the 3D Viewport.
- n toggles the 3D View Properties Panel
- Numpad -. (period) centres the view on the selected object.
- Numpad-0 toggles between this view and camera view.
- TAB toggles the selected mesh in and out of Edit mode (and we won’t be using this).
Remember that Blender is a studio for animators. It is designed to allow you to sculpt new objects, and the generate many frames of animation in which various objects are lit by lights and shot from a specific camera. We are not going to create any new objects, and are going to shoot only a single frame; so there are many controls we will not use.
However, setting up our light and camera are crucial, and that’s what we do in Part 2.