Attempt to make an influence map in Unity like the one in Endless space.
This project is a proof of concept. A small personal challenge. The code is delivered as is and no big optimization has been done on it.
I make multiple passes between two textures to achieve this result.
- In the first pass I render all the discs with negative values as an SDF using the smin function of Inigo Quilez.
The values being in negative, the preview above has been reversed for a more comprehensive rendering.
- I take only the lowest channels (and therefore the ones closest to the center of their discs) and output a flat value. If green is the channel with the lowest value, I get pure green (0.0, 1.0, 0.0, 0.0). This gives me clean blobs where the zones do not overlap.
The black area is the alpha channel. It is not visible but is also used.
- I blur to get nice even gradients. The gradient is done in two passes (vertical then horizontal for preformance reasons)
- Then it is very easy in the last pass to reverse the gradients and isolate nice edges too.
Here I use custom colors by channels, so I could put white instead of the alpha channel.
I made a second version in an attempt not to be limited to 4 colors. I also replaced the blur by a jumpFlooding, in order to have a fast result for the gradients and more exact borders between the blobs.
This version relies much more on a compute shader & compute buffer. It can potentially become very heavy quickly. In the other hand, it should be possible to easily compute it on a small buffer and resized afterwards only for the last step.