infogr computer graphics - universiteit utrecht - geometry and...Β Β· previous slides:...

33
INFOGR – Computer Graphics Jacco Bikker - April-July 2015 - Lecture 3: β€œGeometry” Welcome!

Upload: others

Post on 10-Oct-2020

2 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: INFOGR Computer Graphics - Universiteit Utrecht - geometry and...Β Β· previous slides: 𝑝1=βˆ’3,βˆ’1 𝑝2 ... For the generic case, we lookup the color value in a pixel buffer

INFOGR – Computer GraphicsJacco Bikker - April-July 2015 - Lecture 3: β€œGeometry”

Welcome!

Page 2: INFOGR Computer Graphics - Universiteit Utrecht - geometry and...Β Β· previous slides: 𝑝1=βˆ’3,βˆ’1 𝑝2 ... For the generic case, we lookup the color value in a pixel buffer

Today’s Agenda:

2D Primitives

3D Primitives

Textures

Page 3: INFOGR Computer Graphics - Universiteit Utrecht - geometry and...Β Β· previous slides: 𝑝1=βˆ’3,βˆ’1 𝑝2 ... For the generic case, we lookup the color value in a pixel buffer

2D Primitives

INFOGR – Lecture 3 – β€œGeometry”

Recap

Last time: vectors and their properties:

Magnitude, direction Scalar product Null vector, normal Parallel, linear (in)depence Commutative addition & subtraction Dot product, cross product

Concepts:

ℝd spaces (orthonormal) 2D basis, Cartesian Left handed, right handed

41

12

53

Page 4: INFOGR Computer Graphics - Universiteit Utrecht - geometry and...Β Β· previous slides: 𝑝1=βˆ’3,βˆ’1 𝑝2 ... For the generic case, we lookup the color value in a pixel buffer

2D Primitives

INFOGR – Lecture 3 – β€œGeometry”

Implicit representation

Implicit curve:

𝑓 π‘₯, 𝑦 = 0

Function f maps two-dimensional points to a real value, i.e.

π‘₯, 𝑦 β†’ 𝑓(π‘₯, 𝑦)

The points for which this value is 0 are on the curve.

Example: circle

π‘₯2 + 𝑦2 βˆ’ π‘Ÿ2 = 0

If 𝑝 = (x, y) is a point on the circle, and 𝑝 is a vector from the origin to 𝑝, it’s length must be π‘Ÿ, so ⃦ 𝑝 ⃦ = π‘Ÿ.

Example: circle with center c and radius r:

(x-cπ‘₯)2 + 𝑦 βˆ’ 𝑐𝑦2 βˆ’ π‘Ÿ2 = 0

c

𝑝

𝑝

Page 5: INFOGR Computer Graphics - Universiteit Utrecht - geometry and...Β Β· previous slides: 𝑝1=βˆ’3,βˆ’1 𝑝2 ... For the generic case, we lookup the color value in a pixel buffer

2D Primitives

INFOGR – Lecture 3 – β€œGeometry”

Implicit representation

Implicit curve:

𝑓 π‘₯, 𝑦 = 0

Function f maps two-dimensional points to a real value, i.e.

π‘₯, 𝑦 β†’ 𝑓(π‘₯, 𝑦)

The points for which this value is 0 are on the curve.

Example: line

Slope-intersect form:

𝑦 = π‘Žπ‘₯ + 𝑐

Implicit form:

βˆ’π‘Žπ‘₯ + 𝑦 βˆ’ 𝑐 = 0

In general:

𝐴π‘₯ + 𝐡𝑦 + 𝐢 = 0

𝑦 =2

3π‘₯ + 1

𝑐

βˆ†π‘₯

βˆ†π‘¦

π‘Ž =βˆ†y

βˆ†x

Page 6: INFOGR Computer Graphics - Universiteit Utrecht - geometry and...Β Β· previous slides: 𝑝1=βˆ’3,βˆ’1 𝑝2 ... For the generic case, we lookup the color value in a pixel buffer

2D Primitives

