i'm writing a shader program that composes several colors.
to be more clear, i'm rendering several things with different colors and these things can be overlapping on the screen, i want to apply a weighted average on their colors if they are overlapping.
what i want to do is to generate fragments during the fragment shader containing the color (the colors are added up by the blending function later) and the weight (the weights are also added up by the blending function) in the alpha channel.
and during the next pass i divide the color with the weight to have the final color.
the equation looks like this:
my question is, how to store the output of the pass 1, because the color may be saturated if my fragment buffer supports only 8 bit for each color channel.
is there a way to format the fragment buffer, such that each color channel is a 32 float?
or should i save the result on a texture map and access it during the next pass?