Download presentation source
Download
Report
Transcript Download presentation source
CS 551 / 645:
Introductory Computer Graphics
Geometric transforms: perspective projection
Color
David Luebke
7/27/2016
Administrivia
Problems submitting assignment 2 late
Hand out assignment 3….or not
Graphics Lunch (Glunch)…Fridays at noon,
typically in Olsson 236D (this week in 228E)
– uva.cs.graphics
David Luebke
7/27/2016
Perspective Projection
We talked about geometric transforms,
focusing on modeling transforms
– Ex: translation, rotation, scale, gluLookAt()
– These are encapsulated in the OpenGL
modelview matrix
Can also express perspective projection (and
other projections) as a matrix
Next few slides: representing perspective
projection with the projection matrix
David Luebke
7/27/2016
Recap: Transformation Matrices
Represent these transformation using
matrices
– Rotation, scale, shear: 3x3 matrices suffice
– Would be nice to work translation and projection
into the same system
Solution: homogeneous coordinates
– A point in homogeneous coordinates: [x, y, z, w]T
– Corresponding point in 3-D: [x/w, y/w, z/w]T
– Now transformation matrices are 4x4
David Luebke
7/27/2016
Recap: Homogeneous
Coordinates
4x4 matrix for rotation about the X axis:
0
0
1
0 cos() sin( )
Rx
0 sin( ) cos()
0
0
0
David Luebke
0
0
0
1
7/27/2016
Recap: Homogeneous
Coordinates
4x4 matrix for scaling by Sx, Sy, Sz:
Sx 0
0 Sy
S
0 0
0 0
David Luebke
0 0
0 0
Sz 0
0 1
7/27/2016
Recap: Homogeneous
Coordinates
4x4 matrix for translating by Tx, Ty, Tz:
1
0
T
0
0
David Luebke
0 0 Tx
1 0 Ty
0 1 Tz
0 0 1
7/27/2016
Recap: Compositing Transforms
We can composite the effect of multiple
transforms by multiplying their matrices:
Ex: rotate 90° about X, then 10 units down Z:
x' 1
y ' 0
z ' 0
w' 0
David Luebke
0 0 0 1
0
0
1 0 0 0 cos(90) sin( 90)
0 1 10 0 sin( 90) cos(90)
0 0 1 0
0
0
0 x
0 y
0 z
1 w
7/27/2016
Recap: Compositing Transforms
These transforms, in general, do not
commute
– Translate then rotate very different from rotate
then translate
Write transforms down from right to left in the
order in which they take place
– Example: p’ = Ry-1 Rx -1 Rz Rx Ry p
David Luebke
7/27/2016
More On Homogeneous Coords
The w coordinate of a homogeneous point is
typically 1
Decreasing w makes the point “bigger”,
meaning further from the origin
Homogeneous points with w = 0 are thus
“points at infinity”, meaning infinitely far away
in some direction. (What direction?)
To help illustrate this, imagine subtracting two
homogeneous points
David Luebke
7/27/2016
Perspective Projection
In the real world, objects exhibit perspective
foreshortening: distant objects appear smaller
The basic situation:
David Luebke
7/27/2016
Perspective Projection
When we do 3-D graphics, we think of the
screen as a 2-D window onto the 3-D world:
How tall should
this bunny be?
David Luebke
7/27/2016
Perspective Projection
The geometry of the situation is that of
similar triangles. View from above:
View
plane
X
P (x, y, z)
x’ = ?
(0,0,0)
Z
d
What is x’?
David Luebke
7/27/2016
Perspective Projection
Desired result for a point [x, y, z, 1]T projected
onto the view plane:
x' x
,
d z
dx
x
x'
,
z
z d
y' y
d z
dy
y
y'
, zd
z
z d
What could a matrix look like to do this?
David Luebke
7/27/2016
A Perspective Projection Matrix
Answer:
1
0
Mperspective
0
0
David Luebke
0
1
0
0
0
1
0 1d
0
0
0
0
7/27/2016
A Perspective Projection Matrix
Example:
x 1
y 0
z 0
z d 0
0
1
0
0
0
1
0 1d
0 x
0 y
0 z
0 1
Or, in 3-D coordinates:
x
,
z d
David Luebke
y
, d
zd
7/27/2016
A Perspective Projection Matrix
OpenGL’s gluPerspective() command
generates a slightly more complicated matrix:
f
aspect
0
0
0
where
0
0
f
0
Ζ far Z near
Z Z
far
near
1
0
0
0
0
2 Z far Z near
Z Z
near
far
0
fov y
f cot
2
– Can you figure out what this matrix does?
David Luebke
7/27/2016
Projection Matrices
Now that we can express perspective
foreshortening as a matrix, we can composite
it onto our other matrices with the usual
matrix multiplication
End result: a single matrix encapsulating
modeling, viewing, and projection transforms
David Luebke
7/27/2016
Matrix Operations In OpenGL
Certain commands affect the current matrix
in OpenGL
– glMatrixMode() sets the current matrix
– glLoadIdentity() replaces the current matrix
with an identity matrix
– glTranslate() postmultiplies the current matrix
with a translation matrix
– gluPerspective() postmultiplies the current
matrix with a perspective projection matrix
It is important that you understand the order
in which OpenGL concatenates matrices
David Luebke
7/27/2016
Matrix Operations In OpenGL
In OpenGL:
– Vertices are multiplied by the modelview matrix
– The resulting vertices are multiplied by the
projection matrix
Example:
– Suppose you want to scale an object, translate it,
apply a lookat transformation, and view it under
perspective projection. What order should you
make calls?
David Luebke
7/27/2016
Matrix Operations in OpenGL
Problem: scale an object, translate it, apply a lookat
transformation, and view it under perspective
A correct code fragment:
glMatrixMode(GL_PERSPECTIVE);
glLoadIdentity();
gluPerspective(…);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
gluLookAt(…);
glTranslate(…);
glScale(…);
/* Draw the object... */
David Luebke
7/27/2016
Matrix Operations in OpenGL
Problem: scale an object, translate it, apply a lookat
transformation, and view it under perspective
An incorrect code fragment:
glMatrixMode(GL_PERSPECTIVE);
glLoadIdentity();
glTranslate(…);
glScale(…);
gluPerspective(…);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
gluLookAt(…);
/* Draw the object... */
David Luebke
7/27/2016
Color
Next topic: Color
To understand how to make realistic images, we
need a basic understanding of the physics and
physiology of vision. Here we step away from the
code and math for a bit to talk about basic
principles.
David Luebke
7/27/2016
Basics Of Color
Elements of color:
David Luebke
7/27/2016
Basics of Color
Physics:
– Illumination
Electromagnetic spectra
– Reflection
Material properties (i.e., conductance)
Surface geometry and microgeometry (i.e., polished
versus matte versus brushed)
Perception
– Physiology and neurophysiology
– Perceptual psychology
David Luebke
7/27/2016
Physiology of Vision
The eye:
The retina
– Rods
– Cones
David Luebke
Color!
7/27/2016
Physiology of Vision
The center of the retina is a densely packed
region called the fovea.
– Cones much denser here than the periphery
David Luebke
7/27/2016
Physiology of Vision: Cones
Three types of cones:
– L or R, most sensitive to red light (610 nm)
– M or G, most sensitive to blue light (560 nm)
– S or B, most sensitive to blue light (430 nm)
– Color blindness results from missing cone type(s)
David Luebke
7/27/2016
Physiology of Vision: The Retina
Weirdly, rods and
cones are at the back
of the retina, behind a
mostly-transparent
neural structure that
collects their
response.
David Luebke
7/27/2016
Perception: Metamers
A given perceptual sensation of color derives
from the stimulus of all three cone types
Identical perceptions of color can thus be
caused by very different spectra
David Luebke
7/27/2016
Perception: Other Gotchas
Color perception is also difficult because:
– It varies from person to person (thus std observers)
– It is affected by adaptation (transparency demo)
– It is affected by surrounding color:
David Luebke
7/27/2016
Color Spaces
Three types of cones suggests color is a 3D
quantity. How to define 3D color space?
Idea: shine given wavelength () on a
screen, and mix three other wavelengths
(R,G,B) on same screen. Have user adjust
intensity of RGB until colors are identical:
David Luebke
How closely does this
correspond to a color CRT?
Problem: sometimes need
to “subtract” R to match
7/27/2016
CIE Color Space
The CIE (Commission Internationale
d’Eclairage) came up with three hypothetical
lights X, Y, and Z with these spectra:
Note that:
X~R
Y~G
Z~B
Idea: any wavelength can be matched
perceptually by positive combinations of X,Y,Z
David Luebke
7/27/2016
CIE Color Space
The gamut of all colors perceivable is thus a
three-dimensional shape in X,Y,Z:
For simplicity, we
often project to the
2D plane X+Y+Z=1
X = X / (X+Y+Z)
Y = Y / (X+Y+Z)
Z=1-X-Y
David Luebke
7/27/2016
CIE Chromaticity Diagram (1931)
David Luebke
7/27/2016
Device Color Gamuts
Since X, Y, and Z are hypothetical light
sources, no real device can produce the
entire gamut of perceivable color
Example: CRT monitor
David Luebke
7/27/2016
Device Color Gamuts
The RGB color cube sits within CIE color
space something like this:
David Luebke
7/27/2016
Device Color Gamuts
We can use the CIE chromaticity diagram to
compare the gamuts of various devices:
Note, for example,
that a color printer
cannot reproduce
all shades available
on a color monitor
David Luebke
7/27/2016
Converting Color Spaces
Simple matrix operation:
R' XR
G ' YR
B' ZR
XG
YG
ZG
XB R
YB G
ZB B
The transformation C2 = M-12 M1 C1 yields
RGB on monitor 2 that is equivalent to a
given RGB on monitor 1
David Luebke
7/27/2016
Converting Color Spaces
Converting between color models can also
be expressed as such a matrix transform:
0.11 R
Y 0.30 0.59
I 0.60 0.28 0.32 G
Q 0.21 0.52 0.31 B
YIQ is the color model used for color TV in
America. Y is luminance, I & Q are color
– Note: Y is the same as CIE’s Y
– Result: backwards compatibility with B/W TV!
David Luebke
7/27/2016
Gamma Correction
We generally assume colors are linear
But most display devices are inherently
nonlinear
– I.e., brightness(voltage) != 2*brightness(voltage/2)
Common solution: gamma correction
– Post-transformation on RGB values to map them
to linear range on display device:
1
– Can have separate for R, G, B
yx
David Luebke
7/27/2016