Hi,
Love this book!
I just finished the section “Diffuse reflection” under “5.9 The dot product”, https://www.raywenderlich.com/books/metal-by-tutorials/v2.0/chapters/5-lighting-fundamentals#toc-chapter-008-anchor-009
I just created a MDLMesh sphere instead of the train.
Build and run, and I see this issue – it seems the sunlight is being rotated on the sphere… cool but not quite right since the sunlight is still as you can see with the yellow lines. What could be the issue here?
Movie here Movie
The sphere is animated like this:
var shaderUniforms = uniforms
rotation = [-(timer * 500).degreesToRadians, -(timer * 500).degreesToRadians, 0]
scale = float3(3 + sin(timer * 30) * 0.25)
shaderUniforms.modelMatrix *= modelMatrix
shaderUniforms.normalMatrix = modelMatrix.upperLeft
renderEncoder.setVertexBytes(&shaderUniforms, length:MemoryLayout<Uniforms>.stride, index:Indexes.uniforms.rawValue)