Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

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

Thread: virtual object occluded by real object

  1. #1
    Junior Member Newbie
    Join Date
    Apr 2012
    Posts
    20

    virtual object occluded by real object

    hi guys, does anyone interest in Augmented Reality? I'm trying to occlude my virtual object created by openGL with the real one. what I'm trying to achieve is like this one http://www.youtube.com/watch?v=dbpaLdVEE0g

    I'm pretty sure that by using the depth buffer I can occlude the virtual with the real one. But after conducting numerous trials, I havent succeed. Does anyone want to help me to figure out?


    thanks

  2. #2
    Advanced Member Frequent Contributor
    Join Date
    Dec 2007
    Location
    Hungary
    Posts
    941
    How you plan to acquire the depth buffer of the real scene? This is a non-trivial problem that most of the times requires multiple cameras to reproject the images captured by the cameras into 3D space.

    In the video you've linked probably doesn't perform a true reprojection, but simply handles this special scene, i.e. uses the knowledge that the occluder object is circle shaped and uses a hardcoded value to define it's distance (or recalculate the distance based on knowing the size of the object). That could be easily done by doing a Hough transform to determine the position and size of the circle representing the occluder, however, in general case such an approach won't work.
    Disclaimer: This is my personal profile. Whatever I write here is my personal opinion and none of my statements or speculations are anyhow related to my employer and as such should not be treated as accurate or valid and in no case should those be considered to represent the opinions of my employer.
    Technical Blog: http://www.rastergrid.com/blog/

  3. #3
    Super Moderator OpenGL Lord
    Join Date
    Dec 2003
    Location
    Grenoble - France
    Posts
    5,655
    Provided you know the position/shape of the real occluder, it is only a matter of render video background, render virtual occluder with a depth buffer and color mask so that color buffer is not updated, then virtual objects with depth testing normally.

  4. #4
    Junior Member Newbie
    Join Date
    Apr 2012
    Posts
    20
    thanks for replying.

    zbuffer, can you write the pseudocode for obvious explanation?

    thanks

  5. #5
    Junior Member Regular Contributor Kopelrativ's Avatar
    Join Date
    Apr 2011
    Posts
    212
    I am curious, how do you get the positions of the real world objects?

  6. #6
    Advanced Member Frequent Contributor
    Join Date
    Dec 2007
    Location
    Hungary
    Posts
    941
    Quote Originally Posted by deduu10 View Post
    thanks for replying.

    zbuffer, can you write the pseudocode for obvious explanation?

    thanks
    Code :
    glEnable(GL_DEPTH_TEST);
    glDepthMask(GL_TRUE);
    glColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE);
    renderOccluders();
    glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
    renderOccludees();

    This is what zbuffer explained and that's the only OpenGL related code needed to implement what he proposed. You have to figure out the rest.
    Disclaimer: This is my personal profile. Whatever I write here is my personal opinion and none of my statements or speculations are anyhow related to my employer and as such should not be treated as accurate or valid and in no case should those be considered to represent the opinions of my employer.
    Technical Blog: http://www.rastergrid.com/blog/

  7. #7
    Junior Member Newbie
    Join Date
    Apr 2012
    Posts
    20
    Quote Originally Posted by aqnuep View Post
    Code :
    glEnable(GL_DEPTH_TEST);
    glDepthMask(GL_TRUE);
    glColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE);
    renderOccluders();
    glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
    renderOccludees();

    This is what zbuffer explained and that's the only OpenGL related code needed to implement what he proposed. You have to figure out the rest.
    kopelrativ, I use marker to get the position of the real occluder.

    aqnuep, thanks for writing the code. I have ever tried that code before, my virtual occluder succeed occlude my virtual object, but when I used colormask, indeed my virtual occluder was not rendered, but it was occluded by my virtual object. I will keep trying another way. Thanks

  8. #8
    Advanced Member Frequent Contributor
    Join Date
    Dec 2007
    Location
    Hungary
    Posts
    941
    Quote Originally Posted by deduu10 View Post
    aqnuep, thanks for writing the code. I have ever tried that code before, my virtual occluder succeed occlude my virtual object, but when I used colormask, indeed my virtual occluder was not rendered, but it was occluded by my virtual object. I will keep trying another way. Thanks
    Well, then you've probably done something wrong. Let me rephrase then the explanation:

    Code :
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
     
    glDisable(GL_DEPTH_TEST);
    glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
     
    render real world picture as a full screen quad
     
    glEnable(GL_DEPTH_TEST);
    glDepthMask(GL_TRUE);
    glColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE);
     
    render simple geometry (e.g. sphere) that acts as the virtual occluder
     
    glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
     
    render your virtual objects (whatever it be) that acts as the virtual occludee

    If you follow this method, it has to work, otherwise there may be a different problem with your code.
    Disclaimer: This is my personal profile. Whatever I write here is my personal opinion and none of my statements or speculations are anyhow related to my employer and as such should not be treated as accurate or valid and in no case should those be considered to represent the opinions of my employer.
    Technical Blog: http://www.rastergrid.com/blog/

  9. #9
    Junior Member Newbie
    Join Date
    Apr 2012
    Posts
    20
    Quote Originally Posted by aqnuep View Post
    Well, then you've probably done something wrong. Let me rephrase then the explanation:

    Code :
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
     
    glDisable(GL_DEPTH_TEST);
    glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
     
    render real world picture as a full screen quad
     
    glEnable(GL_DEPTH_TEST);
    glDepthMask(GL_TRUE);
    glColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE);
     
    render simple geometry (e.g. sphere) that acts as the virtual occluder
     
    glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
     
    render your virtual objects (whatever it be) that acts as the virtual occludee

    If you follow this method, it has to work, otherwise there may be a different problem with your code.
    thanks for your explanation, I had tried this one also.. the problem is my real scene was cleared to black as I put GL_COLOR_BUFFER_BIT to glClear(). These code is supposed to work if I know how to maintain my real scene..

  10. #10
    Advanced Member Frequent Contributor
    Join Date
    Dec 2007
    Location
    Hungary
    Posts
    941
    Quote Originally Posted by deduu10 View Post
    thanks for your explanation, I had tried this one also.. the problem is my real scene was cleared to black as I put GL_COLOR_BUFFER_BIT to glClear(). These code is supposed to work if I know how to maintain my real scene..
    Presenting your real scene goes to the line I've noted as "render real world picture as a full screen quad", not before glClear. That way it cannot clear your image.
    Disclaimer: This is my personal profile. Whatever I write here is my personal opinion and none of my statements or speculations are anyhow related to my employer and as such should not be treated as accurate or valid and in no case should those be considered to represent the opinions of my employer.
    Technical Blog: http://www.rastergrid.com/blog/

Posting Permissions

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