Home 

2D Bump Mapping using Java

Bump Mapping is quite a cool looking effect that takes very little coding. There are many examples of bump mapping available on the Internet. The three basic ingredients are:-
  • A height map or bump map. This is generated, in my examples, from a greyscale image. The program will attempt to average the three colour channels, so coloured images will work, but may not give the expected result! White areas represent maximum bump (or depression) and black represents flat areas. Normals are calculated for each pixel based on the relative heights of neighbouring pixels.

  • A colour table, which usually moves from black (indicating no light) to the chosen light colour. My examples include a Phong element so I interpolate black to chosen light colour and then interpolate chosen light colour to white. The ratio between the two depends upon the Phong size parameter.

  • An environment map or light map. Another map of normals this time based on the pixel's position relative to the center. Using the Z normal element (ranging from 0 to 1) we can determine the appropriate colour table entry.

For each frame of animation we calculate the difference between each bump map pixel's X/Y normal and the X/Y normal of the light source relative to our current position. This is then used as an offset index into the environment map. Smaller differences indicate a narrow angle between the pixel and the light source, larger differences would indicate a point that is far away from the light source or perhaps angled away from it.


Launch
Applet


This second demo applet uses a larger light source with greater Phong element.


Launch
Applet