Blog

Aug 28, 2011

EDITING HEIGHTMAPS IN ZBRUSH

If Unity3D had a Flatten brush as part of it's Terrain sculpting tools, then working alongside Terrain Toolkit would mean you have a fairly good editor for creating real time landscapes. But it doesn't. If you want to sculpt a ramp of any kind, say a path up a hill, a winding road or something similar, then it's almost impossible, and there's certainly no fun to be had trying to do it.

So I wanted to demonstrate the simplest way I could find to get a Terrain into Zbrush where you can sculpt what you need to, then quickly create a Heightmap (alpha depth mask in the ZBrush vernacular) to bring back into Unity3D or some other engine.

So here's a Heightmap in Unity3D that I've downloaded via Google Earth by loading this file: http://www.ambiotek.com/topoview. I explain how to do this in an earlier post.

Let's say we want to create a path from one terrace level to another around here:

First you want to export your Terrain as a mesh .obj, so you'll need to grab the TerrainObjExporter script from the Unity3D Wiki:

You must place the script in a folder named Editor in your project's Assets folder for it to work properly. Also it must be called "ExportTerrain" or it won't run.

Now select your Terrain>  in your Project pane, go to Menu > Terrain and select 'Export to Obj'. Choose Quads (ZBrush doesn't like Triangles) and Full from the little menu you get, then import the .obj as a tool into ZBrush.

Once you've done this, draw the mesh onto the Zbrush canvas and hit Edit. Now you're ready to hit 'B', choose a brush, and begin sculpting.

This of course is also what you need to do if you're using your Terrain as a stand in while sculpting overhanging rock formations, caves, cliffs and so on to later merge with your Heightmap as a 3D asset. You can always export your Terrain as Half if you're not using it rebuild a Heightmap, but just as a guide.

ZBrush is not the best program for navigating a large mesh unfortunately, but you can use CTRL + SHIFT to drag out a marquee over the area you want to focus on, hiding the rest of the mesh. When you're done just hold CTRL + SHIFT again and click on an empty part of the canvas and your whole model will pop back into view. Also keep Local checked on the right of the canvas which allows you to pivot the model around the last area on the mesh you touched with a brush.

Here I've used the Clay Tubes, Flatten  and Move brushes to quickly sculpt a kind of ramp. You don't need to get too refined when creating details in a Heightmap like this because the resolution of the mesh is fairly low anyway.

When you've done your sculpting, rotate your mesh to view from above, then hold SHIFT and rotate some more to snap it to the Top axis. 

This is where we create the new Heightmap. Go to Menu > Alpha > Grab Doc. You should see a grey scale Heightmap appear in the alpha tab on the left. Note that you could now use this alpha map to sculpt details onto a mesh. Just leave it where it is and try sculpting..

 

Now Menu > Alpha > Export, save it as a .psd and load it up into Photoshop. You will probably need to crop the Heightmap, rotate and or flip your image to match the original orientation, and you'll also need to resize it.

With your original Heightmap on your screen, go into Levels in Photoshop and adjust the light and dark values of your new Heightmap until you have something close to what you began with. 

Import your new Heightmap into Unity3D. You might still need to tweak the height value: Menu > Terrain > Set Resolution >Terrain Height. 

I've thrown down some quick texture coverage with the Terrain Toolkit Texture feature... and we're done!