The Metal by Example Book is Now Available!

Metal by Example is now a book! You can buy it here as a DRM-free PDF.

Since I started this site, I’ve been wanting to turn Metal by Example into a book. Although the blog format is good for quickly publishing techniques one at a time, a book is necessarily a more cohesive experience. For the past month or so, all of my energy has been directed at revising, rewriting, expanding, and editing my Metal content to turn it into a book.

Of course, this project would never have been possible without you, the reader. Thank you for your support over the last year.

If you want to support the work I’ve done here and benefit from the more streamlined, consistent experience of the book, please consider buying it. Thanks again!—Warren

Update (September 13, 2016): Thanks to everyone for the support over the past year! The book is now available on a pay-what-you-want basis. A lot has changed in the world of Metal since I started writing two years ago, and it doesn’t make sense to keep charging full-price for this material, some of which has grown out-of-date. I hope even more people can find it useful, even as it ages, now that price isn’t a factor.

Metal Performance Shaders in Swift

What is the Metal Performance Shaders Framework?

Announced at WWDC 2015, the Metal Performance Shaders (MPS) framework is a collection of high-performance image filters for iOS 9. Each filter in the library is an efficient black-box implementation of a common image processing task: blur, edge detection, convolution, etc. One useful trait of Apple’s black-box approach with the framework is that Apple can improve the implementation of these filters as new hardware becomes available, and users of MPS can avoid having to code them from scratch.

Download the sample project here.
Continue reading

First Look at MetalKit

MetalKit is a forthcoming framework on iOS 9 and OS X El Capitan that greatly eases certain tasks such as presenting Metal content in a UIView or NSView, texture loading, and working with model data.

This post is an overview of the features offered by MetalKit. Many of our articles so far have focused on details that are not expressly related to Metal, but are instead required to give Metal something to draw on the screen: texture loading, 3D model loading, and setting up the interface between Metal and UIKit.

MetalKit seeks to make these tasks easier by providing classes that perform common operations. In this article, we’ll look briefly at these capabilities.
Continue reading

Compressed Texture Formats in Metal

In this article, we will consider several GPU-friendly compressed texture formats. These formats allow us to trade some image quality for substantial improvements in disk usage and performance. In particular, we will look at the ETC2, PVRTC, and ASTC formats.

The sample app showcases a variety of compressed texture formats

The sample app showcases a variety of compressed texture formats

Continue reading

Rendering Text in Metal with Signed-Distance Fields

In this article, we will discuss a method for rendering high-fidelity text with Metal. It’s easy to overlook text rendering when thinking about 3D graphics. However, very few games or applications can get by without displaying any text, so it’s important to consider how we can best use the GPU to incorporate text into our Metal apps.

Text rendered by the sample app

Text rendered by the sample app, using the signed-distance field technique

Continue reading

Translucency and Transparency in Metal


One of the topics we’ve handily avoided so far in our exploration of Metal is rendering of materials that are not opaque. In this post, we’ll explore a couple of related techniques for achieving transparency and translucency: alpha testing and alpha blending.

The sample scene for this post is a desert containing many palm trees and a few pools of water. The leaves of the palm trees consist of a few polygons each, textured with a partially-transparent texture, and the water is rendered as a translucent surface via alpha blending, which we’ll discuss in detail below.

The sample application from this article demonstrates alpha testing and alpha blending

The sample application from this article demonstrates alpha testing and alpha blending

Continue reading

Video: An Introduction to 3D Graphics with Metal in Swift

In November 2014, I was privileged to deliver a talk to San Francisco’s Swift Language User Group, hosted by Realm. They’ve now uploaded the video, with subtitles and synchronized slide deck to their site. You can view the video here.

Speaking at Realm, November 4, 2014 (Photo credit: Scott Stevenson)

Speaking at Realm, November 4, 2014 (Photo credit: Scott Stevenson)

Mipmapping and the Blit Command Encoder

In this article we will learn about mipmapping, an important technique for rendering textured objects at a distance. We will find out why mipmapping is important, how it complements regular texture filtering, and how to use the blit command encoder to generate mipmaps efficiently on the GPU.

The sample app illustrates the effect of various mipmapping filters

The sample app illustrates the effect of various mipmapping filters. The mipmap used here is artificially colored for demonstration purposes.

Continue reading

Instanced Rendering in Metal

In this article, we will discuss an important technique for efficiently drawing many objects with a single draw call: instanced rendering. This technique helps you get the most out of the GPU while keeping memory and CPU usage to a minimum.

The sample app for this post renders several dozen animated cows moving on top of a randomly-generated terrain patch. Each cow has its own position, orientation, and movement direction, all of which are updated every frame. We do all of this drawing with only two draw calls. The app consumes only a few percent of the CPU, but maxes out the GPU, drawing over 240,000 triangles per frame. Even with this large load, the device manages to render at an ideal 60 frames per second.

Dozens of animated characters can be drawn efficiently with instanced rendering.

Dozens of animated characters can be drawn efficiently with instanced rendering. (Grass texture provided by Simon Murray of

Continue reading

Cubic Environment Mapping in Metal: Reflection and Refraction

In this post, we’ll talk about some of the more advanced features of texturing in Metal. We’ll apply a cube map to a skybox to simulate a detailed environment surrounding the scene. We’ll also introduce a technique called cubic environment mapping to simulate reflection and refraction, to further enhance the realism of our virtual world.

The environment map reflected off a torus knot

The environment map reflected off a torus knot. Textures courtesy of Emil Persson (

Continue reading