INFOGR – Lecture 3 – β€œGeometry”

Implicit line representation

𝐴π‘₯ + 𝐡𝑦 + 𝐢 = 0

In this case:

A = βˆ’2

3, B = 1 , C = βˆ’1

The vector (A,B) is a normal of the line.

𝑐

βˆ†π‘₯

βˆ†π‘¦

Slope-intersect form:

𝑦 = π‘Žπ‘₯ + 𝑐

Implicit form:

βˆ’π‘Žπ‘₯ + 𝑦 βˆ’ 𝑐 = 0

General form:

𝐴π‘₯ + 𝐡𝑦 + 𝐢 = 0

𝑦 =2

3π‘₯ + 1

𝑝(π‘₯, 𝑦)

𝑝(βˆ’π‘₯,βˆ’π‘¦)

𝑝(𝑦,βˆ’π‘₯)

𝑝(βˆ’π‘¦, π‘₯)

Page 7: INFOGR Computer Graphics - Universiteit Utrecht - geometry and...Β Β· previous slides: 𝑝1=βˆ’3,βˆ’1 𝑝2 ... For the generic case, we lookup the color value in a pixel buffer

2D Primitives

INFOGR – Lecture 3 – β€œGeometry”

Implicit line representation

𝐴π‘₯ + 𝐡𝑦 + 𝐢 = 0

In this case:

A = βˆ’2

3, B = 1 , C = βˆ’1

The vector (A,B) is a normal of the line.

𝑐

βˆ†π‘₯

βˆ†π‘¦

We can use the normal to calculate the distance of a point to the line:

𝑑 = 𝑁 βˆ™ 𝑝 + 𝐢

For 𝑝 = 3,3 :

𝑑 = βˆ’2

3βˆ— 3 + 1 βˆ— 3 βˆ’ 1

= βˆ’2 + 3 βˆ’ 1 = 0

For 𝑝 = 0,0 :

𝑑 = βˆ’2

3βˆ— 0 + 1 βˆ— 0 βˆ’ 1

= βˆ’1 (? )

𝑦 =2

3π‘₯ + 1

Page 8: INFOGR Computer Graphics - Universiteit Utrecht - geometry and...Β Β· previous slides: 𝑝1=βˆ’3,βˆ’1 𝑝2 ... For the generic case, we lookup the color value in a pixel buffer

2D Primitives

INFOGR – Lecture 3 – β€œGeometry”

Implicit line representation

𝐴π‘₯ + 𝐡𝑦 + 𝐢 = 0

Given point 𝑝1 and 𝑝2, we determine A, B and C as follows:

𝑙 = 𝑝2 βˆ’ 𝑝1

𝑁 = βˆ’π‘™π‘¦ , 𝑙π‘₯

𝐴 = 𝑁π‘₯ , 𝐡 = 𝑁𝑦 , 𝐢 = βˆ’(𝑁 Β· 𝑝1)

It is convenient to normalize the normal:

Only when ǁ𝑁ǁ = 1, |C| is the distance of the line to the origin.

p1

p2

Test with the line from the previous slides:

𝑝1 = βˆ’3,βˆ’1𝑝2 = 3,3

𝑙 = 6,4

𝑁 = βˆ’4,6𝐴 = βˆ’4, 𝐡 = 6𝐢 = βˆ’( βˆ’4 βˆ— βˆ’3 + 6 βˆ— βˆ’1)

= βˆ’6

βˆ’4π‘₯ + 6𝑦 βˆ’ 6 = 0

βˆ’2

3π‘₯ + 𝑦 βˆ’ 1 = 0

|𝐢|+

-

Page 9: INFOGR Computer Graphics - Universiteit Utrecht - geometry and...Β Β· previous slides: 𝑝1=βˆ’3,βˆ’1 𝑝2 ... For the generic case, we lookup the color value in a pixel buffer

2D Primitives

INFOGR – Lecture 3 – β€œGeometry”

Parametric representation

Parametric curve:

π‘₯𝑦 =

𝑔(𝑑)β„Ž(𝑑)

Example: line

