News:

Building a 3D Ray Tracer  By stevmjon

Main Menu

Fire Effect

Started by ScottieBro1, January 16, 2024, 12:03:44 PM

Previous topic - Next topic

ScottieBro1

I have some questions maybe kevin could help.
To optimize this fast enough It has to be poked memcopy I think
as for color I hate not being able to get to color registers like I used to.
So not only is it slow I don't know how to add palette.

This needs optimizations for sure.

Any suggestions?

ScottieB

kevin

#1
  A quick clean up,  but doing an average across the points around the current point is pretty costly.   You can reduce this ! Just think about how the filter is moving through the buffer.  

 I suggest picking through my older replies as unfortunately i'd just be repeating myself.

PlayBASIC Code: [Select]
X_Screen_Res = 640
Y_Screen_Res = 480

Color_Mode = 32
Screen_Type = 1

OpenScreen X_Screen_Res,Y_Screen_Res,Color_Mode,Screen_Type

Dim Buffer_1(X_Screen_Res,Y_Screen_Res)
Dim Buffer_2(X_Screen_Res,Y_Screen_Res)

Do

Cls

For X = 0 To X_Screen_Res - 1

Buffer_1(X,Y_Screen_Res - 1) = Rnd(50) + 100
Buffer_1(X,Y_Screen_Res - 2) = Rnd(50) + 100
Buffer_1(X,Y_Screen_Res - 3) = Rnd(50) + 100

Next X

Hotspots = Rnd(40) + 10

For I = 0 To Hotspots - 1

X_Rand = Rnd(X_Screen_Res - 2) + 1

For Y = -1 To 1
For X = -1 To 1
Buffer_1(X_Rand + X,(Y_Screen_Res - 2) + Y) = 255
Next X
Next Y

Next I

For Y = 1 To Y_Screen_Res - 1
Y_Minus1 = Y-1
Y_Plus1 = Y+1

For X = 1 To X_Screen_Res - 2

X_Minus1 =X-1
X_Plus1 =X+1

Top_Left = Buffer_1(X_Minus1 ,Y_Minus1)
Top = Buffer_1(X ,Y_Minus1)
Top_Right = Buffer_1(X_Plus1 ,Y_Minus1)

Left = Buffer_1(X_Minus1 ,Y)
Middle = Buffer_1(X ,Y)
Right = Buffer_1(X_Plus1 ,Y)

Bottom_Left = Buffer_1(X_Minus1 ,Y_plus1)
Bottom = Buffer_1(X ,Y_plus1)
Bottom_Right = Buffer_1(X_Plus1 ,Y_plus1)

Average = (Top_Left + Top + Top_Right + Left + Right + Bottom_Left + Bottom + Bottom_Right) / 8

If Average <= 0 Then Average = 0

Buffer_2(X,Y_Minus1) = Average

Next X
Next Y

LockBuffer

Seed = Point(0,0)

Scaler# = (1/255.0) * 100
For Y = 0 To Y_Screen_Res - 1

For X = 0 To X_Screen_Res - 1
FastDot X,Y,RGBFade(RGB(255,255,255),Buffer_2(X,Y) * Scaler#)
Next X

Next Y
UnLockBuffer


text 10,10,fps()
Sync

CopyArray Buffer_2(),Buffer_1()

Loop






 #Version #2 - Pre computed Palette

PlayBASIC Code: [Select]
X_Screen_Res = 640
Y_Screen_Res = 480

Color_Mode = 32
Screen_Type = 1

OpenScreen X_Screen_Res,Y_Screen_Res,Color_Mode,Screen_Type

Dim Buffer_1(X_Screen_Res,Y_Screen_Res)
Dim Buffer_2(X_Screen_Res,Y_Screen_Res)


Dim Palette(32000)
Init_Palette()



for lp=0 to 10
sync
wait 100
next



Do

Cls

For X = 0 To X_Screen_Res - 1

Buffer_1(X,Y_Screen_Res - 1) = Rnd(50) + 100
Buffer_1(X,Y_Screen_Res - 2) = Rnd(50) + 100
Buffer_1(X,Y_Screen_Res - 3) = Rnd(50) + 100

Next X

Hotspots = Rnd(40) + 10

For I = 0 To Hotspots - 1

X_Rand = Rnd(X_Screen_Res - 2) + 1

For Y = -1 To 1
For X = -1 To 1
Buffer_1(X_Rand + X,(Y_Screen_Res - 2) + Y) = 255
Next X
Next Y

Next I

For Y = 1 To Y_Screen_Res - 1
Y_Minus1 = Y-1
Y_Plus1 = Y+1

For X = 1 To X_Screen_Res - 2

X_Minus1 =X-1
X_Plus1 =X+1

Top_Left = Buffer_1(X_Minus1 ,Y_Minus1)
Top = Buffer_1(X ,Y_Minus1)
Top_Right = Buffer_1(X_Plus1 ,Y_Minus1)

Left = Buffer_1(X_Minus1 ,Y)
Middle = Buffer_1(X ,Y)
Right = Buffer_1(X_Plus1 ,Y)

Bottom_Left = Buffer_1(X_Minus1 ,Y_plus1)
Bottom = Buffer_1(X ,Y_plus1)
Bottom_Right = Buffer_1(X_Plus1 ,Y_plus1)

Average = (Top_Left + Top + Top_Right + Left + Right + Bottom_Left + Bottom + Bottom_Right) / 8
Buffer_2(X,Y_Minus1) = cliprange(Average,0, 256 * 8 )

Next X
Next Y


LockBuffer
Seed = Point(0,0)
For Y = 0 To Y_Screen_Res - 1
For X = 0 To X_Screen_Res - 1
FastDot X,Y,Palette(Buffer_2(X,Y))
Next X
Next Y
UnLockBuffer

text 10,10,fps()
Sync

CopyArray Buffer_2(),Buffer_1()
Loop




function Init_Palette()
Scaler# = (1/255.0) * 100
for lp=0 to GetarrayElements(Palette())
Palette(lp)=RGBFade(RGB(255,255,255),lp * Scaler#)
next
endfunction





 



  Links:

   Array Wrapping / Filtering / Sampling Speed Ideas
   Palette Mapping
   Tutorial - A Crash Course In BASIC program Optimization