david luebke11/14/2015 cs 551 / 645: introductory computer graphics david luebke...
TRANSCRIPT
David Luebke 04/20/23
CS 551 / 645: Introductory Computer Graphics
David Luebke
http://www.cs.virginia.edu/~cs551
David Luebke 04/20/23
Administrivia
Office hours today: 4:30-5:30
David Luebke 04/20/23
Recap: Rigid-Body Transforms
Goal: object coordinatesworld coordinates Rigid-body transforms
– Translation– Rotation– Scale– Shear
David Luebke 04/20/23
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 04/20/23
Recap: Homogeneous Coordinates 4x4 matrix for rotation about the X axis:
1000
0)cos()sin(0
0)sin()cos(0
0001
xR
David Luebke 04/20/23
Recap: Homogeneous Coordinates 4x4 matrix for rotation about the Y axis:
1000
0)cos(0)sin(
0010
0)sin(0)cos(
yR
David Luebke 04/20/23
Recap: Homogeneous Coordinates 4x4 matrix for rotation about the Z axis:
1000
0100
00)cos()sin(
00)sin()cos(
zR
David Luebke 04/20/23
Recap: Homogeneous Coordinates 4x4 matrix for scaling by Sx, Sy, Sz:
1000
000
000
000
z
y
x
S
S
S
S
David Luebke 04/20/23
Recap: Homogeneous Coordinates 4x4 matrix for translating by Tx, Ty, Tz:
1000
100
010
001
z
y
x
T
T
T
T
David Luebke 04/20/23
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:
w
z
y
x
w
z
y
x
1000
0)90cos()90sin(0
0)90sin()90cos(0
0001
1000
10100
0010
0001
'
'
'
'
David Luebke 04/20/23
Recap: Compositing Transforms
Now that we can represent translation as a matrix, we can composite it with other transformations
Ex: rotate 90° about X, then 10 units down Z:
w
z
y
x
w
z
y
x
1000
0010
0100
0001
1000
10100
0010
0001
'
'
'
'
David Luebke 04/20/23
Recap: Compositing Transforms
Now that we can represent translation as a matrix, we can composite it with other transformations
Ex: rotate 90° about X, then 10 units down Z:
w
z
y
x
w
z
y
x
1000
10010
0100
0001
'
'
'
'
David Luebke 04/20/23
Recap: Compositing Transforms
Rigid-body transformations, 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 04/20/23
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 particular direction. – (What direction?)
To help illustrate this, imagine subtracting two homogeneous points
David Luebke 04/20/23
Perspective Projection
In the real world, objects exhibit perspective foreshortening: distant objects appear smaller
The basic situation:
David Luebke 04/20/23
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 shouldthis bunny be?
David Luebke 04/20/23
Perspective Projection
The geometry of the situation is that of similar triangles. View from above:
What is x’?
P (x, y, z)X
Z
Viewplane
d
(0,0,0) x’ = ?
David Luebke 04/20/23
Perspective Projection
Desired result for a point [x, y, z, 1]T projected onto the view plane:
What should a matrix look like to do this?
dzdz
y
z
ydy
dz
x
z
xdx
z
y
d
y
z
x
d
x
,','
',
'
David Luebke 04/20/23
A Perspective Projection Matrix
Answer:
An aside: what fundamental difference do you notice about this matrix from the others?
0100
0100
0010
0001
d
M eperspectiv
David Luebke 04/20/23
A Perspective Projection Matrix
Example:
Or, in 3-D coordinates:
10100
0100
0010
0001
z
y
x
ddz
z
y
x
d
dz
y
dz
x,,
David Luebke 04/20/23
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
Coming up after the exam: parallel (a.k.a. orthographic) projections, and the viewport transformation
David Luebke 04/20/23
Review for Exam
Quick recap of lecture topics for exam… – Display technologies
Vector versus raster: what’s a pixel? CRT (black & white, color): shadow mask, phosphors,
electron guns LCD: polarizing crystals that line up under an E-field,
losing their polarization and acting as light valves Pros and cons of different technologies
– Framebuffers Fast, dual-ported memory bank for holding pixels True-color (24-bit) vs Pseudocolor (8-bit indexed) vs hi-
color (16-bit, 6-6-4 ?)
David Luebke 04/20/23
Review For Exam
Color– Basic physiology: retina, rods, cones
– Different types of cones: L, M, S
– Metamers: perceptually identical color senstions caused by different spectra
– CIE Color Space (X, Y, Z) Color mix-and-match experiment Hypothetical light sources X, Y, Z (why?) Three dimensional shape, often simplified to 2-D gamut
– Other color spaces (RGB, HSV)
– Gamma correction: linearize non-linear response of display device
David Luebke 04/20/23
Review For Exam
Rasterizing lines– A methodology in optimizing code– Simplest way: solve slope-intercept equation
Check slope and step in X or Y
– DDA: find incremental change per inner loop– Bresenham: take advantage of rational slope,
endpoints to optimize with integer arithmetic
David Luebke 04/20/23
Review For Exam
Rasterizing polygons– Can break into triangles for convenience
Trivial for convex polys, difficult for complex polys
– Edge equations: Evaluate equation of edge (linear expression) per pixel If all three edges are positive, light pixel Can evaulate R,G,B as linear expressions too Hardware: SIMD array Software: bounding box Issues: ensuring consistent edge equations, numerical
stability when evaluating edge equations
David Luebke 04/20/23
Review For exam
Rasterizing triangles: edge walking– Find edges (DDA)– Interpolate colors down edges– Interpolate colors across scanlines– Fast: touches only pixels necessary– Difficult: lots of special cases, fractional offsets,
precision worries
Rasterizing triangles: general issues– Need consistent rules about pixels right on edge
David Luebke 04/20/23
Review For Test
Can also rasterize general polygons– Active edge table: sort edges by ymin and ymax,
then by x intersection w/ scanline– March up scanline by scanline, filling pixels
according to parity rule– Hard to interpolate color, etc. correctly -- not
planar in color space, in general
David Luebke 04/20/23
Review For Test
Clipping– Want only portions of lines, polygons in viewport– Cohen-Sutherland line clipping: binary outcodes– Polygon clipping is harder
Triangle in, 7-gon out Concave polyon in, 2 polygons out
– Sutherland-Hodgman: clip against view planes in succession
In-out rules Line-plane intersection
David Luebke 04/20/23
Review For Test
3-D graphics:
Transform
Illuminate
Transform
Clip
Project
Rasterize
Model & CameraModel & CameraParametersParameters Rendering PipelineRendering Pipeline FramebufferFramebuffer DisplayDisplay
David Luebke 04/20/23
Review For Test Rendering pipeline:
ModelingTransforms
Scene graphObject geometry
LightingCalculations
ViewingTransform
Clipping
ProjectionTransform
Result:Result:
• All vertices of scene in shared 3-D “world” coordinate All vertices of scene in shared 3-D “world” coordinate systemsystem
• Vertices shaded according to lighting modelVertices shaded according to lighting model
• Scene vertices in 3-D “view” or “camera” coordinate Scene vertices in 3-D “view” or “camera” coordinate systemsystem
• Exactly those vertices & portions of polygons in view Exactly those vertices & portions of polygons in view frustumfrustum
• 2-D screen coordinates of clipped vertices2-D screen coordinates of clipped vertices
David Luebke 04/20/23
Review For Test
Transformations– Shift in coordinate systems (basis sets)– Accomplished via matrix multiplication– Modeling transforms: object->world– Viewing transform: world->view– Projection transform: view->screen
David Luebke 04/20/23
Review For Test
Rigid-body transforms– Rotation: 2-D. 3-D (canonical & arbitrary axis)– Scaling– Translation: homogeneous coords, 4x4 matrices– Composiing transforms
Matrix multiplication Order from right to left
Projection transforms– Geometry of perspective projection– Derive perspective projection matrix