Fog of war in hexagonal grid

Hi. I’m developing an hexagonal grid strategy game. Maps can have ~ 6000 hexagons. Currently I’m handling the selelection of units and highlighting of the terrain with a shader, but I’ve experienced problems when creating arrays more than 1024. So I think there’s a limit in the size of uniform float arrays that can be put in a shader.

Here’s the problem: for making the fog of war, it’s possible the number of hexagons that are “shadowed” (or lighted, if we think in the opposite way) it’s very high, more than the limit for floats imposed by the shader limits.

I’m wondering if there’s a way to “shadow” a region of the hexagonal grid that could be larger than the shader uniform size limit.

Note: I could try to think some algoritms to make it possible but maybe there’s a solution that doesn’t involve, e.g., using bigger shapes and some kind of algorithm to create the shadow using bigger and smaller shapes of hexagon “circles”.

Hi hhaamm,

Have you considered storing the information about the hexagons in a texture? From my (very limited) experience with hex grids, I think it’s possible to transform them to and from a grid space with a simple skew transform, so you could actually store hex-specific information (specifically which hexes are “foggy” and which aren’t) in precise pixels addressable directly from the hex coordinates. That would remove the constraints associated with arrays. I’m not 100% sure it would work for your scenario, but it’s something to try.


That makes sense. I can pass more than one texture to the shaders, right? (because I’m already using the texture of the ground in the shader)

Yep, definitely! I forget how many textures is the maximum number you can have (16, maybe?), but it’s certainly more than one. Here’s an example from the PBR shader of where two different textures are being declared (given the correct defines).

1 Like

Then this will work for me! Also it will allow me to remove a lot of unnecessary arrays I was using. Thanks a lot!