1

Suppose a sphere was calculated and drawn using OpenGL such as it is done here for example.

I am interested in learning, how one would go about finding the specific vertex that correspond to an arbitrary given pixel on the screen (x,y)?

I've already read about ray casting and the selection buffer, however, since I need to iterate over a large number of pixels (let's say >10k) and find all the corresponding vertices those solutions didn't seem to be suitable for this kind of stuff.

Ideally, I would like to find a way that is both fast and modern in the sense of modern OpenGL.

Is there an "out-of-the-box"-solution for this or do I need to write a shader? In either case, any details you could give would be highly appreciated!

Community
  • 1
  • 1
ekk
  • 45
  • 5
  • well actually the most pixel you need to iterate through, the most suitable is the selection buffer (well at least it seems to me), because you are using a lot of information among those that you computed in this buffer, why wouldn't it be suitable ? – Guiroux Feb 02 '16 at 13:29
  • Thx for your reply @Guiroux. I've read that the selection buffer is antiquated and may not even be supported by some of the modern graphic chips anymore (being a beginner in all things opengl, I can't really validate that though). Do you happen to have a good resource handy on how to work with the selection buffer for this use case? – ekk Feb 02 '16 at 13:39

1 Answers1

1
  1. Add an integer "face ID" vertex attribute, make it the same for each vertex of a given triangle
  2. Pass the face ID through the VS to the FS & write it to an integer FBO
  3. Read back the FBO pixels (use PBOs for async FBO readback) in the desired location(s), giving the face ID at each point
genpfault
  • 51,148
  • 11
  • 85
  • 139