I currently trying to emulate the line-of-sight fog of war found in most MOBAs and RTS games that behaves like so:
A unit/structure would have a script on it that reveals the enemy/neutral units within a certain radius. At the same time, either with a texture or a shader, the area’s of the map that are not visible via line of sight are partially hidden with a transparent fog of war. I think I have the unit rendering handled but I am stuck on render the fog itself. Any suggestions?
A common method of creating fog of war is to create a plane over the battlefield which has a material that uses a shader supporting vertex colors with a black texture. The plane needs to be diveded into several ploygons, not only two. The more, the better. Then each gameObject that is able to reveal fog of war sends one or several raycasts upwards (in a cone / at an angle if more than one) which, upon hitting the FOW plane’s collider, use the raycast hit to get the vertices belonging to the hit polygon. The alpha values of these vertices’ colors are then set to 0, resulting in the texture becoming transparent around those vertices with a smooth gradient towards the vertices which are still in black areas of the plane.
Sounds complicated? There are loads of tutorial videos about this and other methods.