2
\$\begingroup\$

In games like Command & Conquer or Age of Empires, players can't see all of the map. Terrain and enemies are revealed only when the player has soldiers nearby.

As I understand it, the most performant way of doing this is by representing map visibility as a grid of cells. When a unit moves into a new cell it updates all cells within a circle shape around the unit.

However, I would like to know how to integrate sight blocking. What I mean by this, is that if a cell is occupied by something which a unit can't see past (like a wall) all cells behind the wall are covered by fog-of-war.

Here's a YouTube video of what it should look like. The author doesn't go into how they did it, aside from mentioning "brute force shadow casting".

\$\endgroup\$
  • 2
    \$\begingroup\$ The author of that video gives a step-by-step breakdown in this Tumblr post, which might be useful to you. \$\endgroup\$ – DMGregory Aug 16 '18 at 13:27
  • \$\begingroup\$ @DMGregory I think that may have answered my question. \$\endgroup\$ – inappropriateCode Aug 16 '18 at 14:15
  • 1
    \$\begingroup\$ Sweet! If you get it working, it would be great to add an answer here yourself, so it's easier for future users working on similar issues to search for. \$\endgroup\$ – DMGregory Aug 16 '18 at 14:16
  • \$\begingroup\$ I am working on a performant implementation of a Fog of War, checkout my twitter twitter.com/arielsan, my idea is to make a blog post about the it at some point but if you see something that could help you could ask me directly. I will try to answer the question too. \$\endgroup\$ – arielsan Aug 27 '18 at 0:55
2
\$\begingroup\$

Basically what I do is, for each pixel in vision range, I go pixel by pixel and check a line to the center (using the Bresenham's line algorithm), if there is no obstacle, then the pixel is visible, otherwise, it is blocked.

It works pretty well, ~100 units at 60fps, check out this tweet to see it working. I plan to write a blog post to explain in detail the implementation.

Don't know if that works for you as an answer.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.