Oh Field! My Field!

Hello guys,

Here I am with my first blog post on 3D models which involves textures and height maps. Before I begin, I assume you already are familiar with the terms texture, height map and terrain.

A texture is definitely the first thing you need to create a terrain. A texture is an aerial view of an area. Google Maps is a great solution when it comes to obtaining the aerial view. It’s satellite imagery has solved great problems for us!

So I obtained this image from Google Maps:

and here’s what we’ll be creating at the end of the day:

What we need now is the height map. The basic purpose of this tutorial is actually to teach you how to create a height map out of the texture. We’ll be using Photoshop for this purpose.

A height map has to be black and white. The lowest regions are shown in black while the highest are shown in white. So in the first step, we need to open this texture  Photoshop and make it black and white.

Once you have opened it in PS, go to Image > Adjustments > Hue/Saturation:

In the window that comes up, decrease the saturation to -100 (the minimum):

This will change the color scheme of the image to black and white. As you must have guessed, the areas we want to show lowest appear white and the areas we want to appear highest appear black. This is not what we want. It is necessary that we invert the colors.

Go to Image > Adjustments > Invert:

This solves many problems but there’s still a long way to go. We cant simply leave this as is since it has a rough textureand will create lots of “bumps” in our 3D terrain. We need to make it smoother. this is where the eyedropper tool comes into action. Pick the dominant color in each distinct region and spray that entire region with this color using the brush. The following picture makes it clear what I mean. This is all we need.

The above image can now serve as a good height map for our terrain.

In the screenshot above, I have used DarkGDK to compile my terrain. If you have DarkGDK, you can use the following source to check out my work on your machine.

#include "DarkGDK.h"

void DarkGDK ( void )
dbSyncOn ( );
dbSyncRate ( 60 );
dbSetCameraRange ( 1.0f, 30000.0f );
dbLoadImage ( "texture.png", 1 );
dbSetupTerrain ( );
dbMakeObjectTerrain ( 1 );
dbSetTerrainHeightMap ( 1, "map.png" );
dbSetTerrainScale ( 1, 3.0f, 0.6f, 3.0f );
dbSetTerrainTexture ( 1, 1, 2 );
dbBuildTerrain ( 1 );
dbPositionCamera ( 385, 23, 100 );
dbSetObjectTexture ( 2, 3, 1 );

while ( LoopGDK ( ) )
dbControlCameraUsingArrowKeys ( 0, 2.0f, 2.0f );
float fHeight = dbGetTerrainGroundHeight ( 1, dbCameraPositionX ( ), dbCameraPositionZ ( ) );
dbPositionCamera ( dbCameraPositionX ( ), fHeight + 10.0f, dbCameraPositionZ ( ) );
dbUpdateTerrain ( );
dbSync ( );

Happy coding!


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s