News:

Function Finder  Find all the functions within source code files

Main Menu

Spot Light

Started by kevin, February 01, 2006, 12:31:40 PM

Previous topic - Next topic

kevin

Here's a bit of spot light effect.  The effect is drawing a full screen tile map to one FX image,  then draw some inverted (sort) gouraud triangles to a second image.  The pair are then merged during the blit image process.  It's certainly a bit of huge  mouthful for my trusty duron 800mhz,  but should be more than viable on faster machines.     This one's an MMX only effect.  

The effect is running full screen here, you could selectively limit it to only blit the 'visible region' with a bit of clever coding.

kevin

Here's an update of the light map feature.  Now it can be used to add blended coloured lights.  While not express on my duron 800, it's a pretty effect :)

Available in PB1.29

kevin

#2
require PB1.29

PlayBASIC Code: [Select]
   w=640
h=480
If ScreenModeExist(w,h,32)=False
Cls 0
Print "Sorry This Demo Requires A 32 bit Colour Screen Mode"
Print "press any key to close"
Sync
WaitKey
End
EndIf
OpenScreen w,h,32,2


; Create an FX copy of the display
FXScreen =NewImage(GetScreenWidth(),GetScreenHeight())
PrepareFXImage FXscreen


; Create BlitIMage's blend surface.
w=GetScreenWidth()
h=GetScreenHeight()
BlendFXScreen=NewImage(w,h)
PrepareFXImage BlendFXscreen
SetBlitImageBuffer BlendFXscreen
RenderToImage BlendFXScreen
ShadeBox 0,0,w,h,RndRGB(),RndRGB(),RndRGB(),RndRGB()



Gosub CReateMapStuff



RenderToImage FXscreen

; create a camera. This camera will attach itself to the current image
; which will be the FX screen
CreateCamera 1
CameraCls 1,Off



WhiteLIghtColour=$ffffff


NumbOflights=5

Dim Balls( NumbOflights)

balls(1)=Make_SpotLight($ff7f3f)
For lp=2 To NUmbOFlights
balls(lp)=Make_SpotLight(RndRGB())
Next

Type tLight
X#,Y#
Xdir#,Ydir#
Angle#
Sprite
RadiusX
RadiusY
EndType
Dim Lights(NumbOflights) As tlight


For lp=1 To NumbOflights
x=Rnd(GetScreenWidth())
y=Rnd(GetScreenHeight())
lights(lp).x#=x
lights(lp).y#=y
lights(lp).angle#=Rnd(360)
lights(lp).RadiusX=RndRange(50,160)
lights(lp).RadiusY=RndRange(50,160)
If lp=1
ThisBall=1
Else
ThisBall=RndRange(1,NumbOflights)
EndIf
ThisLight=NewSprite(x,y,balls(ThisBall))
CenterSpriteHandle ThisLight
SpriteDrawMode ThisLight,2+16
ScaleSprite ThisLIght,rndrange(1,5)
lights(lp).sprite=ThisLIght
Next


ShowControls=Timer()+10000


Do

; Tell pPB to capture the following drawn items to the scene buffer
CaptureToScene
; clear the buffer
ClsScene
; draw our map to the scene buffer
DrawMap thisMap,1,0,0
DrawCamera 1


RenderToImage BlendFXScreen

FadeAngle#=WrapAngle(FadeAngle#,2)
Cls RGBFade(WhiteLightColour,50+Sin(FadeAngle#)*50)

If MouseButton()
WhiteLIghtColour=RndRGB()
EndIf

xpos=MouseX()
ypos=MouseY()

For lp=2 To NumbOflights
x#=lights(lp).x#
y#=lights(lp).y#

angle#=WrapAngle(lights(lp).Angle#,5)
lights(lp).Angle=Angle#
x#=x#+CosRadius(angle#,lights(lp).RadiusX)
y#=y#+SinRadius(angle#,lights(lp).RadiusY)
PositionSprite Lights(lp).sprite,x#,y#
DrawSprite Lights(lp).sprite
Next

PositionSprite Lights(1).sprite,xpos,ypos
DrawSprite Lights(1).sprite

angle#=WrapAngle(angle#,1)

RenderToScreen

BlitImageAlphaMultImage(Fxscreen,0,0,BlendFXscreen)

; if the demo has been running for less than 10 second then show
; the controls message
If ShowControls>Timer()
CenterText GetScreenWidth()/2,GetScreenHeight()/2,"Use Arrows to Scroll Window"
EndIf

; updtae the map animations
UpdateMapAnims Thismap


c$=str$(rgbR(WhiteLIghtColour))+","
c$=c$+str$(rgbG(WhiteLIghtColour))+","
c$=c$+str$(rgbB(WhiteLIghtColour))

Login required to view complete source code




kevin

#3
I've updated the Multiply Blit mode to support 16bit 565 mode (mmx + none mmx).  Resulting in a nice 40-45 FPS effect.  Very useful on my duron 800mhz machine.  Which should mean it'll be very useful for you guys too.  

I've also added 16bit support to Alpha Blit Merge subtract + Addition..  

Anyway here's a screenie..

kevin

I've now added 16bit (565) support  Alpha ADD/blendimage.  Bellow is variant of the previous spotlight demo.  This time the light map is being added to to the source image.  The circle in the middle is a being masked off the lightmap.  Creates a rather cool by product..

Jeku

Wow, this looks really neat!
**
Automaton Games - Home of WordTrix 2.0, WordZap, and GameBasic
Jeku's Music - Easy listening electronic...
**

2dman

"of huge mouthful for my trusty duron 800mhz..."

800mhz is probably too HIGH of a spec if you're going for the casual game market. You should spec your development end on very low end machines. No sense giving us all these wonderful fx if it takes a fast cpu to render them. In that case we'll just use a hardware accelerated engine like PBFX, right?

kevin

Quote800mhz is probably too HIGH of a spec if you're going for the casual game market. You should spec your development end on very low end machines. No sense giving us all these wonderful fx if it takes a fast cpu to render  them.

 Sigh,  damn if do, damned if we don't.    

 Fill rate is proportional. Slow clock speeds/videos card & bus speeds obviously have a lower throughput.   Thus, users should spec their demos/games at the appropriate resolution/screen depth for the system their targeting.   Irrespective of design, there can be no guarantee's on any PC.    



QuoteIn that case we'll just use a hardware accelerated engine like PBFX, right? 

 Not necessarily, since PBFX opposite end of the spectrum..