Jump to content
  • Advertisement
suliman

Fog of war (large texture overlay?)

Recommended Posts

Posted (edited)

Hi

In a tilebased topdown 2D map-view (see pic below) the player in a RPG can explore by moving around the map (unexplored areas are black).

  • I want the current location to be lit (a circular light, radius is the current vision range of the hero).
  • I want all "explored" locations to stay slightly lit, so you can see terrain but nut as lit as where the hero currently is.

I dont want to draw a black image for each non-explored tile as this will be very jagged. My idea is to draw a soft-edged white circular sprite to a large black texture where the player is (when the player is moving). This large "light-texture" is then drawn (color multiplied) on top of the map (so unexplored areas are black and explored areas are "carved out" (white parts of this texture will be transparent thus letting the player see the map below). Is this a good idea?

The problem I see is if my gameworld is large, I need a very large texture to hold the explored/unexplored data of the entire map. I can use a smaller "light-texture" and then draw it upscaled 2-3 times I guess to lessen the problem somehow. But preferably i'd want to use max 2048x2048 textures to allow older graphics cards to run the game (or is that too conservative?)...

image.png.5f0ee7b301ddbdc834d992fae975cd9d.png

Edited by suliman

Share this post


Link to post
Share on other sites
Advertisement
Posted (edited)

Hmm they seem to still use tile-based exploration and then blur it during drawing to hide the tiles. Im not sure that would look good on my map.

The game Battle Brothers uses a smooth exploration method, anyone knows how they did that? The game "remembers" where you have explored by carving out the "fog texture" it seems.

Bildresultat för battle brothers map

 

Edited by suliman

Share this post


Link to post
Share on other sites
Posted (edited)

Does it have smooth exploration? All those circles seem to be centered on towns, so it could just draw circles for each explored town?

An image at some scale would be the simplest for arbitrary per-pixel smooth exploration. The image could maybe be at a slightly lower resolution than the screen and scaled (especially if can zoom in a long way), but still far higher resolution than 1 tile = 1 exploration "pixel".

If you did want a higher resolution than is practical, you can optimise it. Mark each tile, or maybe group of tiles as either fully explored, not explored, or partially explored. For partially explore sections, then have a high resolution image.

Otherwise but more complex (never tried this way for any project) you could maybe use like vector graphics, and add or merge vertices as needed. To get smooth curved edges would need either a large number of vertices, or to be able to draw curves.

 

image.png.3f16a150895f83b005ee6aaae1b8bd1c.png

Edited by SyncViews
Clarity

Share this post


Link to post
Share on other sites
Posted (edited)

It DOES have smooth exploration where the player moves, not just around each town (yeah that pic wasn't clear on that. See pic below.)

So it means the game uses a large texture for the entire world, possibly scaled? Would 4096x4096 be safe to use for such a system? Do "all" (reasonably new) PCs handle such textures? (My game is PC only and directx - based).

Or must I stick to 2048x2048 textures as the biggest "fog of war texture"?

Bildresultat för battle brothers map wilderness

Edited by suliman

Share this post


Link to post
Share on other sites

You could just use multiple textures.

(I'm not really fond of using a texture to store fog of war, because fog of war is part of the game state, and to my mind the game state belongs on the CPU side of the CPU/GPU divide.  But using splitting a big texture into multiple smaller textures to get around texture size limits is such an obvious trick that I just had to mention it.)

Share this post


Link to post
Share on other sites
Posted (edited)

But are my size limit more or less reasonable? Would 2k or even 4k be ok?

(i also store explored status for each tile as descreet flags which is what the game logic uses, this texture is just for the sweet smooth looks)

Edited by suliman

Share this post


Link to post
Share on other sites

4096x4096 is probably OK, since its just a mask you dont need a full RGBA texture so that is about 16MB.

At a quick glance D3D11 with feature level 9 requires 4096 support, 10 supports 8192 and 11 supports 16384. But depends on how much resolution you wan for the smoothness, if you want say 64x64 pixels for a tile, that is only 64 tiles for 4096, but go down to say 4x4 pixels and you get 1024 tiles.

But if you want more than that I think my fully explore, not explored, partially explored "compression" should be simple enough. It provides a useful value for game logic and the number of partially explored "edge" tiles that need an image is pretty low.

 

https://docs.microsoft.com/en-us/windows/desktop/direct3d11/overviews-direct3d-11-resources-limits#resource-limits-for-feature-level-11-hardware

 

So if these were your tiles (done quickly, so not to scale with the picture), then only the yellow tiles need any image/smoothness data. The green ones are entirely visible, and the red ones entirely hidden.

image.png.3b745f52ba82eea3273a28bdf6849fc0.png 

Share this post


Link to post
Share on other sites
Posted (edited)

Im using an old engine (based on directx 8.0!) and 4k textures works fine for me with the engine, I just want to keep lots of compability with other people who might play the game (it's not a commercial project).

SyncViews you are talking about drawing "light-sprites" to the screen based on explored tiles each frame? This is different from what we are talking about in the thread I guess (drawing filled circles where the exploring agent is onto a persistant world-texture)

Edited by suliman

Share this post


Link to post
Share on other sites

It is more like "texture compression". Lets say for not explored you have a mask with 0's in it. Initially you have nothing explored so no point having such a texture for the entire world (red cells). As you explore areas ("drawing circles" with a blurred edge) you will need to create new small textures on the fly to draw onto (yellow cells). At some point some of those small tile/cell textures will be all 1.0's, so they can be deleted (green cells).

Then to draw the fog, you draw nothing where you deleted/marked the fully explored cells (green areas in my picture), you draw the fog without any mask in the unexplored cells (red cells), and you use the small exploration textures as a mask for the fog texture in the partially explored cells (yellow cells).

Share this post


Link to post
Share on other sites

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

  • Advertisement
×

Important Information

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

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!