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

Thread: How to find visible primitives?

  1. #1
    Junior Member Newbie
    Join Date
    Mar 2000
    Location
    Springfield, VA, U.S.A.
    Posts
    8

    How to find visible primitives?

    Does anyone know of a way to find all visible primitives in a frame? Any suggestions would be welcome.

    Currently, I have a method to find out which primitive is visible at a given pixel (x,y) in the viewport, which I use for picking/selection. The method relies on drawing to a 1-pixel selection region and examining hit records to see which primitives in the selection region have the smallest z- window coordinates.

    Unfortunately, the method seems to be slow for using in a loop such as the one below:

    for (i = 0; i < w; i++)
    {
    for (j = 0; j < h; j++)
    {
    // get closest primitive
    // insert primitive into a container
    }
    }

    Is there a faster way to find which primitives are visible?

    Vishnu

  2. #2
    Intern Contributor
    Join Date
    Apr 2000
    Posts
    78

    Re: How to find visible primitives?

    I presume that it might be possible with the projection matrix, but I dont know how to do it... Anyone?

  3. #3
    Junior Member Newbie
    Join Date
    May 2000
    Location
    Austria
    Posts
    21

    Re: How to find visible primitives?

    I think you need a Selection Buffer or a Feedback Buffer. But I don't know how this works.

    Mexx

  4. #4

    Re: How to find visible primitives?

    I'd assign each primitive a different color, then render the entire scene into an offscreen buffer. Then simply run over that buffer checking the values. The set of all colors in that image is the set of all primitves that are visible. Whether this is fast enough, of course, depends on what you're doing. But this will be faster than the method you were using (which hits each primitive once for each pixel in screen space it would cover).

  5. #5
    Junior Member Regular Contributor
    Join Date
    Apr 2000
    Posts
    134

    Re: How to find visible primitives?

    YngWar is right with the Occlusion Buffer it could save time if you are managing really huge scenes.. (something like a millions of polys) It could save 30% more primitives compared to simple backface culling. Moreover you can always use a scale factor onto your occlusion/flat buffer to reduce reading time!
    But for realtime purposes the easiest way is to use clustering (3d blocks) or Bsp culling..
    Good luck..

  6. #6
    Junior Member Newbie
    Join Date
    Mar 2000
    Location
    Springfield, VA, U.S.A.
    Posts
    8

    Re: How to find visible primitives?

    For anyone who may be interested in this, Yngwar's suggestion works very well.

    I solved this problem by

    1) rendering the scene using a unique color for each primitive,
    2) using glReadPixels to get the RGB values of all pixels in the framebuffer,
    3) made a set of colors of pixels in the framebuffer,
    4) compared the set of colors in 3) to an STL map of colors I made during the process of rendering the scene (a map being an associative array in which color is the 'key' and a primitive is the 'value').

    Where a match was found in 4), I extracted the 'value' from the entry in the map.

    Vishnu

  7. #7
    Intern Contributor
    Join Date
    Jun 2000
    Location
    Rostov-on-Don,Russia
    Posts
    51

    Re: How to find visible primitives?

    Visit the "view frustum culling" thread iin this forum for another solution ( may be better, may be worse )
    Aristarkh Zagorodnikov aka onyXMaster
    ICQ 36987938

  8. #8
    Junior Member Newbie
    Join Date
    Mar 2000
    Location
    Springfield, VA, U.S.A.
    Posts
    8

    Re: How to find visible primitives?

    It seems to me that finding which primitives are visible in a viewport is not the same as culling primitives outside a viewing volume, which I think, is view frustum culling (correct me if I'm wrong). Primitives outside the viewing volume are always invisible, but primitives inside a viewing volume are only visible if they pass the z-buffer test.

    I don't see any reference to how one finds visible primitives in the disussions on view frustum culling.

    Vishnu

  9. #9
    Intern Contributor
    Join Date
    Jun 2000
    Location
    Rostov-on-Don,Russia
    Posts
    51

    Re: How to find visible primitives?

    Ahh, yes ... I misunderstood you, sorry
    Aristarkh Zagorodnikov aka onyXMaster
    ICQ 36987938

Posting Permissions

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