PDA

View Full Version : Dividing colors by alpha



Taicoon
10-30-2010, 09:04 AM
I am generating graphics which has premultiplied alpha so a pure red rendered with 10% opasity would result in 10% red.

Now the problem is that the mixer receiving this signal does some alphamultiplication again leaving the red at 10% color*10% alpha = 1% color. For this reason I need to predevide my color with alpha, so my rendered 10% color is divided with 10% resulting in 100% color and 10% alpha which the mixer can then multiply my 100% red with 10% alpha resulting in 10% color which is what I want.

Ok, the question is then if opengl might have support for something like this? Can it perform a component wise operation for each pixel or will I have to implement this in a shader myself? I assume the latter, but before implementing it I would check here :-)

Alfonse Reinheart
10-30-2010, 02:59 PM
Now the problem is that the mixer receiving this signal does some alphamultiplication again leaving the red at 10% color*10% alpha = 1% color.

Then don't do that. Do you not control the "mixer"? If you don't, then you can't use premultiplied alpha.

mfort
10-31-2010, 12:39 AM
Use fragment shader to divide by alpha. Beware of alpha 0.0. Output black in this case.

Taicoon
10-31-2010, 06:26 AM
"then you can't use premultiplied alpha."
The thing is that rendering something semi transparent on a black background will blend with this background, in essence doing an alpha multiplication. I have tried avoiding blending with the background, but see no solution.

"Use fragment shader to divide by alpha. Beware of alpha 0.0. Output black in this case."
Will do. Alpha=0 =>black is ok since the mixer will ignore my graphics for alpha=0, so I can actually return any value here, but of course avoiding devide by zero is batter :-)

Alfonse Reinheart
10-31-2010, 10:07 AM
The thing is that rendering something semi transparent on a black background will blend with this background, in essence doing an alpha multiplication. I have tried avoiding blending with the background, but see no solution.

I'm more interested/concerned with the fact that you don't seem to have control over how your fragment processing works. My question, "Do you not control the 'mixer'?" was not strictly rhetorical.

You said, "Now the problem is that the mixer receiving this signal does some alphamultiplication again leaving the red at 10% color*10% alpha = 1% color." If your 'mixer' is giving you problems with pre-multiplied alpha, then fix that rather than trying to change how pre-multiplied alpha works.

mfort
10-31-2010, 11:35 AM
I suppose the mixer is HW video device that cannot be 'fixed'.

Taicoon
11-01-2010, 07:55 AM
"I suppose the mixer is HW video device that cannot be 'fixed'."

You suppose correctly. :-)
That is the nice thing about OpenGL development. Here people generally understand that rendering can be used for other things than games.