I’m implementing a fog simulation with different colored fogs.
Therefore I’ve got three three-dimensional grids that contain the density of either red, green or blue fog per voxel.
I’m rendering the fog by an volume visualization that displays a set of square plains in front of each other blended by opengl. (Each of these plains has a texture with the density of the according layer in my density grid (by now I’m using one grid in a black and white version)
Ok, now there’s the problem:
I want to blend my three colors into one texture.
The problem is, that I’ve got an alpha value per color. My resulting color should be the result of the source colors (r, g, b) weighted by their alpha value.
So, i’ve got three rgba colors:
[1, 0, 0, a_r]
[0, 1, 0, a_g]
[0, 0, 1, a_b]
my result should be:
[a_r/(a_r+a_g+a_b), a_g/(a_r+a_g+a_b), a_b/(a_r+a_g+a_b)]
Why? Some examples:
- only red fog with 20% alpha
-> [1, 0, 0, 0.2]
- red fog 20% alpha, blue fog 40% alpha
-> [0.33, 0, 0.66, 0.6]
- red fog 20% alpha, green fog 90% alpha, blue fog 40% alpha
-> [0,1333, 0,6, 0,333, 1]
Is there a possibility to get this using the gpu? The grids have 64^3=262144 Voxels * 3 Divisions = too much for computing by software.
Thanks a lot!