diff --git a/04-3d-transforms/README.md b/04-3d-transforms/README.md new file mode 100644 index 0000000..dd9e433 --- /dev/null +++ b/04-3d-transforms/README.md @@ -0,0 +1,27 @@ +# Chapter 3: 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.stride * vertices.count, options: []) +renderEncoder.setVertexBuffer(originalBuffer, offset: 0, index: 0) +renderEncoder.setVertexBytes(&matrix, length: MemoryLayout.stride, index: 1) +renderEncoder.setFragmentBytes(&lightGrayColor, length: MemoryLayout.stride, index: 0) +renderEncoder.drawPrimitives(type: .point, vertexStart: 0, vertexCount: vertices.count) +renderEncoder.setVertexBytes(&matrix, length: MemoryLayout.stride, index: 1) +// var transformedBuffer = device.makeBuffer(bytes: &vertices, length: MemoryLayout.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.stride, index: 1) +renderEncoder.setFragmentBytes(&redColor, length: MemoryLayout.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. \ No newline at end of file diff --git a/README.md b/README.md index 577307b..90ca816 100644 --- a/README.md +++ b/README.md @@ -15,6 +15,7 @@ You can also download the source code from [here](https://store.raywenderlich.co * [Chapter 1: Hello, Metal!](https://github.com/daemyung/MetalByTutorials/tree/main/01-introduction-to-metal) * [Chapter 2: 3D Models](https://github.com/daemyung/MetalByTutorials/tree/main/02-3d-models) * [Chapter 3: The Rendering Pipeline](https://github.com/daemyung/MetalByTutorials/tree/main/03-rendering-pipeline) + * [Chapter 4: Coordinate Spaces](https://github.com/daemyung/MetalByTutorials/tree/main/04-3d-transforms) ## Copyright