𝑝0 = π‘₯𝑝0, 𝑦𝑝0 , 𝑝1 = (π‘₯𝑝1, 𝑦𝑝1)

π‘₯𝑦 =

π‘₯𝑝0

𝑦𝑝0+ 𝑑

π‘₯𝑝1 βˆ’ π‘₯𝑝0

𝑦𝑝1 βˆ’ 𝑦𝑝0

Or

𝑝 𝑑 = 𝑝0 + 𝑑 𝑝1 βˆ’ 𝑝0 , 𝑑 ∈ ℝ.

p0

p1

In this example:

𝑝1 is the support vector;𝑝1 βˆ’ 𝑝0 is the direction vector.

Page 10: INFOGR Computer Graphics - Universiteit Utrecht - geometry and...Β Β· previous slides: 𝑝1=βˆ’3,βˆ’1 𝑝2 ... For the generic case, we lookup the color value in a pixel buffer

2D Primitives

INFOGR – Lecture 3 – β€œGeometry”

Slope-intercept:

𝑦 = π‘Žπ‘₯ + 𝑐

Implicit representation:

βˆ’π‘Žπ‘₯ + 𝑦 βˆ’ 𝑐 = 0𝐴π‘₯ + 𝐡𝑦 + 𝐢 = 0

Parametric representation:

𝑝 𝑑 = 𝑝0 + 𝑑 𝑝1 βˆ’ 𝑝0

p0

p1

βˆ†π‘₯

βˆ†π‘¦

Page 11: INFOGR Computer Graphics - Universiteit Utrecht - geometry and...Β Β· previous slides: 𝑝1=βˆ’3,βˆ’1 𝑝2 ... For the generic case, we lookup the color value in a pixel buffer

2D Primitives

INFOGR – Lecture 3 – β€œGeometry”

Circle - parametric

π‘₯𝑦 =

π‘₯𝑐 + π‘Ÿ cosπœ™π‘¦π‘ + π‘Ÿ sinπœ™

πœ™

c

πœ™

π‘Ÿ

π‘₯

𝑦

cosπœ™ =π‘₯

π‘Ÿ

𝑠𝑖𝑛 πœ™ =𝑦

π‘Ÿ

π‘‘π‘Žπ‘› πœ™ =𝑦

π‘₯

adjacent

op

po

site

SOH CAH TOA

Page 12: INFOGR Computer Graphics - Universiteit Utrecht - geometry and...Β Β· previous slides: 𝑝1=βˆ’3,βˆ’1 𝑝2 ... For the generic case, we lookup the color value in a pixel buffer

Today’s Agenda:

2D Primitives

3D Primitives

Textures

Page 13: INFOGR Computer Graphics - Universiteit Utrecht - geometry and...Β Β· previous slides: 𝑝1=βˆ’3,βˆ’1 𝑝2 ... For the generic case, we lookup the color value in a pixel buffer

3D Primitives

INFOGR – Lecture 3 – β€œGeometry”

Circle – sphere (implicit)

Recall: the implicit representation for a circle with radius π‘Ÿ and center 𝑐 is:

π‘₯ βˆ’ π‘₯𝑐 2 + 𝑦 βˆ’ 𝑦𝑐 2 βˆ’ π‘Ÿ2 = 0

or: βˆ₯ p βˆ’ c βˆ₯ 2 βˆ’ π‘Ÿ2 = 0 βˆ₯ 𝑝 βˆ’ 𝑐 βˆ₯ = π‘Ÿ

In ℝ3, we get:

π‘₯ βˆ’ 𝑐π‘₯2 + 𝑦 βˆ’ 𝑐𝑦

2 + 𝑧 βˆ’ 𝑐𝑧 2 βˆ’ π‘Ÿ2 = 0

or: βˆ₯ 𝑝 βˆ’ 𝑐 βˆ₯= π‘Ÿ

c

𝑝

Page 14: INFOGR Computer Graphics - Universiteit Utrecht - geometry and...Β Β· previous slides: 𝑝1=βˆ’3,βˆ’1 𝑝2 ... For the generic case, we lookup the color value in a pixel buffer

