View Full Version : How to find visible primitives?
05-24-2000, 10:51 AM
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?
05-24-2000, 11:33 AM
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.
05-24-2000, 11:43 PM
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).
05-26-2000, 01:32 AM
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..
06-02-2000, 09:34 AM
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.
06-07-2000, 02:49 AM
Visit the "view frustum culling" thread iin this forum for another solution ( may be better, may be worse )
06-07-2000, 06:35 AM
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.
06-07-2000, 10:26 PM
Ahh, yes ... I misunderstood you, sorry http://www.opengl.org/discussion_boards/ubb/smile.gif
Powered by vBulletin® Version 4.2.0 Copyright © 2013 vBulletin Solutions, Inc. All rights reserved.