Summerize Chapter 22: Integrating SpriteKit & SceneKit
This commit is contained in:
parent
9d6a5e19fe
commit
c1179f41e3
|
|
@ -0,0 +1,42 @@
|
|||
# Chapter 22: Integrating SpriteKit & SceneKit
|
||||
|
||||
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.
|
||||
|
||||
## The fwidth function
|
||||
|
||||
fwidth() is equivalent to:
|
||||
|
||||
```
|
||||
abs(dfdx(p)) + abs(dfdy(p))
|
||||
```
|
||||
|
||||
The camera position is defined by the constant value in the fragment shader. It's not good because the camera position can be changed.
|
||||
|
||||
In Shaders.metal, in shipFragment(), replace:
|
||||
|
||||
```
|
||||
float3 v = normalize(float3(0, 0, 10)); // camera position
|
||||
```
|
||||
|
||||
With:
|
||||
|
||||
```
|
||||
float3 v = normalize(cameraPosition);
|
||||
```
|
||||
|
||||
Add the float3 as a parameter to the fragment function:
|
||||
|
||||
```
|
||||
constant float3 &cameraPosition
|
||||
```
|
||||
|
||||
In GameViewController.swift, in the conditional block where you set up the material, add this:
|
||||
|
||||
```
|
||||
let cameraPosition = cameraNode.position
|
||||
material.setValue(cameraPosition, forKey: "cameraPosition")
|
||||
```
|
||||
|
||||
step() generates a step function by comparing x to edge:
|
||||
|
||||

|
||||
Binary file not shown.
|
After Width: | Height: | Size: 57 KiB |
|
|
@ -35,6 +35,7 @@ You can see color images in this book at [here](https://www.raywenderlich.com/bo
|
|||
* [Chapter 19: Advanced Shadows](https://github.com/daemyung/metal-by-tutorials/tree/main/19-shadows)
|
||||
* [Chapter 20: Advanced Lighting](https://github.com/daemyung/metal-by-tutorials/tree/main/20-advanced-lighting)
|
||||
* [Chapter 21: Metal Performance Shaders](https://github.com/daemyung/metal-by-tutorials/tree/main/21-metal-performance-shaders)
|
||||
* [Chapter 22: Integrating SpirteKit & SceneKit](https://github.com/daemyung/metal-by-tutorials/tree/main/22-integrating-spritekit-scenekit)
|
||||
|
||||
## Copyright
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue