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 5 of 5

Thread: GLSL: why is alpha value modifying RGB??

Hybrid View

  1. #1
    Junior Member Newbie
    Join Date
    Jul 2013
    Posts
    4

    GLSL: why is alpha value modifying RGB??

    Hi,

    I want to use a texture as a 2D vec4 array, without alpha effects, but I'm running into this problem where the sampled R,G, and B values are modified by the alpha value:

    // to test, all colors in the texture image are (1,0,0,0.5)

    vec4 color = texture2D(texture0,coords.st);

    // result: color = (0.5,0,0,0.5)

    --------------------------------------

    // all colors in the texture image are (0,1,0,0.75)

    vec4 color = texture2D(texture0,coords.st);

    // result: color = (0,0.75,0,0.75)

    --------------------------------------

    what I want is the result to be the same as what I set in the texture image, not with the R,G, and B values modified.

    Anyone have any ideas?

  2. #2
    Member Regular Contributor Nowhere-01's Avatar
    Join Date
    Feb 2011
    Location
    Novosibirsk
    Posts
    251
    it's called blending and it is enabled by default. if you want pure output color while writing to alpha channel, you call glDisable(GL_BLEND); before rendering. and you call glEnable(GL_BLEND) if you want blending enabled again.

    i think, you need to read some beginners OpenGL literature, it's not really an advanced question.

  3. #3
    Junior Member Newbie
    Join Date
    Jul 2013
    Posts
    4
    it makes no difference if i disable blending or not, the result is the same.

    So if I disable blending and I still have the same issue is this still a beginner question?

  4. #4
    Member Regular Contributor Nowhere-01's Avatar
    Join Date
    Feb 2011
    Location
    Novosibirsk
    Posts
    251
    where does this texture come from? if it's color is mixed with black(or whatever was in the background) using alpha value, it must be you using it as a framebuffer attachment and rendering to it with blending enabled. alpha-blending happens when texture is being rendered to, not when you are sampling it. so the problem lies at the stage, where that particular texture is filled.
    Last edited by Nowhere-01; 07-16-2013 at 11:30 AM.

  5. #5
    Junior Member Newbie
    Join Date
    Jul 2013
    Posts
    4
    Thanks Nowhere-01. I think maybe my problem has to do with premultiplication by alpha values possibly done in AWTTextureIO.

Posting Permissions

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