MetalByTutorials/22-integrating-spritekit-sc...
daemyung jang c1179f41e3
Summerize Chapter 22: Integrating SpriteKit & SceneKit
2022-04-14 08:12:50 +09:00
..
challenge/CarGame Copy source code from the official website 2021-04-15 11:39:00 +09:00
final Copy source code from the official website 2021-04-15 11:39:00 +09:00
projects Copy source code from the official website 2021-04-15 11:39:00 +09:00
starter Copy source code from the official website 2021-04-15 11:39:00 +09:00
README.md Summerize Chapter 22: Integrating SpriteKit & SceneKit 2022-04-14 08:12:50 +09:00
references.markdown Copy source code from the official website 2021-04-15 11:39:00 +09:00
step-function.png Summerize Chapter 22: Integrating SpriteKit & SceneKit 2022-04-14 08:12:50 +09:00

README.md

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: