Dark BASIC Pro ( DBpro ) Bump Mapper Ported to PlayBASIC

Started by kevin, May 29, 2020, 12:21:19 PM

Previous topic - Next topic

kevin

Dark BASIC Pro ( DBpro ) Bump Mapper Ported to PlayBASIC

I found this old optimization source code on my harddrive that does bump mapping in software. The only problem with it's written in another language, so I decided to port it PlayBASIC and see how it'd perform in PB V1,65...

Runs fine




PlayBASIC Code: [Select]
; PROJECT : Bump Mapper Dbpro Port
; AUTHOR : Raven & Kev Picone
; CREATED : 28/05/2020
; EDITED : 30/05/2020
; ---------------------------------------------------------------------


openscreen 512, 512, 32,1
titlescreen "Bump Mapping (Software)"

Type Vector2
X As Float
Y As Float
EndType

Type TimeType
Old As Integer
New As Integer
Due As Integer
Accum As Integer
isValid As Integer ;Boolean
EndType

Type ScreenType
Height As Integer
Width As Integer
EndType


Type tBumpPixelOffsets
x1
y1
x2
y2
EndType

Dim Environment(255, 255) ;As Integer
Dim Bump(GetScreenWidth(), GetScreenHeight()) ;As Integer

` precalc bidirectional normals
Dim BumpNX(GetScreenWidth(), GetScreenHeight()) ;As Integer
Dim BumpNY(GetScreenWidth(), GetScreenHeight()) ;As Integer
Dim Surface(GetScreenWidth(), GetScreenHeight()) ;As Integer

dim Screen As ScreenType
Screen = New ScreenType
Screen.Width = GetScreenWidth()
Screen.Height = GetScreenHeight()


dim Light As Vector2
Light = New Vector2
dim Alpha As Integer
dim Time As TimeType
Time = new TimeType

GoSub __LoadSamples


Size=Screen.width*Screen.Height*4

createbank 1,Size
createbank 2,Size
createbank 3,(Size+1)*2

` Copy To Src Buffer
SrcBufferAddress=getBankPtr(2)
SrcBufferModulo=Screen.width*4

BumpBufferAddress=GetBankPtr(3)


For Y = 0 To GetScreenHeight()-1
RowAddress=SrcBufferAddress+(Y*SrcBufferModulo)
BumpRowAddress=BumpBufferAddress+(Y*(SrcBufferModulo*2))
ScrnWidth=GetScreenWidth()-1
For X = 0 To ScrnWidth
pokeint RowAddress,Surface(X, Y)
inc RowAddress,4

pokeint BumpRowAddress,BumpNX(X, Y)
inc BumpRowAddress,4

pokeint BumpRowAddress,BumpNY(X, Y)
inc BumpRowAddress,4
Next X
Next Y

// ---------- MAIN LOOP ------------------------------

Repeat


Time.isValid = TimeUpdate( 1000 / 30)

Light.X = MouseX()
Light.Y = MouseY()


MapTime=timer()
If 1 ;Time.isValid

Clip_DestX1=LIght.X-128
Clip_DestY1=LIght.Y-128
Clip_DestX2=LIght.X+128
Clip_DestY2=LIght.Y+128

ClippedPixels=1
if Clip_destX1<1
ClippedPixels=1-Clip_destX1
Clip_DestX1=1
endif
Clip_SrcX=ClippedPixels

ClippedPixels=1
if Clip_destY1<1
ClippedPixels=1-Clip_destY1
Clip_destY1=1
endif
Clip_SrcY=ClippedPixels

If Clip_DestX2=>Screen.Width then Clip_DestX2=Screen.Width - 1
If Clip_DestY2=>Screen.Height then Clip_DestY2=Screen.Width - 1

LightX=Light.x
LightY=Light.y

DestBufferAddress=getBankPtr(1)
DestBufferModulo=Screen.width*4

SrcBufferAddress=getbankPtr(2)
SrcBufferModulo=Screen.width*4

BumpBufferAddress=GetBankptr(3)
BumpBufferModulo=(Screen.width*4)*2


For Y=Clip_destY1 To Clip_destY2

DestRowAddress =DestBufferAddress +(y*DestBufferModulo)+(Clip_DestX1*4)
SrcRowAddress =SrcBufferAddress +(y*SrcBufferModulo)+(Clip_DestX1*4)
BumpRowAddress =BumpBufferAddress +(y*BumpBufferModulo)+(Clip_DestX1*8)

Dim Row as tBumpPixelOffsets Pointer
Row = BumpRowAddress

For X=Clip_DestX1 To Clip_DestX2 step 2

Login required to view complete source code


 Have fun !


stevmjon

hey kev, this looks pretty good.

do you have the images default_color.png and default_bump.png so i can run the code?

thanks stevmjon
It's easy to start a program, but harder to finish it...

I think that means i am getting old and get side tracked too easy.

kevin


  It's attached above..   looking at the two images closer, the bump file is just a gray scale version of the colour.

  In the middle of a Pblive video on this atm.

kevin

 PlayBASIC LIVE - Porting Dbpro Bump Mapper To PlayBASIC V1 65 - (31st May 2020 )



Today we'll look at converting some source code from DBpro to PlayBASIC V1.65.  I originally optimized the DBpro back in 2013 for another forum member.   Ran into the code again recently and decided it might make a nice little PlayBASIC live video.   Then during recording the screen captures with OBS, I kept running into problem after problem, but finally got it recorded.    There's a few continuity issues, but it was created over several days..      





Credits:



  Video By:
  Kevin Picone
  http://playbasic.com  
  https://underwaredesign.com
  https://www.underwaredesign.com/forums/   (Forums)


  Original Dbpro Source Code:
  Raven
  Optimized Code Kevin Picone
 

 Pexels Artwork:
 Coffee Animation by Kelly Lacy
 Clouds Time lapse by Pexels

  Music:
 Spirit of Fire by  Jesse Gallagher




PlayBASIC LIVE PLAYLIST
https://www.youtube.com/playlist?list=PL_dvm0gvzzIVGlAhx34N6z2ce0ffMMOZ8

PlayBASIC BLOG PLAYLIST
https://www.youtube.com/playlist?list=PL_dvm0gvzzIU0Hnr6veV5UvwkSapHCo1J

PlayBASIC on FACEBOOK
http://www.facebook.com/pages/PlayBasic/127905400584274   (Facebook Page)

PlayBASIC on TWITTER
https://twitter.com/PlayBasic