Realtime bumpmapping in 2D
Realtime bumpmapping in 2D
Hi,
I just converted an example by Andreas Blixt on the blitzcoder forum to PureBasic...
You can download a zipfile, containing source and exe here.
See the post on blitzcoder forums here.
-Lars
*edit*
-Fixed a integer/float bug
-Added FPS text
*edit*
also.. *edit* <backspace> *edit* saves a screenshot..
I just converted an example by Andreas Blixt on the blitzcoder forum to PureBasic...
You can download a zipfile, containing source and exe here.
See the post on blitzcoder forums here.
-Lars
*edit*
-Fixed a integer/float bug
-Added FPS text
*edit*
also.. *edit* <backspace> *edit* saves a screenshot..
Last edited by LarsG on Sat Oct 11, 2003 6:12 pm, edited 3 times in total.
AMD Athlon XP2400, 512 MB RAM, Hercules 3D Prophet 9600 256MB RAM, WinXP
PIII 800MHz, 320 MB RAM, Nvidia Riva Tnt 2 Mach 64 (32MB), WinXP + Linux
17" iMac, 1.8 GHz G5, 512 MB DDR-RAM, 80 GB HD, 64 MB Geforce FX 5200, SuperDrive, OSX
It doesn't look right at all. andreas_blixt's looks fine but this one is just all pixelated and weird. I would post a screenshot but for some reason the PrintScreen button doesn't work while running the PureBasic app...?
Let us know if you can fix the problem(s), and then have some FPS readings on the two examples to compare them.
Let us know if you can fix the problem(s), and then have some FPS readings on the two examples to compare them.
Hi Cyberseth.. good to see you have stopped by to say hello on this forum.. 
I uploaded the new version (as I also mentioned in the showcase on blitzcoder).
The pixelation was due to my using integers where I was supposed to used floats.. hehe.
It's all fixed now, and a new version is at the same link above..
-Lars
(ps. I'll add some FPS soon..) *edit* added *edit*

I uploaded the new version (as I also mentioned in the showcase on blitzcoder).
The pixelation was due to my using integers where I was supposed to used floats.. hehe.
It's all fixed now, and a new version is at the same link above..
-Lars
(ps. I'll add some FPS soon..) *edit* added *edit*
AMD Athlon XP2400, 512 MB RAM, Hercules 3D Prophet 9600 256MB RAM, WinXP
PIII 800MHz, 320 MB RAM, Nvidia Riva Tnt 2 Mach 64 (32MB), WinXP + Linux
17" iMac, 1.8 GHz G5, 512 MB DDR-RAM, 80 GB HD, 64 MB Geforce FX 5200, SuperDrive, OSX
Yes, you are probably missing something, as there are two links in my first post!! 
the two links are:
http://www.tola-travels.com/_pure/bump.zip
(which is the PB version)
and
http://www.blitzcoder.com/cgi-bin/showc ... omments=no
(which is the post on the blitzcoder forum)
-Lars

the two links are:
http://www.tola-travels.com/_pure/bump.zip
(which is the PB version)
and
http://www.blitzcoder.com/cgi-bin/showc ... omments=no
(which is the post on the blitzcoder forum)
-Lars
AMD Athlon XP2400, 512 MB RAM, Hercules 3D Prophet 9600 256MB RAM, WinXP
PIII 800MHz, 320 MB RAM, Nvidia Riva Tnt 2 Mach 64 (32MB), WinXP + Linux
17" iMac, 1.8 GHz G5, 512 MB DDR-RAM, 80 GB HD, 64 MB Geforce FX 5200, SuperDrive, OSX
Lars,
That's pretty COOL!
I have a suggestion to make your code faster:
Move the test for UT <> 0 immediately after the assignment statement:
"UT = environmentmap(nnx,nny)",
instead of after all the calculations are done.
That way, you can skip all the time-consuming work if you're not going to plot the point anyway.
I got a 5 FPS speed-up on my machine with this change.
Regards,
Eric
That's pretty COOL!
I have a suggestion to make your code faster:
Move the test for UT <> 0 immediately after the assignment statement:
"UT = environmentmap(nnx,nny)",
instead of after all the calculations are done.
That way, you can skip all the time-consuming work if you're not going to plot the point anyway.
I got a 5 FPS speed-up on my machine with this change.
Regards,
Eric
It's cool, it's very cool!

11 FPS speed-up here.ebs wrote:I have a suggestion to make your code faster:
Move the test for UT <> 0 immediately after the assignment statement:
"UT = environmentmap(nnx,nny)",
instead of after all the calculations are done.
That way, you can skip all the time-consuming work if you're not going to plot the point anyway.
I got a 5 FPS speed-up on my machine with this change.

P4 2.4GHz, 256 MB, WinXP Pro, onboard video&audio.
The Programmer's Drinking Song:
"99 little bugs in the code,
99 little bugs.
Fix one bug, recompile
100 little bugs in the code."
The Programmer's Drinking Song:
"99 little bugs in the code,
99 little bugs.
Fix one bug, recompile
100 little bugs in the code."
Here's the drawing code with every optimzation I could think of:
Eric
Code: Select all
.
.
.
Repeat
timer = gettickcount_()
ClearScreen(0,0,0)
ExamineKeyboard() : ExamineMouse()
Event = WindowEvent()
If StartDrawing(ScreenOutput())
For y = 1 To 478
For x = 1 To 638
nnx = bumpmap(x + 1,y) - bumpmap(x - 1,y) - (x - MouseX()) + 128
nny = bumpmap(x,y + 1) - bumpmap(x,y - 1) - (y - MouseY()) + 128
If nnx < 0 Or nnx > 255 : nnx = 0 : EndIf
If nny < 0 Or nny > 255 : nny = 0 : EndIf
UT = environmentmap(nnx,nny)
If UT
sxy = surface(x,y)
r = (UT * (sxy & $FF)) >> 7
sxy >> 8
g = (UT * (sxy & $FF)) >> 7
sxy >> 8
b = (UT * (sxy & $FF)) >> 7
If r > 255 : r = 255 : EndIf
If g > 255 : g = 255 : EndIf
If b > 255 : b = 255 : EndIf
Plot(x,y,RGB(r,g,b))
EndIf
Next
Next
.
.
.
Thanks Ebs...
I used your optimization, and added some of my own, and the result is getting better...
New version uploaded to same place..
-Lars
I used your optimization, and added some of my own, and the result is getting better...
New version uploaded to same place..
-Lars
AMD Athlon XP2400, 512 MB RAM, Hercules 3D Prophet 9600 256MB RAM, WinXP
PIII 800MHz, 320 MB RAM, Nvidia Riva Tnt 2 Mach 64 (32MB), WinXP + Linux
17" iMac, 1.8 GHz G5, 512 MB DDR-RAM, 80 GB HD, 64 MB Geforce FX 5200, SuperDrive, OSX
8O Don't mind those minor technicalities, Proteus...Proteus wrote:WOW!
FPS is now 62 about 50% of the time...
The other 50% it's -2147483648...

-Lars
AMD Athlon XP2400, 512 MB RAM, Hercules 3D Prophet 9600 256MB RAM, WinXP
PIII 800MHz, 320 MB RAM, Nvidia Riva Tnt 2 Mach 64 (32MB), WinXP + Linux
17" iMac, 1.8 GHz G5, 512 MB DDR-RAM, 80 GB HD, 64 MB Geforce FX 5200, SuperDrive, OSX
Lars,
Limiting the drawing to just the spotlight area makes lots of sense, and provides a good speed-up.
I've got one more suggestion. I'm not really sure if this one is faster, but it seems like it should be.
Instead of using MouseX() and MouseY() inside the drawing loops, set two variables right after "Event = WindowEvent()", like this:
then use mx and my instead of MouseX() and MouseY() everywhere in the code. I don't know if reading a variable is significantly faster than calling the MouseX()/MouseY() routines, but it seems likely.
Eric
I just noticed that your original code did this - OOPS!
Limiting the drawing to just the spotlight area makes lots of sense, and provides a good speed-up.
I've got one more suggestion. I'm not really sure if this one is faster, but it seems like it should be.
Instead of using MouseX() and MouseY() inside the drawing loops, set two variables right after "Event = WindowEvent()", like this:
Code: Select all
mx = MouseX()
my = MouseY()
Eric
I just noticed that your original code did this - OOPS!

hehe.. yes it did, but i didn't notice much speed difference when you used MouseX() and MouseY() in the loop.. but I can always change it back...
-Lars
-Lars
AMD Athlon XP2400, 512 MB RAM, Hercules 3D Prophet 9600 256MB RAM, WinXP
PIII 800MHz, 320 MB RAM, Nvidia Riva Tnt 2 Mach 64 (32MB), WinXP + Linux
17" iMac, 1.8 GHz G5, 512 MB DDR-RAM, 80 GB HD, 64 MB Geforce FX 5200, SuperDrive, OSX