Lingheng Tony Tao

Writing · 22 parts

Metal

Building a renderer on Apple's Metal API, one stage at a time: from the first MTKView to deferred shading, tessellation and hardware ray tracing.

  1. 0Metal #0 Swift ReviewThe Swift you need before the first triangle: declarations, optionals, closures, protocols and the value/reference split.April 29, 2024
  2. 1Metal #1 InitializationThe smallest complete Metal application: MTKView, device, command queue, and the four steps every Metal frame goes through.April 30, 2024
  3. 2Metal #2 Rendering PipelinePipeline state, vertex descriptors and the render command encoder — how geometry actually reaches the screen in Metal.May 11, 2024
  4. 3Metal #3 Vertex FunctionThe vertex function: vertex descriptors, attribute binding, the three ways to pass uniforms, and why the MVP transform belongs here.May 18, 2024
  5. 4Metal #4 Fragment FunctionThe fragment function: interpolation qualifiers, depth and blending, multiple render targets, and why the quad is the GPU's real unit of work.May 25, 2024
  6. 5Metal #5 TextureTextures: loading and pixel formats, samplers and address modes, mipmaps and anisotropy, and why sRGB has to be left to the hardware.June 1, 2024
  7. 6Metal #6 NavigationCameras and interaction: what the view matrix really is, perspective versus orthographic, Metal's [0,1] depth convention, and a usable orbit camera.June 15, 2024
  8. 7Metal #7 LightingLighting: Phong and Blinn-Phong, the three light types, attenuation models, and where the multi-light loop should live.June 29, 2024
  9. 8Metal #8 MaterialsMaterials: from Phong parameters to the metallic-roughness PBR workflow, normal maps and TBN, and what each Cook-Torrance term computes.July 13, 2024
  10. 9Metal #9 Render PassesRender passes: why load and store actions are the most important switches on a TBDR GPU, offscreen targets, MTLHeap, and how a frame is organized.July 27, 2024
  11. 10Metal #10 ShadowShadow mapping: the depth pass, the shadow matrix, where acne and Peter Panning come from and how to fix them, PCF and cascades.August 10, 2024
  12. 11Metal #11 Deferred RenderingDeferred rendering: laying out and compressing the G-Buffer, the lighting pass, and single-pass deferred using tile memory on Apple Silicon.August 24, 2024
  13. 12Metal #12 Particle SystemParticle systems: simulating in a compute shader, emission and recycling on the GPU, instanced rendering, and the sorting problem.September 7, 2024
  14. 13Metal #13 TessellationTessellation: Metal's unusual compute-driven factor stage, displacement mapping and terrain LOD, and where cracks come from.September 21, 2024
  15. 14Metal #14 Post-processingPost-processing: HDR and tone mapping, bloom, SSAO sampling strategy, and why the post chain should be compute rather than fullscreen triangles.October 12, 2024
  16. 15Metal #15 Reflection and RefractionReflection and refraction: cube maps and IBL, planar reflections, how screen-space reflection works and how it necessarily fails, refraction and dispersion.October 26, 2024
  17. 16Metal #16 AnimationAnimation: interpolating transforms with quaternions, the skinning matrix palette, two ways to skin on the GPU, and when keyframes belong in compute.November 9, 2024
  18. 17Metal #17 Ray Tracing (I) Rendering AlgorithmRay tracing part one: the rendering equation, Monte Carlo estimation and importance sampling, plus Metal's acceleration structures and intersector API.November 23, 2024
  19. 18Metal #18 Ray Tracing (II) Shadows and LightingRay tracing part two: shadow rays and soft shadows, next event estimation, the path tracing loop and Russian roulette, and hybrid pipelines.December 7, 2024
  20. 19Metal #19 Ray Tracing (III) Performance OptimizationRay tracing part three: ray divergence and wavefront reordering, acceleration structure build strategy, sampling sequences, and finding the bottleneck with a GPU capture.December 21, 2024
  21. 21Metal #21 [Appendix] Compute ShadersUsing the GPU for work that is not drawing: kernel functions, threadgroups, and how to size a dispatch correctly.September 14, 2024
  22. 22Metal #22 [Appendix] Metal in SwiftUISwiftUI's shader modifiers let Metal Shading Language reach ordinary views. How the bridge works, and where it stops.September 30, 2024