This is going to be a really short post because of two reasons:
- This concept is explained by
Apple
really well in this documentation page. All I did was to port their code fromObjective-C
toSwift
since I have not seen aSwift
version to date. - My book, Metal by Tutorials, will have an entire chapter dedicated to the
Metal Performance Shaders
framework and raytracing.
In a nutshell, the Metal Performance Shaders
framework now has a high performance intersector that helps speeding up ray-triangle intersections using an acceleration structure that contains all the vertices in the scene necessary for calculating intersections.
This project is only capable of rendering planes and boxes but in Metal by Tutorials you will be learning about how to render any shape or volume because you will be using a model loader.
If you build and run the project you should be able to see something similar:

The source code is posted on Github
as usual.
Until next time!