第八章 illumination and shading

47
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.

Upload: jessamine-frye

Post on 02-Jan-2016

120 views

Category:

Documents


5 download

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 Presentation

TRANSCRIPT

Page 1: 第八章  Illumination and Shading

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.

Page 2: 第八章  Illumination and Shading

2

N

S

V

Camera

Light Source 2Light Source 1

V:Viewing Direction

N:Normal Vector of Surface

S:Direction of Light Source

Page 3: 第八章  Illumination and Shading

3

Object

Object : Absorb( 吸收 )

Reflect( 反射 )

Transmit( 穿透 )

Light

Light emitting source 發光體源

Light reflecting source 反射光源

L

Page 4: 第八章  Illumination and Shading

4

Light

Light sources

(X,Y,Z)

1.Point source

2.Distributed source

SSN

s

N

( Sx,Sy,Sz)

點光源

分佈、分散的光源

{ 平行方向亂射方向

Page 5: 第八章  Illumination and Shading

5

Ambient Light( 周圍的光線 )特性:⊙ uniform illumination

⊙nondirectional source 沒有方向性

( 四面八方過來的光線 )

⊙multiple reflections from nearby surfaces由於附近的其他物體面,反射而造成。

一種無方向性,充滿在周圍的光源。

Page 6: 第八章  Illumination and Shading

6

Illumination Equation

IaKaI

I :物體面上某一點的 Intensity (亮度)

Ia : Ambient light 的 Intensity

( constant for all objects )

ka : Ambient-reflection coefficient

( material property 物體性質)

( 0~1 )

Page 7: 第八章  Illumination and Shading

7

V

N

L

Diffuse Reflection (漫反射、散反射)

( Lambertian Reflection 柔和光亮的反射)

⊙ 在粗糙表面上。

⊙ 物體面從所有方向看都一樣。

⊙ 一點的亮度由 角決定

角: angle between Light Source Direction and Surface Normal

Page 8: 第八章  Illumination and Shading

8

N : Surface Normal

L : Direction of Light source

: angle between N and L

Page 9: 第八章  Illumination and Shading

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 )

Page 10: 第八章  Illumination and Shading

10

Lambert’s cosine Law

LN cos

LN

LN

LN

LNNL

cos

cos

cos

)( LNIpKdI NL

當光源假設為很遠時, 為固定方向。

→ 各點的 影響各點的亮度。L

N

Page 11: 第八章  Illumination and Shading

11

Ip

L

Page 12: 第八章  Illumination and Shading

12

Ambient Light + Diffuse Reflection

合成 2 光源

)( LNIpKdIaKaI 合成 Ambient Diffuse Reflection

Page 13: 第八章  Illumination and Shading

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

Page 14: 第八章  Illumination and Shading

14

Light – Source Attenuation (光線變淡) --衰減為了分出遠近,光線越遠應越淡。

物面上的亮度,越遠應越暗。

若相同 intensity 則無法分出遠近。

較遠者,其 intensity 應較暗才能分出遠近。

Page 15: 第八章  Illumination and Shading

15

Light – Source Attenuation factor

IaKaI

fatt : attenuation factor

由 Light source 及 surface 之間距離決定。

fatt

)( LNIpKd

Page 16: 第八章  Illumination and Shading

16

Attenuation Factor

2

1

Ld

fatt

dL : point Light Source 與 Surface 之間的距離。

但是 ,很近時變化很大。

,很遠時變化很小。

Ld 2

Page 17: 第八章  Illumination and Shading

17

較複雜的表示法

fattmax

min),( 1

3211

2

LLdCdCC

3

2

1

C

C

C

User defined constant

C1 :當很近時, fatt 不致太大。

Max = 1 , fatt 最大 = 1

Page 18: 第八章  Illumination and Shading

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 )

Page 19: 第八章  Illumination and Shading

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 ( )

Page 20: 第八章  Illumination and Shading

20

Specular Reflection (鏡反射)⊙ 在光亮表面上(如金屬表面)

⊙ 鏡子是一個 perfect specular reflection

Point Light Source

SurfaceNormalReflected

Light

ViewPoint

L

Nr

v

:Nandrbetween

NandLbetween

vandrbetween

Page 21: 第八章  Illumination and Shading

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 (粉筆)

