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

  • #1 written by Ben
    about 3 years ago

    SkinnedModel sample?

  • #2 written by Catalin Zima
    about 3 years ago

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

  • #3 written by zizizi
    about 3 years ago

    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?

  • #4 written by Catalin Zima
    about 3 years ago

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