Compare commits

...

2 Commits

Author SHA1 Message Date
daemyung jang 6e21d3a9e9
Summerize Chapter 18: Rendering with Rays 2022-04-04 00:46:17 +09:00
daemyung jang ae0cf5ed91
Fix runtime errors 2022-04-03 21:56:43 +09:00
6 changed files with 85 additions and 12 deletions

View File

@ -0,0 +1,80 @@
# Chapter 18: Rendering with Rays
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.
## Signed distance functions
There is a runtime error in because Shaders.metal files isn't included in the bundle. But we have the default library.
In Renderer.swift, in initializeMetal(), replace this:
```
guard let path = Bundle.main.path(forResource: "Shaders", ofType: "metal") else { fatalError() }
let input = try String(contentsOfFile: path, encoding: String.Encoding.utf8)
let library = try device.makeLibrary(source: input, options: nil)
```
With:
```
let library = device.makeDefaultLibrary()!
```
## The raymarching algorithm
There is a runtime error in because Shaders.metal files isn't included in the bundle. But we have the default library.
In Renderer.swift, in initializeMetal(), replace this:
```
guard let path = Bundle.main.path(forResource: "Shaders", ofType: "metal") else { fatalError() }
let input = try String(contentsOfFile: path, encoding: String.Encoding.utf8)
let library = try device.makeLibrary(source: input, options: nil)
```
With:
```
let library = device.makeDefaultLibrary()!
```
## Creating random noise
There is a runtime error in because Shaders.metal files isn't included in the bundle. But we have the default library.
In Renderer.swift, in initializeMetal(), remove this:
```
let path = Bundle.main.path(forResource: "Shaders", ofType: "metal")
```
Replace this:
```
let input = try String(contentsOfFile: path!, encoding: String.Encoding.utf8)
let library = try device!.makeLibrary(source: input, options: nil)
```
With:
```
let library = device.makeDefaultLibrary()!
```
## Marching clouds
There is a runtime error in because Shaders.metal files isn't included in the bundle. But we have the default library.
In Renderer.swift, in initializeMetal(), replace this:
```
guard let path = Bundle.main.path(forResource: "Shaders", ofType: "metal") else { fatalError() }
let input = try String(contentsOfFile: path, encoding: String.Encoding.utf8)
let library = try device.makeLibrary(source: input, options: nil)
```
With:
```
let library = device.makeDefaultLibrary()!
```

View File

@ -16,9 +16,7 @@ public class Renderer: NSObject, MTKViewDelegate {
device = MTLCreateSystemDefaultDevice()
queue = device!.makeCommandQueue()
do {
guard let path = Bundle.main.path(forResource: "Shaders", ofType: "metal") else { fatalError() }
let input = try String(contentsOfFile: path, encoding: String.Encoding.utf8)
let library = try device.makeLibrary(source: input, options: nil)
let library = device.makeDefaultLibrary()!
guard let kernel = library.makeFunction(name: "compute") else { fatalError() }
pipelineState = try device.makeComputePipelineState(function: kernel)
} catch {

View File

@ -17,9 +17,7 @@ public class Renderer: NSObject, MTKViewDelegate {
device = MTLCreateSystemDefaultDevice()
queue = device!.makeCommandQueue()
do {
guard let path = Bundle.main.path(forResource: "Shaders", ofType: "metal") else { fatalError() }
let input = try String(contentsOfFile: path, encoding: String.Encoding.utf8)
let library = try device.makeLibrary(source: input, options: nil)
let library = device.makeDefaultLibrary()!
guard let kernel = library.makeFunction(name: "compute") else { fatalError() }
pipelineState = try device.makeComputePipelineState(function: kernel)
} catch {

View File

@ -17,10 +17,8 @@ public class Renderer: NSObject, MTKViewDelegate {
func initializeMetal() {
device = MTLCreateSystemDefaultDevice()
queue = device!.makeCommandQueue()
let path = Bundle.main.path(forResource: "Shaders", ofType: "metal")
do {
let input = try String(contentsOfFile: path!, encoding: String.Encoding.utf8)
let library = try device!.makeLibrary(source: input, options: nil)
let library = device.makeDefaultLibrary()!
let kernel = library.makeFunction(name: "compute")!
pipelineState = try device!.makeComputePipelineState(function: kernel)
} catch {

View File

@ -17,9 +17,7 @@ public class Renderer: NSObject, MTKViewDelegate {
device = MTLCreateSystemDefaultDevice()
queue = device!.makeCommandQueue()
do {
guard let path = Bundle.main.path(forResource: "Shaders", ofType: "metal") else { fatalError() }
let input = try String(contentsOfFile: path, encoding: String.Encoding.utf8)
let library = try device.makeLibrary(source: input, options: nil)
let library = device.makeDefaultLibrary()!
guard let kernel = library.makeFunction(name: "compute") else { fatalError() }
pipelineState = try device.makeComputePipelineState(function: kernel)
} catch {

View File

@ -31,6 +31,7 @@ You can see color images in this book at [here](https://www.raywenderlich.com/bo
* [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)
* [Chapter 18: Rendering with Rays](https://github.com/daemyung/metal-by-tutorials/tree/main/18-rendering-with-rays)
## Copyright