Author Topic: Pixelwise Particle Fire![BB2D]  (Read 5698 times)

0 Members and 1 Guest are viewing this topic.

Offline Shockwave

  • good/evil
  • Founder Member
  • DBF Aficionado
  • ********
  • Posts: 17409
  • Karma: 498
  • evil/good
    • View Profile
    • My Homepage
Pixelwise Particle Fire![BB2D]
« on: May 11, 2006 »
Original post by Shockwave, taken from the old board.
Quote
Lots of people were interested in this technique... Here it is;

Code: [Select]
; Fast Fire (for Daf, Chris And Bill).
; Coded By Shockwave / DBF 2005.
;
; This is the stripped down version of the fire effect with a computer generated cool map
; There's nothing stopping you drawing a cool map and importing it in.
; Also taken out the warp map to simplify it as much as possible.
;
; I think this is about as optimised as it can get but feel free to prove me wrong!
;
; NB, you would not believe how good this will look if you create a graphic cool map
; using microsoft paint, the computer generated one is ok but a REAL hand drawn one
; is so much better, you can make VERY realistic fire patterns that way.
;
; Also Jason is pissed at me because I kicked him out an hour ago so I could code this!
; Put it to good use guys.
;
;---------------------------------------------------------------------

        Const        xres        =        320;                Screen Width
        Const        yres        =        240;                Screen Height

;---------------------------------------------------------------------

        Graphics        xres,yres,0,1;                Set GFX
        SetBuffer BackBuffer()
       
;---------------------------------------------------------------------
; Our Cool map is going to be a list of numbers ranging from 0-255 which will then
; Be anti-aliassed to smooth the flames and give a slower cool.
; Alter the number of AA passes for different fire intensities.
; If you draw a cool map it should be all drawn in pure blue with no green or red
; component.
;---------------------------------------------------------------------

        Dim cool_map(xres+1,yres+1);        Storage space for cool map.
        make_cool_map();                                Create Cooling map.
        blurr_cool_map(9);                                Blurr the Cooling map. Higher numbers = more blurr

;---------------------------------------------------------------------

        Dim        flamebuffer(xres,yres);                Storage for the fire buffer!
        Global cool_map_offset = 1;                "Scroll" offset for coolmap.

        Dim        fire_colours(255);                        Storage for fire palette
        make_flame_colours()
       
;=====================================================================
; Begin Main Loop;
;=====================================================================

While Not KeyDown(1)


        updatebuffers()
        renderbuffer()
       
;---------------------------------------------------------------------
; Plot some random flames at the bottom of the screen so we can see it working
;---------------------------------------------------------------------

        genad=genad+5
sym=80*Cos(genad/2)
        For a=5 To xres-5
               
                flamebuffer (a,120+sym*Sin(genad+a))=Rand(150,255)
        Next
       
        Flip
        Cls
Wend

;=====================================================================
; End Main Loop /\
;=====================================================================
End

;---------------------------------------------------------------------
; This function is critical, it scrolls the flames upward by one pixel
; also it changes the cool map offset to scroll the cool map although
; we dont actually scroll the cool map because it does not need to be
; physically displayed, just scroll the offset.
; The fire buffer is also anti-aliased too.
;---------------------------------------------------------------------

Function updatebuffers()
;---------------------------------------------------------------------

        Local        loopx;                                         X loop
        Local        loopy;                                         Y loop
        Local        pixel;                                        Temp pixel value
        Local        coolpos=cool_map_offset;Position in coolmap
;---------------------------------------------------------------------
; Cool The flames according to the cool map;
;---------------------------------------------------------------------

        For loopy        =        1 To yres-2
                For loopx        =        1 To xres-1
;---------------------------------------------------------------------

                pixel =(flamebuffer(loopx,loopy)-(cool_map(loopx,coolpos)))
                If pixel<0 pixel = 0
                flamebuffer(loopx,loopy)=pixel

;---------------------------------------------------------------------

                Next

;---------------------------------------------------------------------

                coolpos=coolpos-1
                If coolpos <= 1 coolpos = yres-5

;---------------------------------------------------------------------

        Next

;---------------------------------------------------------------------
; Scroll the cool map;
;---------------------------------------------------------------------

        cool_map_offset=cool_map_offset-1
        If cool_map_offset<=1 cool_map_offset=yres-1

;---------------------------------------------------------------------
; Anti-Alias And Scroll The fire pixels map
;---------------------------------------------------------------------

        For loopy        =        1 To yres-2
                For loopx        =        1 To xres-1

;---------------------------------------------------------------------

                pixel        =        (flamebuffer(loopx+1,loopy)+flamebuffer(loopx-1,loopy)+flamebuffer(loopx,loopy+1)+flamebuffer(loopx,loopy-1)) Shr 2
                flamebuffer(loopx,loopy)=pixel
                flamebuffer(loopx,loopy-1)=                flamebuffer(loopx,loopy)

;---------------------------------------------------------------------

                Next
        Next


End Function
;#####################################################################




;---------------------------------------------------------------------
; This function is fairly simple and just writes any pixel hotter than
; 0 to the screen, discarding any pixels that are black for speed.
; To add a warp map you need to texture map the flame buffer onto another
; buffer which is displayed :-P Sure you got a couple of TM routines
; knocking about by now!
; DON'T use perspective correct, affine is much better for this as there
; is no Z co-ord to fuck things up.
;---------------------------------------------------------------------

Function renderbuffer()

LockBuffer BackBuffer()
;---------------------------------------------------------------------

        Local        loopx;                                         X loop
        Local        loopy;                                         Y loop

;---------------------------------------------------------------------

        For loopy        =        1 To yres-1
                For loopx        =        1 To xres-1

;---------------------------------------------------------------------

                If flamebuffer(loopx,loopy)>0 Then

                WritePixelFast loopx,loopy,fire_colours(flamebuffer(loopx,loopy))
                               
                End If
               
;---------------------------------------------------------------------

                Next
        Next
UnlockBuffer BackBuffer()

End Function
;#####################################################################






;---------------------------------------------------------------------
; It is necessary to smooth the cool map to avoid lame, grainy flames
; It will achieve a much smoother and more realistic looking fire.
;---------------------------------------------------------------------

Function blurr_cool_map(blurr_factor)

;---------------------------------------------------------------------

        Local        loopx;                                         X loop
        Local        loopy;                                         Y loop
        Local        passes;                                        Outer loop
        Local        pixel;                                        Temp pixel value
       
;---------------------------------------------------------------------

For passes        =        1 To blurr_factor

;---------------------------------------------------------------------

        For loopy        =        1 To yres-1
                For loopx        =        1 To xres-1

;---------------------------------------------------------------------

                pixel        =        (cool_map(loopx+1,loopy)+cool_map(loopx-1,loopy)+cool_map(loopx,loopy+1)+cool_map(loopx,loopy-1)) /5
                cool_map(loopx,loopy)=pixel

;---------------------------------------------------------------------

                Next
        Next
       
;---------------------------------------------------------------------

Next

End Function
;#####################################################################





;---------------------------------------------------------------------
; Create Random Cool Map; You can load your pic here if you want!
;---------------------------------------------------------------------

Function make_cool_map()

;---------------------------------------------------------------------
        Local        loopx;                                         X loop
        Local        loopy;                                         Y loop
;---------------------------------------------------------------------
;LockBuffer ImageBuffer(coolm)

        For loopy        =        1 To yres-1
                For loopx        =        1 To xres-1

;---------------------------------------------------------------------
                        cool_map(loopx,loopy)=Rand(0,255)
;---------------------------------------------------------------------

                Next
        Next
       
;UnlockBuffer(ImageBuffer)
End Function
;#####################################################################





;---------------------------------------------------------------------
; This function simply creates a palette for the flame colours;
;---------------------------------------------------------------------

Function make_flame_colours()

;---------------------------------------------------------------------

Local        red
Local        grn
Local        blu
Local        loop
Local        colour

;---------------------------------------------------------------------

For loop=1 To 255

;---------------------------------------------------------------------
        red=red+5
        grn=grn+3
        blu=blu+2
        If red>255 red=255
        If grn>255 grn=255
        If blu>255 blu=255
        colour=(((red Shl 8)+grn) Shl 8) + blu
        fire_colours(loop)=colour
