Computer Graphics and Applications Computer Graphics and - - PowerPoint PPT Presentation

computer graphics and applications computer graphics and
SMART_READER_LITE
LIVE PREVIEW

Computer Graphics and Applications Computer Graphics and - - PowerPoint PPT Presentation

Computer Graphics and Applications Computer Graphics and Applications IGR201 Kiwon Um CG, IMAGES, IDS 1 What is Computer Graphics (CG)? What is Computer Graphics (CG)? A basic idea: Synthesis of 2D image(s) from scene data Video game


slide-1
SLIDE 1

Computer Graphics and Applications Computer Graphics and Applications

IGR201

Kiwon Um

CG, IMAGES, IDS

1

slide-2
SLIDE 2

Video game AR VR Mobile 3D

What is Computer Graphics (CG)? What is Computer Graphics (CG)?

A basic idea:

Synthesis of 2D image(s) from scene data

Scene data (often 3D data)

(3D) geometry and transformations Lights Material properties

Topics

Computer animation 3D modeling Image processing Scientific visualization Computer vision Etc.

Kiwon Um IGR201, Telecom Paris 2

slide-3
SLIDE 3

What's real? What's real?

3

slide-4
SLIDE 4

Were your eyes sharp? Were your eyes sharp?

4

slide-5
SLIDE 5

One more chance, what's real? One more chance, what's real?

5

slide-6
SLIDE 6

Are you getting better? Are you getting better?

6

slide-7
SLIDE 7

Rendering Rendering

"The automatic process of generating a photorealistic or non- photorealistic image from a 2D or 3D model by means of computer programs." – [ ]

[Albrecht Dürer: Der Zeichner des liegenden Weibes]

Wikipedia

Kiwon Um IGR201, Telecom Paris 7

slide-8
SLIDE 8

Drawing a Dot Drawing a Dot

Hello dot! (Conceptual codes)

// ... int main(int argc, char** argv) { // ... drawPixel(x, y, R, G, B, A); // ... } // ...

Kiwon Um IGR201, Telecom Paris 8

slide-9
SLIDE 9

Drawing a Triangle Drawing a Triangle

Hello triangle! (Conceptual codes)

// ... int drawTriangle(const Point p1, const Point p2, const Point p3, const Color c) { // ... drawPixel(p1.x, p1.y, c.R, c.G, c.B, c.A); drawPixel(p1.x+1, p1.y-1, c.R, c.G, c.B, c.A); drawPixel(p1.x+2, p1.y-1, c.R, c.G, c.B, c.A); drawPixel(p1.x+3, p1.y-1, c.R, c.G, c.B, c.A); // ... } int main(int argc, char** argv) { // ... drawTriangle(Point(x1, y1), Point(x2, y2), Point(x3, y3), Color(R, G, B, A)); // ... } // ...

Kiwon Um IGR201, Telecom Paris 9

slide-10
SLIDE 10

Drawing a Model Drawing a Model

Hello model! (Conceptual codes)

// ... int drawModel(const Point *vs, const int *ts, const Color *cs) { // ... drawTriangle(vs[ts[3*0+0]], vs[ts[3*0+1]], vs[ts[3*0+2]], cs[0]); drawTriangle(vs[ts[3*1+0]], vs[ts[3*1+1]], vs[ts[3*1+2]], cs[1]); drawTriangle(vs[ts[3*2+0]], vs[ts[3*2+1]], vs[ts[3*2+2]], cs[2]); // ... } int main(int argc, char** argv) { // ... drawModel(vertices, triangles, colors); // ... } // ...

Kiwon Um IGR201, Telecom Paris 10

slide-11
SLIDE 11

If you extend the idea … If you extend the idea …

11

slide-12
SLIDE 12

[Rendered by Charles Nandeya Ehouman using ]

… you can create an image like this. … you can create an image like this.

LuxCoreRender

12

slide-13
SLIDE 13

If you extend the idea If you extend the idea further to multiple images … further to multiple images …

13

slide-14
SLIDE 14

[ , directed by Andy Goralczyk, rendered using Blender]

… you can create a video like this. … you can create a video like this.

Spring

14

slide-15
SLIDE 15

Programming Guide Programming Guide

Good news

You do not need to implement all primitive drawing functions.

Graphics APIs: (or Microsoft DirectX)

Interface to GPU

Official guide book

(also known as OpenGL Red Book)

Programming tools and libraries

GLUT, QT, GTK+, etc.

Applications

For modeling, rendering, animation, etc. E.g., , , , , , , , …

OpenGL

