Computer Graphics Seminar MTAT.03.305 Fall 2019 Raimond Tunnel - - PowerPoint PPT Presentation

computer graphics seminar
SMART_READER_LITE
LIVE PREVIEW

Computer Graphics Seminar MTAT.03.305 Fall 2019 Raimond Tunnel - - PowerPoint PPT Presentation

Computer Graphics Seminar MTAT.03.305 Fall 2019 Raimond Tunnel Computer Graphics Graphical illusion via the computer Displaying something meaningful (incl art) Math Computers are good at... computing. To do computer graphics, we


slide-1
SLIDE 1

Computer Graphics Seminar

MTAT.03.305 Fall 2019

Raimond Tunnel

slide-2
SLIDE 2

Computer Graphics

  • Graphical illusion via the computer
  • Displaying something meaningful (incl art)
slide-3
SLIDE 3

Math

  • Computers are good at... computing.
  • To do computer graphics, we need math for the

computer to compute.

  • Geometry, algebra, calculus.
slide-4
SLIDE 4

Math

  • For creating and manipulating 3D objects we use:
  • Analytic geometry – math about coordinate systems
  • Linear algebra – math about vectors and spaces
slide-5
SLIDE 5

Skills for Computer Graphics

  • Mathematical understanding
  • Geometrical (spatial) thinking
  • Programming
  • Visual creativity & aesthetics

(

a b c d) ⋅( x y)=( ax+by cx+dy)

GLuint vaoHandle; glGenVertexArrays(1, &vaoHandle); glBindVertexArray(vaoHandle);

slide-6
SLIDE 6

The Standard Graphics Pipeline

Vertex transformations Culling & Clipping Rasterization Fragment shading Visibility tests & Blending Vertex shader Data

Define geometry and transformations

Apply geometry and transformations

slide-7
SLIDE 7

Point

  • Simplest geometry primitive
  • In homogeneous coordinates:

(x, y, z, w), w ≠ 0

  • Represents a point (x/w, y/w, z/w)
  • Usually you can put w = 1 for points
  • Actual division will be done by GPU later

(x, y, z, 1)

slide-8
SLIDE 8

Line (segment)

  • Consists of:
  • 2 endpoints
  • Infinite number of points between
  • Defined by the endpoints
  • Interpolated and rasterized in the GPU

(x1, y1, z1, 1) (x2, y2, z2, 1)

slide-9
SLIDE 9

Line (segment)

  • Consists of:
  • 2 endpoints
  • Infinite number of points between
  • Defined by the endpoints
  • Interpolated and rasterized in the GPU

(x1, y1, z1, 1) (x2, y2, z2, 1)

slide-10
SLIDE 10

Line (segment)

  • Consists of:
  • 2 endpoints
  • Infinite number of points between
  • Defined by the endpoints
  • Interpolated and rasterized in the GPU

(x1, y1, z1, 1) (x2, y2, z2, 1)

slide-11
SLIDE 11

Triangle

  • Consists of:
  • 3 points called vertices
  • 3 lines called edges
  • 1 face
  • Defined by 3 vertices
  • Face interpolated and rasterized in the GPU
  • Counter-clockwise order defines the front face

(x1, y1, z1, 1) (x2, y2, z2, 1) (x3, y3, z3, 1)

slide-12
SLIDE 12

Triangle

  • Consists of:
  • 3 points called vertices
  • 3 lines called edges
  • 1 face
  • Defined by 3 vertices
  • Face interpolated and rasterized in the GPU
  • Counter-clockwise order defines the front face

(x1, y1, z1, 1) (x2, y2, z2, 1) (x3, y3, z3, 1) Front face

slide-13
SLIDE 13

Why triangles?

  • They are in many ways the simplest polygons
  • 3 different points always form a plane
  • Easy to rasterize (fill the face with pixels)
  • Every other polygon can be converted to triangles
slide-14
SLIDE 14

Why triangles?

  • They are in many ways the simplest polygons
  • 3 different points always form a plane
  • Easy to rasterize (fill the face with pixels)
  • Every other polygon can be converted to triangles
  • OpenGL used to support other polygons too
  • Must have been:

– Simple – No edges intersect each other – Convex – All points between any two inner points are inner points

slide-15
SLIDE 15

Examples of polygons

A B C D A B C D E F G H I J K L F A B C D E C A B

slide-16
SLIDE 16

OpenGL < 3.1 primitives

OpenGL Programming Guide 7th edition, p49

slide-17
SLIDE 17

After OpenGL 3.1

OpenGL Programming Guide 8th edition, p89-90

slide-18
SLIDE 18

