How iOS 12 Renders Lighting and Shadows on Memoji
Introduced in iOS 12, Memoji utilizes Apple’s advanced graphics frameworks to generate expressive, real-time 3D avatars. To achieve a stylized yet lifelike appearance, iOS 12 relies on a combination of SceneKit, the Metal graphics API, Physically Based Rendering (PBR), and dynamic light estimation. This article breaks down the underlying rendering techniques, lighting models, and shadow mechanisms that allow Memoji avatars to interact realistically with light during tracking and animation.
SceneKit and the Metal Graphics Pipeline
At the core of Memoji rendering is SceneKit, Apple’s high-level 3D graphics framework, operating directly on top of the low-overhead Metal API. When the TrueDepth camera captures facial geometry and expressions via ARKit blend shapes, SceneKit processes the 3D mesh at 60 frames per second. Metal executes optimized vertex and fragment shaders that compute real-time lighting calculations without taxing the CPU or draining battery life, ensuring smooth real-time performance in Messages and FaceTime.
Physically Based Rendering (PBR) Materials
iOS 12 applies Physically Based Rendering principles to the stylized Memoji assets. PBR models the interaction of light with surfaces based on real-world physics, defined by key texture maps:
- Albedo (Base Color): Defines the diffuse surface color of the skin, hair, and accessories without baked-in shadows.
- Roughness: Controls microfacet distribution. Lower roughness produces sharp, glossy specular highlights (such as on the eyes or metallic earring frames), while higher roughness creates diffuse, matte surfaces (such as skin and cloth).
- Metalness: Distinguishes dielectric materials (skin, fabric, plastic) from conductive materials (metal jewelry, glasses frames), dictating reflectivity and specular tint.
By utilizing PBR, a Memoji reacts consistently and predictably under changing virtual illumination conditions.
Dynamic Lighting and ARKit Light Estimation
Memoji lighting adapts depending on whether the avatar is rendered against a blank background (such as the sticker panel in Messages) or integrated into a live camera feed.
In standalone rendering, SceneKit establishes a virtual studio lighting setup. This setup consists of a directional primary key light to carve out facial contours, a subtle fill light to soften contrast, and an ambient light source to prevent total darkness in unlit areas.
When used inside camera applications or AR experiences, ARKit's light estimation comes into play. The system analyzes incoming camera sensor data to estimate the ambient intensity and color temperature of the real-world environment. These values are mapped directly to the virtual lights in the scene, allowing a Memoji to reflect warm incandescent room lighting or cool outdoor daylight seamlessly.
Real-Time Shadow Mapping and Depth
Shadows give Memoji spatial grounding and prevent facial features from appearing flat:
- Shadow Mapping: Directional lights generate real-time shadow maps to project accurate, soft-edged drop shadows. For instance, the nose casts a directional shadow over the upper lip, the chin projects shadows onto the neck, and accessories like glasses or hats cast dynamic shadows onto the face.
- Ambient Occlusion: Screen-Space Ambient Occlusion (SSAO) and contact shadowing darken crevices and contact points where ambient light cannot easily reach. This creates natural depth around the nostrils, ear folds, eyelids, and beneath the hairline.
Specialized Shaders for Skin and Hair
To avoid a harsh, plastic look, iOS 12 applies custom shader approximations for biological surfaces:
- Subsurface Scattering Simulation: While full subsurface scattering (SSS) is computationally expensive, SceneKit employs an optimized wrap-around diffuse shader technique. This mimics the way light penetrates and scatters through semi-translucent human skin, giving Memoji faces a warm, soft finish rather than a rigid, opaque shell.
- Anisotropic Hair Shading: Memoji hair models utilize anisotropic specular highlights, stretching reflections perpendicular to the strand direction to capture dynamic sheen as the avatar turns and tilts.