;---------------------------------------------------------------------
       
Next

End Function
;#####################################################################
« Last Edit: July 21, 2007 by Shockwave »
Shockwave ^ Codigos
Challenge Trophies Won:

Offline Shockwave

  • good/evil
  • Founder Member
  • DBF Aficionado
  • ********
  • Posts: 17409
  • Karma: 498
  • evil/good
    • View Profile
    • My Homepage
Re: Pixelwise Particle Fire!
« Reply #1 on: May 16, 2006 »
I think I'm going to convert this into FB, it should be cool.
Shockwave ^ Codigos
Challenge Trophies Won:

Offline zparticle

  • Atari ST
  • ***
  • Posts: 168
  • Karma: 11
    • View Profile
    • ScottShaver2000
Re: Pixelwise Particle Fire!
« Reply #2 on: June 12, 2006 »
Converted to BlitzMax, much faster than the BlitzPlus version on my machine.



Code: [Select]
'---------------------------------------------------------------------
' Fast Fire
' Converted to Blitz Max by ZParticle
'
' The BLiztMax version seems quite a bit faster than the original BlitzPlus
' version on my machine.
'
' Original comments below
'---------------------------------------------------------------------
' Coded By Shockwave / DBF 2005.
'
' This is the stripped down version of the fire effect with a computer generated cool map
' There's nothing stopping you drawing a cool map and importing it in.
' Also taken out the warp map To simplify it as much as possible.
'
' I think this is about as optimised as it can get but feel free To prove me wrong!
'
' NB, you would Not believe how good this will look If you create a graphic cool map
' using microsoft paint, the computer generated one is ok but a REAL Hand drawn one
' is so much better, you can make VERY realistic fire patterns that way.
'
' Also Jason is pissed at me because I kicked him out an hour ago so I could code this!
' Put it To good use guys.
'
'---------------------------------------------------------------------
Strict

Framework BRL.GlMax2D
Import BRL.System
Import BRL.Basic
Import BRL.pngloader
Import BRL.Retro
Import BRL.Max2D

Const xres:Int = 640 ' Screen Width
Const yres:Int = 480 ' Screen Height
Const blur:Int = 9Â  ' Blur amount


Graphics xres,yres,32

Global cool_map:Int[xres+1,yres+1] ' Storage space For cool map.
Global flamebuffer:Int[xres,yres] ' Storage For the fire buffer!
Global fire_colours[255] ' Storage For fire palette
Global cool_map_offset:Int = 1 ' "Scroll" offset For coolmap.

make_cool_map() ' Create Cooling map.
blurr_cool_map(blur) ' Blurr the Cooling map. Higher numbers = more blurr
make_flame_colours()

Global genad:Double=0

While Not KeyHit(KEY_ESCAPE)
Cls
updatebuffers()
renderbuffer()

genad:+5
Local sym:Double=80.0*Cos(genad/2.0)
For Local a:Int=5 To xres-5
flamebuffer[a,120+sym*Sin(genad+a)]=Rand(150,255)
Next

Flip
Wend
End

'---------------------------------------------------------------------
' This Function is critical, it scrolls the flames upward by one pixel
' also it changes the cool map offset To scroll the cool map although
' we dont actually scroll the cool map because it does Not need To be
' physically displayed, just scroll the offset.
' The fire buffer is also anti-aliased too.
'---------------------------------------------------------------------
Function updatebuffers()
Local coolpos:Int = cool_map_offset ' Position in coolmap

' Cool The flames according To the cool map
For Local loopy:Int = 1 To yres-2
For Local loopx:Int = 1 To xres-1
Local pixel:Int =flamebuffer[loopx,loopy]-cool_map[loopx,coolpos]
If pixel<0 Then pixel = 0
flamebuffer[loopx,loopy]=pixel
Next

coolpos:-1
If coolpos <= 1 Then coolpos = yres-5
Next

' Scroll the cool map;
cool_map_offset:-1
If cool_map_offset<=1 Then cool_map_offset=yres-1

