Implementing fog of war in opengl es 2.0 game
- by joxnas
Hi game development community, this is my first question here! ;)
I'm developing a tactics/strategy real time android game and I've been wondering for some time what's the best way to implement an efficient and somewhat nice looking fog of war to incorporate in it.
My experience with OpenGL or Android is not vast by any means, but I think it is sufficient for what I'm asking here.
So far I have thought in some solutions:
Draw white circles to a dark background, corresponding to the units
visibility, then render to a texture, and then drawing a quad with
that texture with blend mode set to multiply. Will this approach be
efficient? Will it take too much memory? (I don't know how to render
to texture and then use the texture. Is it too messy?)
Have a grid object with a vertex shader which has an array of
uniforms having the coordinates of all units, and another array
which has their visibility range. The number of units will very
probably never be bigger then 100. The vertex shader needs to test
for each considered vertex, if there is some unit which can see it.
In order to do this it, will have to loop the array with the coordinates and do
some calculations based on distance. The efficiency of this is
inversely proportional to the looks of it. A more dense grid will
result in a more beautiful fog of war... but will require a greater
amount of vertexes to be checked. Is it possible to find a nice
compromise or is this a bad solution from the start?
Which solution is the best? Are there better alternatives? Which ones?
Thank you for your time.