Sign in to follow this  

Implementing fog of war?

This topic is 2955 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I'm redeveloping an old Macintosh game my dad started in the early 90's. It's tile based and the tiles are 32x32 pixels. The original game window was sized to fill the Mac II's 512x384 pixel screen and it only shows 11x11 tiles at one time. This is clearly not an option now. On my 1920x1080 monitor, the window is centered and very tiny. However, making the window fullscreen shows too much of the level. The way I look at it, there are two options: 1.) Redesign the tiles and make them 64x64 or 128x128. 2.) Implement a fog of war. I think #2 is my best bet, but how do I do this? One idea is to make a bitmap the physical size of the level (in this case 8256x8256 pixels), paint it black, clear a circular area at the player's location each frame and blit this on top of the tiles. I cannot imagine that this is the best way though. The memory requirements would be staggering. I want the visible portion of the FOW to fade to black (feathered at the edges), so a 1-bit bitmap is not an option either. How is this typically done?

Share this post


Link to post
Share on other sites
I admit that I've never implemented this myself but the first idea that comes to mind is to draw a simple quad over the whole scene (parallel to the ground, not camera) and have a shader leave all the pixels black that are too far from some specific point (and interpolate black->transparent at the edges)

Share this post


Link to post
Share on other sites
Yes, but the problem is that I need to keep track of where the character has already been. The fog should only hide places the character hasn't yet moved over.

I guess I should clarify. I don't want to hide all parts of the level for the duration of the game. I want to hide the parts that haven't been viewed to make it harder on the player. However, once the area has been viewed, the fog is permanently repealed. Think Warcraft.

Share this post


Link to post
Share on other sites
Fog of war has been discussed quite a few times before, so I'm sure if you did a search you'll find plenty of information on different methods. And just to clarify, what you're talking about doing is more often referred to as "shroud" in RTS development circles, since it's something that is permanently removed once the player discovers an area. Fog of war usually refers to a dark tint that returns after some delay to simulate outdated intelligence, however the two terms are often interchanged.

The basic idea is that each tile knows if the player has already seen it using a boolean flag (updating this flag based on visibility is discussed here). Each frame, you create a texture equal in size to the number of tiles on-screen (so for 114x64 visible tiles, you create a 114x64 texture). Each tile sets its associated pixel to either white (seen) or black (not seen). Then you just render the texture over the screen, setting up your texture coordinates so that the center of each pixel is over the center of its tile. The fact that you're up-sampling a low-resolution texture across the entire screen gives you feathering and edge interpolation for free.

Share this post


Link to post
Share on other sites

This topic is 2955 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this