https://www.glprogramming.com/red/ Blender Houdini 3ds Max Maya PBRT LuxCoreRender RenderMan

Kiwon Um IGR201, Telecom Paris 15

slide-16
SLIDE 16

Geometric Objects Geometric Objects

Bunny Armadillo Lucy

[ ]

Let's bring the objects into our computer. How can we model (or represent) these models for computer?

Geometry Materials

Visualization Physical properties

http://graphics.stanford.edu/data/3Dscanrep/

Kiwon Um IGR201, Telecom Paris 16

slide-17
SLIDE 17

Primitives Primitives

[ ] https://www.ntu.edu.sg/home/ehchua/programming/opengl/CG_BasicsTheory.html

Kiwon Um IGR201, Telecom Paris 17

slide-18
SLIDE 18

Polygon Mesh Polygon Mesh

A popular modeling technique in CG Usually use triangles for faces (known as triangle mesh) For instance, a box object

edges vertices faces polygons surfaces

[ ] Wikipedia

Kiwon Um IGR201, Telecom Paris 18

slide-19
SLIDE 19

Modeling Example (Subdivision) Modeling Example (Subdivision)

Let's create a sphere of radius 1.

Start from a coarse polygon mesh (e.g., diamond). The center is at origin; all 6 points are of distance 1 from the center.

Consider a triangle; subdivide into 4 sub-triangles.

Kiwon Um IGR201, Telecom Paris 19

slide-20
SLIDE 20

Modeling Example (cont'd) Modeling Example (cont'd)

If we recursively do the subdivision for all triangles… … we come closer to a sphere.

Accounting for level of details (LOD), i.e., the complexity of a 3D model representation

Complexity affects the processing (e.g., rendering) cost.

[ ] http://glasnost.itcarlow.ie/~powerk/3DGraphics2/Theory/Levelofdetail.htm

Kiwon Um IGR201, Telecom Paris 20

slide-21
SLIDE 21

Polygon Mesh Example Polygon Mesh Example

A 3D bunny model example:

[ ] Frey and Borouchaki

# OBJ file format with ext .obj # vertex count = 2503 # face count = 4968 ... v 7.8152700e-003 5.5050680e-002 5.2750250e-002 v 3.7955090e-002 1.0488710e-001 -3.2031800e-003 v -7.9003790e-002 1.2850550e-001 5.3149340e-002 v -7.9778990e-002 1.3448894e-001 5.0990290e-002 v -5.9129700e-002 1.5039712e-001 3.4489540e-002 v -6.5691790e-002 1.4961818e-001 3.8160980e-002 v -3.1951660e-002 1.2518394e-001 1.9400580e-002 ... f 291 76 292 f 292 237 50 f 2159 1696 1767 f 583 929 850 f 1584 1585 1616 f 1495 1490 1188 f 1557 1489 1660 f 1078 1069 1494 ...

Kiwon Um IGR201, Telecom Paris 21

slide-22
SLIDE 22

Surface Normal Surface Normal

The orientation of a surface of a geometric object The vector perpendicular to a plane Vertices Faces (indices) Two vectors on the surface:

: cross product

Normalize: = [1.0, −1.0, 1.0] v1 = [1.5, 1.0, 1.2] v2 = [−1.0, 0.5, 1.0] v3 ⋯ = [1, 2, 3] f1 = ⋯ f2 ⋯

= ( − ) × ( − ) n ^1 v2 v1 v3 v1

×

= n1

n ^1 || || n ^1

Kiwon Um IGR201, Telecom Paris 22

slide-23
SLIDE 23

Back Face Culling Back Face Culling

Cull the back faces that are not visible from the viewer. Determine if a polygon is a front face or a back face.

Compute normal for each polygon. Generate a vector connecting the viewer and a vertex of the polygon. Take the dot product, i.e., .

: back face : front face : projected as an edge or a silhouette of on a screen

n v v ⋅ n

v ⋅ n > 0 v ⋅ n < 0 v ⋅ n = 0

Kiwon Um IGR201, Telecom Paris 23

slide-24
SLIDE 24

Vertex Normal Vertex Normal

Defined at vertices … can be given as additional data; e.g.,

Vertices Normals

… or, can be computed from faces Weighted average:

Angles, areas, etc. = [1.0, −1.0, 1.0] v1 = [1.5, 1.0, 1.2] v2 = [−1.0, 0.5, 1.0] v3 ⋯ = [−1.0, 0.0, 0.0] n1 = [0.0, 1.0, 0.0] n2 = [0.0, 0.0, 1.0] n3 ⋯

= n ^

∑i θini ∑i θi

