第八章 illumination and shading
DESCRIPTION
第八章 Illumination and Shading. Illumination and Shading( 照明與遮蔽 ). Rendering:The process of creating realistic graphic scenes from geometric data. ( 看起來像真實物體). Illumination Models:determining a surface ’ s color at a given point. 也可稱為 Shading Models. V:Viewing Direction - PowerPoint PPT PresentationTRANSCRIPT
1
第八章 Illumination and Shading
Illumination and Shading( 照明與遮蔽 )
Rendering : The process of creating realistic graphic scenes from geometric data. (看起來像真實物體)Illumination Models : determining a surface’s color at a given point.
也可稱為 Shading Models.
2
N
S
V
Camera
Light Source 2Light Source 1
V:Viewing Direction
N:Normal Vector of Surface
S:Direction of Light Source
3
Object
Object : Absorb( 吸收 )
Reflect( 反射 )
Transmit( 穿透 )
Light
Light emitting source 發光體源
Light reflecting source 反射光源
L
4
Light
Light sources
(X,Y,Z)
1.Point source
2.Distributed source
SSN
s
N
( Sx,Sy,Sz)
點光源
分佈、分散的光源
{ 平行方向亂射方向
5
Ambient Light( 周圍的光線 )特性:⊙ uniform illumination
⊙nondirectional source 沒有方向性
( 四面八方過來的光線 )
⊙multiple reflections from nearby surfaces由於附近的其他物體面,反射而造成。
一種無方向性,充滿在周圍的光源。
6
Illumination Equation
IaKaI
I :物體面上某一點的 Intensity (亮度)
Ia : Ambient light 的 Intensity
( constant for all objects )
ka : Ambient-reflection coefficient
( material property 物體性質)
( 0~1 )
7
V
N
L
Diffuse Reflection (漫反射、散反射)
( Lambertian Reflection 柔和光亮的反射)
⊙ 在粗糙表面上。
⊙ 物體面從所有方向看都一樣。
⊙ 一點的亮度由 角決定
角: angle between Light Source Direction and Surface Normal
8
N : Surface Normal
L : Direction of Light source
: angle between N and L
9
Diffuse Reflection( 光線在物體法向量方向的分量 )
I :物體面上一點的 Intensity (亮度)
Ip : Intensity of point light source
Kd : Material’s diffuse-reflection coefficient
每種材質不同( 0~1 )
完全吸光線 = 0
cosIpKdI
: angle between and N L
N
L
: Surface Normal ( unit vector ): Light Source Direction ( unit vector )
10
Lambert’s cosine Law
LN cos
LN
LN
LN
LNNL
cos
cos
cos
)( LNIpKdI NL
當光源假設為很遠時, 為固定方向。
→ 各點的 影響各點的亮度。L
N
11
Ip
L
12
Ambient Light + Diffuse Reflection
合成 2 光源
)( LNIpKdIaKaI 合成 Ambient Diffuse Reflection
13
計算一個 Surface 上各點 Pixel 的亮度
1.Surface 定義 → Pixels
2. 計算每一個 pixel 點位置,在幾何上的 Surface Normal
3. 決定 Light Source
4. 計算各點
5. 找到 Surface 的 Kd (與材質有關)
6. 決定 IP ( intensity and scolor )
7. 決定 I ( intensity and color )
N
L
)( LandNbetween
LN cos
14
Light – Source Attenuation (光線變淡) --衰減為了分出遠近,光線越遠應越淡。
物面上的亮度,越遠應越暗。
若相同 intensity 則無法分出遠近。
較遠者,其 intensity 應較暗才能分出遠近。
15
Light – Source Attenuation factor
IaKaI
fatt : attenuation factor
由 Light source 及 surface 之間距離決定。
fatt
)( LNIpKd
16
Attenuation Factor
2
1
Ld
fatt
dL : point Light Source 與 Surface 之間的距離。
但是 ,很近時變化很大。
,很遠時變化很小。
Ld 2
17
較複雜的表示法
fattmax
min),( 1
3211
2
LLdCdCC
3
2
1
C
C
C
User defined constant
C1 :當很近時, fatt 不致太大。
Max = 1 , fatt 最大 = 1
18
Colored Lights and Surfaces在一個 color model 中每一個 component 都是一個 Intensity Equation 。Diffuse Color ( OdR , OdG , OdB )材質色
red green blue
Illuminating Light ( IpR , IpG , IpB )燈光色
red green blueReflection 比例( KdOdR , Kd , OdG , KdOdB )
19
元素分別計算再合成
( 1 ) Red Component
)( LNKdOfattIKaOIIdRpRdRaRR
( 2 ) Gree Component
( 3 ) Blue Component
G aG dG pG dGI I KaO fattI KdO N L ( )
B aB dB pB dBI I KaO fattI KdO N L ( )
20
Specular Reflection (鏡反射)⊙ 在光亮表面上(如金屬表面)
⊙ 鏡子是一個 perfect specular reflection
Point Light Source
SurfaceNormalReflected
Light
ViewPoint
L
Nr
v
:
:Nandrbetween
NandLbetween
vandrbetween
21
Phong Model ( specular reflection )
1. 最大 specular reflection 發生在
2. 當 增加, specular reflection 急速減小
3. 由 決定 specular reflection
0
ncos
r
n大
r
n小
)()(1~0cos
90~0
o
n : type of surface
很亮: 100
灰暗: 1 (粉筆)
22
:R Direction of Reflection ( unit vector )
:v View Direction ( unit vector )
: Angle between andR v
vR cos
LN cos
))()(( nRvKsLNKdfattIpIaKaI Ambient
Diffuse
Reflection
Specular
Reflection
23
R
S S
L
R
cosN
已知 , , ,求N L v R
Projection of onto
→
L N
cosN
LLNNR
LNR
LNNR
LNS
SNR
)(2
cos2
coscos
cos
cos
24
Phong 的 Specular Reflection Model
中以 決定 specular reflection 大小ncos
: Angle between and v rn = 1 to hundred
當 n = 時,為 perfect specular
n 意義: n = 1 時,是 broad gentle fall-off
n 較高時是 sharp focused highlight
25
Phong Model 式子
))(( nwKdfattIpIaKaI coscos Ambient
Diffuse
Reflection
Specular
Reflection
0 90
0.5
1W
)(W : Surface material specular reflection coefficient
與材質有關的常數
設為一常數 Ks
silver
gold
glass
26
Transparency
Transparent surface :透明的面
Both reflection and transmitted light
N
RL
T
ii
ri
r
( reflection )
( Transmission )
27
Snell’s Law :
iri
r sinsin
r : angle of reflection
ri , :物體性質
T : Transmission vector
Lr
iNri
r
iT
)( coscos
→tranref
KtIIKtI )(1
28
I : Total surface Intensity
Kt : transparency coefficient ( 0~1 )
( 1-Kt ): opacity factor (不透明)
Iref : reflected intensity
Itran : transmitted intensity
透明
Kt=1
29
Shading
Shading Models for Polygons
計算及得到物體每一面中每一 pixel 的亮
度值,以表現立體感觀。
以 Interpolation 得到一面中之 pixels ,不需計算每一 pixel 。
以 polygonal planar surfaces 為主。 Curved surface 需經 apprximation 成為
polygonal planar surface 。
30
Shading Models for Polygons ( cont. )
方法:1. Constant Shading
2. Interpolated Shading
3. Gouraud Shading
4. Phong Shading
31
Shading Models for Polygons ( cont. )
1. Constant Shading (faceted shading 、 flat shading)
方法:( 1 ) sample one pixel
( 2 ) use a single intensity to shade an entire polygon
需符合以下情形,才能使用 constant shading
( 1 ) Light source is
( 2 ) Viewer is atLN is constant across polygon
VN is constant across polygon
( 3 ) Planar Surface only
32
Shading Models for Polygons ( cont. )
2. Interpolated Shading
Shading information is linearly interpolated across
從面的端點之亮度作線性內差,以得到面
a polygon from values of vertices
上一點之亮度
33
Polygon Mesh Shading
( 1 ) Approximation a curved surface
( 2 ) Each polygonal facet in the mesh
3. Gouraud Shading
Shading Models for Polygons ( cont. )
by a polygonal mesh
is shaded individually
也稱作 intensity interpolation shading
使用 average vertex normal 來計算average intensity for each vertex
34
Polygon Mesh Shading (cont.)
方法:1. 計算每一 vertex 的 average intensity
( 1 )處理一端點 vertexV
( 2 )找到交於 vertexV 的所有 surfaces
( 3 )算出所有 Surfaces 的 Normals
4321 ,,, NNNN
( 4 )算出 vertex normal VN
VN 為各 Surface Normals 的平均
44321 NNNN
NV
3. Gouraud Shading ( cont. )
35
Polygon Mesh Shading (cont.)
3. Gouraud Shading ( cont. )
VN
1N
2N3N
4N
vertex normal4
4321 NNNNNV
36
3. Gouraud Shading ( cont. )
2. 用 Illumination Model 算出 vertex intensity
利用 vertex Normal 算出端點亮度 VI
(包含所有亮度)3. Each polygon is shaded by linearly interpolation
of vertex intensities along edges and between edges
用 vertex 的 intensities 作線性內差,算出面上的一點 intensity PI
PI
3VI
4VI
1VI
2VI
37
3. Gouraud Shading ( cont. )
4. Surface 上每一 pixel 點的 intensity
都由 vertex intensity 計算 13121, IIIIII
PI
bIaI
1I
3I
2I
ax Px bx
1y
2y
3y
SyPI求
38
3. Gouraud Shading ( cont. )
21
1211 yy
yyIIII S
a
ab
PbabbP yy
yyIIII
31
1311 yy
yyIIII S
b
3
2
1 6
4
5
21
412
21
2414 yy
yyI
yy
yyII
23
632
23
2636 yy
yyI
yy
yyII
4
452
46
5645 6 yy
yyI
yy
yyII
39
3. Gouraud Shading ( cont. )
For a triangle3I
1I2I
333 , yxP
111 , yxP 222 , yxP
Parametric equation :
13121 PPPPPP
其中 0,0,10
40
3. Gouraud Shading ( cont. )
12131213
131131
yyxxxxyy
xxyyyyxx
其中
12131213
121121
yyxxxxyy
yyxxxxyy
13121 xxxxxx
13121 yyyyyy
41
Shading Models for Polygons ( cont. )
4. Phong Shading ( Normal-vector Interpolation Shading )
特點: interpolates the surface normal N
at each point ( not intensity )
方法: 13121, NNNNNN
( 1 ) Interpolates Normal Vectors at the
polygon edges from vertex normals
1N0N aN bN cN
aP bP cP
從端點 Normal 作線性內差得到邊線上各點的 Normal
42
( 3 ) Each pixel’s normal is interpolated
4. Phong Shading ( cont. )
( 2 )得到邊線上各點的 Normal
along scan line
(面上一點的 normal ,是由邊線上之點,沿著掃瞄線作內差而得。)
3
2
1 6
4 5
5NN4 from 1 , 2
N6 from 2 , 3
N5 from 4 , 6
利用 得 5N
43
4. Phong Shahing ( cont. )
( 4 )由面上各點的 Normal 計算各點的 Intensity
特點:Constant Shading
Interpolated Shading
無變化
平均的變化
44
4. Phong Shahing ( cont. )
Gouraud Shading
Phong Shading
可能失去
highlight
會保留highlight
45
4. Phong Shahing ( cont. )
問題點:
1. Polygonal silhouette
在作 polygonal approximation of curved surface 時,會在邊線產生輪廓
2. Perspective distortion
因為 interpolation 是在 Image Space coordinate 進行,所以與原幾何物件會有誤差
46
3. Orientation dependence
有方向性。 Interpolation 的方向會影響結果。
4. Phong Shahing ( cont. )
IP IP
Rotation 後, IP 不同intersity
47
4. Shared vertices
4. Phong Shahing ( cont. )
A
BC
從左看: C from A , B從右看: C 是單獨
vertex
5. Unrepresentative vertex normalsParallel Normals
若 Normals 都平行 ,不足以代表面的真實情況