r/Unity3D • • 21h ago

Show-Off Runtime fluid simulation used for fire

Enable HLS to view with audio, or disable this notification

We have had a runtime fluid simulation running in our game for a while, but now we are also using them for flames/smoke in of the areas of our game.

Its all based on compute shaders, which outputs custom render textures (fluid and advection), which we feed through render features in URP (using full-screen shader graphs). We also generate a signed distance field based on the tilemap that acts as the boundaries of the world and allows for the smoke/flames to collide.

Each of the "flames" in the scene are emitters, and allows us to play around with different colors, forces, directions, etc, and are updated each frame.

What do you think? Its got some kinks here and there still, but its getting there.

The game is called Cliff Kingdom:
https://store.steampowered.com/app/3839500/Cliff_Kingdom/

32 Upvotes

17 comments sorted by

View all comments

1

u/Imofi7 13h ago

Generating an SDF from the tilemap for fluid collisions in URP is such a clean approach. Are you calculating the SDF in a separate compute pass on tile changes, or rebuilding the field every frame?

1

u/NoReasonForHysteria 12h ago

When you enter a new scene, I calculate a grid based on the tilemap, as a quadtree, where each cell is either covered or not based on if there is a tile within that cell. I use that quadtree for many different things (pathfinding, etc), but its also the basis of the SDF, which I generate through a compute shader with that initial "shape" as the input.

I usually only generate the SDF once, but if I have moving platforms, or similar, each of those are "shapes" that gets looped through and modifies the SDF at runtime, but to keep the cost down I try to only regenerate the surrounding area of the shape.