Pythonstuff GLSL in English Pythonstuff GLSL auf Deutsch Pythonstuff GLSL Pythonstuff
PythonStuff Home
 

 

Making Normalmaps from Heightmaps

To create a normalmap (also often called bumpmap) from a heightmap (an image containing one relevant 8 bit-channel with 0 (“low”) to 255 (“high”)) there is more than one way.

I present two of them:

Look Ma: No programming ! - Bumpmaps with The Gimp

Install

This is ”The GNU Image Manipulation Program”, if there is anyone out there who has still not heard of it. Then install the

On the Plugin's Website you see what you can do with it - a lot of possible adjustments, including an OpenGL preview !

The Image you start with must be a 3 Channel “RGB”-Image (if necessary, simply convert it by Image/Mode/RGB), then use the Plugin by selecting Filter/Map/Normalmap.

Convert to 3-Channel RGB with Gimp Convert to Bumpmap with Gimp

Making Bumpmaps with PIL and Python

The nice thing about making bumpmaps with PIL is that my small program ( about 5700 Bytes last time I looked) runs in the same environment you have already installed to run the example programs presented here. If you just want to run this program, Python 2.6 (or newer) and PIL should suffice.

You can even use the program as a module and import it into your own Pyglet project !

You save the manual conversion of your images during the design phase: The first time you run your program with a changed heightmap, your bumpmap will be magically updated :-).

A drawback may be the lack of options, but if you understand how the program works, you can easily extend it.

Here is the Source:

and the usage:

height2bump.py -<options> <input_file> <output_file>
   calculates a bumpmap (normalmap) from the "R"-Channel of the input_file.
   options:
       s use 5x5-Sobel-Filter instead of 5x5-Scharr
       t write output_file only if older than input_file
         (and ignore missing input_file)
       a put heightmap into the alpha channel
       v verbose
       q really quiet

If you start with the heightmap on the left with

python height2bump.py height.png normal.png

you get the image in the middle. I use a Scharr-Filter that gives slightly better results in my opinion than the classic Sobel filter (picture on the right), that can also be used by:

python height2bump.py -s height.png normal_sobel.png

The option ”-s” gives you the image on the right with Sobel filter.

If you want to understand how the program works, read the program documentation.

Test Heightmap - the hight image Bumpmap/Normalmap with Scharr filter Bumpmap/Normalmap with Sobel filter


Deutschsprachige Version, Start
Impressum & Disclaimer