david luebke12/7/2015 cs 551 / 645: introductory computer graphics review for midterm
TRANSCRIPT
David Luebke 04/21/23
CS 551 / 645: Introductory Computer Graphics
Review for Midterm
David Luebke 04/21/23
Administrivia
Hand out assignment 2 Hand in assignment 3 Late day policy:
– 1 late day = due tomorrow at noon– Subsequent late days add 24 hours each– Weekends and holidays count
Compiling with C++– UNIX C++ compilers: g++ and /bin/CC– I’ll make sure it works before next assignment
David Luebke 04/21/23
Midterm Examination
Midterm is this Thursday (March 9) Study aids:
– This lecture– Earlier lectures (available on course page)– Last semester’s midterm
See http://www.cs.virginia.edu/~luebke/old_cs551/ But, its not quite the same material
No calculators! (you won’t need them)
David Luebke 04/21/23
Display Technologies
Cathode Ray Tubes– Earliest, still most common graphical display– Understand the basic mechanism
Vacuum tube, phosphors, electron beam
– Pros: bright, fairly high-res, leverages TV tech– Cons: bulky, size-limited, finicky
David Luebke 04/21/23
Display Technologies
Vector versus raster display– Vector: traces lines like an oscilloscope
Pros: bright, crisp, uniform lines Cons: wireframe only, flicker for complex scenes
– Raster: fixed scan pattern for electron beam, intensity controlled by scan-out from frame buffer
Pros: display solid objects, image complexity limited only by framebuffer resolution
Cons: discreet sampling (aliasing), memory cost
David Luebke 04/21/23
Display Technologies
LCDs– Understand the basic mechanism
Polarized light, crystals twist 90º unless excited Basically a light valve: reflective or transmissive
– Pros: light-weight and thin– Cons: expensive, high-power (when backlit),
limited in size
David Luebke 04/21/23
Display Technologies
Also know:– Plasma display panels– Digital Micromirror Devices
David Luebke 04/21/23
Framebuffers
Memory array storing image in pixels Issues: memory speed, size, bus contention Different types in common use, motivated
mainly by memory cost– True-Color: 24 bits, 8 per RGB (or 32 bits with )– Hi-Color: 16 bits (R = 6, G = 6, B = 4)– Pseudo-Color: 8 bits index into 256-entiry color
lookup table (entries typically 24-bits)
David Luebke 04/21/23
Mathematical Foundations
Geometry (2-D, 3-D) Trigonometry Vector spaces
– Elements: scalars and vectors– Operations:
Addition (identity & inverse) Scalar multiplication (distributive rule)
– Linear combinations, dimension, basis sets– Inner (dot) product, vector (cross) product
David Luebke 04/21/23
Mathematical Foundations
Affine spaces– Elements: points– Operations:
Subtraction (point - point = vector) Addition (vector + point = point)
Matrices– Linear transforms, vector-matrix multiplication– Matrix-matrix multiplication– Composition of linear transforms = matrix
concatenation
David Luebke 04/21/23
The Rendering Pipeline
Transform
Illuminate
Transform
Clip
Project
Rasterize
Model & CameraParameters
Rendering Pipeline Framebuffer Display
David Luebke 04/21/23
The Rendering Pipeline: 3-D
ModelingTransforms
Scene graphObject geometry
LightingCalculations
ViewingTransform
Clipping
ProjectionTransform
Result:
• All vertices of scene in shared 3-D “world” coordinate system
• Vertices shaded according to lighting model
• Scene vertices in 3-D “view” or “camera” coordinate system
• Exactly those vertices & portions of polygons in view frustum
• 2-D screen coordinates of clipped vertices
David Luebke 04/21/23
Geometric Transforms
Modeling transforms: object coordinates world coordinates
Viewing transform: world coordinates eye coordinates– eye coordinates == camera coordinates == view
coordinates
Projection transform: eye coordinates 2-D screen coordinates
David Luebke 04/21/23
Geometric Transforms
Understand homogeneous coordinates– [x, y, z, w]T == (x/w, y/w, z/w)– Allows us to capture translation and projection as
matrices
Know your 4x4 Euclidean transform matrices:– Translation, scale, rotation about X, Y, Z
Understand rotation about an arbitrary axis Understand order of composition for matrices
– In OpenGL: using column vectors as points order from right to left
David Luebke 04/21/23
Perspective Projection
Geometry of the perspective projection:
P (x, y, z)X
Z
Viewplane
d
(0,0,0) x’ = ?
David Luebke 04/21/23
Perspective Projection
Desired result:
dzdz
y
z
ydy
dz
x
z
xdx
z
y
d
y
z
x
d
x
,','
',
'
David Luebke 04/21/23
Perspective Projection
A matrix that accomplishes this:
0100
0100
0010
0001
d
M eperspectiv
David Luebke 04/21/23
Rasterizing Lines
Review McMillan’s great java-enabled lecture First stab: slope-intercept + symmetry A case study in optimization
– Special case boundary conditions if necessary– Optimize inner loops
Incremental update using DDA (biggest win) Low-level tricks: integer arithmetic, compare to 0, etc. Culmination: Bresenham’s algorithm
– Be aware of diminishing returns and readability/portability tradeoffs
David Luebke 04/21/23
Rasterizing Triangles
Triangles are nice to deal with because they are always planar and always convex
Triangle rasterization techniques:– REYES: recursive subdivision of primitive– Warnock: recursive subdivision of screen– Edge walking– Edge equations
David Luebke 04/21/23
Rasterizing Triangles
Edge walking: – Draw edges vertically
– Fill in horizontal spans for each scanline
– Interpolate colors down edges
– At each scanline, interpolate edge colors across span
– Pros: Fast: touch only lit pixels,
touch pixels only once
– Cons: Finicky: lots of special cases,
hard to get just right
David Luebke 04/21/23
Rasterizing Triangles
Edge Equations– Equation of a line defines two half-spaces– Triangle can be represented as intersection of
three half-spaces:
A1x + B1y + C1 < 0
A2 x + B
2 y + C2 < 0
A 3x
+ B 3
y +
C 3 <
0
A1x + B1y + C1 > 0
A 3x
+ B 3
y +
C 3 >
0 A2 x + B
2 y + C2 > 0
David Luebke 04/21/23
Rasterizing Triangles
Basic algorithm: – Walk pixels in bounding box– Evaluate three edge equations– If all are greater than zero, shade pixel
Issues:– Computing edge equations: numerical precision– Interpolating parameters (i.e., color): just like
another edge equation (why?)
Optimizing the algorithm– Like line rasterization: DDA, early termination, etc.
David Luebke 04/21/23
Rasterizing General Polygons
Parity test:– Starting outside polygon,
count edges crossed.
– Odd = inside,even = outside
Big cost: testing every edgeagainst every pixel
Solution: the active edge table algorithm– Sort edges by Y
– Keep a list of edges that intersect current scanline, sorted by their X-intersection w/ scanline
A
B
C
D
E
F
G I
H
David Luebke 04/21/23
Clipping Lines
Cohen-Sutherland Algorithm– Clip 2-D line segments to rectangular viewport– Designed for rapid trivial accept & trivial reject ops
4-bit outcodes divide screen into 9 regions Bitwise operations determine whether to accept, reject,
or intersect with a viewport edge & recurse May require multiple iterations
David Luebke 04/21/23
Clipping Polygons
Clipping polygons fundamentally more difficult– Polygons can gain or lose edges– Concave polygons can even multiply
Sutherland-Hodgman Algorithm– Simplify by divide-and-conquer: consider each
clipping plane individually Input: polygon as ordered list of vertices Output: polygon as ordered list of vertices Lends itself to pipelined hardware implementation
David Luebke 04/21/23
Clipping Polygons
Sutherland-Hodgman Algorithm– Know the details:
Point-plane test Line-plane intersection Rules:
inside outside
s
p
p output
inside outside
s
p
no output
inside outside
sp
i output
inside outside
sp
i outputp output
David Luebke 04/21/23
Clipping in 3-D
Problem: clipping under perspective must happen before homogeneous divide– Solution 1: clip to hither plane in eye coordinates, then
multiply by projection matrix, then do homogeneous divide
Better: transform to canonical perspective coordinates to simplify clipping
– Solution 2: clip after projection (must clip all 4 homogeneous coordinates)
– Solution 3 (ugly but common): clip to hither & yon before projection, clip to 2-D viewport after projection and divide
David Luebke 04/21/23
Color
Rods and cones Cones and color perception
– Metamers– 3-D color: X, Y, and Z; CIE color space
Gamma correction
David Luebke 04/21/23
Lighting
Definitions: illumination, lighting, shading Illumination:
– Direct versus indirect– Light properties: geometry, spectrum
Common simplifications: ambient, directional, and point
– Surface material: geometry, reflectance, microstructure
Common simplification: Phong lighting Diffuse (Lambertian) reflection: incoming light reflected
equally in all directions, proportional to N • L Specular reflection: approximate falloff with (V • R)nshiny
David Luebke 04/21/23
Lighting
Putting it all together: the Phong lighting model
Note: evaluate per light, per color component Common simplification: constant V (viewer
infinitely far away)
lights
i
n
sdiambientatotal
shiny
RVkLNkIIkI#
1
ˆˆˆˆ
David Luebke 04/21/23
Shading
Where to apply lighting calculations?– Once per face: flat shading– Once per vertex, interpolate resulting color:
Gouraud shading– Once per pixel, interpolating normal vectors from
vertices: Phong shading
Flat shading Phong Shading