Kiwon Um IGR201, Telecom Paris 24

slide-25
SLIDE 25

Interpolation Interpolation

Construct new data points within the range of a discrete set of known data points.

Linear Bilinear

x = (1 − α)a + αb x0x x1x x = (1 − α) + α x00 x01 = (1 − α) + α x10 x11 = (1 − β) + β x0x x1x

Kiwon Um IGR201, Telecom Paris 25

slide-26
SLIDE 26

Barycentric Coordinates Barycentric Coordinates

Represent a point located inside a triangle as a convex combination of three vertices: . The barycentric coordinates of the point .

v v = + + λ0v0 λ1v1 λ2v2

, , ≥ 0 λ0 λ1 λ2 + + = 1 λ0 λ1 λ2 λ0 λ1 λ2 = (( − ) × (v − )) ⋅ a v2 v1 v1 = (( − ) × (v − )) ⋅ a v0 v2 v2 = (( − ) × (v − )) ⋅ a v1 v0 v0 a =

( − )×( − ) v1 v0 v2 v0 ||( − )×( − )|| v1 v0 v2 v0

v = ( , , ) λ0 λ1 λ2

Kiwon Um IGR201, Telecom Paris 26

slide-27
SLIDE 27

Lighting Lighting

Handling of interactions between lights and objects

Local illumination: only between surfaces and direct lights Global illumination: direct lights + indirect lights such as reflection

A shading example

Shading of faces

Light

Color Intensity Type: point light, directional light, spotlight, etc. …

Surface:

Color (or texture) Normal …

Kiwon Um IGR201, Telecom Paris 27

slide-28
SLIDE 28

Phong Lighting Model Phong Lighting Model

The most popular local illumination model

Ambient Diffuse Specular

[ ]

sa sd ss

s = + + sa sd ss

Wikipedia

Kiwon Um IGR201, Telecom Paris 28

slide-29
SLIDE 29

Phong Model: Diffuse Phong Model: Diffuse

Reflections from ideally diffuse surfaces (Lambertian surfaces) are scattered with equal intensity in all directions.

The amount of perceived reflection:

Independent of the view direction Just proportional to the amount of incoming light

Lambert's cosine law

The amount of light that a surface receives . : diffuse reflection constant : diffuse surface color : diffuse light color : component-wise multiplication

∝ n ⋅ l

= max( ⋅ ,0) ⊗ sf,d ∑m∈lights kd nf lm cf,d cm,d

kd cf,d cm,d ⊗

Kiwon Um IGR201, Telecom Paris 29

slide-30
SLIDE 30

Phong Model: Specular Phong Model: Specular

Make a surface look shiny via highlights.

Reflection vector View vector

Highly view-dependent: How to compute the reflection vector Modified Phong reflection model (Blinn-Phong reflection model)

Use a halfway vector , and then instead of

r v

v ⋅ r

q = n cos θ − l q = r − n cos θ r = 2n cos θ − l = 2(n ⋅ l)n − l h =

l+v ||l+v||

n ⋅ h v ⋅ r

Kiwon Um IGR201, Telecom Paris 30

slide-31
SLIDE 31

Phong Model: Specular (cont'd) Phong Model: Specular (cont'd)

: specular reflection constant : shininess : specular surface color : specular light color

Different shininess,

From low (left) to high (right)

[ ]

= max( ⋅ ,0 ⊗ sf,s ∑m∈lights ks vf rm )αcf,s cm,s

ks α cf,s cm,s

α

https://www.scratchapixel.com/lessons/3d-basic-rendering/phong-shader-BRDF

Kiwon Um IGR201, Telecom Paris 31

slide-32
SLIDE 32

Shading Shading

Flat shading

Calculate lighting for each polygon

Smooth shading

Gouraud shading

Calculate lighting for each vertex, and then interpolate the colors

Phong shading

Interpolate normal, and then calculate lighting for each fragment Flat, Gouraud, and Phong shading [ ] GPC

Kiwon Um IGR201, Telecom Paris 32

slide-33
SLIDE 33

Texture Mapping Texture Mapping

[ ]

Define details on model

Map pixels from a texture (usually an image) to a 3D surface

UV mapping

: axes of the 2D texture coordinates

[ ]

Wikipedia

(u, v)

Wikipedia

Kiwon Um IGR201, Telecom Paris 33

slide-34
SLIDE 34

Ray Tracing Ray Tracing

Tracing the path of light

Light Source Scene Object Shadow Ray View Ray Image Camera

[ ]

Simulating a wide variety of optical effects

Reflection/refraction Scattering Dispersion phenomena …

