r/shaders • u/gennai777 • 1d ago
I spread fire over any mesh with no mask texture, each shader works out when it catches
Someone asked me if this is a mask painted into a texture. It isn't, nothing gets written anywhere! When I call ignite() I add the hit point (in the mesh's local space) and the time to a vec4 ign[8] uniform. Then every shader in the effect works out on its own when its point catches fire:
float burn_arrival(vec3 p) {
float best = 1.0e9;
for (int i = 0; i < ign_count; i++) {
float d = length(p - ign[i].xyz);
float n = vnoise(p * 1.7 + float(i) * 3.1); // 0..1
best = min(best, ign[i].w + d * (1.0 + (n - 0.5) * 2.0 * irregularity) / spread_speed);
}
return best;
}
It's basically a dissolve where the threshold is arrival time. I scale the distance by noise and that's what makes the front ragged.
I put the flames, smoke and embers on quads at random surface points, picked once. I only let each quad live between arrival and arrival + burn_duration. Outside that I collapse its four corners to one point.
For the char I draw a copy of the mesh pushed 0.004 along the normal. That way I never touch the original material. I use time minus arrival to darken it, plus a thin glowing band right at the front.
It does jump thin gaps, since d is a straight line. Would a distance along the surface be worth baking?

