Fog of War #2

Published November 25, 2006
Advertisement
Today I got the fog of war re-written. It's not quite as nice as the old version, but it's blazing fast, so...



First I tried the technique I mentioned in the last update, but it didn't look good at all. For one, the amount of blurring required was too great, and it had a very rectangular look due to the undersampling I got when stretching down the fog of war part of the back buffer.

What you really want is some way to just incrementally update the fog of war as you go. As the player uncovers new areas, you mark them, but save those that you already marked. Last time, I mentioned a cpu-heavy method last time of marking a 25x25 meter area in the navgrid, which would tax the CPU more than it is already while also not allowing walls and things not in the navgrid to show up.

So, the solution, which is not perfect, but I believe good enough, is to have a separate 512x512 fog of war texture, that is mapped to be centered on the navgrid's bounding box. It's mapped to a 1 texel/meter scale, and each time the player reaches a new nav grid point, that point's coords are added to the list. Any new ones added to the list this frame have 50x50 pixel ( for a 50x50 fog of war uncovering radius ) quad rendered to the buffer at the nav grid location.

When drawing the overhead map, I modulate with the fog of war texture using the world-space x & z coords to index into it.

To get the updating looking good, I use the MAX blending op, which uses the bigger of the src or dest color, which is what you want for this type of thing. Using ONE,ONE or INVDESTCOLOR,ONE blending just saturates out way too quickly.

Here is a shot from perfhud, from during the map rendering, using the map mask as the 2nd texture.



One downside of this approach is that it's a little jumpy when the map is updated, b/c the map is only rendered to every time you add a new nav point, but that's a minor issue compared to the look & speed issues that this method fixes...
Previous Entry Fog of War
Next Entry Scanning & Portals
0 likes 2 comments

Comments

zedzeek
WRT to the fog (im sure youve thought of this)
but with your 512x512 fog alpha texture
just render into it when the player enters a new area ( in gl glTexSubImage(..) )
so it will draw the areas the player has been through

or else recreate that texture anew each frame or 10 frames
by clearing the texture to black + then render the path taken (in grey)
and finally the current position in white

+ use the greyscale texture as a alphablending lookup texture
November 25, 2006 09:30 PM
Jotaf
Quote:Original post by SimmerD
One downside of this approach is that it's a little jumpy when the map is updated, b/c the map is only rendered to every time you add a new nav point, but that's a minor issue compared to the look & speed issues that this method fixes...


Nothing that a little fade effect wouldn't fix :)
In many games the new areas pop-up quite abruptly (I'm thinking games like Starcraft), but this effect is minimized by slowly fading between the 2 different states. Now that I think of it, the FOW is only updated every 2 seconds in Starcraft and they ditch the issue entirely - but I do remember seeing this fade effect in some other RTS game.

There's also a much more "organic" way to do this, which would be to continuously render this quad (or every so miliseconds) at the player's position. But if the walls are thin enough (and they probably are), the player would be able to peek through walls in the minimap, which happens in some old-school games, but wouldn't be very nice.
November 26, 2006 09:00 AM
You must log in to join the conversation.
Don't have a GameDev.net account? Sign up!
Profile
Author
Advertisement

Latest Entries

1.2 Almost ready...

1112 views

Sound Paths

1331 views

Stately Progress

1133 views

State Lines

1283 views

Pulsing

866 views

Return to The Ship!

1007 views

Cameras & Boxes

1124 views
Advertisement