Very high degree of visual realism Very expensive

Wikipedia

Kiwon Um IGR201, Telecom Paris 34

slide-35
SLIDE 35

You might notice that You might notice that it's all about it's all about points, vectors, and so on. points, vectors, and so on.

35

slide-36
SLIDE 36

Let's play with them more. Let's play with them more.

36

slide-37
SLIDE 37

Transformation Transformation

A function that maps a point/vector into another point/vector Mostly interested in affine transformations, preserving:

Colinearity between points Parallelism Convexity of sets Ratios of lengths of parallel line segments Barycenters

E.g., translation, scaling, rotation, reflection, shear, etc.

[ ]

Wikipedia

Kiwon Um IGR201, Telecom Paris 37

slide-38
SLIDE 38

Translation Translation

[ ] = [ ] + [ ] = [ ] x′ y′ x y dx dy x + dx y + dy

Kiwon Um IGR201, Telecom Paris 38

slide-39
SLIDE 39

Scaling Scaling

Uniform: Non-uniform:

[ ] = [ ] [ ] = [ ] x′ y′ sx sy x y x sx y sy

= sx sy ≠ sx sy

Kiwon Um IGR201, Telecom Paris 39

slide-40
SLIDE 40

Rotation Rotation

Q: Can you derive the matrix?

Hint 1: when the distance is Hint 2:

[ ] = [ ] [ ] = [ ] x′ y′ cos θ sin θ − sin θ cos θ x y x cos θ − ysin θ x sin θ + ycos θ

(x, y) = (r cos ϕ, r sin ϕ) r

Trigonometric addition formulas sin(α ± β) = sinαcos β ± cos αsinβ cos(α ± β) = cos αcos β ∓ sinαsinβ

Kiwon Um IGR201, Telecom Paris 40

slide-41
SLIDE 41

Transformation Matrices Transformation Matrices

Translation Scaling Rotation Addition vs. Multiplication

[ ] = [ ] + [ ] x′ y′ x y dx dy [ ] = [ ] [ ] x′ y′ sx sy x y [ ] = [ ] [ ] x′ y′ cosθ sin θ − sin θ cosθ x y

Kiwon Um IGR201, Telecom Paris 41

slide-42
SLIDE 42

Homogeneous Coordinates Homogeneous Coordinates

Deal with different transformations

Translation: vector addition Scaling and rotation: matrix composition

Can we treat them uniformly?

Yes!!! Homogeneous coordinates!

A point in Cartesian coordinates is represented as in homogeneous coordinates where .

E.g., typically, .

Practical motivations in computer graphics:

Treat transformations uniformly Deal with perspective projection (… later)

(x,y) (wx,wy,w) w ≠ 0

(2, 3) ⇒ (2, 3, 1) = (4, 6, 2) = (5, 7.5, 2.5) = ⋯ w = 1

Kiwon Um IGR201, Telecom Paris 42

slide-43
SLIDE 43

Homogeneous Coordinates (cont'd) Homogeneous Coordinates (cont'd)

Translation ( ) Scaling ( ) & rotation ( ) E.g., (1) rotate, (2) scale, and then (3) translate a point

three transformations compose a matrix as where

= Lx x′

= ⎡ ⎣ ⎢ x′ y′ 1 ⎤ ⎦ ⎥ ⎡ ⎣ ⎢ 1 1 dx dy 1 ⎤ ⎦ ⎥ ⎡ ⎣ ⎢ x y 1 ⎤ ⎦ ⎥

= Sx x′ = Rx x′

= & = ⎡ ⎣ ⎢ x′ y′ 1 ⎤ ⎦ ⎥ ⎡ ⎣ ⎢ sx sy 1 ⎤ ⎦ ⎥ ⎡ ⎣ ⎢ x y 1 ⎤ ⎦ ⎥ ⎡ ⎣ ⎢ x′ y′ 1 ⎤ ⎦ ⎥ ⎡ ⎣ ⎢ cos θ sin θ − sin θ cos θ 1 ⎤ ⎦ ⎥ ⎡ ⎣ ⎢ x y 1 ⎤ ⎦ ⎥

x

= LSRx x′ = Tx x′ T = LSR

Kiwon Um IGR201, Telecom Paris 43

slide-44
SLIDE 44

Transformations in 3D Transformations in 3D

Homogeneous coordinate for 3D

, e.g.,

Translation Scaling (x, y, z) ⇒ (wx, wy, wz, w) (x, y, z, 1)

