Fog of war shader, how to handle slightly tilted camera angle?

How might Northgard / Starcraft 2 etc. render their fog of war?

I am most interested in how they manage to cover the trees and terrains, while also prevent camera line of sight issue due to their camera tilt.

In particular:

  • If the fog of war is a volume, then towards the bottom of the screen, line of sight may cross the fog volume, causing the fog to appear to cover more area than it actually is.

  • If the fog of war is a plane, then I wonder what trick they use to cover everything above it, just ztest always + creative depth based shading?


(I also found some Starcraft 2 mod that can see the fog of war from ground level, which suggest they might be using fog volume; but given this fog height, how did they avoid line-of-sight issue?)

I figure the best solution is either:

  1. use the separate camera and render using orthogonal mode.

  2. depth projection, basically reconstruct the world space position from depth and then use it to shade, mask out area that’s not within the volume. so the fog appear to “stick” to ground.

I am going with plan 2, I just have a question: if I don’t want a screen-space post-process effect, but instead use a volume (a cube) in world, how can I convert the volume’s vertex position to view-space vertex position on far plane, so that we can do the depth projection?

(Pretty sure this is the most efficient way, any thoughts @bgolus ?)

Actually I am overthinking this, I can either:

  1. use normalized view direction and depth (pixel depth and depth texture) to calculate the world position
  2. use view space position and depth ratio (again, pixel depth and depth texture), which will also give me the same result.

Recommended reading:

1 Like

Both games appear to just be using a top down 2D projection for the actual fog of war. Northgard is additionally using some noise to make the edge more interesting. I can’t entirely pin down what else they’re doing, because some objects poke out of the fog more than they should, and others seem to go dark on their heights when they shouldn’t. My best guess is they’re using a low resolution static 3D noise to add some additional dynamics to the 2D fog of war mask.