So I have been working on adding a fog of war effect to my game. Fog of War normally means an effect in strategy games where parts of the map without any player units are unlit and in order to reveal that area, the player will have to send a unit there. Doing so will light up that area of the map and reveal any enemy units that were hiding out there.
I wanted a similar effect, but instead of units, I wanted my beams of light to reveal parts of the level. It turns out that this was very wrong of me, as it took over two weeks and more than 63 hours of coding, banging my head against the monitor, research, more coding, more head-smashing, more research, etc.
At first, I thought I would just implement a simple fog of war effect using shaders and quads. This worked fine for single objects that did not extend to far in any one direction, but just didn't look very nice for light beams.
Then, I thought just using Unity's built in lights would be the next obvious step, but they did not produce the results I wanted, and had awful side effects like washing out the little color that I have in the game and making some elements look even more unattractive than before.
My penultimate step was to look at particle systems. This actually seemed like it might work, but I ran into bug after bug after bug, even after literally copying and pasting code from Unity's own website. So I gave up on that.
I was about to just quit and when I remembered a subject that I had researched in some detail months ago for my Digestion Game: metaballs! Now, before you get sick images of balls made of other balls, metaballs are simple a way to take overlapping sprites and combining their properties in various ways. They have been used for water rendering, influence mapping, and for lots of other stuff. I quickly found a few shaders that looked promising, tweaked their code, and set up some prefabs in Unity. The actual setup to produce the effect took less than an hour, but I spent a good 4 hours working out the best (to my mind and to my current abilities) solution for handling them together with my lights. It is still not fool proof, but I think I have got a pretty nice solution.
No comments:
Post a Comment