Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

AppGameKit Classic Chat / Best way to make a non tile-based fog of war?

Author
Message
BuccaneerBob
AGK Developer
13
Years of Service
User Offline
Joined: 18th Aug 2010
Location: Canada
Posted: 3rd Jan 2019 04:46
Hey folks

Have a question for you all, looking for a few recommendations.

What I'm trying to sit down and pen out is the best way to create a "Fog of War" system on a 2d Map (the map is -NOT- tile based, characters move around based on World Position. Tile based would be super easy to do, and I could whip that up, but doesn't align with what I have in my head for gameplay. So, what would you recommend for creating a Fog of War? Think Age of Empires or something similar to that where the sprite has a radius around it that is visible but everything else remains black or darkened.

Cheers

Rob
Robert Janes (Samu Games)
http://www.samugames.com/artifact
GaborD
6
Years of Service
User Offline
Joined: 3rd Dec 2017
Location:
Posted: 3rd Jan 2019 05:19 Edited at: 3rd Jan 2019 06:52
If the fog is just distance based (not line of sight based) then you could use a simple standard-ish shader and just add one uniform for the player position, then darken pixels based on the distance from it. There is a distance() command in GLSL.
That's the simplest approach I guess. Costs basically no performance and you don't have to constantly run distance checks in your gameloop.
You can either use a 3D distance check (creating a 3D bubble around the player) or just use XZ for a flat 2D darkening effect that ignores height.

It's also very simple to have a nicely accurate smooth edge to the fog with something like
float darkeningMultiplicator = 1.0 - smoothstep(innerDist, outerDist, dist);
janbo
15
Years of Service
User Offline
Joined: 10th Nov 2008
Location: Germany
Posted: 3rd Jan 2019 15:10 Edited at: 3rd Jan 2019 15:13
If you want the fog to be cut away as the player passes you could use a blob image and play pingpong with the render targets while updating the blobs position accordingly.
Imagine a completely black image and stamping your blob image on it, but because we would loose the last position of the "stamped" blob you need to capture the last result before stamping the new position on it.
And because you don't want to create new images over and over again you just reuse the previous one, thats what we mean when we talk about playing pingpong with render targets
I think you don't even need a high resolution image for the pinpong if you apply a clever blur or something to it afterwards, not sure if that makes sense performance wise

@GaborD: You mean the same ? (not explaining the pinpong part) but instead of using an image you want to calculate the blob in the shader right ?

Login to post a reply

Server time is: 2024-04-20 12:51:37
Your offset time is: 2024-04-20 12:51:37