r/howdidtheycodeit • u/RunningInTheTwilight • Jun 22 '23
Question How did they code this voxel-based fog simulation in this CS:GO2 trailer?
https://www.youtube.com/watch?v=kDDnvAr6gGI
I want to implement something similar for my graduation project. Hearing some opinions might help me in doing some research since fluid simulation is a huge field. Thanks in advance.
27
Upvotes
View all comments
21
u/heyheyhey27 Jun 22 '23 edited Jun 23 '23
It's not really a fluid simulation. If you look closely, the fog is represented with pretty coarse voxels. Smoke grenades add to the voxel grid, and then events can subtract from it. It's more of a cellular automata than a fluid.
Real-time clouds/fog rendering has been around for a while, and there are a lot of resources for it in different engines. It's done with raymarching. You march a ray along the view direction, and at each step march a secondary ray towards the light source to see how much light reaches that step of the view ray. Then that step light is further attenuated from the fog your main ray has marched through already, and finally that light is added to the total light entering the camera.
EDIT: I should point out, there are plenty of optimizations to be made from what I said above. In particular, the secondary ray marches are very expensive, and you'll probably want each grenade to have its own little voxel grid rather than a single massive one covering the level.