What is a Transformation?

What is a Transformation?
• Maps points (x, y) in one coordinate system to
points (x', y') in another coordinate system
Transformations
x' = ax + by + c
y' = dx + ey + f
• For example, IFS:
CSCI-9692 Advanced Graphics
Cutler
Simple Transformations
CSCI-9692 Advanced Graphics
Transformations are used to:
•
•
•
•
•
• Can be combined
• Are these operations invertible?
Cutler
Position objects in a scene
Change the shape of objects
Create multiple copies of objects
Projection for virtual cameras
Describe
animations
Yes, except scale = 0
CSCI-9692 Advanced Graphics
Cutler
Outline
•
•
•
•
•
•
•
CSCI-9692 Advanced Graphics
Cutler
Rigid-Body / Euclidean Transforms
Classes of Transformations
Representing Transformations
Combining Transformations
Transformations in Modelling
Orthographic & Perspective Projections
OpenGL Basics
Color/Normal Interpolation
CSCI-9692 Advanced Graphics
Cutler
• Preserves distances
• Preserves angles
Rigid / Euclidean
Translation
Identity
Rotation
CSCI-9692 Advanced Graphics
Cutler
1
Similitudes / Similarity Transforms
Linear Transformations
• Preserves angles
Similitudes
Similitudes
Rigid / Euclidean
Identity
Translation
Linear
Rigid / Euclidean
Rotation
Isotropic Scaling
CSCI-9692 Advanced Graphics
Translation
Cutler
Identity
Rotation
Scaling
Isotropic Scaling
Reflection
Shear
CSCI-9692 Advanced Graphics
Cutler
Linear Transformations
Affine Transformations
• L(p + q) = L(p) + L(q)
• L(ap) = a L(p)
• preserves
parallel lines
Affine
Similitudes
Identity
Translation
Rotation
Similitudes
Linear
Rigid / Euclidean
Scaling
Isotropic Scaling
Reflection
Shear
CSCI-9692 Advanced Graphics
Linear
Rigid / Euclidean
Cutler
Translation
Identity
Rotation
Scaling
Isotropic Scaling
CSCI-9692 Advanced Graphics
Projective Transformations
Reflection
Shear
Cutler
Perspective Projection
• preserves lines
Projective
Affine
Similitudes
Linear
Rigid / Euclidean
Translation
Identity
Rotation
Scaling
Isotropic Scaling
Perspective
CSCI-9692 Advanced Graphics
Reflection
Shear
Cutler
CSCI-9692 Advanced Graphics
Cutler
2
General (free-form) transformation
Outline
• Does not preserve lines
• Not as pervasive, computationally more involved
•
•
•
•
•
•
•
Classes of Transformations
Representing Transformations
Combining Transformations
Transformations in Modelling
Orthographic & Perspective Projections
OpenGL Basics
Color/Normal Interpolation
From Sederberg and Parry, Siggraph 1986
CSCI-9692 Advanced Graphics
Cutler
CSCI-9692 Advanced Graphics
How are Transforms Represented?
Cutler
Homogeneous Coordinates
• Add an extra dimension
x' = ax + by + c
y' = dx + ey + f
• in 2D, we use 3 x 3 matrices
• In 3D, we use 4 x 4 matrices
• Each point has an extra value, w
x'
=
y'
a
d
p' =
b
e
x
c
+
y
f
Mp
CSCI-9692 Advanced Graphics
+ t
p' =
a b
d e
Mp
+ t
CSCI-9692 Advanced Graphics
Mp
x'
y' =
1
p' =
Cutler
x
y
z
w
Cutler
Homogeneous Coordinates
• Most of the time w = 1, and we can ignore it
Homogeneous formulation
x
c
+
y
f
p' =
CSCI-9692 Advanced Graphics
x' = ax + by + c
y' = dx + ey + f
x'
=
y'
c
g
k
o
Cutler
Translation in homogenous coordinates
Affine formulation
d
h
l
p
a b
x'
e f
y'
=
i j
z'
m n
w'
a b c
d e f
0 0 1
Mp
x
y
1
x'
y'
z'
1
=
a
e
i
0
b
f
j
0
c
g
k
0
d
h
l
1
x
y
z
1
• If we multiply a homogeneous coordinate
by an affine matrix, w is unchanged
CSCI-9692 Advanced Graphics
Cutler
3
Homogeneous Visualization
Translate (tx, ty, tz)
• Divide by w to normalize (homogenize)
• W = 0? Point at infinity (direction)
• Why bother with the
extra dimension?
Because now translations
can be encoded in the matrix!
(0, 0, 1) = (0, 0, 2) = …
(7, 1, 1) = (14, 2, 2) = …
(4, 5, 1) = (8, 10, 2) = …
x'
y'
z'
1
w=1
w=2
CSCI-9692 Advanced Graphics
Cutler
Scale (sx, sy, sz)
0
1
0
0
0
0
1
0
CSCI-9692 Advanced Graphics
p'
q
sx
0
=
0
0
0
sy
0
0
0
0
sz
0
CSCI-9692 Advanced Graphics
0
0
0
1
• About (kx, ky, kz), a unit
vector on an arbitrary axis
(Rodrigues Formula)
Cutler
ZRotate(θ)
p'
θ
x'
y'
z'
1
=
cos θ -sin θ
sin θ cos θ
0
0
0
0
0
0
1
0
CSCI-9692 Advanced Graphics
Cutler
0
0
0
1
x
y
z
1
• Often, w is not stored (always 1)
• Needs careful handling of direction vs. point
θ
k
kxkx(1-c)+c kzkx(1-c)-kzs kxkz(1-c)+kys
x'
kykx(1-c)+kzs kzkx(1-c)+c kykz(1-c)-kxs
y'
=
kzkx(1-c)-kys kzkx(1-c)-kxs kzkz(1-c)+c
z'
0
0
0
1
x
Storage
Rotate(k, θ)
z
p
z
x
y
z
1
y
x
y
z
1
q'
Cutler
Rotation
tx
ty
tz
1
y
x
x'
y'
z'
1
x
c
• About z axis
p
p'
p
Rotation
Scale(s,s,s)
y
• Isotropic (uniform)
scaling: sx = sy = sz
=
1
0
0
0
Translate(c,0,0)
y
x
0
0
0
1
x
y
z
1
– Mathematically, the simplest is to encode directions
with w=0
– In terms of storage, using a -3 component array for
both direction and points is more efficient
– Which requires to have special operation routines for
points vs. directions
where c = cos θ & s = sin θ
CSCI-9692 Advanced Graphics
Cutler
CSCI-9692 Advanced Graphics
Cutler
4
Outline
How are transforms combined?
•
•
•
•
•
•
•
Scale then Translate
Classes of Transformations
Representing Transformations
Combining Transformations
Transformations in Modelling
Orthographic & Perspective Projections
OpenGL Basics
Color/Normal Interpolation
(1,1)
(0,0)
(2,2)
Scale(2,2)
Translate(3,1)
(5,3)
(3,1)
(0,0)
Use matrix multiplication: p' = T ( S p ) = TS p
TS =
1 0 3
0 1 1
0 0 1
2 0 0
0 2 0
0 0 1
=
2 0 3
0 2 1
0 0 1
Caution: matrix multiplication is NOT commutative!
CSCI-9692 Advanced Graphics
Cutler
CSCI-9692 Advanced Graphics
Cutler
Non-commutative Composition
Non-commutative Composition
Scale then Translate: p' = T ( S p ) = TS p
Scale then Translate: p' = T ( S p ) = TS p
(1,1)
(0,0)
(2,2)
Scale(2,2)
Translate(3,1)
(5,3)
TS =
(3,1)
(0,0)
(8,4)
Translate(3,1)
(4,2)
(3,1)
Scale(2,2)
(0,0)
CSCI-9692 Advanced Graphics
Cutler
(6,2)
2 0 0
0 2 0
0 0 1
ST =
2 0 0
0 2 0
0 0 1
1 0 3
0 1 1
CSCI-9692 Advanced Graphics
Scene Hierarchy
•
•
•
•
•
•
•
• Logical organization of scene
CSCI-9692 Advanced Graphics
Cutler
=
0 0 1
Today
Classes of Transformations
Representing Transformations
Combining Transformations
Transformations in Modelling
Orthographic & Perspective Projections
OpenGL Basics
Color/Normal Interpolation
=
2 0 3
0 2 1
0 0 1
Translate then Scale: p' = S ( T p ) = ST p
Translate then Scale: p' = S ( T p ) = ST p
(1,1)
1 0 3
0 1 1
0 0 1
CSCI-9692 Advanced Graphics
2 0 6
0 2 2
0 0 1
Cutler
Cutler
5
Simple Example with Groups
Group {
numObjects 3
Material { <BLUE> }
Group {
numObjects 3
Box { <BOX PARAMS> }
Box { <BOX PARAMS> }
Box { <BOX PARAMS> } }
Group {
numObjects 2
Material { <BROWN> }
Group {
Box { <BOX PARAMS> }
Box { <BOX PARAMS> }
Box { <BOX PARAMS> } }
Group {
Material { <GREEN> }
Box { <BOX PARAMS> }
Material { <RED> }
Sphere { <SPHERE PARAMS> }
Material { <ORANGE> }
Sphere { <SPHERE PARAMS> } } }
Material { <BLACK> }
Plane { <PLANE PARAMS>
}
CSCI-9692}Advanced
Graphics
Cutler
Group {
numObjects 3
Group {
numObjects 3
Box { <BOX PARAMS> }
Box { <BOX PARAMS> }
Box { <BOX PARAMS> } }
Group {
numObjects 2
Group {
Box { <BOX PARAMS> }
Box { <BOX PARAMS> }
Box { <BOX PARAMS> } }
Group {
Box { <BOX PARAMS> }
Sphere { <SPHERE PARAMS> }
Sphere { <SPHERE PARAMS> } } }
Plane { <PLANE PARAMS> } }
CSCI-9692 Advanced Graphics
Cutler
Adding Transformations
Simple Example with Transforms
Group {
numObjects 3
Transform {
ZRotate { 45 }
Group {
numObjects 3
Box { <BOX PARAMS> }
Box { <BOX PARAMS> }
Box { <BOX PARAMS> } } }
Transform {
Translate { -2 0 0 }
Group {
numObjects 2
Group {
Box { <BOX PARAMS> }
Box { <BOX PARAMS> }
Box { <BOX PARAMS> } }
Group {
Box { <BOX PARAMS> }
Sphere { <SPHERE PARAMS> }
Sphere { <SPHERE PARAMS> } } } }
Advanced Graphics
Cutler
Plane { <PLANE CSCI-9692
PARAMS>
} }
• To position the logical
groupings of objects
within the scene
CSCI-9692 Advanced Graphics
Adding Materials
Cutler
Nested Transforms
Questions?
p' = T ( S p ) = TS p
Translate
Scale
Translate
Scale
same as
Sphere
Sphere
Transform {
Transform {
Translate { 1 0.5 0 }
Translate { 1 0.5 0 }
Transform {
Scale { 2 2 2 }
Scale { 2 2 2 }
Sphere {
Sphere {
center 0 0 0
center 0 0 0
radius 1 } }
radius CSCI-9692
1 } } Advanced
}
Graphics
Cutler
CSCI-9692 Advanced Graphics
Cutler
6
Today
Orthographic vs. Perspective
•
•
•
•
•
•
•
• Orthographic
Classes of Transformations
Representing Transformations
Combining Transformations
Transformations in Modelling
Orthographic & Perspective Projections
OpenGL Basics
Color/Normal Interpolation
CSCI-9692 Advanced Graphics
• Perspective
Cutler
CSCI-9692 Advanced Graphics
Cutler
Simple Orthographic Projection
Simple Perspective Projection
• Project all points along the z axis to the z = 0 plane
• Project all points along the z axis to the z = d
plane, eyepoint at the origin:
x
y
0
1
=
1
0
0
0
0
1
0
0
0
0
0
0
0
0
0
1
CSCI-9692 Advanced Graphics
homogenize
x
y
z
1
x*d/z
1
x
y*d/z
0
y
=
=
d
0
z
1
0
z / dAdvanced Graphics
CSCI-9692
Cutler
Alternate Perspective Projection
this perspective
projection matrix...
1
0
0
0
homogenize
1
0
0
0
Cutler
0 0
1 0
0 0
0 1/d
0
0
0
1
0
0
0
0
x
y
z
1
In the limit, as d → ∞
• Project all points along the z axis to the z = 0
plane, eyepoint at the (0,0,-d):
x * d / (z + d)
x
y * d / (z + d)
y
=
=
0
0
1
(z +Advanced
d)/ Graphics
d
CSCI-9692
0 0
1 0
0 1
0Cutler1/d
x
y
z
1
0 0
1 0
0 0
0 1/d
0
0
0
1
...is simply an
orthographic projection
→
CSCI-9692 Advanced Graphics
1
0
0
0
0
1
0
0
0
0
0
0
0
0
0
1
Cutler
7
Today
•
•
•
•
•
•
•
OpenGL Basics: GL_POINTS
Classes of Transformations
Representing Transformations
Combining Transformations
Transformations in Modelling
Orthographic & Perspective Projections
OpenGL Basics
Color/Normal Interpolation
glDisable(GL_LIGHTING);
glBegin(GL_POINTS);
glColor3f(0.0,0.0,0.0);
glVertex3f(…);
glEnd();
• lighting should be disabled...
CSCI-9692 Advanced Graphics
Cutler
OpenGL Basics: GL_QUADS
CSCI-9692 Advanced Graphics
OpenGL Basics: Transformations
• Useful commands:
glEnable(GL_LIGHTING);
glBegin(GL_QUADS);
glNormal3f(…);
glColor3f(1.0,0.0,0.0);
glVertex3f(…);
glVertex3f(…);
glVertex3f(…);
glVertex3f(…);
glEnd();
glMatrixMode(GL_MODELVIEW);
glPushMatrix();
glPopMatrix();
glMultMatrixf(…);
• lighting should be enabled...
• an appropriate normal should be specified
CSCI-9692 Advanced Graphics
Cutler
From OpenGL Reference Manual
Cutler
Questions?
CSCI-9692 Advanced Graphics
Cutler
Today
•
•
•
•
•
•
•
Classes of Transformations
Representing Transformations
Combining Transformations
Transformations in Modelling
Orthographic & Perspective Projections
OpenGL Basics
Color/Normal Interpolation
Image by Henrik Wann Jensen
CSCI-9692 Advanced Graphics
Cutler
CSCI-9692 Advanced Graphics
Cutler
8
Color Interpolation
Normal Interpolation
• Interpolate colors of the 3 vertices
• Linear interpolation, barycentric coordinates
glBegin(GL_TRIANGLES);
glColor3f(1.0,0.0,0.0);
glVertex3f(…);
glColor3f(0.0,1.0,0.0);
glVertex3f(…);
glColor3f(0.0,0.0,1.0);
glVertex3f(…);
glEnd();
ray tracing
scan conversion
flat shading
CSCI-9692 Advanced Graphics
glBegin(GL_TRIANGLES);
glNormal3f(…);
glVertex3f(…);
glNormal3f(…);
glVertex3f(…);
glNormal3f(…);
glVertex3f(…);
glEnd();
Cutler
scan conversion
gouraud shading
CSCI-9692 Advanced Graphics
Cutler
Gouraud Shading
Phong Normal Interpolation (Not Phong Shading)
• Instead of shading with the normal of the triangle,
shade the vertices with the average normal and
interpolate the shaded color across each face
• Interpolate the average vertex normals across
the face and compute per-pixel shading
Illusion of a smooth
surface with smoothly
varying normals
Must be
renormalized
CSCI-9692 Advanced Graphics
Cutler
CSCI-9692 Advanced Graphics
Cutler
Gouraud Interpolation
Bump Mapping
• Gouraud: interpolate color linearly in screen space.
Is it correct?
• Use textures to alter the surface normal
• No, we should use hyperbolic interpolation
It’s costly (division) but can now be done on modern hardware
– Does not change the actual shape of the surface
– Just shaded as if it were a different shape
image
[R0,
z0 G0, B0]
x’
x
[R1,z1
G1, B1]
CSCI-9692 Advanced Graphics
Cutler
Sphere w/Diffuse Texture
Swirly Bump Map
CSCI-9692 Advanced Graphics
Sphere w/Diffuse Texture & Bump Map
Cutler
9
What's Missing?
Displacement Mapping
• There are no bumps on
the silhouette of a
bump-mapped object
• Use the texture map to actually move the surface point
• The geometry must be displaced before visibility is determined
• Bump maps
don’t allow
self-occlusion
or self-shadowing
CSCI-9692 Advanced Graphics
Cutler
Displacement Mapping
CSCI-9692 Advanced Graphics
Cutler
Displacement Mapping
Image from:
Geometry Caching for
Ray-Tracing Displacement Maps
by Matt Pharr and Pat Hanrahan.
note the detailed shadows
cast by the stones
CSCI-9692 Advanced Graphics
Cutler
CSCI-9692 Advanced Graphics
Cutler
CSCI-9692 Advanced
Graphics
Cutler
Ken Musgrave
Questions?
10