Archived

This topic is now archived and is closed to further replies.

mtemple

Fog of War II

Recommended Posts

mtemple    115
Gentlemen, Ok, so nobody knows anything about how Blizzard did their Fog of War for Starcraft. I have actually implemented a Warcraft style Fog-of-War that works just fine but it does not do alpha blending. Does anyone know anything about any kind of Fog-of-War just so I can check myself and be sure my reverse engineered methodology is not butt-slow and totally flawed? I know someone must know of something because Fog-of-War is a pretty integral part of this type of game. Any thoughts, references, magazine articles, pamphlets, communist propaganda, air-dropped leaflets, or ANYTHING would be greatly appreciated. Thanks in advance.

Share this post


Link to post
Share on other sites
draqza    122
Hop over to SourceForge and download the code for Freecraft and see if it has anything useful for you--it probably will.
--


WNDCLASSEX Reality;
...
...
Reality.lpfnWndProc=ComputerGames;
...
...
RegisterClassEx(&Reality);


Unable to register Reality...what''s wrong?
---------
Dan Upton
Lead Designer
WolfHeart Software

Share this post


Link to post
Share on other sites
Kylotan    9859
I don''t know what your actual problem is (looks like you''re referring to another thread), but you can simulate simple alpha-blending with transparency by only drawing some pixels, leaving others clear. This can be faster if you don''t have hardware acceleration and are using video memory. For example, 1 black + 3 transparent in every 4 pixels is similar to 25% black, and 3 black + 1 transparent in every 4 is like 75% black.

Share this post


Link to post
Share on other sites
Alamar    256
"so nobody knows anything about how Blizzard did their Fog of War for Starcraft"

I don''t recall the fog of war in starcraft being all that mysterious...

Are we just talking about how you could see terrain, but not units? That''s really easy to do...And there are lots of ways to do it...Especially with using 3D cards to do the ''effects'' like alpha...

If you currently have a black-out FOW and you just need to add the alpha for the terrain that you''ve discovered, just draw it on top of what you currently have with some transparency...

As for using stippled alpha, as Kylotan mentioned. Sure it''s faster, but then you''ll look like you''re running the game on a Matrox Mystique...Bleh!

G''luck,
-Alamar

Share this post


Link to post
Share on other sites
Kylotan    9859
Hey! I AM running the game on a Matrox Mystique

By the way, that simple alpha stuff doesn''t look too bad if you''re in a high enough resolution (1024x768 or above). Besides, that''s the only way you''re gonna get fast enough alpha blending if you use video memory for your graphics without the whole 3D pipeline business, as reading from vid mem is v. slow.

Share this post


Link to post
Share on other sites
mtemple    115
Thanks to you guys for the input. I appreciate it because there does not seem to be much written about it, though I agree it doesn''t seem too mysterious on the surface.
As far as my stuff goes, I already have a working FOW that looks like Warcraft II. With this, I am simply drawing monochrome bitmaps (tiles) that are either totally black (unexplored tiles), or some combination of black and/or black checkered (stippled) pixels for the explored but not currently visible areas. I keep track of the fog by simply marking each underlying map tile according to whether it is explored or visible. This was how I did it before I was able to alpha blend.
To implement alpha blending, I know the easiest thing to do would be to just replace the FOW tiles that have checkered areas with black tiles that are drawn partially alpha blended. But alpha blending is none too fast (like kylotan says, reading from video memory, ecccch!) and I wanted to be sure that this was how Starcraft was doing it.
But the real problem is that I am simply drawing my FOW as the last drawing step, on top of everything else (tiles, units, buildings, etc.). This seems a little heavy handed and my profiler shows quite a bit of time used to do this. It may be that this is how it''s done and I just need to buff it out to make it faster. I also need come up with a system to avoid drawing the stuff that is just going to be covered with a black FOW tile anyway.
But, I was wondering if there was some clever system of possibly just fading certain areas to black (I use 16bpp by the way). Is my tiling system with alpha blending really the fastest way to do this? I just don''t want to be doing it the stupid way if everyone else knows of a better system.
Like, (alamar) what do you mean by 3D cards to do the ''effects'' like alpha? That sounds interesting. I think what I have now is the system that (kylotan) is describing, am I correct?

Thanks again very much for the suggestions,

Mark Temple
Enemy Technology

Share this post


Link to post
Share on other sites
Thathmew    122
Well, for one, if I remember correctly Starcraft is actually only 256 colors in game which actually allows them to do much faster alpha blending via look-up tables.

If you''re doing you''re own blitting routines and locking surfaces a lot, don''t use video memory. Assemble everything in one offscreen software surface, then blit all at once to the screen, this is much faster than reading from video memory. Alernatively assemble you''re base layer with blending in software, blit to you''re back-buffer, blit in all units and what-not, then flip it all forward. So you''d be keeping terrain and what-not in software surfaces and units and such in video. By keeping the base layer in a seperate surface you only need to update it when visibility changes as well, also keep track of whether or not a tile has changed so you don''t have to re-blend it if it hasn''t, if the alpha blending is slow, you want to do it as little as possible and it shouldn''t be necessary to to it every frame.

If you''re storing on a per-tile bases visibility, then I assume you''re not drawing tiles that are entirely black at all, unless you''re assembling a surface with all the tiles ahead of time? You don''t want to black-out tiles after drawing them, rather don''t draw them in the first place.

If you only need one level of "blending" it''s probably a lot faster to pre-calc a blended version of a tile and use that. It does double the memory for art, but will be a lot faster. Of course, it is difficult to get nice smooth edges or fading doing this. Also sticking to a couple discreet levels can be faster, i.e. 50 percent 25 percent 75 percent darkenning, etc...

3-D hardware can do alpha blending faster, but if you only need some simple darkening, I''d keep it to 2-D.

cheers,


mat williams
Lead Programmer, Designer
Zero Sum Software
www.zero-sum.com

Share this post


Link to post
Share on other sites
mtemple    115
Mat,

Outstanding! If I understand you correctly, the only thing you would lose by having the fog and map tiles maintained on a separate suface in system memory, is that units could not be shaded as they emerge form the fog since they are drawn after the map surface has been blitted to VRAM. They would just "pop" out, which is no big deal since that is what StarCraft and Warcraft seem to do anyway. And yes, I completely understand that I do not want to be drawing tiles that are completely blacked out.
As for the discreet levels of blending, I''m guessing that means that I draw the fog edge tiles with just a couple passes at 75% to 25% blending since I am unsure if I can do "per pixel" blending in 16bpp. And in any case, the per-pixel blending would be much slower even if I had it, right?
Well, that sounds like a very workable plan. I believe I shall implement it!

Thanks again!

Mark.

Share this post


Link to post
Share on other sites
Thathmew    122
Right, that''s the only trade off, the popping in of units, but that''s pretty standard.

If you want have absolutely best speed and looks you maintain 2 versions of each tile, in fog and out of fog. You draw appropriately from the correct version. Then you flag the tiles which border the two regions. Then use per-pixel alpha blending only on the edge tiles to get a smooth transition.
Assuming you fogged terrain is 50% darker than your normal, you could just blend 3 pixels along the edge of the unfogged area and still get a much smoother transition (12.5%, 25%, 37.5%) and the same for the fogged-black edges (62.5, 75, 87.5).
Done properly you''re only blending a few pixels and only when the tile''s view state gets changed and you''re never blending tiles that are not edges.

Let me know how it turns out,
cheers,



mat williams
Lead Programmer, Designer
Zero Sum Software
www.zero-sum.com

Share this post


Link to post
Share on other sites
Guest Anonymous Poster   
Guest Anonymous Poster
Mmmmm. Yes. And since my terrain map does not use too many tiles, having a duplicate of each would really not have too much of an impact.

Thanks again!!!

Share this post


Link to post
Share on other sites
bogdanontanu    122
Well we did the same FOW style as Starcraft in our game Hostile Encounter (www.hostileencounter.com)

We use 32bitASM at a resolution of 800x600x16....goes pretty nice and fast we also do shadows, glow and other lots of stuff...

FOW will have to be redraw every frame and yeh we do all operations in system ram as video ram read is 10x slower,

also you can use a faster 50% alpha with and AND and a shift/add

we know everything about Fog Of War

tell me if you want details

Share this post


Link to post
Share on other sites
mtemple    115
bogdanontanu,

Yes! I would love details if it''s not too much trouble. I am working in 800x600x16 also so this would really be a great help. FOW seems to be a bit of a black art so whatever you are willing to share would be GREATLY appreciated.

Thank you very much,


Mark Temple
Enemy Technology

"We have found the enemy, and he is us!"

Share this post


Link to post
Share on other sites
Vlion    151
I`m working on a quasi-3d engine designed for a RTS.
Currently I`m using shaded tile for the map and OGL.
Anyway, I`m thinking about using fog for my FOW.
I have not sat down and implemented it yet, I have textureing to implement and a culling prob to work out, so I dont know how it would work.
So, I`m thinking that a fog with something like R = 0, G = 0, B = 0 A = 128 would be okay.
Thats what I`m gonna try.
~V''lion


I came, I saw, I got programmers block.
~V''''lion

Share this post


Link to post
Share on other sites
Guest Anonymous Poster   
Guest Anonymous Poster
Here''s a suggestion for fog of war that''s a bit different from the ones previously mentioned. It does require a bit more muscle on the processing side to run smoothly, but in an efficiently coded engine, it looks pretty nice. Instead of giving the tiles in your map the FOG_IN/OUT property, make an entire layer on your map for the fog. Whenever drawing the map, do it so that the entire map is fogged. In other words, draw the entire screen with a darkening filter. Or, just load your map at the beginning of the game darkened. Then, use your object array to draw a fading ''lightening'' circle around each object that should clear the fog of war, with a radius equal to that object''s visibility range. The effect is that the fog does not look ''tiley'', but smooth. There is no impact on memory, because you''re using data that you would need in the game anyways, but like I said earlier, it eats a lot of processing time if you have many units on the screen. However, with a bit of optimization, the effect really pays off, and makes the game look more polished. For one thing, you could make your visibility ranges in set denominations, and load the different circles in the background, then add the preloaded images on top of the objects, instead of recalculating them each time. I''m currently working on a multiplayer online RTS engine for java, and I''m implementing this method. It runs OK with a fast system under JRE, so it should run fine in a language more suitable for graphic-intensive games.

--kcigam

Share this post


Link to post
Share on other sites