16
Introduction to Computer Science Lecture 9: Computer 3D Graphics Tian-Li Yu Taiwan Evolutionary Intelligence Laboratory (TEIL) Department of Electrical Engineering National Taiwan University [email protected] Slides made by Tian-Li Yu, Jie-Wei Wu, and Chu-Yu Hsu Tian-Li Yu Computer 3D Graphics 1 / 16

Introduction to Computer Science Lecture 9: Computer 3D ...ocw.aca.ntu.edu.tw/ocw_files/101S210/101S210_CS18L01 .pdfIntroduction to Computer Science Lecture 9: Computer 3D Graphics

  • Upload
    others

  • View
    1

  • Download
    0

Embed Size (px)

Citation preview

Page 1: Introduction to Computer Science Lecture 9: Computer 3D ...ocw.aca.ntu.edu.tw/ocw_files/101S210/101S210_CS18L01 .pdfIntroduction to Computer Science Lecture 9: Computer 3D Graphics

Introduction to Computer ScienceLecture 9: Computer 3D Graphics

Tian-Li Yu

Taiwan Evolutionary Intelligence Laboratory (TEIL)Department of Electrical Engineering

National Taiwan University

[email protected]

Slides made by Tian-Li Yu, Jie-Wei Wu, and Chu-Yu Hsu

Tian-Li Yu Computer 3D Graphics 1 / 16

Page 2: Introduction to Computer Science Lecture 9: Computer 3D ...ocw.aca.ntu.edu.tw/ocw_files/101S210/101S210_CS18L01 .pdfIntroduction to Computer Science Lecture 9: Computer 3D Graphics

Projection

Parallel vs. Prospective Projection

Tian-Li Yu Computer 3D Graphics 2 / 16

Page 3: Introduction to Computer Science Lecture 9: Computer 3D ...ocw.aca.ntu.edu.tw/ocw_files/101S210/101S210_CS18L01 .pdfIntroduction to Computer Science Lecture 9: Computer 3D Graphics

Projection

Simple Projection

Suppose camera is fixed at (0,0,d).Projection plane is fixed at z = d − 1Usually keep z information

Parallel projection

(x , y , z)→ (x , y , z)

Prospective projection

(x , y , z)→ (x

d − z,

yd − z

, z)

(x,y,z)

1

d-z

(0,0,d)

z

Tian-Li Yu Computer 3D Graphics 3 / 16

Page 4: Introduction to Computer Science Lecture 9: Computer 3D ...ocw.aca.ntu.edu.tw/ocw_files/101S210/101S210_CS18L01 .pdfIntroduction to Computer Science Lecture 9: Computer 3D Graphics

Transposition

Translations & Rotations

Translations- Simply add a vector.

Rotations

RX (θ) =

1 0 00 cosθ − sinθ0 sinθ cosθ

RY (θ) =

cosθ 0 sinθ0 1 0

− sinθ 0 cosθ

RZ (θ) =

cosθ − sinθ 0sinθ cosθ 0

0 0 1

4

RotateX (-90)

RotateY (45)

RotateX (30)

Tian-Li Yu Computer 3D Graphics 4 / 16

Page 5: Introduction to Computer Science Lecture 9: Computer 3D ...ocw.aca.ntu.edu.tw/ocw_files/101S210/101S210_CS18L01 .pdfIntroduction to Computer Science Lecture 9: Computer 3D Graphics

Modeling

Modeling

Typically use triangles andquadrangles.Easy to compute the normal vector.

How to increase resolution?- Spline and Bezier curves

Tian-Li Yu Computer 3D Graphics 5 / 16

Page 6: Introduction to Computer Science Lecture 9: Computer 3D ...ocw.aca.ntu.edu.tw/ocw_files/101S210/101S210_CS18L01 .pdfIntroduction to Computer Science Lecture 9: Computer 3D Graphics

Modeling

Bezier Curves

May be defined on different degree of polynomials.Here we introduce the cubic one with 4 control points:

P1

P2

P3

P0

((1 − t) + t)3 = (1 − t)3 + 3t(1 − t)2 + 3t2(1 − t) + t3

P(t) = (1 − t)3P0 + 3t(1 − t)2P1 + 3t2(1 − t)P2 + t3P3

Tian-Li Yu Computer 3D Graphics 6 / 16

Page 7: Introduction to Computer Science Lecture 9: Computer 3D ...ocw.aca.ntu.edu.tw/ocw_files/101S210/101S210_CS18L01 .pdfIntroduction to Computer Science Lecture 9: Computer 3D Graphics

Modeling

Recursive Subdivision

A cubic Bezier curve can be subdivided intotwo cubic curves.

Given any t (0.4),

- P11 = (1 − t)P0 + tP1- P21 = (1 − t)P1 + tP2- P31 = (1 − t)P2 + tP3

- P12 = (1 − t)P11 + tP21- P22 = (1 − t)P21 + tP31

- P13 = (1 − t)P12 + tP22

P0,P11,P12,P13 forms one curve.P13,P22,P31,P3 forms the other.