= ⎡ ⎣ ⎢ ⎢ ⎢ x′ y′ z′ 1 ⎤ ⎦ ⎥ ⎥ ⎥ ⎡ ⎣ ⎢ ⎢ ⎢ 1 1 1 dx dy dz 1 ⎤ ⎦ ⎥ ⎥ ⎥ ⎡ ⎣ ⎢ ⎢ ⎢ x y z 1 ⎤ ⎦ ⎥ ⎥ ⎥ = ⎡ ⎣ ⎢ ⎢ ⎢ x′ y′ z′ 1 ⎤ ⎦ ⎥ ⎥ ⎥ ⎡ ⎣ ⎢ ⎢ ⎢ ⎢ sx sy sz 1 ⎤ ⎦ ⎥ ⎥ ⎥ ⎥ ⎡ ⎣ ⎢ ⎢ ⎢ x y z 1 ⎤ ⎦ ⎥ ⎥ ⎥

Kiwon Um IGR201, Telecom Paris 44

slide-45
SLIDE 45

Rotation in 3D Rotation in 3D

We need an axis of rotation. In 2D, by convention, positive rotation is counterclockwise. Right-handed (e.g., OpenGL) vs. left-handed (e.g., DirectX) Rotation about the z-axis :

Rz

= ⎡ ⎣ ⎢ ⎢ ⎢ x′ y′ z′ 1 ⎤ ⎦ ⎥ ⎥ ⎥ ⎡ ⎣ ⎢ ⎢ ⎢ cosθz sinθz − sinθz cosθz 1 1 ⎤ ⎦ ⎥ ⎥ ⎥ ⎡ ⎣ ⎢ ⎢ ⎢ x y z 1 ⎤ ⎦ ⎥ ⎥ ⎥

Kiwon Um IGR201, Telecom Paris 45

slide-46
SLIDE 46

Rotation in 3D (cont'd) Rotation in 3D (cont'd)

Rotation about the x-axis :

Remind!!! Rotation about the z-axis :

Attention! The order of multiple rotations! Q: Rotation about the y-axis?

Hint: permutation

Rx

Rz

= x cos − y sin x′ θz θz = x sin + y cos y′ θz θz = z z′

= x x′ = y cos − z sin y′ θx θx = y sin + z cos z′ θx θx

⇒ = ⎡ ⎣ ⎢ ⎢ ⎢ x′ y′ z′ 1 ⎤ ⎦ ⎥ ⎥ ⎥ ⎡ ⎣ ⎢ ⎢ ⎢ 1 cos θx sin θx − sin θx cos θx 1 ⎤ ⎦ ⎥ ⎥ ⎥ ⎡ ⎣ ⎢ ⎢ ⎢ x y z 1 ⎤ ⎦ ⎥ ⎥ ⎥

≠ RzRx RxRz x → y → z → x → ⋯

Kiwon Um IGR201, Telecom Paris 46

slide-47
SLIDE 47

Rendering Pipeline Rendering Pipeline

[ ] https://www.ntu.edu.sg/home/ehchua/programming/opengl/CG_BasicsTheory.html

Kiwon Um IGR201, Telecom Paris 47

slide-48
SLIDE 48

Rendering Pipeline [ ]

Rendering Pipeline (OpenGL) Rendering Pipeline (OpenGL)

Vertex processing

Vertex shader (programmable) Primitive tessellation stages (programmable) Geometry shader (programmable)

Vertex post-processing Primitive assembly Rasterize primitives

Generates fragments

Fragment shader (programmable)

Processes each fragment.

Per-sample processing

Scissor test, stencil test, depth test, blending, logical

  • peration, write mask, etc.

OpenGL Wiki

Kiwon Um IGR201, Telecom Paris 48

slide-49
SLIDE 49

Coordinates Transformation Coordinates Transformation

[ ] https://www.ntu.edu.sg/home/ehchua/programming/opengl/CG_BasicsTheory.html

Kiwon Um IGR201, Telecom Paris 49

slide-50
SLIDE 50

Model Transform Model Transform

A model (e.g., a teapot)

Its polygons are defined in its model space (a.k.a. local space or object space).

Model space

Bring a teapot or multiple teapots into our virtual world, where we define the world space.

Affine transformations!

Translation, scaling, rotation, etc.

World space

Kiwon Um IGR201, Telecom Paris 50

slide-51
SLIDE 51

View Transform View Transform

A camera in the world space

Eye position: Look at point: Up vector:

Eye Up At World space

The camera space (a.k.a. view space)

Defined by a basis that consists of three unit vectors

Eye Up At World space Camera space

Eye = ( , , ) ex ey ez At = ( , , ) ax ay az Up = ( , , ) ux uy uz { , , } xc yc zc = zc

