Summerize Chapter 6: Textures

This commit is contained in:
daemyung jang 2021-12-17 20:50:36 +09:00
parent f15fb0e017
commit 52755cc253
11 changed files with 115 additions and 0 deletions

19
06-textures/README.md Normal file
View File

@ -0,0 +1,19 @@
# Chapter 6: Textures
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.
## sRGB color space
* Actually we can't do math on non-linear space because `1 + 1 != 2` in non-linear space. Let's explain a reason in detail.
![](./gamma-correction-gamma-curves.png)
Data in the reality are in linear space and those are encoded non-linear space because the limitation of memory.
It made sRGB color format that compromised between how cathode ray tube monitors worked and what colors the human eye sees.
Let's think about that you are calculating `0.5 + 0.5` and the result must be `1.0`. However `0.5` is in non-linear space
so it is `0.729` in linear space. So `0.5 + 0.5` in non-linear space equals to `0.729 + 0.729` so the result is `1.458` not `1.0`.
Thus when you do the math, you must check values are in linear space.
* If texture's format is sRGB then OpenGL, Vulkan and DirectX convert from non-linear space to linear space automatically
when you fetch a texel with a sampler. However Metal don't do that. This book give a code how to convert from non-linear space to linear space.
But the code is not compiled when you copy. Try this code `baseColor = pow(baseColor, 1.0 / 2.2);`. You can do the gamma correction by yourself.

Binary file not shown.

After

Width:  |  Height:  |  Size: 61 KiB

View File

@ -0,0 +1,33 @@
//
/**
* Copyright (c) 2019 Razeware LLC
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* Notwithstanding the foregoing, you may not use, copy, modify, merge, publish,
* distribute, sublicense, create a derivative work, and/or sell copies of the
* Software in any work that is designed, intended, or marketed for pedagogical or
* instructional purposes related to programming, coding, application development,
* or information technology. Permission for such use, copying, modification,
* merger, publication, distribution, sublicensing, creation of derivative works,
* or sale is expressly withheld.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
import Foundation

View File

@ -0,0 +1,6 @@
{
"info" : {
"author" : "xcode",
"version" : 1
}
}

View File

@ -0,0 +1,16 @@
{
"info" : {
"author" : "xcode",
"version" : 1
},
"properties" : {
"interpretation" : "data"
},
"textures" : [
{
"filename" : "Universal.mipmapset",
"idiom" : "universal",
"pixel-format" : "astc-8x8"
}
]
}

View File

@ -0,0 +1,12 @@
{
"info" : {
"author" : "xcode",
"version" : 1
},
"levels" : [
{
"filename" : "lowpoly-barn-color.png",
"mipmap-level" : "base"
}
]
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 867 KiB

View File

@ -0,0 +1,16 @@
{
"info" : {
"author" : "xcode",
"version" : 1
},
"properties" : {
"interpretation" : "data"
},
"textures" : [
{
"filename" : "Universal.mipmapset",
"idiom" : "universal",
"pixel-format" : "astc-8x8"
}
]
}

View File

@ -0,0 +1,12 @@
{
"info" : {
"author" : "xcode",
"version" : 1
},
"levels" : [
{
"filename" : "barn-ground.png",
"mipmap-level" : "base"
}
]
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.7 MiB

View File

@ -17,6 +17,7 @@ You can also download the source code from [here](https://store.raywenderlich.co
* [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)
* [Chapter 6: Textures](https://github.com/daemyung/MetalByTutorials/tree/main/06-textures)
## Copyright