In the beginning there were points

  • We can now define our geometric objects!
slide-19
SLIDE 19

In the beginning there were points

  • We can now define our geometric objects!
  • We want to move our objects!

World's (0, 0, 0)

slide-20
SLIDE 20

Transformations

  • Homogeneous coordinates allow easy:
  • Linear transformations

– Scaling, reflection – Rotation – Shearing

  • Affine transformations

– Translation (moving / shifting)

  • Projection transformations

– Perspective – Orthographic

slide-21
SLIDE 21

Transformations

  • Homogeneous coordinates allow easy:
  • Linear transformations

– Scaling, reflection – Rotation – Shearing

  • Affine transformations

– Translation (moving / shifting)

  • Projection transformations

– Perspective – Orthographic Actually these we could do without homogeneous coordinates... T h i s t

  • .

. .

slide-22
SLIDE 22

Transformations

  • Every transformation is a function
  • As you remember from algebra, all linear

functions can be represented as matrices

f (v)=( 2⋅x y z ) =( 2 1 1) ⋅( x y z) v∈R

3

v=( x y z)

Column-major format

slide-23
SLIDE 23

Transformations

  • Every transformation is a function
  • As you remember from algebra, all linear

functions can be represented as matrices

f (v)=( 2⋅x y z ) =( 2 1 1) ⋅( x y z) v∈R

3

v=( x y z)

Column-major format Linear function, which increases the first coordinate two times.

slide-24
SLIDE 24

Transformations

  • Every transformation is a function
  • As you remember from algebra, all linear

functions can be represented as matrices

f (v)=( 2⋅x y z ) =( 2 1 1) ⋅( x y z) v∈R

3

v=( x y z)

Column-major format Linear function, which increases the first coordinate two times. Same function as a matrix

slide-25
SLIDE 25

Transformations

  • GPU-s are built for doing transformations with

matrices on points (vertices).

ALU ALU ALU ALU ALU ALU ALU ALU ALU ALU ALU ALU ALU ALU ALU ALU ALU ALU ALU ALU ALU ALU ALU ALU ALU ALU ALU ALU ALU ALU ALU ALU

Control Cache Control Cache Control Cache Control Cache Control Cache Control Cache Control Cache Control Cache

DRAM ... ... ... ... ... ... ... ...

M⋅ v0 M⋅ v1 M⋅ v2

Vertex shader code

slide-26
SLIDE 26

Transformations

  • GPU-s are built for doing transformations with

matrices on points (vertices).

  • Linear transformations satisfy:

f (a1 x1+ ...+ an xn)=a1 f (x1)+ ...+ an f (xn)

We do not use homogeneous coordinates at the moment, but they will be back...

slide-27
SLIDE 27

Linear Transformation

Scale

slide-28
SLIDE 28

Scaling

  • Multiplies the coordinates by a scalar factor.

(

2 1) ⋅( x y)

(

2 1) ⋅( 1.5 1.5)=( 3 1.5)

slide-29
SLIDE 29

Scaling

  • Multiplies the coordinates by a scalar factor.
  • Scales the standard basis vectors / axes.

(

2 1) ⋅( 1 0)=( 2 0)=e0

(

2 1) ⋅( 1)=( 1)=e1

slide-30
SLIDE 30

Scaling

  • In general we could scale each axis

(

a x a y a z)

ax – x-axis scale factor ay – y-axis scale factor az – z-axis scale factor

  • If some factor is negative, this matrix will reflect

the points from that axis. Thus we get reflection.

What happens to out triangles when an

  • dd number of factors are negative?
slide-31
SLIDE 31

Linear Transformation

Shear

slide-32
SLIDE 32

Shearing

  • Not much used by itself, but remember it for

translations later.

  • Tilts only one axis.
  • Squares become parallelograms. (

1 1 1) ⋅( x y)

(

1 1 1) ⋅( 1 2)=( 1 3)

(

1 1 1) ⋅( 2)=( 2)

slide-33
SLIDE 33

Shearing

  • Shear-y, we tilt parallel to y-axis

by angle φ counter-clockwise

  • Shear-x, we tilt parallel to x-axis

by angle φ clockwise

(

1 tan(ϕ) 1) ⋅( x y)=( x y+ tan(ϕ) ⋅x)

(

1 tan(ϕ) 1 ) ⋅( x y)=( x+ tan(ϕ) ⋅y y

)

slide-34
SLIDE 34

Linear Transformation

Rotation

slide-35
SLIDE 35

Rotation

  • Shearing moved only one axis
  • Also changed the size of the basis vector
  • Can we do better?

Did you notice that the columns of the transformation matrix show the coordinates of the new basis vectors?

slide-36
SLIDE 36

Rotation

e'0=(∣a∣,∣b∣)=(cos(α),sin(α)) e'1=(∣a'∣,∣b'∣)=(−sin(α),cos(α)) cos(α)= ∣a∣ ∣e'0∣=∣a∣ 1 =∣a∣

slide-37
SLIDE 37

Rotation

  • So if we rotate by α in counter-clockwise order

in 2D, the transformation matrix is:

(

cos(α) −sin(α) sin(α) cos(α))

e'0 e'1

  • In 3D we can do rotations in each plane (xy, xz,

yz), so there can be 3 different matrices.

slide-38
SLIDE 38

Rotation

  • To do a rotation around an arbitrary axis, we

can:

  • Rotate that axis to be the x-axis
  • Rotate around the new x-axis
  • Invert the first rotations

(move the old x-axis back)

  • OpenGL provides a command for rotating

around a given axis.

  • Generally quaternions are used for rotations.

(

1 cos(α) −sin(α) sin(α) cos(α) 1)

Quaternions are elements of a number system that extend the complex numbers...

slide-39
SLIDE 39

Do we have everything now?

  • We can scale, shear and rotate our geometry

around the origin...

What if we have an object not centered in the origin?

slide-40
SLIDE 40

Affine Transformation

Translation

slide-41
SLIDE 41

Translation

  • Imagine that a 1D world is located at y=1 line in

2D space.

  • Notice that all the points are in the form: (x, 1)
slide-42
SLIDE 42

Translation

  • Imagine that a 1D world is located at y=1 line in

2D space.

The 1D world Objects

  • Notice that all the points are in the form: (x, 1)
slide-43
SLIDE 43

Translation

  • Do a shear-x(45°) operation on the 2D world!
  • Everything in the 1D world has moved

magically one x-coordinate to the right...

tan(45°) = 1

slide-44
SLIDE 44

Translation

  • What if we do shear-x(63.4°)?

tan(63.4°) = 2

  • Everything has now moved 2 x-coordinates to

the right from the original position

  • We can do translation (movement)!
slide-45
SLIDE 45

Translation

  • When we represent our points in one dimension

higher space, where the extra coordinate is 1, we get to the homogeneous space.

(

1 xt 1) ⋅( x 1)=( x+ xt 1 )

(

1 xt 1 yt 1) ⋅( x y 1) =( x+ xt y+ yt 1 ) ( 1 xt 1 yt 1 zt 1) ⋅( x y z 1) =( x+ xt y+ yt z+ zt 1 )

slide-46
SLIDE 46

Transformations

  • This together gives us a very good toolset to

transform our geometry as we wish.

(

a b c xt d e f yt g h i zt 1) ⋅( x y z 1) =( ax+ by+ cz+ xt dx+ ey+ fz+ yt gx+ hy+ iz+ zt 1

)

Used for perspective projection... Translation column Linear transformations

Affine trasnformation

slide-47
SLIDE 47

Multiple transformations

  • Everything starts from the origin!
  • To apply multiple transformations, just multiply

matrices.

slide-48
SLIDE 48

Multiple transformations

Our initial geometry defined by vertices: (-1, -1), (1, -1), (1, 1), (-1, 1)

slide-49
SLIDE 49

Multiple transformations

(cos(45))

(

cos(45°) −sin(45°) sin(45°) cos(45°) 1)

slide-50
SLIDE 50

Multiple transformations

(

1 4 1 1)

slide-51
SLIDE 51

Multiple transformations

  • We can combine the transformations to a single

matrix.

(

1 4 1 1) ⋅( cos(45°) −sin(45°) sin(45°) cos(45°) 1) =( cos(45°) −sin(45°) 4 sin(45°) cos(45°) 1)

  • This works for combining different affine transfor-

mations, but the result is hard to read...

  • Order of transformations / matrices is important!
  • http://cgdemos.tume-maailm.pri.ee
slide-52
SLIDE 52

Now You Know

Vertex transformations Culling & Clipping Rasterization Fragment shading Visibility tests & Blending Vertex shader Data

M =M 1⋅M 2 ⋅M 3 ⋅ ...

v1 v0 v 2

P⋅V⋅M⋅v

v1 v0 v 2 v1 v0 v 2 vs

(

vx vw , v y vw , v z vw)

v1 v0 v 2

slide-53
SLIDE 53

Next time...

  • What is color in computer graphics?
  • How to color our rasterized pixels?
  • Light calculations.

Rasterization Fragment shading Visibility tests & Blending Fragment shader