I have been getting my feet wet in Metal programming. Most recently I have given myself the task of learning how to do hit testing in a MTKView. I looked around for sample code but what I found involved ray tracing which I didn't find attractive. I ended up implementing a technique I had used in OpenGL. Here one renders a scene off-screen using psuedo colors unique to each of the objects one wishes pick. One then reads the "color" at the click point to determine what was hit.
I wrote a little proof of concept program and figured out how to do this in Metal. It works quite well I think. I have uploaded the project files to GitHub:
github.com/MackenzieBD/Sample-Code
Anyone interested in how I solved this problem may download the XCode project in the file HitTest.zip. My hope is to help other novice Metal programmers like me. Also, I would welcome any criticisms from more experienced coders. Have I done anything really asinine? What would be the advantages of a different approach?
I wrote a little proof of concept program and figured out how to do this in Metal. It works quite well I think. I have uploaded the project files to GitHub:
github.com/MackenzieBD/Sample-Code
Anyone interested in how I solved this problem may download the XCode project in the file HitTest.zip. My hope is to help other novice Metal programmers like me. Also, I would welcome any criticisms from more experienced coders. Have I done anything really asinine? What would be the advantages of a different approach?