WWDC23 introduces lots of new additions to SwiftUI, notably Metal shader support with these modifiers
- colorEffect: Returns a new view that applies shader to self as a filter effect on the color of each pixel.
- layerEffect: Returns a new view that applies shader to self as a filter on the raster layer created from self.
- distortionEffect: Returns a new view that applies shader to self as a geometric distortion effect on the location of each pixel.
So you can create effects like these
New in #SwiftUI for iOS 17, you can use Metal Shader for effects 🧙 #WWDC23 #iosdev— Khoa 🔥 (@onmyway133) June 10, 2023
There are layerEffect, colorEffect and distortionEffect to apply Shader on raster layer, filter effect and geometric distortion effect.
Now what's left is to learn Metal Shader. Here I wrote… pic.twitter.com/byUSW0EuqX
Before we could also use Metal with SwiftUI by wrapping
SpriteView with shader, so learning a bit about Metal helps a long way
Here are the resources I’ve found to be very useful
Shader Toy is a shader community where people share very creative and interesting shader effects in OpenGL. OpenGL and Metal language are somewhat similar so you can read and understand the logic
Great book by Warren Moore, who worked on camera and photo apps at Apple. As of March 2023 you can download the book for free on this site.
Warren also has a very nice 30 days of Metal tutorials that we can follow along the basics like device, buffer and texture.
A playground for shading languages.
You can compile HLSL and GLSL using fxc.exe, dxc.exe, glslangValidator.exe, spirv-cross.exe, and mali-sc.exe. You can see the compiler output and disassembly. You can chain multiple shader compilers together to transpile one language to another. You can share permalinks to shaders
Gentle step-by-step guide through the abstract and complex universe of Fragment Shaders, by Patricio Gonzalez Vivo
Resource and links from Apple how to best use Metal in apps and games.
Get introduced to the architecture and feature set of Metal and learn a step-by-step approach for transitioning OpenGL-based apps to the Metal API
Whether you’re new to Metal or trying to port code from OpenGL, understanding the Metal language is essential. In this spec you’ll learn about primitive types like float, float4, float4x4
In Metal you can access vector component in a very convenient way.
A Youtube playlist on how to use Metal from easy to advanced features.
Great tutorials by Eugene on how to use Metal compute and kernel shader to apply cool effects to texture