INFOGR โ Computer GraphicsJacco Bikker - April-July 2015 - Lecture 3: โGeometryโ
Welcome!
Todayโs Agenda:
2D Primitives
3D Primitives
Textures
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
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
๐
๐
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
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
๐(๐ฅ, ๐ฆ)
๐(โ๐ฅ,โ๐ฆ)
๐(๐ฆ,โ๐ฅ)
๐(โ๐ฆ, ๐ฅ)
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
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
|๐ถ|+
-
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.
2D Primitives
INFOGR โ Lecture 3 โ โGeometryโ
Slope-intercept:
๐ฆ = ๐๐ฅ + ๐
Implicit representation:
โ๐๐ฅ + ๐ฆ โ ๐ = 0๐ด๐ฅ + ๐ต๐ฆ + ๐ถ = 0
Parametric representation:
๐ ๐ก = ๐0 + ๐ก ๐1 โ ๐0
p0
p1
โ๐ฅ
โ๐ฆ
2D Primitives
INFOGR โ Lecture 3 โ โGeometryโ
Circle - parametric
๐ฅ๐ฆ =
๐ฅ๐ + ๐ cos๐๐ฆ๐ + ๐ sin๐
๐
c
๐
๐
๐ฅ
๐ฆ
cos๐ =๐ฅ
๐
๐ ๐๐ ๐ =๐ฆ
๐
๐ก๐๐ ๐ =๐ฆ
๐ฅ
adjacent
op
po
site
SOH CAH TOA
Todayโs Agenda:
2D Primitives
3D Primitives
Textures
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
๐
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
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.
๏ฟฝ
๐
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
Todayโs Agenda:
2D Primitives
3D Primitives
Textures
Textures
INFOGR โ Lecture 3 โ โGeometryโ
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) = โฏ .
๐ข
๐ฃ
Textures
INFOGR โ Lecture 3 โ โGeometryโ
Example:
๐น(ฮป1, ฮป2) = sin(ฮป1)
Another example:
๐น(ฮป1, ฮป2) = ( int (2 โ ฮป1) + (int)ฮป2) & 1
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.
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
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)โ
๐๐ค๐๐๐กโ
๐โ๐๐๐โ๐ก
๐ฅ๐ฆ =
๐๐๐๐(๐ โ ๐ข)
๐๐๐๐(๐ โ ๐ฃ)โ
๐๐ค๐๐๐กโ
๐โ๐๐๐โ๐ก
Textures
INFOGR โ Lecture 3 โ โGeometryโ
Texture mapping: oversampling
Textures
INFOGR โ Lecture 3 โ โGeometryโ
Texture mapping: undersampling
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)
Textures
INFOGR โ Lecture 3 โ โGeometryโ
Fixing oversampling
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.
Textures
INFOGR โ Lecture 3 โ โGeometryโ
Textures
INFOGR โ Lecture 3 โ โGeometryโ
Textures
INFOGR โ Lecture 3 โ โGeometryโ
Trilinear interpolation: blending between MIP levels.
Todayโs Agenda:
2D Primitives
3D Primitives
Textures
INFOGR โ Computer GraphicsJacco Bikker - April-July 2015 - Lecture 3: โGeometryโ
END of โGeometryโnext lecture: โ3D Engine Fundamentalsโ