News:

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

Main Menu

Super Sampling (In Software)

Started by kevin, November 09, 2010, 08:30:46 AM

Previous topic - Next topic

kevin

  Super Sampling (In Software)
 
    Super sampling is type of full screen anti aliasing found in modern 3d hardware.  It works by up scaling the render surface by 2 or more,  then filtering the larger version down into the original screen size.  Bellow we're using the built in the features of PlayBasic to emulate this, just slowly :).

    To emulate the sampling, we first render the screen to a double sized surface (so we scaled everything up by 2), then we blur this surface to smudge the pixels together. For output, we can use the bi-linear filtering when scaling it down by 50%.   Which gives an interesting approximation.  

 
   Bellow are a couple of demos using this effect.


    Tunnel


PlayBASIC Code: [Select]
  Screen=NewFxImage(1600,1200)   



Do

rendertoimage Screen
if Spacekey()
Cls $000000
else
inkmode 1+2048
boxc 0,0,GetImageWidth(Screen),GetImageHeight(screen),true,$f8e8a8
inkmode 1
endif

x=mousex()*2
y=mousey()*2


Offset=MOd(Offset+10,80)
inkmode 1+64

for lp=0 to 100

Depth=100+(lp*80)+Offset
size=(500*500)/Depth
Ring(Angle#+lp,x,y,size)
next

angle#=wrapangle(angle#,2)

inkmode 1
Blurimage Screen,9.1
rendertoscreen
drawrotatedimage screen,0,0,0,0.50,0.50,0,0,false+8

Sync
loop



Function Ring(Angle#,x,y,size)

StepValue=10

For lp=0 to 359 step StepValue
angle2#=wrapangle(angle#,lp)
x2=x+cos(angle2#)*size
y2=y+sin(angle2#)*size

angle2#=wrapangle(angle#,lp+StepValue)
x3=x+cos(angle2#)*size
y3=y+sin(angle2#)*size
linec x2,y2,x3,y3,$446688

next

EndFunction







    Flower

PlayBASIC Code: [Select]
  Screen=NewFxImage(1600,1200)   



Do

rendertoimage Screen
if Spacekey()
Cls $000000
else
inkmode 1+2048
boxc 0,0,GetImageWidth(Screen),GetImageHeight(screen),true,$f8e8a8
inkmode 1
endif

x=mousex()*2
y=mousey()*2


Offset=MOd(Offset+10,80)
inkmode 1+64


Ring(Angle#+lp,x,y,1000)

angle#=wrapangle(angle#,2)

inkmode 1
Blurimage Screen,9.1
rendertoscreen
drawrotatedimage screen,0,0,0,0.50,0.50,0,0,false+8

Sync
loop




Function Ring(Angle#,x,y,size)

StepValue=8

For lp=0 to 359 step StepValue
angle2#=wrapangle(angle#,lp)
x2=x+cos(angle2#)*size
y2=y+sin(angle2#)*size

angle2#=wrapangle(angle#,lp+StepValue)
x3=x+cos(angle2#)*(size/2)
y3=y+sin(angle2#)*(size/2)

if Toggle
Toggle=0
tric x,y,x2,y2,x3,y3,$999999
else
tric x,y,x2,y2,x3,y3,$110041
Toggle=1
endif

next

EndFunction




ATLUS

#1
amazing  :o

monkeybot


kevin

#3
  Super Sampled (Anti Aliased) Filled Circle

   Here's a function that will render a circle to a temp image,  super sample it (blur and scaling it down) and render the result. There's a bit of bug in the blurimage routine in V1.64M (and bellow) which doesn't take the alpha channel into account, so the result image has the wrong alpha level, but you the get the idea.


PlayBASIC Code: [Select]
   Loadfont "Verdana",1,32
makebitmapfont 1,$ffffffff,8
FontDrawMode 1,1

screen=newimage(800,600,2)

do
RenderToIMage Screen
cls $00304060
centertext 400,10,"Super Sampled (Anti Aliased) Filled Circle"

x=mousex()
y=mousey()
radius=100
; super sampled circle
DrawAliasedCircle(x,y,RAdius,$ffffffff)

; normal circle
circlec x,y+Radius*2,radius,true,$ffffffff

rendertoscreen
drawimage screen,0,0,false

sync
loop


Function DrawAliasedCircle(x,y,radius,colour)
surface=getsurface()

w=Radius*4
h=Radius*4
tempimage=newfximage(w,h,true)
rendertoimage tempimage
circlec radius*2,radius*2,Radius*2,true,Colour
blurimage tempimage,9.1
rendertoimage surface
scaleimage tempimage,radius*2,radius*2,1
drawimage tempimage,x-radius,y-radius,true
deleteimage tempimage

EndFUnction





ATLUS

#4
and video
View On YouTube