1 of 115

Transforms & Texture Mapping

Computer Graphics and Imaging

UC Berkeley CS 184/284A

Discussion 03

2 of 115

Worksheet link!

https://tinyurl.com/2wmh4ewe

3 of 115

Icebreaker!

celebrationFavorite Movie?

Share with your neighbors!

  • What is your favorite movie?
    • Recent watch?
    • Childhood favorite?
    • Can practically quote from start to finish?

  • Happy 20th bday to Cars!!
    • Who here is younger than Cars 👀

4 of 115

Week 3 Announcements

alarm

Homework 0

Due on Thursday (9/10)!

assignment

Homework 1

Will be released on Wednesday (9/15)!

groups

Project Partners

Homeworks can be completed with a partner.

Search on Ed:�"Find a Project Partner"

5 of 115

Disc 2 Review!

6 of 115

Review Discussion

1. Rasterization

  • What is rasterization?
  • How do you rasterize this triangle? →

2. Aliasing

  • What is aliasing and when does it occur?
  • What are some real-world examples?
  • What anti-aliasing methods did we learn?

3. Nyquist Theorem

  • What is the Nyquist theorem and why does it matter?

7 of 115

Disc 2 Leftovers!

8 of 115

3. Nyquist Theorem

9 of 115

Nyquist frequency

The Nyquist frequency is half of the sampling frequency of your device.

Ex: If your camera has a frame rate of 24 (runs at 24 Hz), the Nyquist frequency is 12 Hz.

10 of 115

Nyquist theorem

There is no aliasing from frequencies in the signal that are less than the Nyquist frequency.

Ex (previous slide): Your camera can capture signals with frequency less than 12 Hz without aliasing.

11 of 115

11

12 of 115

12

1/16

1/32

1/64

1/128

1/256

> 2 * 1/16 = ⅛

> 1/16

> 1/32

> 1/64

> 1/128

13 of 115

Hint:

In 1 rotation, a wheel with n spokes shows the same ”image” n times, so if that rotation took 1 second, it would have a frequency of n hz

14 of 115

Hint:

In 1 rotation, a wheel with n spokes shows the same ”image” n times, so if that rotation took 1 second, it would have a frequency of n hz

Wheel A: 4 * 6 = 24 Hz → frame rate: 48

Wheel B: 6 * 5 = 30 Hz → frame rate: 60

15 of 115

4. Ashley’s Helicopter

16 of 115

What’s the Nyquist frequency of Ashley’s video camera?

17 of 115

The Nyquist frequency of Ashley’s video camera is 64 frames per second

So long as the helicopter rotates at less than 64 cycles per second, Ashley will not see any aliasing. The helicopter has 8 blades, so rotating at 8 rotations/second achieves the Nyquist frequency of 64 cycles per second.

18 of 115

Moving onto this week's topic!

19 of 115

Transformation Matrices

20 of 115

1. Basic Transforms

21 of 115

Transformations

Isometric - transformation that preserves size, shape, and distance

Which transformation method holds this property?

22 of 115

22

23 of 115

23

24 of 115

[Review] Matrix Vector Manipulation

25 of 115

Matrix-Vector Multiplication

cosθ

-sinθ

sinθ

cosθ

1

0

=

26 of 115

Matrix-Vector Multiplication

cosθ

-sinθ

sinθ

cosθ

1

0

=

cosθ

27 of 115

Matrix-Vector Multiplication

cosθ

-sinθ

sinθ

cosθ

1

0

=

cosθ

sinθ

28 of 115

Matrix-Vector Multiplication

cosθ

-sinθ

sinθ

cosθ

1

0

=

cosθ

sinθ

cosθ

-sinθ

sinθ

cosθ

0

1

=

-sinθ

29 of 115

Matrix-Vector Multiplication

cosθ

-sinθ

sinθ

cosθ

1

0

=

cosθ

sinθ

cosθ

-sinθ

sinθ

cosθ

0

1

=

-sinθ

cosθ

30 of 115

Matrix-Vector Multiplication

cosθ

-sinθ

sinθ

cosθ

1

0

=

cosθ

sinθ

cosθ

-sinθ

sinθ

cosθ

0

1

=

-sinθ

cosθ

θ

θ

31 of 115

31

32 of 115

Why do we have points defined in 3D?

Translation

Goal: We want x + t_x, y + t_y

⇒ We need constant terms

33 of 115

Homogeneous Coordinates

34 of 115

Homogeneous Coordinates

  • Represent a point in n-dimensional space using n + 1 coordinates.

35 of 115

Homogeneous Coordinates

  • Represent a point in n-dimensional space using n + 1 coordinates.

cosθ

-sinθ

sinθ

cosθ

cosθ

-sinθ

0

sinθ

cosθ

0

0

0

1

(x, y)T → (x, y, w)T

(x, y, z)T → (x, y, z, w)T

  • w = 1 to represent a point.
  • w = 0 to represent a vector.

x

y

x

y

1

36 of 115

Homogeneous Coordinates

  • Homogeneous coordinates to represent translations as matrices!
  • To shift right by tx, shift up by ty:

1

0

tx

0

1

ty

0

0

1

x

y

1

x + tx

y + ty

1

=

37 of 115

37

What does this mean?

38 of 115

38

39 of 115

39

40 of 115

40

NOTHING :)

41 of 115

Homogeneous Coordinates

  • Represent a point in n-dimensional space using n + 1 coordinates.

42 of 115

Transformation Matrices

43 of 115

Transformation Matrices

Coordinate System�Change

44 of 115

Hint:

45 of 115

⚠️Order matters!⚠️

46 of 115

Slide link!

