Main Menu

Sprite Draw Modes

Started by kevin, May 12, 2005, 10:18:41 PM

Previous topic - Next topic

kevin

Sprite Draw Modes (on a Alpha Subtraction Buffer)

  This demo has 100 rotating + mixed mode sprites rendered to an FX buffer, then the fx buffer is alpha subtracted back to the screen.  Which makes the nice trailing effects..

 It's running at a  solid 50fps on my duron 800mhz with 100 effect sprites..


Sprites have the following modes built in (at the time of writing, still a few more to do)

 - Solid/Transparent  
 - Rotated
 - Alpha Blend (variable)
 - Alpha Blend 50/50  
 - Alpha ADD
 - Alpha SUB
 - Fade  (uniform)
 - Gouruad Blend 50/50 (vertex rgbs are blended with image prior to plotting)
 - Colour Flash
 - Coluur Alpha   (cross fade image to colour..)
 - Colour Add  
 - Colour Sub



kevin

#1
Sprite Draw Modes
==============

 
This Version have 3 new modes in it.  

* Texture/Gouraud Shaded  (So sprites can be shaded at each vertex.)
* Colour Replace   (You can replace a key colour to a user defined coluor)
* ScanLine Colour Replace (this lets you run raster colour bars through a sprite)

All modes are rotated,.  


Demo code (requires PB 1.07b)





; convert default font #1 from a true type font to a bitmap version
MakeBitmapFont 1,$ffffff

; load the bubble image
LoadImage CurrentDir$()+"..\..\gfx\bubble_64x64.bmp",1
; Prepare this image for Effects (rotation in this case)
  PrepareFXImage 1

; load the back drop image
LoadImage CurrentDir$()+"..\..\gfx\bg22.jpg",2

; get the Screen widht/height
sw=GetScreenWidth()
sh=GetScreenHeight()


BackDropImg=GetFreeImage()
CreateImage BackDropImg,Sw,sh
PrepareFximage BackDropImg
 


 iw=GetImagewidth(1)
 ih=GetImageHeight(1)


; ==================================================================
; Manually Create Some Sprites, each with different DRAW MODES..
; ==================================================================

Spr=1

; ==============================
; NORMAL ROTATED SPRITE
; ==============================
CreateSprite Spr
SpriteImage Spr,1
  SpriteDrawMode spr,2
centerspritehandle spr
inc spr


; ==============================
; ALPHA ROTATED SPRITE
; ==============================
CreateSprite Spr
SpriteImage Spr,1
  SpriteDrawMode spr,2+4
centerspritehandle spr
inc spr


; ==============================
; ALPHA 50/50 ROTATED SPRITE
; ==============================
CreateSprite Spr
SpriteImage Spr,1
  SpriteDrawMode spr,2+8
centerspritehandle spr
inc spr

; ==============================
; ALPHA ADD ROTATED SPRITE
; ==============================
CreateSprite Spr
SpriteImage Spr,1
  SpriteDrawMode spr,2+16
centerspritehandle spr
inc spr


; ==============================
; ALPHA SUB ROTATED SPRITE
; ==============================
CreateSprite Spr
SpriteImage Spr,1
  SpriteDrawMode spr,2+32
centerspritehandle spr
inc spr


; ==============================
; SHADE ROTATED SPRITE
; ==============================
CreateSprite Spr
SpriteImage Spr,1
  SpriteDrawMode spr,2+64
SpriteFadeLevel Spr,0.5
centerspritehandle spr
inc spr


; ==============================
; Gouraud SHADE ROTATED SPRITE
; ==============================
CreateSprite Spr
SpriteImage Spr,1
  SpriteDrawMode spr,2+128
centerspritehandle spr
  SpriteImageIntensity Spr,0,255
  SpriteImageIntensity Spr,1,255
  SpriteImageIntensity Spr,2,105
  SpriteImageIntensity Spr,3,5
inc spr



; ==============================
; Gouraud SHADE 50/50 BLend ROTATED SPRITE
; ==============================
CreateSprite Spr
SpriteImage Spr,1
  SpriteDrawMode spr,2+256
centerspritehandle spr
inc spr


; ==============================
; Gouraud SHADE ADDition ROTATED SPRITE
; ==============================
CreateSprite Spr
SpriteImage Spr,1
  SpriteDrawMode spr,2+512
centerspritehandle spr
inc spr



; ==============================
; Colour Flash ROTATED SPRITE
; ==============================
CreateSprite Spr
  SpriteFlashColour Spr,$ff0000
SpriteImage Spr,1
  SpriteDrawMode spr,2+1024
centerspritehandle spr
inc spr


; ==============================
; Alpha Colour ROTATED SPRITE
; ==============================
CreateSprite Spr
SpriteImage Spr,1
  SpriteDrawMode spr,2+2048
  SpriteAlphaColour Spr,$ffff00
  centerspritehandle spr
inc spr

; ==============================
; Alpha Colour ADD  ROTATED SPRITE
; ==============================
CreateSprite Spr
SpriteImage Spr,1
  SpriteDrawMode spr,2+4096
  SpriteAlphaAddColour Spr,$ff0000
  centerspritehandle spr
inc spr

; ==============================
; Alpha Colour SUB ROTATED SPRITE
; ==============================
CreateSprite Spr
SpriteImage Spr,1
  SpriteDrawMode spr,2+8192
  SpriteAlphaSubColour Spr,$00ff00
  centerspritehandle spr
inc spr