Page 22: 第八章  Illumination and Shading

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

Page 23: 第八章  Illumination and Shading

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

Page 24: 第八章  Illumination and Shading

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

Page 25: 第八章  Illumination and Shading

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

Page 26: 第八章  Illumination and Shading

26

Transparency

Transparent surface :透明的面

Both reflection and transmitted light

N

RL

T

ii

ri

r

( reflection )

( Transmission )

Page 27: 第八章  Illumination and Shading

27

Snell’s Law :

iri

r sinsin

r : angle of reflection

ri , :物體性質

T : Transmission vector

Lr

iNri

r

iT

)( coscos

→tranref

KtIIKtI )(1

Page 28: 第八章  Illumination and Shading

28

I : Total surface Intensity

Kt : transparency coefficient ( 0~1 )

( 1-Kt ): opacity factor (不透明)

Iref : reflected intensity

Itran : transmitted intensity

透明

Kt=1

Page 29: 第八章  Illumination and Shading

29

Shading

Shading Models for Polygons

計算及得到物體每一面中每一 pixel 的亮

度值,以表現立體感觀。

以 Interpolation 得到一面中之 pixels ,不需計算每一 pixel 。

以 polygonal planar surfaces 為主。 Curved surface 需經 apprximation 成為

polygonal planar surface 。

Page 30: 第八章  Illumination and Shading

30

Shading Models for Polygons ( cont. )

方法:1. Constant Shading

2. Interpolated Shading

3. Gouraud Shading

4. Phong Shading

Page 31: 第八章  Illumination and 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

Page 32: 第八章  Illumination and Shading

32

Shading Models for Polygons ( cont. )

2. Interpolated Shading

Shading information is linearly interpolated across

從面的端點之亮度作線性內差,以得到面

a polygon from values of vertices

上一點之亮度

Page 33: 第八章  Illumination and Shading

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

Page 34: 第八章  Illumination and Shading

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. )

Page 35: 第八章  Illumination and Shading

35

Polygon Mesh Shading (cont.)

3. Gouraud Shading ( cont. )

VN

1N

2N3N

4N

vertex normal4

4321 NNNNNV

Page 36: 第八章  Illumination and Shading

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

Page 37: 第八章  Illumination and Shading

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求

Page 38: 第八章  Illumination and Shading

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

Page 39: 第八章  Illumination and Shading

39

3. Gouraud Shading ( cont. )

For a triangle3I

1I2I

333 , yxP

111 , yxP 222 , yxP

Parametric equation :

13121 PPPPPP

其中 0,0,10

Page 40: 第八章  Illumination and Shading

40

3. Gouraud Shading ( cont. )

12131213

131131

yyxxxxyy

xxyyyyxx

其中

12131213

121121

yyxxxxyy

yyxxxxyy

13121 xxxxxx

13121 yyyyyy

Page 41: 第八章  Illumination and Shading

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

Page 42: 第八章  Illumination and Shading

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

Page 43: 第八章  Illumination and Shading

43

4. Phong Shahing ( cont. )

( 4 )由面上各點的 Normal 計算各點的 Intensity

特點:Constant Shading

Interpolated Shading

無變化

平均的變化

Page 44: 第八章  Illumination and Shading

44

4. Phong Shahing ( cont. )

Gouraud Shading

Phong Shading

可能失去

highlight

會保留highlight

Page 45: 第八章  Illumination and Shading

45

4. Phong Shahing ( cont. )

問題點:

1. Polygonal silhouette

在作 polygonal approximation of curved surface 時,會在邊線產生輪廓

2. Perspective distortion

因為 interpolation 是在 Image Space coordinate 進行,所以與原幾何物件會有誤差

Page 46: 第八章  Illumination and Shading

46

3. Orientation dependence

有方向性。 Interpolation 的方向會影響結果。

4. Phong Shahing ( cont. )

IP IP

Rotation 後, IP 不同intersity

Page 47: 第八章  Illumination and Shading

47

4. Shared vertices

4. Phong Shahing ( cont. )

A

BC

從左看: C from A , B從右看: C 是單獨

vertex

5. Unrepresentative vertex normalsParallel Normals

若 Normals 都平行 ,不足以代表面的真實情況