Eye−At ||Eye−At||

= xc

Up×zc ||Up× || zc

= × yc zc xc

Kiwon Um IGR201, Telecom Paris 51

slide-52
SLIDE 52

View Transform (cont'd) View Transform (cont'd)

Translation: move everything as the eye moves to the origin Rotation: reinterpret in the view space (change of basis) Eye = ⎡ ⎣ ⎢ ex ey ez ⎤ ⎦ ⎥ = Vt ⎡ ⎣ ⎢ ⎢ ⎢ ⎢ 1 1 1 −ex −ey −ez 1 ⎤ ⎦ ⎥ ⎥ ⎥ ⎥ = xc ⎡ ⎣ ⎢ xc,x xc,y xc,z ⎤ ⎦ ⎥ = yc ⎡ ⎣ ⎢ yc,x yc,y yc,z ⎤ ⎦ ⎥ = zc ⎡ ⎣ ⎢ zc,x zc,y zc,z ⎤ ⎦ ⎥ = Vr ⎡ ⎣ ⎢ ⎢ ⎢ ⎢ xc,x yc,x zc,x xc,y yc,y zc,y xc,z yc,z zc,z 1 ⎤ ⎦ ⎥ ⎥ ⎥ ⎥

Kiwon Um IGR201, Telecom Paris 52

slide-53
SLIDE 53

View Transform (cont'd) View Transform (cont'd)

The view matrix:

[ ]

= Mview VrVt

= Mview ⎡ ⎣ ⎢ ⎢ ⎢ ⎢ xc,x yc,x zc,x xc,y yc,y zc,y xc,z yc,z zc,z − ⋅ Eye xc − ⋅ Eye yc − ⋅ Eye zc 1 ⎤ ⎦ ⎥ ⎥ ⎥ ⎥

http://www.codinglabs.net/article_world_view_projection_matrix.aspx

Kiwon Um IGR201, Telecom Paris 53

slide-54
SLIDE 54

Projection Transform Projection Transform

Transform the eye coordinates to the clip coordinates and then to the normalized device coordinates (NDC).

A view frustum: (l)eft, (r)ight, (t)op, (b)ottom, (n)ear, and (f)ar NDC:

Orthographic projection

[ ]

−1 ≤ x, y, z ≤ 1

http://www.songho.ca/opengl/gl_projectionmatrix.html

= Mproj,ortho ⎡ ⎣ ⎢ ⎢ ⎢ ⎢ ⎢ ⎢

2 r−l 2 t−b

2 f−n

− r+l

r−l

− t+b

t−b

− f+n

f−n

1 ⎤ ⎦ ⎥ ⎥ ⎥ ⎥ ⎥ ⎥

Kiwon Um IGR201, Telecom Paris 54

slide-55
SLIDE 55

Projection Transform (cont'd) Projection Transform (cont'd)

Perspective projection

[ ]

Another option for the view frustum: Field of view

[ ] http://www.songho.ca/opengl/gl_projectionmatrix.html

= Mproj,persp ⎡ ⎣ ⎢ ⎢ ⎢ ⎢ ⎢ ⎢

2n r−l 2n t−b

− f+n

f−n

−1 − r+l

r−l

− t+b

t−b

− 2fn

f−n

⎤ ⎦ ⎥ ⎥ ⎥ ⎥ ⎥ ⎥

OpenGL Red Book

= Mproj,persp ⎡ ⎣ ⎢ ⎢ ⎢ ⎢ ⎢ ( ) tan−1

fovx 2

( ) tan−1

fovy 2

− f+n

f−n

−1 − 2fn

f−n

⎤ ⎦ ⎥ ⎥ ⎥ ⎥ ⎥

Kiwon Um IGR201, Telecom Paris 55

slide-56
SLIDE 56

Perspective Division Perspective Division

Each vertex is divided by its w-component.

Recall homogeneous coordinates!

For example,

and

= Mproj,persp ⎡ ⎣ ⎢ ⎢ ⎢ 1 1 −3 −1 −4 ⎤ ⎦ ⎥ ⎥ ⎥

fovx = fovy = π

2

n = 1 f = 2

= → ⎡ ⎣ ⎢ ⎢ ⎢ 1 1 −3 −1 −4 ⎤ ⎦ ⎥ ⎥ ⎥ ⎡ ⎣ ⎢ ⎢ ⎢ ⎢

3 2

− 3

2

1 ⎤ ⎦ ⎥ ⎥ ⎥ ⎥ ⎡ ⎣ ⎢ ⎢ ⎢ ⎢ ⎢

3 2 1 2 3 2

⎤ ⎦ ⎥ ⎥ ⎥ ⎥ ⎥ ⎡ ⎣ ⎢ ⎢ ⎢ ⎢ 1

1 3

1 ⎤ ⎦ ⎥ ⎥ ⎥ ⎥ = → ⎡ ⎣ ⎢ ⎢ ⎢ 1 1 −3 −1 −4 ⎤ ⎦ ⎥ ⎥ ⎥ ⎡ ⎣ ⎢ ⎢ ⎢ −2 1 ⎤ ⎦ ⎥ ⎥ ⎥ ⎡ ⎣ ⎢ ⎢ ⎢ 2 2 ⎤ ⎦ ⎥ ⎥ ⎥ ⎡ ⎣ ⎢ ⎢ ⎢ 1 1 ⎤ ⎦ ⎥ ⎥ ⎥

Kiwon Um IGR201, Telecom Paris 56

slide-57
SLIDE 57

Perspective vs. Orthographic Perspective vs. Orthographic

Perspective vs. Orthographic [ ] Reflect CGI

Kiwon Um IGR201, Telecom Paris 57

slide-58
SLIDE 58

Viewport Transform Viewport Transform

The window coordinates on your screen

with the width and height

[ ]

(x, y) (w, h)

OpenGL Red Book

= Mviewport ⎡ ⎣ ⎢ ⎢ ⎢ ⎢ w/2 h/2

f-n 2

x + w/2 y + h/2

f+n 2

1 ⎤ ⎦ ⎥ ⎥ ⎥ ⎥

Kiwon Um IGR201, Telecom Paris 58

slide-59
SLIDE 59

Vertex Transformation (Recap!) Vertex Transformation (Recap!)

Stages of Vertex Transformation [ ] OpenGL Red Book

Kiwon Um IGR201, Telecom Paris 59

slide-60
SLIDE 60

[ ]

Z-Buffering Z-Buffering

Also known as depth buffering Solve the visibility problem: when multiple fragments are drawn at the same pixel

Z-culling: early pixel elimination

The Z-buffer is implemented as hardware in almost all devices. Q: How does the z-buffer work?

Wikipedia

Kiwon Um IGR201, Telecom Paris 60

slide-61
SLIDE 61

OpenGL Shading Language (GLSL) OpenGL Shading Language (GLSL)

A is a user-defined program.

Designed to run on some stage of a graphics processor (GPU) Execute one of the programmable stages of the rendering pipeline

Different shading languages:

  • f DirectX
  • f NVIDIA (obsolete now)

Programmable stages

and Shaders

… not only for Computer Graphics!

General-Purpose Computation on Graphics Processing Units (GPGPU) But, we also have .

Shader

HLSL Cg Vertex Shaders Tessellation Control Evaluation Geometry Shaders Fragment Shaders Compute Shaders CUDA

Kiwon Um IGR201, Telecom Paris 61

slide-62
SLIDE 62

An Example of Vertex Shader An Example of Vertex Shader

C-style syntax

// simpleVS.glsl uniform mat4 uMvpMat; // model-view-projection matrix in vec4 iPos; // input vertex position void main () { gl_Position = u_matMVP * iPos; // gl_Position: predefined in VS } // main.cpp // ... // const GLchar *shaderSource = ...; // load the shader codes "simpleVS.glsl" as string void initializeShaderPrograms() { program = glCreateProgram(); // Create a GPU program GLuint shader = glCreateShader(GL_VERTEX_SHADER); glShaderSource(shader, 1, &shaderSource, NULL); // load the VS source codes glCompileShader(shader); // Compile the codes glAttachShader(program, shader); // Attatch the VS glDeleteShader(shader); // ... may load/compile/attatch other shaders glLinkProgram(program); // the GPU program is ready to handle streams of polygons ... } // ...

Kiwon Um IGR201, Telecom Paris 62

slide-63
SLIDE 63

Recap Programming in C/C++ Recap Programming in C/C++

63

slide-64
SLIDE 64

Object-oriented Programming Object-oriented Programming

"a programming paradigm based on the concept of objects, which can contain data, in the form of fields (often known as attributes or properties), and code, in the form of procedures (often known as methods)" – [ ] Principles

Encapsulation Abstraction Information hiding Inheritance Polymorphism …

… can be realized in C++, Java, Python, etc. Wikipedia

Kiwon Um IGR201, Telecom Paris 64

slide-65
SLIDE 65

2D Vector Object in C++ 2D Vector Object in C++

Access specifiers: private, public, and protected

