Grid Based Fog of War in 3D - JME

Lots of progress recently. The first thing I did was update the textures with some ones I purchased low cost. I've also swapped the theme over from Warhammer 40k to something a bit more a akin to the alien movies. So the scene looks a bit more like this now:

As you can see the new models are pretty great, the textures are cool and I've added the walls to the shadow map - I think this gives the scene more depth. On to the new stuff..

Fog of war is a feature of many RTS games that prevents the player seeing areas that their units haven't explored yet. I've implemented it a few times in tile based games in 2D, generally you can just use a grid with vertex colors set based on line of sight visibility checks. You blend this over the tilemap and it hides areas that haven't been seen.

I've spent my last few coding sessions trying to get a similar thing working in my JME scene, on the derelict. I don't want a shader dependency, though I tried out this method first. So, what did I try instead:

a) Just rendering a mesh of cubes across the scene and fading the colours appropriately. Worked fine, but the performance was pretty terrible - especially to get any sort of resolution on the fog.

b) OpenGL fog coordinates, ended up trying to add this feature to JME. It's a nice thing to have, you can supply a fog depth for each vertex in the scene. This allows you to control the fog rendering and get very good performance. Unfortunately this works a bit like OpenGL lighting and needs lots of triangles (high tesselation) for smooth effects.

c) A texture where each texel represents a cell of the fog of war grid. This texture is then projected onto the scene geometry in a separate pass (which is blended onto the existing scene rendered). When an area is discovered the texture is updated. This gives a really good resolution for reasonably small overhead. This is the one I've gone with:

As you might be able to tell, I've also limited the view distance of units so you don't get massive look ahead down corridors. The approach also gives some smoothing at the edges due to texturing filtering.

All in all I'm pretty how it's turned out.

Reply

*
*
The content of this field is kept private and will not be shown publicly.

*

  • Lines and paragraphs break automatically.