3D Primitives

INFOGR – Lecture 3 – β€œGeometry”

Line – plane (implicit)

Recall: the implicit representation for a line is:

𝐴π‘₯ + 𝐡𝑦 + 𝐢 = 0

In ℝ3, we get a plane:

𝐴π‘₯ + 𝐡𝑦 + 𝐢𝑧 + 𝐷 = 0p1

p2

Page 15: INFOGR Computer Graphics - Universiteit Utrecht - geometry and...Β Β· previous slides: 𝑝1=βˆ’3,βˆ’1 𝑝2 ... For the generic case, we lookup the color value in a pixel buffer

3D Primitives

INFOGR – Lecture 3 – β€œGeometry”

Parametric surfaces

A parametric surface needs two parameters:

π‘₯ = 𝑓(𝑒, 𝑣),𝑦 = 𝑔(𝑒, 𝑣),𝑧 = β„Ž(𝑒, 𝑣).

For example, a sphere:

π‘₯ = π‘Ÿ cosπœ™ sin πœƒ,𝑦 = π‘Ÿ sinπœ™ sin πœƒ,𝑧 = π‘Ÿ cos πœƒ.

Doesn’t look very convenient (compared to the implicit form), but it will prove useful for texture mapping.

οΏ½

πœƒ

Page 16: INFOGR Computer Graphics - Universiteit Utrecht - geometry and...Β Β· previous slides: 𝑝1=βˆ’3,βˆ’1 𝑝2 ... For the generic case, we lookup the color value in a pixel buffer

3D Primitives

INFOGR – Lecture 3 – β€œGeometry”

Parametric planes

Recall the parametric line definition:

𝑝 𝑑 = 𝑝0 + 𝑑 𝑝1 βˆ’ 𝑝0

For a plane, we need to parameters:

𝑝 𝑠, 𝑑 = 𝑝0 + 𝑠 𝑝1 βˆ’ 𝑝0 + 𝑑(𝑝2 βˆ’ 𝑝0)

or:𝑝 𝑠, 𝑑 = 𝑝0 + 𝑠 𝑣 + 𝑑𝑀

where: 𝑝0 is a point on the plane; 𝑣 and 𝑀 are two linearly independent

vectors on the plane; 𝑠, 𝑑 ∈ ℝ.

y

z

x

𝑣

𝑀

𝑝0

Page 17: INFOGR Computer Graphics - Universiteit Utrecht - geometry and...Β Β· previous slides: 𝑝1=βˆ’3,βˆ’1 𝑝2 ... For the generic case, we lookup the color value in a pixel buffer

Today’s Agenda:

2D Primitives

3D Primitives

Textures

Page 18: INFOGR Computer Graphics - Universiteit Utrecht - geometry and...Β Β· previous slides: 𝑝1=βˆ’3,βˆ’1 𝑝2 ... For the generic case, we lookup the color value in a pixel buffer

Textures

INFOGR – Lecture 3 – β€œGeometry”

Page 19: INFOGR Computer Graphics - Universiteit Utrecht - geometry and...Β Β· previous slides: 𝑝1=βˆ’3,βˆ’1 𝑝2 ... For the generic case, we lookup the color value in a pixel buffer

Textures

INFOGR – Lecture 3 – β€œGeometry”

Back to the world of graphics…

Given a plane: 𝑦 = 0 (i.e., with a normal vector (0,1,0) ).

Two vectors on the plane define a basis: 𝑒 = (1,0,0) and 𝑣 = (0,0,1).

Using these vectors, any point on the plane can be reached: 𝑃 = Ξ»1𝑒 + Ξ»2 𝑣.

We can now use Ξ»1, Ξ»2 to define a color at P: 𝐹(Ξ»1, Ξ»2) = β‹― .

𝑒

𝑣

Page 20: INFOGR Computer Graphics - Universiteit Utrecht - geometry and...Β Β· previous slides: 𝑝1=βˆ’3,βˆ’1 𝑝2 ... For the generic case, we lookup the color value in a pixel buffer

