Page 1 of 2 12 LastLast
Results 1 to 10 of 20

Thread: Inverted reverse subtractive blending

  1. #1
    Junior Member Newbie
    Join Date
    Jul 2008
    Posts
    10

    Inverted reverse subtractive blending

    Greetings all,

    as a fairly new user of OpenGL I've got a question.

    Reverse subtractive blending can be done by:
    Code :
    glBlendFunc(GL_ONE,GL_ONE);
    glBlendEquation(GL_FUNC_REVERSE_SUBTRACT);
    which would be something like
    Code :
    new = dest-src

    But what I would like is the src inverted first:
    Code :
    new = dest-(255-src)
    or
    new = dest-255+src

    I also tried using glLogicOp() with GL_COLOR_LOGIC_OP enabled, but that seemed to completely override the blending.

    Perhaps the best way is to first do a reverse subtractive blend on a white background and reverse subtractive blend that result, but I'm unsure how to that. What do you people think?

    Sandokan

  2. #2
    Senior Member OpenGL Pro sqrt[-1]'s Avatar
    Join Date
    Jun 2002
    Location
    Australia
    Posts
    1,000

    Re: Inverted reverse subtractive blending

    Can't you just do (1.0 - resultColor) at the end of your shader?
    (if not using shaders, use a glTexEnv call to invert the resulting color)?

  3. #3
    Senior Member OpenGL Pro dletozeun's Avatar
    Join Date
    Jan 2006
    Location
    FRANCE
    Posts
    1,367

    Re: Inverted reverse subtractive blending

    Maybe just setting blend function like this:

    Code :
    glBlendFunc(GL_DST_COLOR,GL_ONE_MINUS_SRC_COLOR);

  4. #4
    Junior Member Newbie
    Join Date
    Jul 2008
    Posts
    10

    Re: Inverted reverse subtractive blending

    @sqrt[-1]:
    Not using shaders indeed, that's for later.
    What parameters should I give glTexEnv()? It looks like there's not much choice (GL_MODULATE, GL_DECAL, GL_BLEND or GL_REPLACE). I don't know if it matters, but I'd like the required openGL version to be as low as possible and I'm at 1.4 now, because I'm using glBlendEquation().

    @dletozeun:
    That doesn't seem to have the wanted effect, I'm afraid.

    If not directly, perhaps it's possible using a color buffer, in the way described earlier. I read a bit about GL_AUX color buffers and such, but I've been unable to use it successfully. What I did was:
    Code :
    int buffers = 0;
    glGetIntegerv(GL_DRAW_BUFFER,&buffers);
     
    glDrawBuffer(GL_AUX0);
    //.. binding and drawing of texture
    glReadBuffer(GL_AUX0);
    glCopyTexImage2D(texID,0,GL_BGR,0,0,200,200,0);
     
    glDrawBuffer(buffers);
    but this didn't do anything noticeable.

  5. #5
    Senior Member OpenGL Pro sqrt[-1]'s Avatar
    Join Date
    Jun 2002
    Location
    Australia
    Posts
    1,000

    Re: Inverted reverse subtractive blending

    On glTexEnv:
    http://www.opengl.org/sdk/docs/man/xhtml/glTexEnv.xml

    Using the "GL_COMBINE" option - which is a kinda early form of "shaders" in OpenGL 1.3.


    You need two texture stages typically (unless you don't have textures)

    You will have to setup the last texture stage to do a GL_REPLACE with a GL_ONE_MINUS_SRC_COLOR thrown in at on the color op.

    Really, this is complex stuff to figure out - but it is possible. (I previously used a macro language that translated it to these texture stage states) Perhaps you can find an old tutorial or example code on these forums or web? (I really don't feel like figuring out this math currently)

    Here is some code that will give you a feel for what it should look like: (math it not correct - just cut and pasted from a website)

    glActiveTexture(GL_TEXTURE0);
    glTexEnv(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE);
    glTexEnv(GL_TEXTURE_ENV, GL_SOURCE0_RGB, GL_TEXTURE);
    glTexEnv(GL_TEXTURE_ENV, GL_COMBINE_RGB, GL_REPLACE);
    glActiveTexture(GL_TEXTURE1);
    glTexEnv(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE);
    glTexEnv(GL_TEXTURE_ENV, GL_SOURCE0_RGB, GL_PREVIOUS);
    glTexEnv(GL_TEXTURE_ENV, GL_SOURCE1_RGB, GL_TEXTURE);
    glTexEnv(GL_TEXTURE_ENV, GL_OPERAND1_RGB, GL_ALPHA);
    glTexEnv(GL_TEXTURE_ENV, GL_COMBINE_RGB, GL_MODULATE);

  6. #6
    Junior Member Newbie
    Join Date
    Jul 2008
    Posts
    10

    Re: Inverted reverse subtractive blending

    Alright, thanks for all the info. I'll try it out.

  7. #7
    Junior Member Newbie
    Join Date
    Jul 2008
    Posts
    10

    Re: Inverted reverse subtractive blending

    Ok it worked with the following code:
    Code :
    glBlendFunc(GL_SRC_ALPHA,GL_ONE);
    glBlendEquation(GL_FUNC_REVERSE_SUBTRACT);
    glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE);
    glTexEnvi(GL_TEXTURE_ENV, GL_SRC0_RGB, GL_TEXTURE);
    glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND0_RGB, GL_ONE_MINUS_SRC_COLOR);
    glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_RGB, GL_REPLACE);
    //.. draw
    //.. reset texture environment to default
    I didn't use glActiveTexture() though, it didn't seem to have an effect. I don't fully grasp that function either.

    Thanks again.

  8. #8
    Senior Member OpenGL Pro dletozeun's Avatar
    Join Date
    Jan 2006
    Location
    FRANCE
    Posts
    1,367

    Re: Inverted reverse subtractive blending

    glActiveTexture activate a texture unit. It is used bound several textures at once.
    If you never use this function, textures are always bound to the texture unit 0, other texture units are not active

  9. #9
    Junior Member Newbie
    Join Date
    Jul 2008
    Posts
    10

    Re: Inverted reverse subtractive blending

    So I can bind multiple textures to a single texture unit and give this texture unit environment setting, which the textures bound to that texture units will 'use' when drawn? That's mighty handy, thanks.

  10. #10
    Senior Member OpenGL Pro dletozeun's Avatar
    Join Date
    Jan 2006
    Location
    FRANCE
    Posts
    1,367

    Re: Inverted reverse subtractive blending

    So I can bind multiple textures to a single texture unit
    No, I will reformulate my answer.
    before the ARB_multitexture extension you were able to bind only one texture per primitive but now, you can bind several texture per primitive attaching them to different texture units. So there is only zero or one texture bound to a texture unit.

    In your case, if it works without multitexturing, this is not useful.

Page 1 of 2 12 LastLast

Similar Threads

  1. Subtractive Blending using GLblendFunc
    By imported_alpha in forum OpenGL: Basic Coding
    Replies: 6
    Last Post: 02-25-2012, 04:10 AM
  2. VSM Shadows Falloff inverted
    By OniDaito in forum OpenGL: Advanced Coding
    Replies: 2
    Last Post: 04-11-2011, 12:26 PM
  3. inverted image
    By ramona in forum OpenGL: Basic Coding
    Replies: 8
    Last Post: 11-25-2008, 05:29 AM
  4. Inverted colors on startup
    By Toni in forum OpenGL: Advanced Coding
    Replies: 4
    Last Post: 01-09-2006, 11:53 AM
  5. Subtractive blending
    By jsgf in forum OpenGL: Advanced Coding
    Replies: 3
    Last Post: 03-11-2001, 12:10 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Proudly hosted by Digital Ocean