scene.org File Archive

File download

<root>­/­mirrors­/­the_scene_archives­/­The_Scene_Archives_Vol_05­/­Disks_are_in_Here­/­Disks_4801_To_4851­/­4806-No_Sense_2­/­Articles/bump.txt

File size:
2 826 bytes (2.76K)
File date:
2005-01-22 23:20:16
Download count:
all-time: 525

Preview

\I[Bumpmapping|By Scout/C-Lous|Section: Coders Pool]
\F1
\F2\4\MBumpmapping
\F1\2
\C[ClipArts/pinnen.Chnk]

\3Bump is essentially having individual XY-offsets in the envmap/phongmap for every pixel.

\M\1\F22d bump
\F1\2
The simplest form requires one phongmap and one bumpmap. The phongmap is your usual phongtexture, and the bumpmap contains one word per pixel. The bumped 2D phong is drawn using this technique:

\F3\3for Y = 0 to scrheight
{
  for X = 0 to scrwidth
  {
    PhongX = X + Bump[X][Y][0]
    PhongY = Y + Bump[X][Y][1]
    C = Phong[PhongX][PhongY]
    putpixel(X,Y,C)
  }
}
\F1\2
An example of this kind of bump can be found in Orange's "The Sea Robot of Love" (PC, 64k at The Party V). Bump with picture can be seen in 3LE's "The Tribe" (first place at Icing '96). Picture/bump is accomplished by adding a pixelread and a shade table lookup to the innerloop.

Bump is a good addition to standard zoomrotators: have a look at C-Lous' "Kolor Remix" (Remedy '96) for an example of it.

\1\F2\M3d bump
\F1\3\M(err... rather "2D polygon bump")
\F1\2
Don't settle with phong bump, go for the real thing! That is, phong bump texture... It does not take much more CPU time.

As the bump and the texture both are fixed on the surface of the 3D-obejct(s), they have the same UV coordinates, thus giving only a few more instructions for adding bump. This is a (slow) example of an inner loop: 
\F3\3
; a0 = texture, a1 = phong, a2 = bump, a3 = shadetab, a4 = screen
.pixel    add.w  tustep,d0
          add.w  tvstep,d1
          add.w  pustep,d2
          add.w  pvstep,d3
          move.w         pustep,d5
\2; Get UV offs in phong
\3          lsr.w     #8,d5
          move.w          pvstep,d4
          move.b          d5,d4
          move.w          tustep,d6
\2; Get UV offs in texture & bump
   \3       lsr.w   #8,d6
          move.w          tvstep,d5
          move.b          d6,d5
          add.w  (a2,d5.w*2),d4
\2; Add the bump offs for current pixel
\3          move.b          (a1,d4.l),d4
\2; Get phong
\3          lsl.w    #8,d4
          move.b          (a0,d5.l),d4
\2; Get texture
\3          move.b       (a3,d4.l),(a4)+
\2; Write shaded pixel to screen
\3          dbf     d7,.pixel
\F1\2
The bump effect adds quite a bit of realism to normal phong texture. 




\M\F2\1Generating the bumpmap
\F1\2
It is tricky to get a good-looking bumpmap. One way (useful for 2D bump) is saying that the brighter a pixel is, the higher above the flat surface it is.
First convert the picture to grayscale using some program like PicCon.
Then the bump value can be calculated in this way: 

\F3\3bump[X][Y][0] = (texture[X-1][Y] - texture[X+1][Y]) * scale
bump[X][Y][1] = (texture[X][Y-1] - texture[X][Y+1]) * scale
\F1\2
Appropriate values for scale varies from texture to texture.

\C[ClipArts/pinnen.Chnk]