' Anti-Alias And Scroll The fire pixels map
For Local loopy:Int = 1 Until yres-2
For Local loopx:Int = 1 Until xres-1
Local pixel:Int = (flamebuffer[loopx+1,loopy]+flamebuffer[loopx-1,loopy]+flamebuffer[loopx,loopy+1]+flamebuffer[loopx,loopy-1]) Shr 2
flamebuffer[loopx,loopy]=pixel
flamebuffer[loopx,loopy-1]= flamebuffer[loopx,loopy]
Next
Next
End Function

'---------------------------------------------------------------------
' This Function is fairly simple And just writes any pixel hotter than
' 0 To the screen, discarding any pixels that are black For speed.
' To add a warp map you need To texture map the flame buffer onto another
' buffer which is displayed :-P Sure you got a couple of TM routines
' knocking about by now!
' DON'T use perspective correct, affine is much better for this as there
' is no Z co-ord To fuck things up.
'---------------------------------------------------------------------

Function renderbuffer()
SetBlend(SOLIDBLEND)
For Local loopy:Int = 1 To yres-1
For Local loopx:Int = 1 To xres-1
If flamebuffer[loopx,loopy]>0 Then
Local r:Int = (fire_colours[flamebuffer[loopx,loopy]] & $00FF0000) Shr 16
Local g:Int = (fire_colours[flamebuffer[loopx,loopy]] & $0000FF00) Shr 8
Local b:Int = (fire_colours[flamebuffer[loopx,loopy]] & $000000FF)
SetColor(r,g,b)
DrawRect(loopx,loopy,1,1)
'Plot loopx,loopy
End If
Next
Next
End Function

'---------------------------------------------------------------------
' It is necessary To smooth the cool map To avoid lame, grainy flames
' It will achieve a much smoother And more realistic looking fire.
'---------------------------------------------------------------------
Function blurr_cool_map(blurr_factor)
For Local passes:Int = 1 To blurr_factor
For Local loopy:Int = 1 To yres-1
For Local loopx:Int = 1 To xres-1
Local pixel:Int = (cool_map[loopx+1,loopy]+cool_map[loopx-1,loopy]+cool_map[loopx,loopy+1]+cool_map[loopx,loopy-1]) / 5
cool_map[loopx,loopy]=pixel
Next
Next
Next

End Function

'---------------------------------------------------------------------
' Create Random Cool Map; You can load your pic here If you want!
'---------------------------------------------------------------------
Function make_cool_map()
For Local loopy:Int = 1 To yres-1
For Local loopx:Int = 1 To xres-1
cool_map[loopx,loopy]=Rand(0,255)
Next
Next
End Function

'---------------------------------------------------------------------
' This Function simply creates a palette For the flame colours;
'---------------------------------------------------------------------
Function make_flame_colours()
Local red:Int
Local grn:Int
Local blu:Int

For Local loop:Int=0 Until 255
red:+5
grn:+3
blu:+2
If red>255 Then red=255
If grn>255 Then grn=255
If blu>255 Then blu=255
Local colour:Int = red Shl 16 | grn Shl 8 | blu
fire_colours[loop]=colour
Next
End Function
« Last Edit: June 12, 2006 by zparticle »

Offline zparticle

  • Atari ST
  • ***
  • Posts: 168
  • Karma: 11
    • View Profile
    • ScottShaver2000
Re: Pixelwise Particle Fire!
« Reply #3 on: June 13, 2006 »
Shockwave, can you give me an example of a hand drawn cool map and talk a bit about how the warp map functions?

Offline Shockwave

  • good/evil
  • Founder Member
  • DBF Aficionado
  • ********
  • Posts: 17409
  • Karma: 498
  • evil/good
    • View Profile
    • My Homepage
Re: Pixelwise Particle Fire!
« Reply #4 on: June 13, 2006 »
Ah I see you've increased the resolution there Zparticle, the speed is faster than blitz2d and maybe blitz plus for sure, I don't think that Bmax is fast enough to do this at 640 X 480 as it's running too slow to use in a demo here, however good job on converting it to Bmax, you've kept the integrity of the original effect intact.

On cool maps, basically all the cool map does is to provide a value to cool each pixel as it travels up the screen. In my original code and the one you converted, it does this by plotting some points and then doing several anti-alias blur passes on the fire to make a nice map to scroll up at the same rate as the flames. Each frame the corresponding pixel to the fire particle is darkened by the value in the corresponding map.

