What is best practice for hit testing with Metal?

I'm relatively new to Metal. Let's say I have a large scene with many objects/primitives and I want a quick way to know what object has been clicked/touched on? I'm familiar with bsp data structures I might use on the CPU and, of course, there is the MPS ray tracing stuff, but is there a more common approach? Maybe culling to a reduced frustum around the hit point and rendering geometry using a special shader and reading back some result?

Replies

I am not an expert on this, but I remember a WWDC 2018 session mentioned that there is an MPS that can be used to detect intersection, or hit testing? Maybe you want to check out this page: https://developer.apple.com/documentation/metalperformanceshaders/mpsrayintersector


The session can be replayed here, with sample code for downloads: https://developer.apple.com/videos/play/wwdc2018/606/

h ttp://metalkit.org/2017/08/31/using-arkit-with-metal-part-2.html


...note the hit-testing/plane detection demo at the end.