Results 1 to 6 of 6

Thread: Using depth map for occlusion

  1. #1
    Junior Member Newbie
    Join Date
    Apr 2004
    Posts
    16

    Using depth map for occlusion

    Hi,

    I'm trying to create a program that displays a photo on the screen with 3d objects overlayed on top of it. I want the 3d objects to be occluded by certain objects in the actual photo.

    I got this working by modeling the objects in the photo and drawing them with the color buffer disabled. Here's the basic outline of my program right now:

    - Draw photo on the screen
    - Disable color buffer
    - Draw static objects in photo
    - Enable color buffer
    - Draw dynamic objects which can be occluded by photo

    It works fine now, but instead of modelling each object in the photo I would like to create a greyscale version of the photo that represents the depth at each pixel.

    I tried doing this by copying the depth image to the depth buffer using glDrawPixels. However, glDrawPixels is too slow.

    Does anybody know of another way to do this? I was thinking of drawing the depth image to the screen and using a vertex program to convert the texture value to the depth value, but from my understanding, you can't perform texture fetches inside a vertex program.

    Any comment is greatly appreciated.

    -Farshid

  2. #2
    Senior Member OpenGL Pro
    Join Date
    May 2001
    Location
    The Round Table at Camelot
    Posts
    1,264

    Re: Using depth map for occlusion

    I tried doing this by copying the depth image to the depth buffer using glDrawPixels. However, glDrawPixels is too slow.
    Use glTexSubImage2D and a fullscreen quad instead.

    I was thinking of drawing the depth image to the screen and using a vertex program to convert the texture value to the depth value, but from my understanding, you can't perform texture fetches inside a vertex program.
    You can do this with GeForce 6 series of hardware currently.

    -SirKnight
    -SirKnight

  3. #3
    Junior Member Newbie
    Join Date
    Jun 2004
    Posts
    23

    Re: Using depth map for occlusion

    Hi
    If you own 3D Studio MAX 6.0, you can render a scene as a ZBuffer depth bitmap.

    Might be helpfull somehow

  4. #4
    Junior Member Newbie
    Join Date
    Apr 2004
    Posts
    16

    Re: Using depth map for occlusion

    Hi,

    Thanks for the advice. Unfortunately, I don't have a GeForce 6.

    Also, I might have been a little unclear. I already have the depth map image. My problem is copying the data from the depth map texture to the zbuffer.

    I looked at the glTexSubImage2D command but it seems as though this is for copying data into a texture. Did I misinterpret the use of this command?

    Again, thanks for the help

    -Farshid

  5. #5
    Senior Member OpenGL Pro
    Join Date
    May 2001
    Location
    The Round Table at Camelot
    Posts
    1,264

    Re: Using depth map for occlusion

    The parameter in glTexSubImage2D called "format" which is the 7th parameter has the same meaning as the "format" parameter in glDrawPixels which is the 5th parameter. So you can pass into glTexSubImage2D the constant GL_DEPTH_COMPONENT just like you did with glDrawPixels to write the height data into the depth buffer.

    --EDIT--

    BTW, Make sure when you do this operation to disable color writes, glColorMask( 0, 0, 0, 0 ), then after the depth buffer has been filled turn color writes back on, glColorMask( 1, 1, 1, 1 ).

    -SirKnight
    -SirKnight

  6. #6
    Junior Member Newbie
    Join Date
    Apr 2004
    Posts
    16

    Re: Using depth map for occlusion

    Thanks for the tip SirKnight. The documentation I was looking at must be outdated. It said the following about the glTexSubImage2D command:

    "In general, texture images can be represented by the same data formats as the pixels in a glDrawPixels command, except that GL_STENCIL_INDEX and GL_DEPTH_COMPONENT cannot be used."

    I've also considered using a fragment program and writing the texture value to result.depth. However I can't find any documentation on this. Is result.depth a linear mapping from [0,1]?

    - Farshid

Similar Threads

  1. Replies: 11
    Last Post: 05-19-2015, 01:48 AM
  2. Occlusion query with depth disabled pass
    By _NK47 in forum OpenGL: Basic Coding
    Replies: 5
    Last Post: 10-08-2009, 09:56 AM
  3. Occlusion quereis and depth test using shaders
    By yalmar in forum OpenGL: Advanced Coding
    Replies: 2
    Last Post: 08-19-2006, 07:13 PM
  4. depth buffer test / occlusion culling?
    By wow in forum OpenGL: Basic Coding
    Replies: 1
    Last Post: 11-23-2003, 11:21 PM
  5. Point Occlusion with Stencil/Depth Buffer
    By beko in forum OpenGL: Advanced Coding
    Replies: 1
    Last Post: 06-13-2002, 02:03 PM

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