Textures

INFOGR – Lecture 3 – β€œGeometry”

Example:

𝐹(λ1, λ2) = sin(λ1)

Another example:

𝐹(Ξ»1, Ξ»2) = ( int (2 βˆ— Ξ»1) + (int)Ξ»2) & 1

Page 21: INFOGR Computer Graphics - Universiteit Utrecht - geometry and...Β Β· previous slides: 𝑝1=βˆ’3,βˆ’1 𝑝2 ... For the generic case, we lookup the color value in a pixel buffer

Textures

INFOGR – Lecture 3 – β€œGeometry”

Other examples (not explained here):

Perlin noiseDetails: http://www.noisemachine.com/talk1

Voronoi / Worley noiseDetails: β€œA cellular texture basis function”, S. Worley, 1996.

Page 22: INFOGR Computer Graphics - Universiteit Utrecht - geometry and...Β Β· previous slides: 𝑝1=βˆ’3,βˆ’1 𝑝2 ... For the generic case, we lookup the color value in a pixel buffer

Textures

INFOGR – Lecture 3 – β€œGeometry”

Obviously, not all textures can be generated procedurally.

For the generic case, we lookup the color value in a pixel buffer.

π‘₯𝑦 = 𝑃 βˆ™ 𝑒

𝑃 βˆ™ 𝑣

Note that we find the pixel to read based on 𝑃; we don’t find a β€˜π‘ƒβ€™ for every pixel of the texture.

𝑒

𝑣

P

βˆ—π‘‡π‘€π‘–π‘‘π‘‘β„Ž

π‘‡β„Žπ‘’π‘–π‘”β„Žπ‘‘

0 2550

255

Page 23: INFOGR Computer Graphics - Universiteit Utrecht - geometry and...Β Β· previous slides: 𝑝1=βˆ’3,βˆ’1 𝑝2 ... For the generic case, we lookup the color value in a pixel buffer

Textures

INFOGR – Lecture 3 – β€œGeometry”

Retrieving a pixel from a texture:

π‘₯𝑦 = 𝑃 βˆ™ 𝑒

𝑃 βˆ™ π‘£βˆ—

π‘‡π‘€π‘–π‘‘π‘‘β„Ž

π‘‡β„Žπ‘’π‘–π‘”β„Žπ‘‘

We don’t want to read outside the texture. To prevent this, we have two options:

1. Clamping

2. Tiling

Tiling is efficiently achieved using a bitmask. This requires texture dimensions that are a power of 2.

0 2550

255π‘₯𝑦 =

π‘π‘™π‘Žπ‘šπ‘(𝑃 βˆ™ 𝑒, 0, 1)

π‘π‘™π‘Žπ‘šπ‘(𝑃 βˆ™ 𝑣, 0,1)βˆ—

π‘‡π‘€π‘–π‘‘π‘‘β„Ž

π‘‡β„Žπ‘’π‘–π‘”β„Žπ‘‘

π‘₯𝑦 =

π‘“π‘Ÿπ‘Žπ‘(𝑃 βˆ™ 𝑒)

π‘“π‘Ÿπ‘Žπ‘(𝑃 βˆ™ 𝑣)βˆ—

π‘‡π‘€π‘–π‘‘π‘‘β„Ž

π‘‡β„Žπ‘’π‘–π‘”β„Žπ‘‘

Page 24: INFOGR Computer Graphics - Universiteit Utrecht - geometry and...Β Β· previous slides: 𝑝1=βˆ’3,βˆ’1 𝑝2 ... For the generic case, we lookup the color value in a pixel buffer

Textures

INFOGR – Lecture 3 – β€œGeometry”

Texture mapping: oversampling

Page 25: INFOGR Computer Graphics - Universiteit Utrecht - geometry and...Β Β· previous slides: 𝑝1=βˆ’3,βˆ’1 𝑝2 ... For the generic case, we lookup the color value in a pixel buffer

Textures

INFOGR – Lecture 3 – β€œGeometry”

