Small update:
This is my current code:
import SwiftUI
@dynamicMemberLookup
enum MyShaderLibrary {
private static let library: ShaderLibrary = {
let shaderPath = Bundle.main.path(forResource: "Shaders", ofType: "metallib")
let shaderURL = URL(fileURLWithPath: shaderPath!)
let shaderData = try! Data(contentsOf: shaderURL)
let library = ShaderLibrary(data: shaderData)
return library
}()
static subscript(dynamicMember name: String) -> ShaderFunction {
let function = library[dynamicMember: name]
print(function) // Important!
return function
}
}
And I have a passthrough Metal shader:
[[ stitchable ]]
half4 passthrough(float2 position, half4 color) {
return color;
}
When my SwiftUI view calls the shader with:
View()
.colorEffect(MyShaderLibrary.passthrough())
the print function shown above correctly prints this:
ShaderFunction(library: SwiftUI.ShaderLibrary(rbLibrary: <RBShaderLibrary: 0x60000000cf80>), name: "passthrough")
Which tells me that the shader library is being loaded correctly? What else could be going wrong? The code doesn't seem to crash when initializing the ShaderLibrary, but rather, when trying to render the shader?
Topic:
UI Frameworks
SubTopic:
SwiftUI
Tags: