I've a 3D-game using perspective view, through raycasting, I create a mesh that represents the line of sight of my characters.
I'm looking for a way to "darken" (think old-school Fog of War - Unexplored = pitch black, explored but not in sight = darkened) the entire area outside of this mesh, preferably using a shader?
Black grid above scene doesn't really work well with perspective camera + mesh, as they create the hole based on the camera and not the unit. (i.e, I want the shader to act upon the characters line of sight and not the characters line of sight as seen by the camera - otherwise units can see behind walls).
Anyone have any pointers on how to achieve this?
In the following image, the white area is a mesh created by raycasting, I'd like to create a fog-of-war shader that darkens everything outside the LoS-mesh in screen-space.
The result should be similar to what you'd see in older roguelikes, I think it's called "shadowcasting", but in 3D.