Qbasicnews.com

Full Version: I finally did it!!!
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2
Finally!! I eventually worked out bump mapping! Took long enough!

Yes, it is unoptimised, mainly because I want to keep the code neat. Ill probably optimise it later.

EDIT: Optimised better version down the page! \/ \/ \/

Code:
'$DYNAMIC
DIM bumpmap(100, 100)
DIM envmap(100, 100)
SCREEN 13
FOR i = 1 TO 255
  OUT &H3C8, i: OUT &H3C9, i / 255 * 63: OUT &H3C9, i / 255 * 63: OUT &H3C9, i / 255

* 63
NEXT
FOR x = 1 TO 100
  FOR y = 1 TO 100
    PSET (x, y), INT(RND * 255) + 1
  NEXT
NEXT
FOR s = 1 TO 2
  FOR x = 1 TO 100
    FOR y = 1 TO 100
      PSET (x, y), (POINT(x - 1, y - 1) + POINT(x, y) + POINT(x + 1, y - 1) +

POINT(x - 1, y + 1) + POINT(x + 1, y + 1) + POINT(x + 1, y) + POINT(x - 1, y) +

POINT(x, y + 1) + POINT(x, y - 1)) / 9
    NEXT
  NEXT
NEXT

FOR x = 1 TO 100
  FOR y = 1 TO 100
    bumpmap(x, y) = POINT(x, y)
  NEXT
NEXT
CLS
FOR x = 1 TO 100
  FOR y = 1 TO 100
    normx = (x - 50) / 50
    normy = (y - 50) / 50
    normz = 1 - SQR(normx ^ 2 + normy ^ 2)
    IF normz < 0 THEN normz = 0
    envmap(x, y) = normz * 255
  NEXT
NEXT
DO
  a = a + 4
  IF a > 360 THEN a = a - 360
  lightx = COS(a * 3.14 / 180) * 30 + 50
  lighty = SIN(a * 3.14 / 180) * 30 + 50
  FOR x = 2 TO 99
    FOR y = 2 TO 99
      vx = x - lightx
      vy = y - lighty
      normalx = bumpmap(x + 1, y) - bumpmap(x - 1, y) - vx + 50
      normaly = bumpmap(x, y + 1) - bumpmap(x, y - 1) - vy + 50
      IF normalx > 100 THEN normalx = 100
      IF normaly > 100 THEN normaly = 100
      IF normalx < 1 THEN normalx = 1
      IF normaly < 1 THEN normaly = 1
      PSET (x, y), envmap(normalx, normaly)
    NEXT
  NEXT
LOOP

Ok its slow. Bite me.
Awesome, dude. Smile
(what's a bump map?)
Edit: @dark_prevail: That's some really nice stuff!


@Zack: You use a bumpmap when you have an 3d object,
but it would take too many polygons to make it detailed, like
the roughness of a stone etc... The bumpmap is an image
that is placed on the object like a texture and then adds
highlights/shadows based on for example the grey value of the
"active" part of the bumpmap

(Like a sim city (x,y) array where every entry tells how
high the house is



...or something like that)
or like this, from Halo: (halo has beautiful bump mapping effects)

the surface is actually just a flat texture, but is is bump mapped in real time to appear to have depth.

[Image: bt-game.jpg]

Red)marvin: Thanx! ^_^
Halo...*Drools*
Okay, cool. I suppose that's used in pretty much all 3D commercial computer games, hm? Like in Return to Castle Wolfenstein, the walls in some levels have a nice stony texture. Bumpmapped? Or is there an alternate method?
well, the only alternative I could think of would be actually modeling the detail itself... 1000s of extra polys! Ahh!
Another bumpmap example:

[Image: klot.GIF]

Sorry for the grainyness, I saved it as gif directly from paint...
Here:

http://rel.betterwebber.com/junk.php?id=1

First effect. :*)

Dad: Kool FX. :*)
Ok. Heres a better version - Optimised, with highlights and a good bumpmap.

Note: you can change the bumpmap by making a new GIF file and saving it as "bumpmap2.gif" Lighter colours mean a higher surface. darker colours mean the surface is lower. You really must very slightly blur/antialias the picture beforehand. sharp edges will not work well.

Bump.zip
That's really cool, how do you do the light? Which lib?

This is really cool, i've been watching it now for 5 minutes straight...

shadows.. *drools*.. bumpmapping *more drooling* light source *goes insane*
Pages: 1 2