View Full Version : Blending color

04-30-2009, 03:46 AM
Hi all.

I'm using blending functions to composite k transpancy layers. For my purposes I need to know if it's possible that combining n diferents colors with the same transparency factor, the result is the same blended color.

Anybody knows this?


04-30-2009, 11:18 AM
k ? n ? same blender color ? What do you want exactly ?

05-01-2009, 01:17 AM
It's difficult to explain...

I'm rendering high order Voronoi diagrams via GPU. Doing a deepth peeling I have stored in "k" textures the layers of each peel. Now I need to blend all textures in order to obtain the final composition of the high order Voronoi diagram.

Once this done, I have to do some operations over the composite Voronoi diagram (readpixels...). My algorithm only works iff there's no cell of the composite diagram with the same color that belongs to different pairs of cells.

That's because of my question. For instance:

If I blend

red+blue+red+gren+yellow+orange+blue --> Color(143,121,233)

Is it possible that if I Blend:
"Diferents colors than before" --> Color(143,121,233)

If the combination of the different layers are different, that means that belong to a different final cell. So they should have different colors.

My quetion is because I don't know if it could happen that an strange combination of colors and blending the result is the same color.

I now the example is stupid but I think is clear.

I use glBlendFunc(GL_SRC_ALPHA, GL_DST_ALPHA).


05-01-2009, 10:02 AM
So you want to compute something like a non-colliding hash of a number of colors. If the number of different colors is not too big, it should be doable, but the hash must have enough storage bits to encode all the different values (maybe n*k in your case ?).
By the way you have to do this custom blend through a fragment shader, as the old fixed function pipeline would be too restrictive.

05-04-2009, 02:15 AM
Thanks for your reply

I've enough colors 256^3. I need n differents colors and n is never bigger than 100.000.

If I understand your reply, you are recommending me to do the blending in a fragment shader, isn't it? I like very much the idea because I could do the blending in the same shader now I'm doing the peeling, so I should be faster.

I'll try it.


05-04-2009, 03:07 AM
By the way blending can not be done directly in a shader, so each peel you want to resolve on the framebuffer should be stored in a different texture. That may already be the case, depending on how your layers are currently stored.