https://tinyurl.com/57ttm8kd

Attendance!

https://tinyurl.com/4p3xcpsx

Attendance Code:

47 of 115

In case you are VERY ambitious…

[Next week's overview & worksheet sols!]

48 of 115

Coordinate Spaces

49 of 115

How do we specify coordinate spaces?

  • In original coordinate space, specify:
    • Origin, o.
    • Two unit vectors, u and v.

50 of 115

Coordinate System Transformation

  • Transform from (u, v, o) frame to (x, y) frame using:

51 of 115

Coordinate System Transformation

  • Transform from (u, v, o) frame to (x, y) frame using:

52 of 115

Coordinate System Transformation

  • Transform from (u, v, o) frame to (x, y) frame using:

53 of 115

Affine Transformation (General Form)

A is a standard linear transform and b is the translation vector

Vector u represents y’s first basis vector inside of x space

54 of 115

Camera coordinates

55 of 115

Given an object’s camera coordinates, how do we find its world coordinates?

Camera has e, u, v in world coordinates

56 of 115

Given an object’s camera coordinates, how do we find its world coordinates?

Camera has e, u, v in world coordinates

Transformation matrix

57 of 115

Diagram

58 of 115

2. Rebecca Takes a Look

59 of 115

60 of 115

61 of 115

62 of 115

1. Realize that the view direction = -z axis of camera coordinates.

2. Draw the camera coordinate frame axes, and then we find that +z = -v

63 of 115

64 of 115

use right hand rule

65 of 115

66 of 115

67 of 115

Barycentric Coordinates

68 of 115

Barycentric Coordinates

68

  • Represents the distance from a given point to the triangle’s vertices
  • Alpha, beta, and gamma act as weights

69 of 115

Barycentric Coordinates

  • (x, y) as weighted sum of values at triangle vertices.
  • If A, B, C are colors, αA + βB + γC is an in-between color.

70 of 115

Barycentric Coordinates

  • (x, y) as weighted sum of values at triangle vertices.
  • If A, B, C are colors, αA + βB + γC is an in-between color.

71 of 115

71

72 of 115

Barycentric Interpolation

72

73 of 115

3. Barycentric Coordinates

74 of 115

74

75 of 115

75

76 of 115

76

77 of 115

77

78 of 115

78

79 of 115

79

80 of 115

80

81 of 115

81

82 of 115

82

83 of 115

83

84 of 115

Texture Mapping

85 of 115

Texture Coordinates

86 of 115

Texture Coordinates

86

87 of 115

Texture Coordinates

88 of 115

Dealing with aliasing – Minecraft

88

89 of 115

Dealing with aliasing – Minecraft

89

90 of 115

Dealing with aliasing – Minecraft

90

Antialiasing disabled (not using mipmaps): visible artifacts

91 of 115

Dealing with aliasing – Minecraft

91

Antialiasing via mipmaps enabled

92 of 115

Antialiasing Textures

  • Super-sampling, then down-sampling, is equivalent to low-pass filtering.
  • Sample lower-resolution textures to avoid aliasing.
  • Avoids expensive computations.

93 of 115

Antialiasing Textures

  1. Pre-compute lower resolution versions of texture
  2. Store textures in mipmap, using texture cache (if on GPUs).
  3. Adaptively choose mipmap level, D, according to scene.

93

94 of 115

Antialiasing Textures

  1. Pre-compute lower resolution versions of texture
  2. Store textures in mipmap, using texture cache (if on GPUs).
  3. Adaptively choose mipmap level according to scene.

94

Halve the dimensions each time →

95 of 115

Choosing Mipmap Levels

  • Big jump in texture space → use a blurred texture → high D.
  • Small jump in texture space → use a high resolution texture → low D.

96 of 115

Choosing Mipmap Levels

  • Big jump in texture space → use a blurred texture → high D.
  • Small jump in texture space → use a high resolution texture → low D.

97 of 115

97

98 of 115

Mipmap Example

98

512 x 512

256 x 256

128 x 128

64 x 64

99 of 115

Mipmaps

99

100 of 115

100

101 of 115

101

102 of 115

How do we determine which Mipmap level to use?

Idea: Look at a pixel’s neighbors:

  • If there’s a big jump in texture space, we should use a blurred texture
  • If there’s a small jump in texture space, we should use a high res texture

102

Level 0

Level 5

D = level�L = factor that you downsample by

103 of 115

Mathematical Deep Dive - Mipmap Equation

103

(u,v)01

(u,v)10

104 of 115

104

105 of 115

106 of 115

107 of 115

108 of 115

109 of 115

110 of 115

111 of 115

111

112 of 115

Mipmap Equation

112

Bilinear Filtering

Only use values from�one mipmap level

Trilinear Filtering

Linearly interpolate betweentwo mipmap levels

113 of 115

113

114 of 115

Mathematical Deep Dive - Mipmap Equation

114

Why max?

Consider this case:

Using max():

Using min():

Using avg():

Using min would mean we lose 8-10 texture pixels worth of info per pixel in the y direction!

Intuition: We always want to use the “worst-case” mipmap to avoid aliasing

  • Would rather we lose detail in one direction/have a blurry image than try to squeeze too much detail in the other direction

115 of 115

Mathematical Deep Dive - Mipmap Equation

115

Consider are all 1: → D = 0

are all 2: → D = 1

are all 4: → D = 2

Why log2?

In Practice, we use one of two techniques:

  • Bilinear Filtering - we only use values from one mipmap level
  • Trilinear Filtering - we interpolate between two mipmap level

Bilinear: If we only want one level we use:

Exactly what we want!

Trilinear: log2 keeps a consistent scaling as the size increases