Skip to content

About

Render pipeline sample in C++20, using Apple's Metal API

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Repository files navigation

metal-cpp-sample

C++20 Metal macOS License: MIT

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)
Exalted Orb render Minimal triangle

Features

  • 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

Build and run

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]

Download

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

Layout

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

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

Credits

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.

References

About

Render pipeline sample in C++20, using Apple's Metal API

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Contributors

Languages