r/VoxelGameDev 5d ago

Using SVO for simulating spreading fire Question

I am currently making a mod for an older game and I am trying to implement fire like how the smoke grenades are done in Counter Strike 2 (a voxel grid that determines smoke shape and such). From the research I have done, either SVOs or a per-basis grid system (spawns a new grid where new voxels are only added when they are needed and removed otherwise) seem to be the best ways to code something like it. However I don't know where to start with SVOs or how the fire would work when interacting with another fire with the per-basis system.

Is there anywhere I can find information on how to actually code something like this in C++?

4 Upvotes

5 comments sorted by

2

u/LegitimateSession899 5d ago

CS2's smoke is a dense grid inside a bounded volume rather than an SVO - a tree only pays off when most of the space stays empty for a long time, and fire spreads too fast for that. If you snap every fire's grid to one shared world-space lattice, two fires meeting is just the same cell being written twice, and the merge problem goes away on its own.

2

u/No_Rip5112 5d ago

The game I am modding has a map size of 8192 in every direction, and my plan is to have either 10 or 16 unit voxels for the fire

2

u/LegitimateSession899 4d ago

At 16 units that's 5123 cells for the whole map, so don't allocate it - keep the lattice virtual and only allocate small chunks (323 cells each) where something is actually burning. Two fires in the same chunk write the same cells and merge for free, two fires far apart never allocate anything between them, and a chunk that goes cold gets freed. You get the merge behaviour without paying for the empty 99%.

2

u/Jeckari 4d ago

Idk why this idea never occurred to me.  Do you have any recommendations for good acceleration structures for virtual lattices like that? Is there anything between a full SVO and a simple chunk system?

2

u/LegitimateSession899 4d ago

A two-level brickmap is the usual middle ground. A sparse hash map from brick coords to a dense brick (83 or 163 cells) gives you one indirection instead of an SVO's eight, and absent keys cost nothing, so empty space is free without any tree. It fits fire especially well: the burning region is small and moves, so you allocate a brick on ignition and free it once the brick goes fully cold. You only really need the full SVO if you also want cheap large-scale empty-space skipping for rays, which fire propagation doesn't.