Identify visible vertices in OpenGL
Asked Answered
L

1

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

Looksee answered 1/11, 2010 at 21:58 Comment(3)
Would gluProject be what you are looking for? Mapping object coordinates to window coordinates?Shimkus
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?Distemper
I'm targeting OpenGL 3.1 core profile. The answer provided is all I needed, thanks.Looksee
M
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.

Merovingian answered 1/11, 2010 at 22:7 Comment(1)
Great, that is a good trick and works fine. Speed is not very important in this case. Thanks for your help.Looksee

© 2022 - 2024 — McMap. All rights reserved.