Summerize Chapter 16: Particle Systems

This commit is contained in:
daemyung jang 2022-04-01 17:02:16 +09:00
parent ace2b37857
commit 1bc5abb4b0
No known key found for this signature in database
GPG Key ID: 44160C9958A9C67B
2 changed files with 46 additions and 0 deletions

View File

@ -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
}
```

View File

@ -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