News:

PlayBASIC2DLL V0.99 Revision I Commercial Edition released! - Convert PlayBASIC programs to super fast Machine Code. 

Main Menu

Sinus Render (PB2DLL example)

Started by kevin, June 05, 2014, 08:37:25 AM

Previous topic - Next topic

kevin

  Sinus Render (PB2DLL example)

      Attached are two versions of bellow routine compiled to DLL using two different builds of PlayBASIC2DLL.   The routine looks simple enough until you realize there's a square root,  sinus, RGB pack, with multiples and FastDOT pixel plots for every pixel on screen.  The demo defaults to 800*600 resolution, so that's 450 odd thousand iterations, that's a lot of square roots.

      The actual effect is pretty pants, as the focus here has been more on getting the PB2DLL to optimize away as much code as it from common math functions.  Todays build can inline virtually everything from the inner loop bellow and solve it right on the FPU.    These changes make the routine around 3 times faster than when built with yesterdays builds of PB2DLL.   Some of functions like GetDistance2D() bench at up to 15 times faster individually..   Making it quick enough to do a square every pixel.    


     Requires a late PlayBASIC V1.64P beta or higher

PlayBASIC Code: [Select]
 /*
This function computes the distance between the mouse pointer
and every pixel on the surface. The distance is then used as
as sinus angle to create 'wave' The result value is drawn as
dot

*/



Function DLL_SinusRender()

Width=GetSurfaceWidth()
Height=GetSurfaceHeight()

Static BaseAngle#

midx=mousex()
midy=mousey()

lockbuffer
ThisRGB=point(0,0)
for ylp=0 to height-1
for xlp=0 to width-1
Dist#=BaseAngle#+GetDistance2D(xlp,ylp,midx,midy)
Dist=sin(Dist#)*100.0
fastdot xlp,ylp,Rgb(Dist,Dist,dist)
next
next
lockbuffer

BaseAngle#=mod(BaseAngle#+1.5,3600)

EndFunction





     Hopefully you should be able to see this is pretty naive version of the routine, as a lot of the internal work can be pre-computed out.