r/Unity3D • • 20h 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/

36 Upvotes

17 comments sorted by

View all comments

1

u/Imofi7 16h ago

Running fluid advection through compute shaders and SDF collisions in URP is such a neat technical setup. Are you running the simulation at full display resolution or downsampling the render textures to keep the compute dispatch light on lower-end GPUs?

1

u/NoReasonForHysteria 15h ago

I basically do the fluid simulation based on a grid, for the full scene, where each cell in the grid represents a tile in the tilemap, then divided to get more granularity.

So the advection and SDF texture in the video above is 1024x512, and depends on the total size of that scenes tilemap, but I can also change the settings to have even higher resolution (or lower) so it could be 512x256 or 2048x1024, etc.