How Should I Implement Fog of War Using Line of Sight?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By ataboo

I’m prototyping a top down RTS where units have vision ranges that can be blocked by obstacles.

Here’s a quick diagram

I’m working on a fog-of-war effect where terrain that is out of detection range and line of site is masked. There’s no grid snap or turn based so I’d likely need to redraw this multiple times a second so I’ll need to think about performance. I’m not sure what the final scale looks like but I’d like to keep options open to have a few hundred units (this may be a dealbreaker). Not sure if it matters but I’m working in C#.

My thought would be to either:

1. Build and draw polygons in the _draw call of a Sprite/Image Texture

  • Comes with the drawback of not having access to shaders
  • This might also be expensive to perform boolean polygon calculations in CPU since I can’t draw subtractively AFAIK.

2. Paint an Image/Texture Myself

  • From what I can tell, this comes with big overhead.
  1. Start with a filled black mask
  2. Step through each unit and build a polygon circle with slices coped out based on obstacles
  3. Paint the polygons as transparency

3. Do Something With Viewports

I’m not really familiar with what’s possible here. Could there be shaped sprites that combine with shader magic to add/subtract to the intended transparancy then write that to a mask texture over the main camera?

4. Go With Something Simpler

This may not really be viable as is.