== Diffuse Shading ==
? ?? 對表面顏色的控制
? ?? diffuse reflection,漫反射
-
Lambertian Shading Model
現實中大多數物件表面都是非光滑的("matte")

lambertian surface ?? 朗伯表面就是理想情況的漫反射表面,不考慮觀察角度的影響
A Lambertian surface for reflection is a surface that appears uniformly bright from all directions of view and reflects the entire incident light. Lambertian reflectance is the property exhibited by an ideal matte or diffusely reflecting surface.
https://www.azooptics.com/Article.aspx?ArticleID=790
-
Lambert's cosine law
基本定義:物體表面某點的顏色正比于其法向量與光照向量形成角度\(\theta\)?的余弦值\(cos\theta\)? ??
\(c \propto |cos\theta|\)? 用向量形式可以表達為 ?? \(1. \space c \propto max(0, \vec n·\vec l) \\ 2. \space c \propto |\vec n·\vec l|\)?
-
影響因素
- diffuse reflectance \(c_r\) ?? 根據顏色不同反射率也不同
- light intensity \(c_l\)??? 光照強度引起的顏色值變化,規范化到range[0,1]
-
基本形式 \(1. \space c \propto c_rc_lmax(0, \vec n·\vec l) \\ 2. \space c \propto c_rc_l|\vec n·\vec l|\)
- \(cos_\theta\) 小于0時理論上應該沒有顏色,但是代入等式\((2)\)得到存在顏色,因此\((2)\)描述的是一個兩側對稱光照的情況
-
-
Ambient Shading
\(c \propto max(0,\vec n·\vec l)\) 中存在一個明顯的問題,背光處均為黑色,但在實際中光到處反射,使得背光處不可能為完全的黑色,
因此等式中還需要加入環境光\(c_a\)? ?? \(c\propto c_r(c_a+c_lmax(0, \vec n·\vec l))\)?
?? 由于RGB range \([0,1]^3\) ,可能需要進行clamp處理
-
Vertex-Based Diffuse Shading
-
avoid faceted appearance

https://www.gia.edu/gems-gemology/optimizing-face-up-appearance-in-colored-gemstone-faceting
以triangle表面的法線向量(normal vector)來計算顏色值時,得到的顏色值會用于填充整個三角形面的每一個像素點,相鄰兩個三角形面如果顏色差異明顯,會出現faceted appearence的問題,
因此考慮將法線向量放到三角形的頂點上,計算出三角形各頂點的顏色值,再通過插值法得到整個三角形各像素點的顏色 ?? simpest way: just average the normals of triangles which shared that vertice.


http://benchung.com/basic-glsl-displacement-shader-three-js/
-
Surface Normal Vector Interpolation
interpolate vertex color and normal using barycentric coordinates\[\alpha = \frac{S_{cap}}{S_{abc}}\\ \beta = \frac{S_{abp}}{S_{abc}} \\ \theta = \frac{S_{bcp}}{S_{abc}} \]
- vertex color ?? \(c = \alpha c_0 + \beta c_1 + \gamma c_2\)
- vertex normal ?? \(c = \alpha \vec c_0 + \beta \vec n_1 + \gamma \vec c_2\)
-
== Phong Shading ==
? ?? 對高光顏色的控制
? matte surface也會有highlights存在,且高光并非是以表面材料的顏色為主,從材料表面反射的散射光對整體顏色影響不大
-
Phong Lighting Model

https://www.geertarien.com/blog/2017/08/30/blinn-phong-shading-using-webgl/
當視線與反射光的夾角\(\theta\)?? 小于一定值時,我們就會看到高光
可以得到等式 \(c = c_l(\vec v·\vec r)\)??
? ??v stands for view;當\(v = r\)時,反射光與視線重合,\(\vec v·\vec r = 1\) ?? \(c = c_l\)?
-
\(s\)??? Phong exponent
\(c = c_l(max(0,\vec v·\vec r))^s\)???????
?? s stands for specular,鑒于\(\vec v·\vec r\)得到的\(cos\theta\)值range[0,1],更大的Phong指數,會使得高光越小
The
sterm in the equation represents the roughness of the surface. A smooth surface, which should have a smaller highlight, has a larges. Since the cosine of the angle is a number on [0, 1], taking it to a power greater than 1.0 will make the number smaller. Therefore, a largesexponent will make for a small highlight.https://paroj.github.io/gltut/Illumination/Tut11 Phong Model.html
-
halfway vector 表達的等式
\(c = c_l(\vec h·\vec n)^s\)?
-
\(\vec h = \frac{\vec v + \vec l}{||\vec v + \vec l||}\)??
?? highlights appear when \(\vec h\) is near \(\vec n\)

https://www.geertarien.com/blog/2017/08/30/blinn-phong-shading-using-webgl/
?? \(\theta_{new} = \frac{\theta_{old}}{2}\),因此此處的\(s\) 也能和\(c = c_l(max(0,\vec v·\vec r))^s\)的\(s\)有相同的控制效果
-
-
實際使用中通常將Lambertian shading model和Phong Lighting Model中的兩個等式結合在一起
\[c = c_r(c_a + c_l max(0, \vec n · \vec l)) + c_l(\vec h · \vec n)^p \] -
再加入新的控制變數\(c_p\)用于控制高光的顏色
\[c = c_r(c_a + c_l max(0, \vec n · \vec l)) + c_lc_p(\vec h · \vec n)^p \]
-
== ?? ==
-
Fundamentals of Computer Graphics, Fourth Edition - Marschner Steve, Shirely Peter
-
https://developer.valvesoftware.com/wiki/Phong_materials
-
https://paroj.github.io/gltut/Illumination/Tut11 Phong Model.html
-
https://www.scratchapixel.com/lessons/3d-basic-rendering/ray-tracing-rendering-a-triangle/barycentric-coordinates
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/373798.html
標籤:其他
