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?


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

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


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).

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…

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.


Visit the “view frustum culling” thread iin this forum for another solution ( may be better, may be worse )

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.


Ahh, yes … I misunderstood you, sorry