Tian-Li Yu Computer 3D Graphics 7 / 16

Page 8: Introduction to Computer Science Lecture 9: Computer 3D ...ocw.aca.ntu.edu.tw/ocw_files/101S210/101S210_CS18L01 .pdfIntroduction to Computer Science Lecture 9: Computer 3D Graphics

Modeling

Recursive Subdivision

Tian-Li Yu Computer 3D Graphics 8 / 16

Page 9: Introduction to Computer Science Lecture 9: Computer 3D ...ocw.aca.ntu.edu.tw/ocw_files/101S210/101S210_CS18L01 .pdfIntroduction to Computer Science Lecture 9: Computer 3D Graphics

Lighting & Shading

Lighting

Ambient lightingDirectional lightingPoint lighting

I = Ia +(1 − Ia)

1 + αd + βd2

d: distance between light source and target.Ia : intensity of ambient light.

Tian-Li Yu Computer 3D Graphics 9 / 16

Page 10: Introduction to Computer Science Lecture 9: Computer 3D ...ocw.aca.ntu.edu.tw/ocw_files/101S210/101S210_CS18L01 .pdfIntroduction to Computer Science Lecture 9: Computer 3D Graphics

Lighting & Shading

Shading

~n: normal vector of plane.~l: normal vector of light.~c: normal vector of camera.~r : normal vector of reflection.

Phong model- Ambient + Diffusion + Specular

Diffusion: ~n ·~l

Specular: (cosθ)s

- Higher s → more mirror-like surface

light

normal

lv

rvcamera

cv

θ

PLANE

Tian-Li Yu Computer 3D Graphics 10 / 16

Page 11: Introduction to Computer Science Lecture 9: Computer 3D ...ocw.aca.ntu.edu.tw/ocw_files/101S210/101S210_CS18L01 .pdfIntroduction to Computer Science Lecture 9: Computer 3D Graphics

Lighting & Shading

Specular

~l +~r = 2(~l · ~n)~n

~r = 2(~l · ~n)~n −~l

cosθ = ~r · ~c =(2(~l · ~n)~n −~l

)· ~c

light

normal

lv

rvcamera

cv

θ

PLANE

Tian-Li Yu Computer 3D Graphics 11 / 16

Page 12: Introduction to Computer Science Lecture 9: Computer 3D ...ocw.aca.ntu.edu.tw/ocw_files/101S210/101S210_CS18L01 .pdfIntroduction to Computer Science Lecture 9: Computer 3D Graphics

Lighting & Shading

Put It All Together

C = Ia · Co +1 − Ia

1 + αd + βd2

(kd · ~n ·~l · Co + (1 − kd) coss θ · Cl

)

Tian-Li Yu Computer 3D Graphics 12 / 16

Page 13: Introduction to Computer Science Lecture 9: Computer 3D ...ocw.aca.ntu.edu.tw/ocw_files/101S210/101S210_CS18L01 .pdfIntroduction to Computer Science Lecture 9: Computer 3D Graphics

Lighting & Shading

Summary of Parameters

Properties of light

Ia Ambient light intensity (0∼1)

α, β Degree of point lighting

Cl Color of light~l Normal vector of light direction

Properties of object

kd Diffusion coefficient (kd = 1 − ks : specular coefficient)

s Shininess: how mirror-like

Co Color of the object~n Normal vector of the plane

Tian-Li Yu Computer 3D Graphics 13 / 16

Page 14: Introduction to Computer Science Lecture 9: Computer 3D ...ocw.aca.ntu.edu.tw/ocw_files/101S210/101S210_CS18L01 .pdfIntroduction to Computer Science Lecture 9: Computer 3D Graphics

Lighting & Shading

Flat, Gouraud, and Phong Shadings

Flat: one triangle, one color.Gouraud: interpolation of vertices colors.Phong: interpolation of vertices normal vectors.

N

b

cd

a

Vertex normalv2

v1

v3

a

1-a

1-b

b

c 1-c

(1 − c)((1 − a)v1 + av2) + c((1 − b)v1 + bv3)

Tian-Li Yu Computer 3D Graphics 14 / 16

Page 15: Introduction to Computer Science Lecture 9: Computer 3D ...ocw.aca.ntu.edu.tw/ocw_files/101S210/101S210_CS18L01 .pdfIntroduction to Computer Science Lecture 9: Computer 3D Graphics

Lighting & Shading

Flat, Gouraud, and Phong Shadings

Flat Gouraud Phong

Tian-Li Yu Computer 3D Graphics 15 / 16

Page 16: Introduction to Computer Science Lecture 9: Computer 3D ...ocw.aca.ntu.edu.tw/ocw_files/101S210/101S210_CS18L01 .pdfIntroduction to Computer Science Lecture 9: Computer 3D Graphics

Lighting & Shading

License

Page File Licensing Source/ author

5” Mitsubishi EVO”.,Author:Arbiter, Source: http://www.3-d-models.com/3d-model_files/371m729.htm, Date:2013/06/29, Fair use undercopyright law 46,52,65.

Tian-Li Yu Computer 3D Graphics 16 / 16