With some better-looking (albeit stolen) graphics in the game, the visibility fog was looking a bit ugly. Most games with this sort of system smooth the edges of the fog for a better appearance. Could I do that without too much work (after all, this project isn’t about graphics)?

Here’s an article that covers the subject pretty well:

http://www.appsizematters.com/2010/07/how-to-implement-a-fog-of-war-part-2-smooth/

Essentially, you take sub-samples inside the squares and use the results as a bit-mask to look up a shape.

However, this technique can be improved by using samples along the edges of the squares rather than inside them. Internal samples are redundant, because the visibility of a square is determined completely by the visibility along the edges. Using edge samples ensures that the shapes will tile correctly – this won’t always be the case with internal samples. Also, samples along the edges can be shared with adjacent squares, so you get double the sample count for free.

Something that should please most programmers is that two samples on each edge gives 8 bits, rather than 9 for a 3×3 grid. Allowing for rotation and flipping there are only 16 possible shapes.

Still, I can’t be bothered to draw the shapes and store them as tiles. All I need to do is draw an alpha-blended polygon over each square with vertices where the non-visible samples were. If I had an SDL library that could do gouraud shaded alpha polygons it would be nicely smooth. As it is it still looks a lot better than before.

Advertisements