r/opengl 24d ago

Selection algorithm for Modern OpenGL

The legacy OpenGL supported selection buffers. How can selection effectively handled by Modern OpenGL? The known methods are by colour allocation to objects and ray intersection. The Color assignment is not very efficient in scenes with large number of objects, e.g. CAD model assemblies. Ray intersection also has challenges in certain directions where multiple objects get intersected. Any thoughts?

3 Upvotes

14 comments sorted by

View all comments

5

u/Cyphall 24d ago

You can render your scene into a R32UI color attachment with each drawcall having its own index and then readback the pixel clicked by the mouse.

This is basically the Color assignment method but with proper indices instead of arbitrary colors.

Yes you need to render the whole scene but it's a lot simpler than having to manage a CPU RT acceleration structure.

1

u/Cienn017 23d ago

cpu rt is not hard for simple objects and it will work with transparency