Fog of War

I’ve put together a quick sample that shows a way to implement Fog Of War in XNA, for a 3D game. As a word of warning, this is put together in a couple of hours, so it may be hacky in some parts.

The idea is to have the Fog Of War in a texture. The texture represents a view from above, covering all terrain. Using render to texture, I draw a white gradient disk in this texture for each friendly unit of the player, using additive blending.

After this, I draw the scene normally, and when drawing the enemies, the pixel shader gets, based on its position, the corresponding pixel from the Fog of War Texture. Using this information, it sets the alpha value of the output. This way, when the enemy unit is close to the friendly unit, you can see it, at the borders it fades away, and when out of range, it is invisible.

The controls are similar to the ones in SkinnedModel Sample.

The sample can be found here

And some pictures:

fogsample1.jpg fogsample2.jpg

  • Ben

    SkinnedModel sample?

  • http://www.catalinzima.com Catalin Zima

    The Skinned Model sample found on the creator’s club website.

  • zizizi

    I guess if you’re using a texture, the total number of tiles you can set visibility on is 1024×1024. How would this be done without using a texture, or to somehow expand the tile number?

  • http://www.catalinzima.com Catalin Zima

    To expand the number, you can use a larger texture.

  • Pingback: Simple, fast, GPU-driven multi-textured terrain | Allen Pestaluky: Blog

  • Christopher Richmond

    Hi. I’ve attempted to convert the sample code to XNA4.0/VS2010. I’ve got everything working except that the TerrainComponent will not render. Could you provide any assistance?