onmyway133 / blog

🍁 What you don't know is what you haven't learned
https://onmyway133.com/
MIT License
669 stars 33 forks source link

Learning Metal for SwiftUI #919

Open onmyway133 opened 1 year ago

onmyway133 commented 1 year ago

WWDC23 introduces lots of new additions to SwiftUI, notably Metal shader support with these modifiers

So you can create effects like these

Before we could also use Metal with SwiftUI by wrapping `MTKView` in `UIViewRepresentable` or `SpriteView` with shader, so learning a bit about Metal helps a long way Here are the resources I've found to be very useful ### [ShaderToy](https://www.shadertoy.com/) 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 Screenshot 2023-06-16 at 10 37 03 ### [Metal by example](https://metalbyexample.com/the-book/) 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](https://medium.com/@warrenm) that we can follow along the basics like device, buffer and texture. ### [Shader Playground](https://shader-playground.timjones.io/) A playground for shading languages. Screenshot 2023-06-16 at 10 40 15 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 ### [The book of shaders](https://thebookofshaders.com/) Gentle step-by-step guide through the abstract and complex universe of Fragment Shaders, by [Patricio Gonzalez Vivo](http://patriciogonzalezvivo.com/) Screenshot 2023-06-16 at 10 40 49 ### [Accelerate graphics and much more with Metal](https://developer.apple.com/metal/) Resource and links from Apple how to best use Metal in apps and games. Screenshot 2023-06-16 at 10 43 22 There are [videos about Metal at WWDC](https://developer.apple.com/videos/all-videos/?q=Metal) Be sure to check out [Metal documentation](https://developer.apple.com/documentation/metal) for code examples and tutorial links. Screenshot 2023-06-16 at 10 50 34 ### [Bringing OpenGL Apps to Metal](https://developer.apple.com/videos/play/wwdc2019/611/) Screenshot 2023-06-16 at 11 03 21 > 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 ### [Metal shading language specification](https://developer.apple.com/metal/Metal-Shading-Language-Specification.pdf) 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. Screenshot 2023-06-16 at 10 46 17 ### [Metal with SwiftUI](https://www.youtube.com/playlist?list=PLn3eTxaOtL2MThB3r1Pz5Z-EQaqBi3dHt) A Youtube playlist on how to use Metal from easy to advanced features. Screenshot 2023-06-16 at 10 51 52 ### [Introduction to Metal Compute](https://eugenebokhan.io/introduction-to-metal-compute-part-one) Great tutorials by Eugene on how to use Metal compute and kernel shader to apply cool effects to texture Screenshot 2023-06-16 at 10 52 08