infogr computer graphics - universiteit utrecht - geometry and...Β Β· previous slides:...
TRANSCRIPT
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β