Fog Of War ImageEffect post-processor

Hi,

After hours of googling, trawling forums and reading, I admit I need some community help. I’m trying to implement a Fog Of War using the alpha channel of a Texture2D.

Let’s say for ease of discussion my terrain/map is square, with world coordinates (0,0,0) to (1024, 0, 1024) with grid size of 1 - not really important. I’m able to create a Texture2D RGBA image of 1024x1024 pixels, with each pixel representing a point on the terrain grid. In the alpha channel used for FoW, I have black as invisible (fogged), white as visible, and grays inbetween as fade levels. Each character in the game will project an area of influence with decay etc. Generating this “FogTexture2D” map is not what I require help with.

I’d planned for an ImageEffect script similar to SepiaTone to take each rendered frame, and for each pixel:

1 - Get the world (x, z) coordinates of the screen pixel, and convert this to a pixel lookup in FogTexture2D.
2 - Take the alpha channel value for FoW, and set the alpha value of the screen pixel

All this needs to happen before any UI is drawn on top, and it needs to be fast.

Any Shader experts out there who can nudge me in the right direction please?

Many thanks in advance.

I have the same problem.

In addition, I also need to save the current Fog of War state in order to not lose progress.

Does anyone know how to help?

That’s a good approach. Just in case you don’t figure it out, I accomplish it with a mesh, manipulating its vertex colors:

840655–31337–$FogOfWar.js (17.8 KB)
840655–31336–$FogOfWarRevealer.js (5.14 KB)

Thanks blitzen,

The scripts are actually very helpful! Can you also share the Shader you are using together with this?

Thanks, Oliver