Main Menu

FX support for maps

Started by kevin, January 19, 2006, 06:40:49 AM

Previous topic - Next topic

kevin

This piccy is of another feature i've been wanting to implement for some time now.  Which is adding support FX maps.  This allows FX maps to be rendered to system memory buffers.  Anything in system memory you can then run alpha effects over them.  Obviously  This places the rendering burden squarely on your cpu's shoulders.    While some effects and screen modes are optimized for MMX,  many aren't at this time.  

  Anyway, there's still a little bit to flesh out (namely there's no transparent support), but this should give a bit of cpu muscle those an avenue to throw some serious visuals around.  The bellow is the map with a alpha shape masked over it.  It's clocking about 70-90fps on my 800mhz duron.    


 PB 1.11 code
PlayBASIC Code: [Select]
; =======================
; Create Lighting Shape
; =======================

LIghtShape=GetFreeShape()
CreateConvexShape LIghtShape,100,5
ResizeShape LIghtShape,50,50
t=GetFreeShape()
CreateConvexShape t,300,30
MergeShape t,LIghtShape
DeleteShape t




; SetFPS 90

; Makebitmapfont 1,$ffffff


`CReate a Series of Tiles To make the blob Animation.
Frames=10
BlockSize=64
; Create the Animated blocks
Block_Image=CreateBlocks(BlockSize,frames)


; Create a Map with provision For 2 level maps To be created using it's Blocks
Thismap=NewMap(2)

; Import the above Image created into our Map as BLocks
MakeMapGFX ThisMap,Block_image,BlockSize,BlockSize,frames+1,RGB(0,0,0)


; Prepare the Block graphics for FX rendering. This Allows Maps to be
; drawn to the images converted to FX format.
PrepareFXMap ThisMap


; =========================
; Create 3 Animations
; =========================

MaxAnims=6

Create_Map_Anims(ThisMap,MAxAnims,Frames)




; CREATE A LEVEL
Constant z=$80000000

Width=100
height=100

CreateLevel ThisMap,1,Width,height
For ylp=0 To Width
For xlp=0 To height
PokeLevelTile ThisMap,1,xlp,ylp,z Or RndRange(1,MaxAnims)
Next xlp
Next ylp

; SET THIS LEVEL As Transparent + animated..
; LevelTransparent ThisMap,1,0
LevelAnimated ThisMap,1

sw=getscreenwidth()
sh=getscreenheight()

FXScreen=NEwImage(sw,sh)
PrepareFXIMage FXscreen
Rendertoimage FXscreen

createcamera 1

rendertoscreen
Do

capturetoscene
clsscene
DrawMap thisMap,1,0,0
DrawCamera 1

RendertoIMage FXScreen
inkmode 1+32
; circlec sw/2,sh/2,200,1,$800000

ink rgb(155,85,155)
drawshape LIghtShape,sw/2,sh/2,2

inkmode 1
rendertoscreen
inkalpha 0.5+(Sin(angle#)*0.5)

Angle#=WrapAngle(angle#,1)
RotateShape LightShape,angle#,1.5+Cos(angle#)


; BlitImageClr(FXScreen,0,0,ClrRGB)
drawimage FXscreen,0,0,0

if upkey() then MoveCamera 1,0,-5
if Downkey() then MoveCamera 1,0,5
if Rightkey() then MoveCamera 1,5,0
if Leftkey() then MoveCamera 1,-5,0

CenterText GetScreenWidth()/2,0,"Rendering Animated FX Map"

UpdateMapAnims Thismap

Sync
Loop

End




Function BlitImageClr(ThisImage,X#,y#,ClrRGB)
select GetSCreenDepth()
case 16,32
BlitMode=1
blitimage ThisIMage,x#,y#,transparentflag,Blitmode,ClrRGB,0,0
case 24
oldsurface=getsurface()
drawimage ThisIMage,x#,y#,transparentflag
rendertoimage ThisImage
cls ClrRgb
rendertoimage Oldsurface
Endselect
EndFunction








Function CreateBlocks(BlockSize,frames)
; Create a Image to Use to Store out Blob tiles upon
Map_Image=NewImage(BlockSize*(Frames+1),BlockSize)

; CReate the set of Blob
For lp=0 To frames
i=NewImage(BlockSize,BlockSize)
c=$0142f8
Login required to view complete source code



kevin

#1
How about some "water"  :)

All thanks to FX maps and vector shapes

Ian Price

Very nice! Now we can create SNES style lighting (where character etc. is in a dark room, with only a torch and ghosts for company :))
I came. I saw. I played some Nintendo.

kevin

Yeah you could..

i've got another old idea on the to-do list (that i'm working on atm)  is to blit/light combine blitter.

This would allow you take/render a coloured light map and merge them together during the blit.   It's a pretty heavy work load effect though.

Ian Price

I think I know what you're trying to achieve - the GBA does this very well (see CastleVania for examples). It's a nice effect :)
I came. I saw. I played some Nintendo.

kevin

yeah It's certainly not a new idea.    anyway,  each R/B/G of the light map is applied to corresponding pixel of the image your blitting.  R/G/B component of the light map is used/applied as  the intensity of image pixels R/G/B.   Not a cheap effect, and probably a 32bit only effect.