This is going to be a really short post because of two reasons:
- This concept is explained by
Applereally well in this documentation page. All I did was to port their code from
Swiftsince I have not seen a
Swiftversion to date.
- My book, Metal by Tutorials, will have an entire chapter dedicated to the
Metal Performance Shadersframework 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!