Skip to content

Instantly share code, notes, and snippets.

@caligari87
Last active July 4, 2020 03:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save caligari87/e3018ee29aea030994fb11b7b06b8bc1 to your computer and use it in GitHub Desktop.
Save caligari87/e3018ee29aea030994fb11b7b06b8bc1 to your computer and use it in GitHub Desktop.
slightly more controllable and performant particle fire
version "4.3"
const maxparticles = 200;
const rad = 12;
class TestFireSpawner2 : actor {
vector3 firepos[maxparticles];
vector3 firevel[maxparticles];
double fireheat[maxparticles];
color firecolor;
int spawnmax;
override void tick() {
super.tick();
spawnmax = min(spawnmax+2, maxparticles);
for (int i=0; i<spawnmax; i++) {
firevel[i].x += (frandom(-1,1) + frandom(-1,1) + frandom(-1,1)) / (rad * 2);
firevel[i].y += (frandom(-1,1) + frandom(-1,1) + frandom(-1,1)) / (rad * 2);
firevel[i].z += (frandom(0,1) + frandom(0,2) + frandom(0,3)) / (rad * 12);
firevel[i].x += -(firepos[i].x) / (rad * 12);
firevel[i].y += -(firepos[i].y) / (rad * 12);
firevel[i].x = clamp(firevel[i].x, -1, 1);
firevel[i].y = clamp(firevel[i].y, -1, 1);
firevel[i].z = clamp(firevel[i].z, 0, fireheat[i]);
firepos[i] += firevel[i];
fireheat[i] -= 1;
if(fireheat[i] <= 1) {
firepos[i] = (frandom(-rad,rad), frandom(-rad,rad), frandom(-2,-1));
fireheat[i] = 35;
firevel[i]= (0,0,1);
}
static const Color heatcolor[] = {
"070707",
"1F0707",
"2F0F07",
"470F07",
"571707",
"671F07",
"771F07",
"8F2707",
"9F2F07",
"AF3F07",
"BF4707",
"C74707",
"DF4F07",
"DF5707",
"DF5707",
"D75F07",
"D75F07",
"D7670F",
"CF6F0F",
"CF770F",
"CF7F0F",
"CF8717",
"C78717",
"C78F17",
"C7971F",
"BF9F1F",
"BF9F1F",
"BFA727",
"BFA727",
"BFAF2F",
"B7AF2F",
"B7B72F",
"B7B737",
"CFCF6F",
"DFDF9F",
"EFEFC7",
"FFFFFF"
};
firecolor = heatcolor[fireheat[i]];
double alf = double(fireheat[i]) / 35;
self.A_SpawnParticle(
firecolor, // color
SPF_FULLBRIGHT, // flags
2, // lifetime
12 * (16 / fireheat[i]), // size
0, // angle
firepos[i].x, firepos[i].y, firepos[i].z, // pos
firevel[i].x, firevel[i].y, firevel[i].z, // vel
0, 0, 0, // accel
alf, // start alpha
0, // fadestep
0 // sizestep
);
}
}
}
class TestFireSpawner : actor {
int fire[8][8][16];
color firecolor;
double scale;
int ticker;
int maxtick;
override void postbeginplay() {
super.postbeginplay();
scale = 3;
maxtick = 0;
for(int y = 6; y > 1; y--) {
for(int x = 6; x > 1; x--) {
fire[x][y][0] = randompick(0,0,1,2,3,4) * 64;
}
}
}
override void tick() {
super.tick();
if(ticker > 0) { ticker--; return; }
ticker = maxtick;
for(int z = 15; z > 0; z--) {
for(int y = 7; y > 0; y--) {
for(int x = 7; x > 0; x--) {
int offx = clamp(x+random(-1,1), 1, 6);
int offy = clamp(y+random(-1,1), 1, 6);
int offz = clamp(z-1, 0, 15);
fire[x][y][z] = fire[offx][offy][offz] * frandom(0.45, 0.75);
firecolor.r=255;
firecolor.g=fire[x][y][z];
firecolor.b=fire[x][y][z] / 2;
double alf = double(fire[x][y][z]) / 255;
self.A_SpawnParticle(
firecolor, // color
SPF_FULLBRIGHT, // flags
(maxtick+1), // lifetime
4 * scale, // size
0, // angle
x * scale, y * scale, z * scale, // pos
0, 0, 0, // vel
0, 0, 0, // accel
alf, // start alpha
0, // fadestep
0 // sizestep
);
}
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment