Summerize Chapter 5: Lighting Fundamentals

This commit is contained in:
daemyung jang 2021-12-03 16:28:17 +09:00
parent 61e982026b
commit f15fb0e017
3 changed files with 23 additions and 0 deletions

View File

@ -0,0 +1,22 @@
# Chapter 5: Lighting Fundamentals
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.
## Hemispheric lighting
* It's not make sense at all because the normal vector is in the object space. This book mentioned that `if the normals face up, they'll be blue; if they face down, they'll be green` but even you rotate the train to change the normals face up, the color never be changed. I guess it's showing the power of the fragment shader to you so it will be enough to understand that the fragment shader can define final colors. If you want to see the color is changed when you rotate the train, add below code before return in the vertex shader.
```
out.normal = (uniforms.viewMatrix * uniforms.modelMatrix * float4(vertexIn.normal, 0.0)).xyz;
```
![](./hemispheric-lighting.png)
## Diffuse reflection
* This book says that `if you scale an object in one direction (non-linearly), then the normals fo the object are no longer orthogonal and this approach won't work`. Yes it's very correct and you can fix this issue very easily. The normal matrix is that the inversed transposed model matrix. You can read more detail at [here](https://paroj.github.io/gltut/Illumination/Tut09%20Normal%20Transformation.html). Also this sample code already has the implementation to calculate the normal matrix. You can easily get the normal matrix like below.
```
// uniforms.normalMatrix = uniforms.modelMatrix.upperLeft
uniforms.normalMatrix = float3x3(normalFrom4x4: uniforms.modelMatrix)
```

Binary file not shown.

After

Width:  |  Height:  |  Size: 216 KiB

View File

@ -16,6 +16,7 @@ You can also download the source code from [here](https://store.raywenderlich.co
* [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)
* [Chapter 5: Lighting Fundamentals](https://github.com/daemyung/MetalByTutorials/tree/main/05-lighting-fundamentals)
## Copyright