You could draw your own map using something as simple as microsoft paint, load it in and read each pixel, then blur the map a bit. This way you can contain words or pictures in your flames if you like.

As far as the warp map goes, it involves linear texture mapping if you want to do it properly. The whole screen is divided into an imaginary wonky grid, with each square of the grid being affected by some sine value, you texture map the imaginary wonky squares into a straight grid pattern, done recursively this gives a nice flow effect with swirling flames.

Texture mapping the screen like this is far too slow for Blitz2D or even Blitzmax I would guess at 640X480 so you can get some quite satisfactory results with some careful use of sine tables on the fire buffer.

It's funny that you should pick now to convert this code to Bmax as I've been busy writing a freebasic version, I will release the source when I've finished the effect. If you are interested in doing pixel pushing like this at higher resolutions then you'd be far better off using C++ or Freebasic instead of Blitz.

I've included the freebasic exe for now to give you a speed comparison.
Nb. This effect is very, very unfinished at the moment and will look wuite different when it's completed.
Shockwave ^ Codigos
Challenge Trophies Won:

Offline zparticle

  • Atari ST
  • ***
  • Posts: 168
  • Karma: 11
    • View Profile
    • ScottShaver2000
Re: Pixelwise Particle Fire!
« Reply #5 on: June 13, 2006 »
Great, thanks for the info. That fire looks incredible. Here is another version for BMax that is OOP-ifeid. Also it let's me draw images into the flame buffer.

http://www.scottshaver2000.com/blitz/effects/fire/fire2.exe





Code: [Select]
'---------------------------------------------------------------------
' Fast Fire 2
'
' Okay I've rearranged the code into a FireEffect Type. I've changed
' it handle drawing with alpha values, this makes it more useful than
' just drawing on a black background. You can now have fire over another
' image. I've also added a function to allow you to draw an image into
' the flame buffer.
'---------------------------------------------------------------------
' Converted to Blitz Max by ZParticle
'
' The BLiztMax version seems quite a bit faster than the original BlitzPlus
' version on my machine.
'
' Original comments below
'---------------------------------------------------------------------
' Coded By Shockwave / DBF 2005.
'
' This is the stripped down version of the fire effect with a computer generated cool map
' There's nothing stopping you drawing a cool map and importing it in.
' Also taken out the warp map To simplify it as much as possible.
'
' I think this is about as optimised as it can get but feel free To prove me wrong!
'
' NB, you would Not believe how good this will look If you create a graphic cool map
' using microsoft paint, the computer generated one is ok but a REAL Hand drawn one
' is so much better, you can make VERY realistic fire patterns that way.
'
' Also Jason is pissed at me because I kicked him out an hour ago so I could code this!
' Put it To good use guys.
'
'---------------------------------------------------------------------
Strict

Framework BRL.GlMax2D
Import BRL.System
Import BRL.Basic
Import BRL.pngloader
Import BRL.Retro
Import BRL.Max2D

Const xres:Int = 640 ' Screen Width
Const yres:Int = 480 ' Screen Height
Graphics xres,yres',32

' load an image in to draw into the flame buffer
Incbin "zp-logo.png"
Global zpimage:TImage = LoadImage("incbin::zp-logo.png")

' create a FireEffect object to play with
Global fire:FireEffect = FireEffect.Create(xres,yres)
fire.DrawImage(zpimage,50,70)

Global genad:Double=0

While Not KeyHit(KEY_ESCAPE)
Cls
If genad Mod 250 = 0 Then fire.DrawImage(zpimage,50,70)
fire.DrawFlamePalette(0,200)
fire.UpdateBuffers()
fire.Draw()

genad:+5
Local sym:Double=80.0*Cos(genad/2.0)
For Local a:Int=5 To fire.width-5
fire.flamebuffer[a,220+sym*Sin(genad+a)]=Rand(150,255)
Next

Flip
Wend
End

Type FireEffect
Field width:Int = 0
Field height:Int = 0
Field cool_map:Int[,] = Null ' Storage space For cool map.
Field flamebuffer:Int[,] = Null ' Storage For the fire buffer!
Field fire_colours:Int[255] ' Storage For fire palette
Field cool_map_offset:Int = 1 ' "Scroll" offset For coolmap.
Field blendMode:Int = ALPHABLEND

