I can already do box selection of visible objects in a scene by assigning a unique color to each object and rendering to a separate frame buffer and reading it on the CPU.
But is there a way to do it such that both visible and occluded objects can be selected if they are within the selection box?
The only way I can come up with is to render in wireframe (or maybe points only?) and render multiple passes. After each pass, I go through the list of objects whose selection color appears in the selection buffer, and disable their rendering for the next pass. I keep doing this until the selection buffer is completely black (i.e. no selection), which means that there is nothing left to select. The final selection is the union of all previous selection passes.
The issue with this is I need to do at least 2 selection passes to make sure everything was selected. Realistically I would probably need to do even more.
Im curious if anyone has a better idea. What is the usual approach used for this in the industry?