; ==============================
; Single Colour Replacement in ROTATED SPRITE
; ==============================
CreateSprite Spr
SpriteImage Spr,1
  SpriteDrawMode spr,2+$4000
  spritetransparent spr,off
  SpriteColourReplacekey Spr,$000000
  SpritereplacementColour Spr,$00ff00
  centerspritehandle spr
inc spr




; ==============================
; Raster Bar Colour Replacement in ROTATED SPRITE
; ==============================

  Dim RasterBuffer(getScreenHeight())

y=0  
radius=16
  For lp=0 to 20
   RasterBar(RasterBuffer(),RndRGB(),y,radius)
 y=y+(radius*2)
  next    
 
 
CreateSprite Spr
SpriteImage Spr,1
  SpriteDrawMode spr,2+$8000
  spritetransparent spr,off
  SpriteColourReplacekey Spr,$000000
SpriteRasterColourBuffer Spr,RasterBuffer()

  centerspritehandle spr
inc spr



   Numb_Of_Sprites=Spr


; Run through and posiiton the sprites across and down the screen
 
 boarder=60
 y=boarder
 X=boarder
 For Spr=1 to  Numb_of_Sprites
  positionsprite spr,X,y
  X=x+(iw+(iw))
  if X>(Sw-boarder)
   x=boarder
   y=y+(ih+(ih))
  endif
 next  




; Start of DO/Loop
Do
// ===================================================================
// Init Sprites, dim's an array sets a bunch of sprites ready for use
  // ====================================================================

rendertoimage BackDropImg


 lockbuffer
 scrollX=mod((scrollX+1),iw)
 scrollY=mod((scrollY+1),ih)

 baseY=(-iw)+ScrollX
 ink $ff7030
 For ylp=0 to 8
  Basey=(-ih)+Scrolly+(ylp*ih)
  basex=(-iw)+ScrollX
  For xlp=0 to 10
   xpos=BAseX+(xlp*iw)
   drawimage 1,xpos,basey,0
  next  
 next


 r=400
 ox=cosradius(angle#,r/8)
 oy=Sinradius(angle#,r/8)
 c=$8faa00  
 inkmode 1+64
  circlec ox+(sw/2)+r,oy+(sh/2)+r,r,1,c
  circlec ox+(sw/2)-r,oy+(sh/2)+r,r,1,c
  circlec ox+(sw/2)+r,oy+(sh/2)-r,r,1,c
  circlec ox+(sw/2)-r,oy+(sh/2)-r,r,1,c

 
 
    // =================================================================
    // Run Through and update all the sprites positions
    // =================================================================
  For Spr=1 to  Numb_of_Sprites
   rotateSprite Spr,Angle#
   SpriteAlphaLEvel Spr,0.5+(Cos(angle#)*0.4)
   SpriteFadeLevel Spr,0.5+(Cos(angle#)*0.4)
     
   scalesprite Spr,1.5
   drawsprite spr
  Next spr
;   DrawallSprites

unlockbuffer

if rightkey()  then Angle#=wrapangle(angle#,3)
if leftkey()  then Angle#=wrapangle(angle#,-3)
 
angle#=wrapangle(angle#,4)

  rendertoscreen
drawimage backdropimg,0,0,0
; BlitImageClr BackDropImg,0,0,$30ff42
;l BlitImageAlphaSUb BackDropImg,0,0,$101010
 
Text 0,0,FPS()
Sync
Loop



Function BlitImageClr(ThisImage,X#,y#,ClrRGB)
 BlitMode=1
 transparentflag=0
 blitimage ThisImage,x#,y#,transparentflag,Blitmode,ClrRGB,0,0
EndFunction



Function BlitImageAlphaSub(ThisImage,X#,y#,ClrRGB)
 BlitMode=128
 transparentflag=0
 blitimage ThisImage,x#,y#,transparentflag,Blitmode,ClrRGB,0,0
EndFunction


Function BlitImageAlphaAdd(ThisImage,X#,y#,ClrRGB)
 BlitMode=64
 transparentflag=0
 blitimage ThisImage,x#,y#,transparentflag,Blitmode,ClrRGB,0,0
EndFunction





Function RasterBar(Me(),C,Offset,radius)
AngleStep#=90.0/Radius
Size=getarrayelements(me(),1)
For lp =0 To radius
 Scaler=Cos(lp*anglestep#)*255
 r=(((C And $ff0000) *Scaler) /256) And $ff0000
 g=(((C And $00ff00) *Scaler) /256) And $00ff00
 b=(((C And $0000ff) *Scaler) /256) And $0000ff
 ThisRgb=r or g or b
 y=Offset-lp  
 If y>-1 and y=<size Then me(y)=ThisRGB
 y=Offset+lp
 If y>-1 and y=<size then me(y)=thisrgb
Next

EndFunction





kevin

#2
Sprite Draw Modes

Play Basic V1.07 has the following built in draw mode for sprites.


1  - Rotated
2  - Alpha Blend (variable)
3  - Alpha Blend 50/50
4  - Alpha ADD
5  - Alpha SUB
6  - Fade (uniform)
7  - Gouraud Fade (each vert has a intensity level)
8  - Gouruad Blend 50/50 (vertex rgbs are blended with image prior to plotting)
9   - Gouruad Alpha Add (vertex rgbs are blended with alpha add prior to plotting)
10 - Colour Flash (draw all texels as a selected colour)
11 - Colour Alpha (cross fade image to colour..)
12 - Colour Add
13 - Colour Sub
14 - Colour Replace
15 - Raster Colour Replacement (allows key colour to be replace from a colour table)


All modes are real time rotated and can be drawn solid or transparent.

The picture is arranged across/down. So it shows modes 1,2,3,4,5  then 6,7,8,9,10 and finally 11,12,13,14,15.