Jump to content
  • Advertisement
Sign in to follow this  
dsr12

OpenGL Need ideas for "fog of war" implementation

This topic is 3812 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 would like advice on implementing a "fog of war" effect for a simple 3D simulation I made (just to prevent confusion, I am not trying to render actual fog in my scene). What I made is a sphere textured with a photo of the earth, and I placed simple icons on it to represent objects on the earth that the player can interact with (this was done with java opengl). For the sake of discussion, let's continue the "fog of war" theme and say that these objects represent armies. This is multiplayer so each player should only see his or her own armies and those of the enemy that that are within a certain range of the player's own armies. Now the problem is I would like to have a relatively complex set of rules for specifying whether an "enemy army" is visible or not. This could be like some armies are better at reconnaissance than others, or other armies are larger and more detectable than others. I think the most intuitive algorithm to implement is to iteratively compare an unknown army against each of your own armies. If one of your armies is capable of seeing that unknown army, then remove that unknown army from the "unknown list" and move on to testing the next one. The amount of computation required for this grows to unacceptable levels when you have large numbers of armies on the world. Is anyone familiar with any clever rendering tricks that I could use to determine whether the enemy "armies" are visible? I'm talking mainly about rendering stuff to the back buffer (without swapping it to become visible) and doing a quick survey of what is there, then using that info to render the scene correctly with the fog or war. If you don't understand what I was just saying, when I was doing this program in 2D, I drew in the back buffer red circles of various radii where my "armies" were. If the enemy "armies" fell on the red circles, they would be drawn in the real scene. I'm just wondering if anyone is familiar with doing fog of war with any technique other than iteratively comparing what sees and what can be seen. Thank you

Share this post


Link to post
Share on other sites
Advertisement
You don't need any clever rendering tricks because this really isn't a rendering issue. If there are a small number of total armies, then simply iterate through each in your rendering loop and only render it if it passes the test. If there is a potentially much larger number of armies, then you can keep a collection of pointers to the visible ones separate, and update this collection at a rate less frequent than your frame rate (although I doubt that would really be necessary).

Share this post


Link to post
Share on other sites
I have around 20,000 objects I would like to display (just simple squares). If this seems unphysical, remember that I said "armies" just to help with explaining what I wanted to do.

Going through iteratively and evaluating whether one object is seen by another is really not working so far because of the massive number of comparisons required for each time I update the screen. Ideally, I would like to have the screen display true information where the "fog of war" is not out of synch. This means evaluating the fog of war at a slower rate is a backup plan that I don't want to resort to just yet.

Share this post


Link to post
Share on other sites
Implement spatial subdivision and responsibility hand-off.

Cover your world with a spatial structure which dictates whether your armies have any degree of vision in a given area. This could be as simple as a kD-tree or similar structure. Break space into manageable chunks either by a lower bound on spatial volume, or an upper bound of contained units. Update this structure when your units move, spawn, die, or when their visual acuity changes. When enemy units move, test their location against this structure and find if they have moved into an area that is in some part visible by your units.

When an enemy unit enters a partially-seen area, add it to a check list for that area, and when it moves around in that area run it against those units of yours which have vision in that area. If you get no hits, it's still hidden. If you get a hit, remember which unit of your own which saw it (you needn't scan all your units unless visual acuity provides more information, as in some wargames), and add it to the visible list.

When an enemy unit moves while it is visible, test its visibility against its assigned spotter. If it leaves his vision, remove it from the visible list, and then run the normal vision check (see previous paragraph). If it is still visible by another unit of yours, then the responsibility of watching that enemy unit moves to him.

If visual acuity counts, test all of the units who have a bead on that enemy unit and give the responsibility to the one with the best sight, instead of taking the first positive hit.

This means you have at most one unit of yours watching each enemy unit, and thus computational expense for re-checking an enemy for becoming invisible is O(1) each, O(N) over all enemy units who moved in the last update cycle. Checking an enemy for becoming visible is as efficient as your spatial subdivision algorithm; with a kD tree, this is amortized to O(log(N)) on the number of enemy units who moved in the last update cycle.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!