Render pipeline sample in C++20, using Apple's Metal API. The program loads a glTF model and renders it with a perspective camera, depth testing, PBR-inspired lighting and procedural bump mapping.
glTF scene (--scene=gltf) |
Minimal scene (--scene=minimal) |
|---|---|
![]() |
![]() |
- glTF: 2.0 via fastgltf (mesh, normals, material factors)
- Camera: perspective, framed from the model's bounding sphere
- Frames in flight: triple-buffered uniforms, semaphore paced
- Lighting: Lambert diffuse, Blinn-Phong specular, Fresnel and procedural environment reflection
- Bump mapping: procedural noise, surface gradient method, no UVs
- Rendering: depth buffer, 4x MSAA (switchable with
--msaa) - Animation: frame-delta turntable rotation with bounded tilt
Requires Apple Clang (GCC / MSVC are not supported), Xcode w/ Metal toolchain, and CMake 3.26+. Tested on macOS 27.0, CMake 4.4.3 and Ninja.
git clone --recursive https://github.com/blakesimpson-dev/metal-cpp-sample.git
cd metal-cpp-sample
cmake -S . -B build -G Ninja
cmake --build build
./build/metal-cpp-sample [--scene=gltf|minimal] [--msaa=on|off]Alternatively, you may download the sample. Run the following on your machine after unzipping (Gatekeeper can be problematic):
xattr -dr com.apple.quarantine metal-cpp-sample-v1.0.0-macos-arm64| Path | Contents |
|---|---|
src/app |
Application and view delegates |
src/renderer |
Metal renderer, camera, math and Metal helpers |
src/scenes |
Scene interface, glTF loader, glTF and minimal scenes |
src/shaders |
Metal shaders, types shared with C++ |
src/platform |
Executable path, metal-cpp ownership helpers |
assets |
glTF model (see Credits) |
docs |
README images |
external |
Dependencies |
| Dependency | Version | Licence |
|---|---|---|
| metal-cpp | macOS27_iOS27 release | Apache-2.0 |
| metal-cpp-extensions | from Apple's LearnMetalCPP | Apache-2.0 |
| fastgltf | v0.9.0 | MIT |
| simdjson | v3.12.3 | Apache-2.0 |
Model: "Exalted Orb" by justingulenchyn (CC-BY-4.0). The application code is my own (MIT, see LICENSE); an LLM was used for explanations, code review and tooling configuration.
- Apple: metal-cpp, "Learn Metal with C++" samples, Metal Best Practices (Triple Buffering, Buffer Bindings)
- glTF: fastgltf, glTF 2.0 specification
- LearnOpenGL: Camera, Basic Lighting, Advanced Lighting
- Bump mapping:
Mikkelsen, "Bump Mapping Unparametrized Surfaces on the GPU",
three.js
bumpmap_pars_fragment, The Book of Shaders: Noise - Triple Buffering
- Buffer Bindings
- C++: Google C++ Style Guide, learncpp.com

