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

Thread: translucency with alpha-blend & depth test

  1. #1
    Junior Member Newbie
    Join Date
    Jun 2004
    Location
    Toronto
    Posts
    24

    translucency with alpha-blend & depth test

    I've got a scene with colour and depth values coming in from an external renderer. I'm using DrawPixels to get them into the frame buffer and I store the result in a buffer region for later redrawing as I move some models through the scene.
    So far that's all good.

    Now, I'd like to add an effect where everything in my background above a certain target depth is translucent. Models should be visible through the translucent stuff, but not through each other or the background where it's below the target depth. Also, models above the translucent stuff should appear solid.

    I'm having trouble finding an effective solution that satisfies all the criteria.

    The big problem is combining alpha-blending and depth test. I tried setting alpha values based on the depths (alpha=0 below target, alpha=1 above)and drawing my models with glBlendFunc(GL_ONE, GL_DST_ALPHA);

    But that doesn't handle the case where the models overlap each other or if they appear completely in front of the translucent areas. It needs to take into account the depth of the model as well as the background...

    Any suggestions? If there's sample code that would be ideal.

  2. #2
    Senior Member OpenGL Guru Relic's Avatar
    Join Date
    Apr 2000
    Posts
    2,453

    Re: translucency with alpha-blend & depth test

    It's not easy to visualize this from the description, but multiple things come to mind:
    - Multi-pass drawing algorithm using stencil buffers where you can exploit the depth comparison result of the glStencilOp.
    - GL_ALPHA_TEST for the hard cut.
    - Or glClipPlane splitting the world into two half-spaces, once drawing behind, once in front.
    - GL_DEPTH_TEST enabled but glDepthMask(0) for the transparent parts.
    - Draw transparent back faces, then transparent front faces to get a cheap per object back to front sorting.
    - Sort all transparent polygons back to front.

  3. #3
    Junior Member Newbie
    Join Date
    Jun 2004
    Location
    Toronto
    Posts
    24

    Re: translucency with alpha-blend & depth test

    Thanks, Relic, but I just realized that the effect I was trying (badly) to describe wouldn't be right anyway.

    The big limitation is that what I've got from the external renderer is just a snapshot of a color + depth buffer with no information about anything that's obscured. 'Til now that's been ok, because my models get cut off correctly by the depth test, so they look fine.

    However, if I've got a model behind something translucent, I have no information about anything deeper down, so I don't know if there's something solid between the transparent top layer and the position of the model.

    Now I think I can do it with two passes in the external renderer. That way my models will get obscured correctly by the solid stuff underneath, and I can draw the top layer with alpha blend and depth test.

    Thanks for letting me bounce this off you! I guess I just needed to write it all down.

Posting Permissions

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