ekk
ekk

Reputation: 45

How to find corresponding primitives or vertices for given pixels on the screen in OpenGL

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!

Upvotes: 1

Views: 202

Answers (1)

genpfault
genpfault

Reputation: 52082

  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

Upvotes: 1

Related Questions