'---------------------------------------------------------------------
' create a new FireEffect object
'---------------------------------------------------------------------
Function Create:FireEffect(width:Int,height:Int,blur:Int=9,cool_map:TImage=Null)
Local retval:FireEffect = New FireEffect
retval.width = width
retval.height = height
retval.cool_map = New Int[width+1,height+1]
retval.flamebuffer = New Int[width,height]
retval.MakeCoolMap() ' Create Cooling map.
retval.BlurCoolMap(blur) ' Blurr the Cooling map. Higher numbers = more blurr
retval.MakeFlameColors()
Return retval
End Function

'---------------------------------------------------------------------
' draw an image into the flame buffer
'---------------------------------------------------------------------
Method DrawImage(image:TImage,x:Int,y:Int)
Local pixmap:TPixmap = LockImage(image)
Local h:Int = ImageHeight(image)
Local w:Int = ImageWidth(image)
For Local loopy:Int = 0 Until h
For Local loopx:Int = 0 Until w
If x+loopx>width Or x+loopx<0 Then Continue
If y+loopy>height Or y+loopy<0 Then Continue
Local pixel:Int = pixmap.ReadPixel(loopx,loopy)' & $00FFFFFF
If pixel & $FF000000 <> 0 Then
Local r:Float = (pixel & $00FF0000) Shr 16
Local g:Float = (pixel & $0000FF00) Shr 8
Local b:Float = (pixel & $000000FF)
flamebuffer[x+loopx,y+loopy]=(((r/255)/3)+((g/255)/3)+((b/255)/3))*255
EndIf
Next
Next
UnlockImage(image)
End Method

'---------------------------------------------------------------------
' It is necessary To smooth the cool map To avoid lame, grainy flames
' It will achieve a much smoother And more realistic looking fire.
'---------------------------------------------------------------------
Method BlurCoolMap(blurr_factor:Int)
For Local passes:Int = 1 To blurr_factor
For Local loopy:Int = 1 To height-1
For Local loopx:Int = 1 To width-1
Local pixel:Int = (cool_map[loopx+1,loopy]+cool_map[loopx-1,loopy]+cool_map[loopx,loopy+1]+cool_map[loopx,loopy-1]) / 5
cool_map[loopx,loopy]=pixel
Next
Next
Next

End Method

'---------------------------------------------------------------------
' Create Random Cool Map; You can load your pic here If you want!
' Our Cool map is going To be a list of numbers ranging from 0-255 which will Then
' Be anti-aliassed To smooth the flames And give a slower cool.
' Alter the number of AA passes For different fire intensities.
' If you draw a cool map it should be all drawn in pure blue with no green Or red
' component.
'---------------------------------------------------------------------
Method MakeCoolMap()
For Local loopy:Int = 1 To height-1
For Local loopx:Int = 1 To width-1
cool_map[loopx,loopy]=Rand(0,255)
Next
Next
End Method

'---------------------------------------------------------------------
' This Function simply creates a palette For the flame colours;
'---------------------------------------------------------------------
Method MakeFlameColors()
Local red:Int
Local grn:Int
Local blu:Int

For Local loop:Int=0 Until 255
red:+5
grn:+3
blu:+2
If red>255 Then red=255
If grn>255 Then grn=255
If blu>255 Then blu=255
Local colour:Int = red Shl 16 | grn Shl 8 | blu
fire_colours[loop]=colour
Next
End Method

'---------------------------------------------------------------------
' draw the palette on screen
'---------------------------------------------------------------------
Method DrawFlamePalette(x:Float=0,y:Float=0)
SetScale(1,1)
SetAlpha(1)
SetRotation(0)
SetBlend(SOLIDBLEND)
For Local loop:Int=0 Until 255
Local r:Int = (fire_colours[loop] & $00FF0000) Shr 16
Local g:Int = (fire_colours[loop] & $0000FF00) Shr 8
Local b:Int = (fire_colours[loop] & $000000FF)
SetColor(r,g,b)
DrawRect(x+loop,y,2,15)
Next
End Method

