How to implement Fog Of War with an shader?
Okay, I'm creating a RTS game and want to implement an AgeOfEmpires-like Fog Of War(FOW). That means a tile(or pixel) can be: 0% transparent (unexplored) 50% transparent black (explored but not in viewrange) 100% transparent(explored and in viewrange) RTS means I'll have many explorers (NPCs, buildings, ...). Okay, so I have an 2d array of bytes byte[,] explored. The byte value correlates the transparency. The question is, how do I pass this array to my shader? Well I think it is not possible to pass an entire array. So: what technique shall I use to let my shader know if a pixel/tile is visible or not?
Yes it is possible. And it is called texture.
Textures are not just pictures – it can be any kind of data*.
Another option would per-vertex data – if you dont mind smooth border between (un)explored. Or just as other post suggested – pass it as per-tile uniform.
* Ofcourse, you need to stay in reasonable array size, defined by maximum texture size. Also note that editing such texture would mean sending it all over again, which could be slow.
I’d simply provide a uniform per tile. For example a simple float that indicates the transparency.
Before you render the tile, you simply set the uniform.
If that’s not possible, try using vertex attributes (also using a simple float).
- Database Administration Tutorials
- Programming Tutorials & IT News
- Linux & DevOps World
- Entertainment & General News
- Games & eSport