I'm new to the 3D rendering with Metal and SceneKit. I see that there is a specific "inverse" transform required to be passed to the renderer / shader. I printed out the transforms, and see no relationship between them. Google search results in a bunch of rather advanced topics.
So I ask a question for dummies, like myself:
What is the meaning of "inverse" view transform for shaders?
What happens if I don't inverse the transform?
// Apple code below (with original comment):
// Pass view-appropriate image transform to the shader modifier so
// that the mapped video lines up correctly with the background video.
let sceneView = renderer as? ARSCNView,
let frame = sceneView.session.currentFrame
let affineTransform = frame.displayTransform(for: .portrait, viewportSize: self.view.bounds.size)
let transform = SCNMatrix4(affineTransform)
let inverse = SCNMatrix4Invert(transform) // pass to shader
transform:
SCNMatrix4(
m11: 0.0, m12: 1.0, m13: 0.0, m14: 0.0,
m21: -1.5227804, m22: 0.0, m23: 0.0, m24: 0.0,
m31: 0.0, m32: 0.0, m33: 1.0, m34: 0.0,
m41: 1.2613902, m42: -0.0, m43: 0.0, m44: 1.0)
----
inversed:
SCNMatrix4(
m11: 0.0, m12: -0.6566935, m13: 0.0, m14: 0.0,
m21: 1.0, m22: 0.0, m23: 0.0, m24: 0.0,
m31: 0.0, m32: 0.0, m33: 1.0, m34: 0.0,
m41: 0.0, m42: 0.8283468, m43: 0.0, m44: 1.0)
Here's some info which suggests that the matrices above are a composite of translation, rotation and scaling. While CGAffine transform splits those into distinct elements, here they are all clamped together:
https://www.javatpoint.com/computer-graphics-3d-inverse-transformations