How would I do fog of war?

Hi, I've reached an impasse in my game development. I know this has been asked many times before, but I just can't seem to figure out how to create fog of war for an RTS game. I've seen many solutions, and one in particular struck me as being doable. That one is modifying the visibility of portions of a mesh depending on a units position relative to it. An idea I had is modifying the visibility of the terrain, and then just using another script (one that I can easily write) to make visible other gameobjects if the unit is in range. Both seem like good ideas, but I've got no idea on how to implement them. That's where you come in... Thanks in advance!

The best idea I have seen is to place plane between your terrain and your camera then raycast from your player upwards into the plane. After that you find the point your raycast hit and lighten that area's vertices.

Here's a forum link with several scripts and examples.Unity Forum/ Fog of War

My only recommendation is to keep the vertex count as low as possible. Fog of war scripts usually require iterating through arrays of mesh colors (or pixels) nearly every frame.

Another idea is to use a texture and change the alpha of pixels instead of vertices. It would work very similarly to the mesh transparency idea.

I once made a fog of war. It was really simple once it was made.
However i can’t locate the files to send you some code, but i remember the algorithm:

  1. lay a plane above the ground
  2. make black generic texture, let’s say 512x512
  3. locate certain pixels on texture (the ones which will represent a point from terrain, location of a real time strategy vehicle unit, for example)
  4. using given pixel coordinates, draw a white circle around it on texture (radius is sight range)
  5. for better looks, use blur shader on texture, to smooth “teeth” on texture
  6. apply texture to plane
  7. repeat each 10 frames, or tweak this until you’re happy

Here is my system:

  1. Edit->Render Settings
  • Enable FOG
  • Fog Mode Exp2
  • Fog Densiti: 0.001
  • Ambient Light: RGB(28,28,28)
  1. Remove all light in your map
  2. Place Point Light inside your character: