Dividing colors by alpha

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 :slight_smile:

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.

Use fragment shader to divide by alpha. Beware of alpha 0.0. Output black in this case.

“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 :slight_smile:

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.

I suppose the mixer is HW video device that cannot be ‘fixed’.

“I suppose the mixer is HW video device that cannot be ‘fixed’.”

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