MetalByTutorials/04-3d-transforms
daemyung jang 61e982026b Fix a typo 2021-11-30 23:30:23 +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
resources Copy source code from the official website 2021-04-15 11:39:00 +09:00
starter Fix a runtime error 2021-04-22 12:25:45 +09:00
README.md Fix a typo 2021-11-30 23:30:23 +09:00

README.md

Chapter 4: The Rendering Pipeline

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.

Matrices on the GPU

  • Vertices are translated by the matrix now. Also you can notice that an original buffer and transformed buffer have same vertices information. So we just need one buffer. We can change the source code like below.
var matrix = matrix_identity_float4x4
let originalBuffer = device.makeBuffer(bytes: &vertices, length: MemoryLayout<float3>.stride * vertices.count, options: [])
renderEncoder.setVertexBuffer(originalBuffer, offset: 0, index: 0)
renderEncoder.setVertexBytes(&matrix, length: MemoryLayout<float4x4>.stride, index: 1)
renderEncoder.setFragmentBytes(&lightGrayColor, length: MemoryLayout<float4>.stride, index: 0)
renderEncoder.drawPrimitives(type: .point, vertexStart: 0, vertexCount: vertices.count)
renderEncoder.setVertexBytes(&matrix, length: MemoryLayout<float4x4>.stride, index: 1)
// var transformedBuffer = device.makeBuffer(bytes: &vertices, length: MemoryLayout<float3>.stride * vertices.count, options: [])
// renderEncoder.setVertexBuffer(transformedBuffer, offset: 0, index: 0)
matrix.columns.3 = [0.3, -0.4, 0, 1]
renderEncoder.setVertexBytes(&matrix, length: MemoryLayout<float4x4>.stride, index: 1)
renderEncoder.setFragmentBytes(&redColor, length: MemoryLayout<float4>.stride, index: 0)
renderEncoder.drawPrimitives(type: .point, vertexStart: 0, vertexCount: vertices.count)

Rotation

  • This book mentioned that each vertex rotates around the world origin. I think it's wrong and it's better that each vertex rotate the object origin. The object origin is the center of the object.