Main Menu

Blur-O-Vision

Started by kevin, March 30, 2009, 11:51:26 AM

Previous topic - Next topic

kevin

 Blur-O-Vision

This is little example that shows how to create the blur/glow effect. It's really nothing more than drawing some alpha additive sprites over a diminishing backdrop. The trick is, that rather than clear the screen at the start of the frame, we scale the pixels from previous frame down by a percentage.   So previously drawn pixels appear to fade away over time.   This combined with the additive blend creates the effect.



 Requires PlayBasic V1.64

PlayBASIC Code: [Select]
   Screen=NewFxImage(GetScreenWidth(),GetScreenHeight())


FadePercent#=0.75

Do
setcursor 0,0

rendertoimage Screen


// Fade old pixels
C=(256*FadePercent#)
inkmode 1+2048
boxc 0,0,GetScreenWIdth(),GetScreenHeight(),true,rgb(c,c,c)



xpos=50
Ypos=60
for lp=1 to 1000
if getSpriteStatus(lp)=false
CreateSprite lp
SpriteIMage lp,MakeParticle(rndrange(32,64),rndrgb())
Centerspritehandle lp
spritedrawmode lp,2 +16
endif
Xpos2=cosnewvalue(Xpos,angle#+(lp*3),20+lp)
Ypos2=Sinnewvalue(ypos,angle#+(lp*5),30+lp*1.5)
POsitionSprite lp,Xpos2,Ypos2
inc Xpos,20
if Xpos>(getScreenWidth()-100) then Xpos=100: Inc ypos,5
next
drawallsprites



if upkey() then dec FadePercent#,0.01
if downkey() then inc FadePercent#,0.01


angle#=wrapangle(Angle#,2)
rendertoscreen

DrawImage Screen,0,0,false

Sync
loop



Function MakeParticle(Size,Col)
ThisImage=NewFXImage(Size,Size)
RenderPhongImage ThisImage,Size/2,Size/2,col,255,260/(size/2)
EndFunction ThisImage






     PlayBASIC Documentation / Help Files

     - INKMODE



kevin

#1
 PLayBasicFX version.

 Really should use vertex colouring in this one, but ya get that :)

PlayBASIC Code: [Select]
   Screen=New3DImage(GetScreenWidth(),GetScreenHeight())


FadePercent#=0.75

Do
setcursor 0,0

// Fade old pixels
C=(256*FadePercent#)
cls 0
drawalphaimage Screen,0,0,FadePercent#,true

xpos=50
Ypos=60
for lp=1 to 1000
if getSpriteStatus(lp)=false
CreateSprite lp
SpriteIMage lp,MakeParticle(rndrange(32,64),rndrgb())
Centerspritehandle lp
spritedrawmode lp,2 +16
endif
Xpos2=cosnewvalue(Xpos,angle#+(lp*3),20+lp)
Ypos2=Sinnewvalue(ypos,angle#+(lp*5),30+lp*1.5)
POsitionSprite lp,Xpos2,Ypos2
Xpos=Xpos+20
if Xpos>(getScreenWidth()-100) then Xpos=100: ypos=Ypos+5
next
drawallsprites



if upkey() then FadePercent#=FadePercent#-0.01
if downkey() then FadePercent#=FadePercent#+0.01


angle#=wrapangle(Angle#,2)

CopyRect 0,0,0,GetScreenWidth(),GetScreenHeight(),Screen,0,0

print FadePercent#
Sync
loop



Function MakeParticle(Size,Col)
ThisImage=New3DImage(Size,Size)
RenderPhongImage ThisImage,Size/2,Size/2,col,255,260/(size/2)
EndFunction ThisImage





kevin

#2

PlayBASIC -  Blur - O Vision based Effect  - Sprites and Alpha Addition Lines

   This demo uses a combination of Alpha addition and Alpha Subtraction on the sprites,  combined with alpha multiplication on to create the 'blur O vision' effect.    The effect is really just a by product of us drawing the next frames sprites over a colour reduced version of the backdrop,  rather than a freshly cleared version.  Which creates all sort of shadowing and bluring effects.   




 



PlayBASIC Code: [Select]
   openscreen 960,720,32,1

Screen=NewFxImage(GetScreenWidth(),GetScreenHeight())

Max= 750
SpriteQuantity Max


for lp=1 to Max
if getSpriteStatus(lp)=false
CreateSprite lp
SpriteIMage lp,MakeParticle(rndrange(32,128),rndrgb())
Centerspritehandle lp
if Rnd(100)>50
spritedrawmode lp,2 +16
else
spritedrawmode lp,2 +32
endif
endif
next


FadePercent#=0.75


xpos=50
Ypos=60

Do
setcursor 0,0

rendertoimage Screen


// Fade old pixels
C=(256*FadePercent#)
inkmode 1+2048
boxc 0,0,GetScreenWIdth(),GetScreenHeight(),true,rgb(c,c,c)

// Ink(pen) mode to Alpha Addition
inkmode 1+64

for lp=1 to Max

Xpos2=cosnewvalue(Xpos#,angle#+(lp*2.3),20+lp)
Ypos2=Sinnewvalue(ypos#+Xpos2#,angle#+(lp*3.5),90+lp*0.25)

Xpos3=wrapvalue(Xpos2,0,960)
Ypos3=wrapvalue(Ypos2,0,720)
POsitionSprite lp,Xpos3,Ypos3

linec xpos2,ypos2,Xpos3,Ypos3,$112211

next
drawallsprites

inkmode 1

Xpos#=wrapvalue(Xpos#+1.1,0,960)
Ypos#=wrapvalue(Ypos#+4.2,0,720)

if upkey() then dec FadePercent#,0.01
if downkey() then inc FadePercent#,0.01


angle#=wrapangle(Angle#,2)
rendertoscreen

DrawImage Screen,0,0,false

Sync
loop spacekey()



Function MakeParticle(Size,Col)
ThisImage=NewFXImage(Size,Size)
RenderPhongImage ThisImage,Size/2,Size/2,col,255,260/(size/2)
EndFunction ThisImage