diff --git a/Roman Gaditskii/MetalBuilder fire.swiftpm.zip b/Roman Gaditskii/MetalBuilder fire.swiftpm.zip new file mode 100644 index 0000000..8b78bae Binary files /dev/null and b/Roman Gaditskii/MetalBuilder fire.swiftpm.zip differ diff --git a/Roman Gaditskii/Readme.md b/Roman Gaditskii/Readme.md new file mode 100644 index 0000000..1c517bb --- /dev/null +++ b/Roman Gaditskii/Readme.md @@ -0,0 +1,26 @@ + +Hi! Here's my submission. +I made it on my iPad in Swift Playgrounds app. + +Though it's not pure SwiftUI and contains some Metal code, it is integrated into SwiftUI view and uses declarative approach for dispatching shaders. +I use my own open source package 'MetalBuilder' for this. +It's a wrapper that alllows to manage Metal objects in a functional manner mimicking SwiftUI. E.g., buffers and textures are created using property wrappers like this: +``` +@MetalBuffer(count: particlesCount, metalName: "particles") var particlesBuffer +@MetalTexture(textureDescriptor + .pixelFormat(.rgba16Float)) var texture +``` +The Metal view is created just like any other SwiftUI view and takes a resultBuilder closure that describes shader dispatch like this: +``` +Compute("integration") + .buffer(particlesBuffer, space: "device", + fitThreads: true) +Render(vertex: "vertexShader", fragment: "fragmentShader", + type: .point, count: particlesCount) + .vertexBuf(particlesBuffer) + .vertexBytes(context.$viewportSize) + .fragBytes($flameType, name: "type") + .toTexture(renderTexture) +``` +As you can see, the wrapper can take Binding as a shader parameter. +Along with it you can pass a name of the metal property that the binded Swift property would represent in shader code, allowing MetalBuilder to generate automatically most of the declarations of the shader function at the time the view loads. This considerably reduces the amount of Metal code that should be written and makes Metal much more simple to use with SwiftUI, making it approachable even for beginners. diff --git a/Roman Gaditskii/fire.mov b/Roman Gaditskii/fire.mov new file mode 100644 index 0000000..0576942 Binary files /dev/null and b/Roman Gaditskii/fire.mov differ