-
Notifications
You must be signed in to change notification settings - Fork 0
Home
BasicSurfaces serves as a proof-of-concept of using Apple's Metal to render 3D scenes inside a SwiftUI View. This allows for, among other things:
- use of, and interaction with, Metal render pipelines inside XCode Previews, and
- coordination between SwiftUI elements – such as
Buttons,Gestures, other – and Metal render pipelines.
This is made possible by the use of MetalUI, which, in short, uses a UIViewRepresentable (NSViewRepresentable for macOS) – itself a View – to wrap an MTKView; in other words, MetalKit is integrated with SwiftUI via MetalUI's MetalView, a UIViewRepresentable. MetalUI's MetalPresenting protocol inherits from MTKView while MetalRendering protocol inherits from MTKViewDelegate.
One could use MetalUI for 2D graphics (or possibly something else), but SwiftUI already has good 2D support (see e.g. Shapes, Drawing and Graphics). Also, for VisionOS, Apple provides 3D options (see Shapes, Drawing and graphics). As can be seen in the second constructor in Sphere.swift, MetalKit alone is sufficient for setting up compute passes (calling kernel shaders). So, at least to me, the most appealing application of MetalUI is 3D graphics. Hence BasicSurfaces.
- Metal Shading Language Specification
- Metal Best Practices Guide, this link may or may not work, but said link was found from the MSL Spec
- Metal by Example
(wiki is wip, will be extended soon)