diff --git a/16-particle-systems/README.md b/16-particle-systems/README.md new file mode 100644 index 0000000..625058a --- /dev/null +++ b/16-particle-systems/README.md @@ -0,0 +1,45 @@ +# Chapter 16: Particle Systems + +As I read this book, I summarize what I think is wrong. If you think my comments are wrong then please let me know. We can dicuss more and update your opinion. + +## Compute + +A metal shader file isn't included in the bundle so we can't read shader so the runtime error is happened. But a metal shader is compiled and saved as the default library. In Renderer.swift, in initializeMetal(), replace: + +``` +guard let device = MTLCreateSystemDefaultDevice(), + let commandQueue = device.makeCommandQueue(), + let path = Bundle.main.path(forResource: "Shaders", ofType:"metal") +else { return nil } + +let pipelineState: MTLComputePipelineState +do { + let input = try String(contentsOfFile: path, encoding: String.Encoding.utf8) + let library = try device.makeLibrary(source: input, options: nil) + guard let function = library.makeFunction(name: "compute") + else { return nil } + pipelineState = try device.makeComputePipelineState(function: function) +} catch { + print(error.localizedDescription) + return nil +} +``` + +With: + +``` +guard let device = MTLCreateSystemDefaultDevice(), + let commandQueue = device.makeCommandQueue() +else { return nil } + +let pipelineState: MTLComputePipelineState +do { + let library = device.makeDefaultLibrary()! + guard let function = library.makeFunction(name: "compute") + else { return nil } + pipelineState = try device.makeComputePipelineState(function: function) +} catch { + print(error.localizedDescription) + return nil +} +``` diff --git a/README.md b/README.md index d91eeaf..309012b 100644 --- a/README.md +++ b/README.md @@ -30,6 +30,7 @@ You can see color images in this book at [here](https://www.raywenderlich.com/bo * [Chapter 13: Instancing & Procedural Generation](https://github.com/daemyung/metal-by-tutorials/tree/main/13-procedural-generation) * [Chapter 14: Multipass & Deferred Rendering](https://github.com/daemyung/metal-by-tutorials/tree/main/14-multipass-rendering) * [Chapter 15: GPU-Driven Rendering](https://github.com/daemyung/metal-by-tutorials/tree/main/15-gpu-driven-rendering) + * [Chapter 16: Particle Systems](https://github.com/daemyung/metal-by-tutorials/tree/main/16-particle-systems) ## Copyright