Member variables and methods

class Vector2D { private: float x, y; public: explicit Vector2D(const float v) : x(v), y(v) {} Vector2D(const float a, const float b) : x(a), y(b) {} void setX(const float x_new) { x = x_new; } void setY(const float y_new) { y = y_new; } float length() const { return std::sqrt(x*x + y*y); } Vector2D& rotate(const float radian) { const float cost=std::cos(radian), sint=std::sin(radian); const Vector2D v_new(cost*x-sint*y, sint*x+cost*y); return (*this) = v_new; } }; Vector2D v(3.0, 3.0); // a 2D vector instance v.y = 4.0; // ERROR! private! v.setY(4.0); // OK! call a member method updating the member variable y v = Vector2D(3.0, 4.0); // OK! assign a new instance float len = v.length(); // len = 5.0 v.rotate(0.5*PI); // v = [-4.0, 3.0]

Kiwon Um IGR201, Telecom Paris 65

slide-66
SLIDE 66

2D Vector Object in C++ (cont'd) 2D Vector Object in C++ (cont'd)

Operator overloading

class Vector2D { // ... // assignmet operator Vector2D& operator+=(const Vector2D& r) { x+=r.x; y+=r.y; return *this; } // ... // unary operator Vector2D operator-() const { return Vector2D(-x, -y); } // ... // binary operator Vector2D operator+(const Vector2D& r) const { return Vector2D(*this)+=r; } // ... }; Vector2D v(1.0, 2.0); // v = [1.0, 2.0] v += Vector2D(1.0, 1.0); // v = [2.0, 3.0] v = -v; // v = [-2.0, -3.0] v = v + Vector2D(1.0, 1.0); // v = [-1.0, -2.0]

Kiwon Um IGR201, Telecom Paris 66

slide-67
SLIDE 67

Pointer and Reference Pointer and Reference

Call by Value vs. Call by Reference

#include <iostream> // Call by Value method void doNothing(Vector2D v) { v.setX(1.0); } // Call by Reference methods void doSomethingWithReference(Vector2D &v) { v.setX(4.0); } void doSomethingWithPointer(Vector2D *v) { v->setX(5.0); } int main(int argc, const char *argv[]) { Vector2D v(2.0, 3.0); doNothing(v); // v = (2.0, 3.0) doSomethingWithReference(v); // v = (4.0, 3.0) doSomethingWithPointer(v); // v = (5.0, 3.0) return 0; }

Kiwon Um IGR201, Telecom Paris 67

slide-68
SLIDE 68

Standard Template Library (STL) Standard Template Library (STL)

A software library for the C++ programming language Components

Algorithms: sort, find, … Containers: list, vector, set, queue, … Functions: Functors, … Iterators: forward, random-access, …

#include <vector> // Vec3f and Vec3i classes ... int main(int argc, char** argv) { std::vector<Vec3f> vbuffer; vbuffer.push_back(Vec3f(0.0, 0.0, 0.0)); vbuffer.push_back(Vec3f(1.0, 0.0, 0.0)); vbuffer.push_back(Vec3f(1.0, 1.0, 0.0)); std::vector<Vec3i> ibuffer; ibuffer.push_back(Vec3i(0, 1, 2)); // ... }

Kiwon Um IGR201, Telecom Paris 68

slide-69
SLIDE 69

How far have we gone? How far have we gone?

69

slide-70
SLIDE 70

Computer Graphics Communities Computer Graphics Communities

Conferences

SIGGRAPH / SIGGRAPH Asia Eurographics (EG) Symposium on Computer Animation (SCA) Pacific Graphics (PG) Conference on Computer Animation and Social Agents (CASA) Computer Graphics International (CGI) …

Journals

ACM Transactions of Graphics (TOG) IEEE Transactions on Visualization and Computer Graphics (TVCG) Computer Graphics Forum (CGF) Computer Animation and Virtual Worlds (CAVW) The Visual Computer (TVC) Computer-Aided Design (CAD) …

Kiwon Um IGR201, Telecom Paris 70

slide-71
SLIDE 71

71

slide-72
SLIDE 72

72

slide-73
SLIDE 73

Are You Interested in More? Are You Interested in More?

We are here in the , , .

Associate Professor Associate Professor

Do not hesitate contact us! We are looking for great team members for PhD/master students as well as undergraduate students! Computer Graphics Group IMAGES IDS Department Telecom Paris Institut Polytechnique de Paris

  • Prof. Dr. Jean-Marc Thiery
  • Prof. Dr. Kiwon Um

Kiwon Um IGR201, Telecom Paris 73