04-21-2004, 11:02 PM
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! \/ \/ \/
Ok its slow. Bite me.
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.