Interactive Volumetric Fog With Fluid Dynamics and Arbitrary Boundaries

Rendering Volumetric

Figure -1- Code for generating a single plane mesh
Figure -2- Creating the stack of layers
Figure -3- The stacks visualization

Creating a Obstacle Map

Figure -4- Comparing the Height of obstacles with simulation area height in camera space
  1. Render the depth of the scene (all objects that should act as obstacles). The camera should be orthogonal to the simulation space with an orthogonal projection (in our case and the usual case this would be a top down view, where the camera is looking at the simulation)
  2. Take the texture produced in step 1 and run a check to see which pixel is closer to the camera than the simulation plane (hence is higher than the simulation plane). Mark those pixels as white, which encodes a pixel covered by obstacles.
  3. After step 2, you are left with a black and white mask of all the obstacles which you provide the fluid engine.

Creating a Depth Map for the Obstacles

  1. Model (local space) to world space: local2World Matrix
  2. World space to Camera (local space of camera game object) space: View Matrix
  3. Camera space to Clip Space: Projection Matrix
  1. I take the vectors which represents the edges of the simulation quad, and by using the cross product find the normal of the simulation plane.
  2. Then I find the middle point of the simulation area, and add the normal times an offset to the mid point, this way we place the camera somewhere above the simulation space.
  3. For the forward vector of the camera we take the flipped normal of the plane (-normal), for the right vector one of the edges of the simulation quad (preferably the one along the x axis) and for up we take the cross product between the two.
Figure -5- Constructing View Matrix
Figure -6- Create Projection Matrix
Figure -7- Render Obstacle Depths
Figure -8- Depth Map

Creating a Obstacles Mask from Depth Map

Figure -9- Construct a Mask From Depth Mask
Figure -9- Obstacle Mask

Problem With Over Hangs in Terrain

Figure -10- Terrain with overhang

SDF Representation

Count Up Count Down Method

Figure -11- Count Up and Down Technique

Last Thoughts

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store