6

What is the most efficient way to identify the vertices that are visible from a particular viewpoint?

I have a scene composed of several 3D models. I want to attach an identifier to each vertex (ModelID, VertexID) then generate 2D images from various viewpoints and for each image generate a list of the visible vertices identifiers (essentially this is for an image processing application).

Initially I thought to perform a dot product between a vertex normal and the camera view vector to figure out if the vertex is facing the camera or not, however if the model is occluded by another object this test would not work.

Thanks in advance

tat0
  • 133
  • 1
  • 5
  • Would gluProject be what you are looking for? Mapping object coordinates to window coordinates? – Jim Nov 01 '10 at 22:04
  • Which OpenGL version do you target? Always include this information. Also, do you need to know which vertices which pass the test, or do you just need the count? –  Nov 01 '10 at 23:09
  • I'm targeting OpenGL 3.1 core profile. The answer provided is all I needed, thanks. – tat0 Nov 02 '10 at 17:26

1 Answers1

4
  1. Disable all lighting/texturing
  2. Render your geometry (GL_TRIANGLES) to populate Z-buffer
  3. Render your geometry again (GL_POINTS), selecting a different RGB color for each vertex, which maps to your model/vertex IDs
  4. Read back framebuffer and scan for the colors you used earlier, mapping back to your model/vertex IDs.

Not very fast, but it should work.

genpfault
  • 51,148
  • 11
  • 85
  • 139
  • Great, that is a good trick and works fine. Speed is not very important in this case. Thanks for your help. – tat0 Nov 02 '10 at 17:22