'---------------------------------------------------------------------
' This Function is critical, it scrolls the flames upward by one pixel
' also it changes the cool map offset To scroll the cool map although
' we dont actually scroll the cool map because it does Not need To be
' physically displayed, just scroll the offset.
' The fire buffer is also anti-aliased too.
'---------------------------------------------------------------------
Method UpdateBuffers()
Local coolpos:Int = cool_map_offset ' Position in coolmap

' Cool The flames according To the cool map
For Local loopy:Int = 1 To height-2
For Local loopx:Int = 1 To width-1
Local pixel:Int =flamebuffer[loopx,loopy]-cool_map[loopx,coolpos]
If pixel<0 Then pixel = 0
flamebuffer[loopx,loopy]=pixel
Next

coolpos:-1
If coolpos <= 1 Then coolpos = height-5
Next

' Scroll the cool map;
cool_map_offset:-1
If cool_map_offset<=1 Then cool_map_offset=height-1

' Anti-Alias And Scroll The fire pixels map
For Local loopy:Int = 1 Until height-2
For Local loopx:Int = 1 Until width-1
Local pixel:Int = (flamebuffer[loopx+1,loopy]+flamebuffer[loopx-1,loopy]+flamebuffer[loopx,loopy+1]+flamebuffer[loopx,loopy-1]) Shr 2
flamebuffer[loopx,loopy]=pixel
flamebuffer[loopx,loopy-1]= flamebuffer[loopx,loopy]
Next
Next
End Method

'---------------------------------------------------------------------
' This Function is fairly simple And just writes any pixel hotter than
' 0 To the screen, discarding any pixels that are black For speed.
' To add a warp map you need To texture map the flame buffer onto another
' buffer which is displayed :-P Sure you got a couple of TM routines
' knocking about by now!
' DON'T use perspective correct, affine is much better for this as there
' is no Z co-ord To fuck things up.
'---------------------------------------------------------------------
Method Draw(x:Float=0,y:Float=0)
SetBlend(blendMode)
For Local loopy:Int = 1 To height-1
For Local loopx:Int = 1 To width-1
If flamebuffer[loopx,loopy]>0 Then
Local r:Float = (fire_colours[flamebuffer[loopx,loopy]] & $00FF0000) Shr 16
Local g:Float = (fire_colours[flamebuffer[loopx,loopy]] & $0000FF00) Shr 8
Local b:Float = (fire_colours[flamebuffer[loopx,loopy]] & $000000FF)
If blendMode=ALPHABLEND Then
SetAlpha(((r/255)/3)+((g/255)/3)+((b/255)/3))
EndIf
SetColor(r,g,b)
DrawRect(x+loopx,y+loopy,1,1)
'Plot loopx,loopy
End If
Next
Next
End Method

End Type

Offline Shockwave

  • good/evil
  • Founder Member
  • DBF Aficionado
  • ********
  • Posts: 17409
  • Karma: 498
  • evil/good
    • View Profile
    • My Homepage
Re: Pixelwise Particle Fire!
« Reply #6 on: June 13, 2006 »
Nice to see you combining some effects there Zparticle.
Cool that you can draw images straight into the flame buffer, you'd need to do it each frame if you want the object to burn.
I have my doubts about doing it in Blitz at this res, but please prove me wrong :)
Shockwave ^ Codigos
Challenge Trophies Won:

Offline asdflkj

  • C= 64
  • **
  • Posts: 45
  • Karma: 2
    • View Profile
Re: Pixelwise Particle Fire!
« Reply #7 on: June 13, 2006 »
-
« Last Edit: August 06, 2025 by marclurr »

Offline Shockwave

  • good/evil
  • Founder Member
  • DBF Aficionado
  • ********
  • Posts: 17409
  • Karma: 498
  • evil/good
    • View Profile
    • My Homepage
Re: Pixelwise Particle Fire!
« Reply #8 on: June 14, 2006 »
Yeah, that's the one Mark, Amorphous darkness is still on the site somewhere;

www.dbfinteractive.com/index.htm

If you download the Amorphous darkness demo and look at the cool map image inside the media folder you'll see the letters DBF in the cool map.
Shockwave ^ Codigos
Challenge Trophies Won: