Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 7 of 7

Thread: Dividing colors by alpha

  1. #1
    Intern Contributor
    Join Date
    Aug 2009
    Posts
    53

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

  2. #2
    Senior Member OpenGL Guru
    Join Date
    May 2009
    Posts
    4,716

    Re: Dividing colors by alpha

    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.

  3. #3
    Member Regular Contributor
    Join Date
    Nov 2003
    Location
    Czech Republic
    Posts
    318

    Re: Dividing colors by alpha

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

  4. #4
    Intern Contributor
    Join Date
    Aug 2009
    Posts
    53

    Re: Dividing colors by alpha

    "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 :-)

  5. #5
    Senior Member OpenGL Guru
    Join Date
    May 2009
    Posts
    4,716

    Re: Dividing colors by 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.
    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.

  6. #6
    Member Regular Contributor
    Join Date
    Nov 2003
    Location
    Czech Republic
    Posts
    318

    Re: Dividing colors by alpha

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

  7. #7
    Intern Contributor
    Join Date
    Aug 2009
    Posts
    53

    Re: Dividing colors by alpha

    "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.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •