开发者

Picking with OpenGL Shading Language

I'm trying to figure out the best way to pick informations rendered using shaders. A window manager buffer (the window) is used for outputting rendering. On user event I should pick the geometry rendered. Using gluPick is easy, but I'm trying to pick using only shaders.

Flexibility of shaders doesn'y aid me to find a correct solution. I've found the following solutions:

  • Rendering using the system provided buffer (indeed using colors). Use glScissor to limit the rendering on a certain region and use glReadPixels for fetching colors, mapped with geometry identifiers
  • Rendering using a separate framebuffer object. Renderbuffer formats need to defined. Maybe can I use plain integers for putting names?
  • Rendering using a framebuffer object, both fo开发者_C百科r rendering and picking. An additionally renderbuffer object containing rendered names.

It seems that the second solution is the best, since doesn't alterate the window buffers and it's possible to define a custom way to specify geometry names.

Any suggestion?

P.S:

Since in a fragment shader i declare an array of vec4 for defining the fragment data, how I could setup a framebuffer holding an render buffer having only the R component, stored in a sized integer internal format?

Is it possible to link a fragment shader output variable with a specific attached render buffer?


I am not sure that shaders are really any help here, except maybe as some form of optimization whereby you render to multiple targets and thus are able to generate your picking values and color values in one pass.

If you are doing picking using rasterization, you're always going to be stuck with a glReadPixels() call or equivalent, and you're always going to be basically drawing your scene to a buffer of some sort with picking values.

If you really wanted to get creative and diverge from the norm, you could try using shaders to perform a ray intersection with the shapes in your scene. This would require a good bit of specialized shader development, and it's hard to see the benefit unless you're doing a LOT of picking (maybe a raytracer?).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