Texture mapping: undersampling

Page 26: INFOGR Computer Graphics - Universiteit Utrecht - geometry and...Β Β· previous slides: 𝑝1=βˆ’3,βˆ’1 𝑝2 ... For the generic case, we lookup the color value in a pixel buffer

Textures

INFOGR – Lecture 3 – β€œGeometry”

Fixing oversampling

Oversampling: reading the same pixel from a texture multiple times.Symptoms: blocky textures.

Remedy: bilinear interpolation:Instead of clamping the pixel location to the nearest pixel, we read from four pixels.

𝑀𝑝1 : (1 βˆ’ π‘“π‘Ÿπ‘Žπ‘(π‘₯)) βˆ— (1 βˆ’ π‘“π‘Ÿπ‘Žπ‘(𝑦))𝑀𝑝2 : π‘“π‘Ÿπ‘Žπ‘ π‘₯ βˆ— (1 βˆ’ π‘“π‘Ÿπ‘Žπ‘ 𝑦 )

𝑀𝑝3 : 1 βˆ’ π‘“π‘Ÿπ‘Žπ‘ π‘₯ βˆ— π‘“π‘Ÿπ‘Žπ‘(𝑦)

𝑀𝑝4 : 1 βˆ’ (𝑀𝑃1 +𝑀𝑃2 +

𝑀𝑃3)

Page 27: INFOGR Computer Graphics - Universiteit Utrecht - geometry and...Β Β· previous slides: 𝑝1=βˆ’3,βˆ’1 𝑝2 ... For the generic case, we lookup the color value in a pixel buffer

Textures

INFOGR – Lecture 3 – β€œGeometry”

Fixing oversampling

Page 28: INFOGR Computer Graphics - Universiteit Utrecht - geometry and...Β Β· previous slides: 𝑝1=βˆ’3,βˆ’1 𝑝2 ... For the generic case, we lookup the color value in a pixel buffer

Textures

INFOGR – Lecture 3 – β€œGeometry”

Fixing undersampling

Undersampling: skipping pixels while reading from a texture.Symptoms: MoirΓ©, flickering, noise.

Remedy: MIP-mapping.

The texture is reduced to 25% by averaging2x2 pixels. This is repeated until a 1x1 imageremains.

When undersampling occurs, we switch tothe next MIP level.

Page 29: INFOGR Computer Graphics - Universiteit Utrecht - geometry and...Β Β· previous slides: 𝑝1=βˆ’3,βˆ’1 𝑝2 ... For the generic case, we lookup the color value in a pixel buffer

Textures

INFOGR – Lecture 3 – β€œGeometry”

Page 30: INFOGR Computer Graphics - Universiteit Utrecht - geometry and...Β Β· previous slides: 𝑝1=βˆ’3,βˆ’1 𝑝2 ... For the generic case, we lookup the color value in a pixel buffer

Textures

INFOGR – Lecture 3 – β€œGeometry”

Page 31: INFOGR Computer Graphics - Universiteit Utrecht - geometry and...Β Β· previous slides: 𝑝1=βˆ’3,βˆ’1 𝑝2 ... For the generic case, we lookup the color value in a pixel buffer

Textures

INFOGR – Lecture 3 – β€œGeometry”

Trilinear interpolation: blending between MIP levels.

Page 32: INFOGR Computer Graphics - Universiteit Utrecht - geometry and...Β Β· previous slides: 𝑝1=βˆ’3,βˆ’1 𝑝2 ... For the generic case, we lookup the color value in a pixel buffer

Today’s Agenda:

2D Primitives

3D Primitives

Textures

Page 33: INFOGR Computer Graphics - Universiteit Utrecht - geometry and...Β Β· previous slides: 𝑝1=βˆ’3,βˆ’1 𝑝2 ... For the generic case, we lookup the color value in a pixel buffer

INFOGR – Computer GraphicsJacco Bikker - April-July 2015 - Lecture 3: β€œGeometry”

END of β€œGeometry”next lecture: β€œ3D Engine Fundamentals”