diff --git a/13-procedural-generation/README.md b/13-procedural-generation/README.md new file mode 100644 index 0000000..94a595f --- /dev/null +++ b/13-procedural-generation/README.md @@ -0,0 +1,40 @@ +# Chapter 13: Instancing & Procedural Generation + +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. + +## Morphing + +Morphing which is explaned by this book isn't the cannonical way of morphing. Morphing is usually a morphable mesh where primitives’ attributes are obtained by adding the original attributes to a weighted sum of targets attributes. + +![](./morphing.png) + +For instance, the the position of vertices for the primitive at index i are computed in this way: + +``` +primitives[i].attributes.POSITION + + weights[0] * primitives[i].targets[0].POSITION + + weights[1] * primitives[i].targets[1].POSITION + + weights[2] * primitives[i].targets[2].POSITION + ... +``` + +Apple's animoji is the most famous example of morphing. + +![](./animoji.webp) + +## Miscalculation of the world position + +In Nature.metal and Houses.metal, the world position is calculated incorrectly, replace: + +``` +out.worldPosition = (uniforms.modelMatrix * vertexIn.position + * instance.modelMatrix).xyz; +``` + +With: + +``` +out.worldPosition = (uniforms.modelMatrix * instance.modelMatrix + * vertexIn.position).xyz; +``` + +The result isn't changed because the world position is not used anywhere. \ No newline at end of file diff --git a/13-procedural-generation/animoji.webp b/13-procedural-generation/animoji.webp new file mode 100644 index 0000000..91073be Binary files /dev/null and b/13-procedural-generation/animoji.webp differ diff --git a/13-procedural-generation/morphing.png b/13-procedural-generation/morphing.png new file mode 100644 index 0000000..b1919b3 Binary files /dev/null and b/13-procedural-generation/morphing.png differ diff --git a/README.md b/README.md index 38a4eb3..0a86f66 100644 --- a/README.md +++ b/README.md @@ -27,6 +27,7 @@ You can see color images in this book at [here](https://www.raywenderlich.com/bo * [Chapter 10: Fragment Post-Processing](https://github.com/daemyung/metal-by-tutorials/tree/main/10-trees-and-fog) * [Chapter 11: Tessellation & Terrains](https://github.com/daemyung/metal-by-tutorials/tree/main/11-tesselation-and-terrains) * [Chapter 12: Environment](https://github.com/daemyung/metal-by-tutorials/tree/main/12-environment) + * [Chapter 13: Instancing & Procedural Generation](https://github.com/daemyung/metal-by-tutorials/tree/main/13-procedural-generation) ## Copyright