diff --git a/22-integrating-spritekit-scenekit/README.md b/22-integrating-spritekit-scenekit/README.md new file mode 100644 index 0000000..d37c24d --- /dev/null +++ b/22-integrating-spritekit-scenekit/README.md @@ -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: + +![](./step-function.png) diff --git a/22-integrating-spritekit-scenekit/step-function.png b/22-integrating-spritekit-scenekit/step-function.png new file mode 100644 index 0000000..c90bb34 Binary files /dev/null and b/22-integrating-spritekit-scenekit/step-function.png differ diff --git a/README.md b/README.md index d492018..847beae 100644 --- a/README.md +++ b/README.md @@ -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