david luebke1/10/2016 cs 551 / 645: introductory computer graphics david luebke...
TRANSCRIPT
David Luebke 04/21/23
CS 551 / 645: Introductory Computer Graphics
David Luebke
http://www.cs.virginia.edu/~cs551
David Luebke 04/21/23
Side Note
Shifts versus additions
David Luebke 04/21/23
Where We’ve Been
Till now we’ve talked about a 2-D world We’ve covered:
– Display technology– Color– Framebuffers– Drawing 2-D lines (and drawing them fast)– Drawing 2-D polygons (especially triangles)– Clipping polygons
David Luebke 04/21/23
Where We’re Going
3-D graphics (finally!) Next lectures:
– The graphics pipeline: the big picture– Rigid-body transforms
Math
– Homogeneous coordinates Math
– The viewing transform Math
– The projection transform Math
David Luebke 04/21/23
3-D Graphics: A Whirlwind Tour
Transform
Illuminate
Transform
Clip
Project
Rasterize
Model & CameraModel & CameraParametersParameters Rendering PipelineRendering Pipeline FramebufferFramebuffer DisplayDisplay
David Luebke 04/21/23
The Display You Know
Transform
Illuminate
Transform
Clip
Project
Rasterize
Model & CameraModel & CameraParametersParameters Rendering PipelineRendering Pipeline FramebufferFramebuffer DisplayDisplay
David Luebke 04/21/23
The Framebuffer You Know
Transform
Illuminate
Transform
Clip
Project
Rasterize
Model & CameraModel & CameraParametersParameters Rendering PipelineRendering Pipeline FramebufferFramebuffer DisplayDisplay
David Luebke 04/21/23
The Rendering Pipeline
Transform
Illuminate
Transform
Clip
Project
Rasterize
Model & CameraModel & CameraParametersParameters Rendering PipelineRendering Pipeline FramebufferFramebuffer DisplayDisplay
Why do we call it a pipeline?
David Luebke 04/21/23
2-D Rendering You Know
Transform
Illuminate
Transform
Clip
Project
Rasterize
Model & CameraModel & CameraParametersParameters Rendering PipelineRendering Pipeline FramebufferFramebuffer DisplayDisplay
David Luebke 04/21/23
Edge Equations You Know
V2
V1
V0 Find edge
equations
David Luebke 04/21/23
Edge Equations You Know
V2
V1
V0
- +
Disable processors where plugging (Xproc,Yproc) into edge equation of {V0,V1} evaluates to negative
David Luebke 04/21/23
Edge Equations You Know
V2
V1
V0 Find edge
equations
David Luebke 04/21/23
Edge Equations You Know
V2
V1
V0
+-
Disable processors where plugging (Xproc,Yproc) into edge equation of {V2,V0} evaluates to negative
David Luebke 04/21/23
Edge Equations You Know
V2
V1
V0
+
-
Disable processors where plugging (Xproc,Yproc) into edge equation of {V2,V1} evaluates to negative
David Luebke 04/21/23
Edge Equations You Know
V2
V1
V0 All enabled
processors evaluate linear expressions for triangle color, depth, etc.
David Luebke 04/21/23
Edge Walking (You Know?)
Traditional method:– Find edge equations
{V0V1} {V0V2} {V2V1}– Find and fill spans
where scanlines cross the edge
– Just a bilinearinterpolation!
V0
V2
V1
David Luebke 04/21/23
The Rendering Pipeline: 3-D
Transform
Illuminate
Transform
Clip
Project
Rasterize
Model & CameraModel & CameraParametersParameters Rendering PipelineRendering Pipeline FramebufferFramebuffer DisplayDisplay
David Luebke 04/21/23
The Rendering Pipeline: 3-D
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/21/23
The Rendering Pipeline: 3-D
Scene graphObject geometry
LightingCalculations
Clipping
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
ModelingTransforms
ViewingTransform
ProjectionTransform
David Luebke 04/21/23
Rendering: Transformations
So far, discussion has been in screen space But model is stored in model space
(a.k.a. object space or world space) Three sets of geometric transformations:
– Modeling transforms– Viewing transforms– Projection transforms
David Luebke 04/21/23
Rendering: Transformations
Modeling transforms– Size, place, scale, and rotate objects parts of the
model w.r.t. each other– Object coordinates world coordinates
Z
X
Y
X
Z
Y
David Luebke 04/21/23
Rendering: Transformations
Viewing transform– Rotate & translate the world to lie directly in front of
the camera Typically place camera at origin Typically looking down -Z axis
– World coordinates view coordinates
David Luebke 04/21/23
Rendering: Transformations
Projection transform– Apply perspective foreshortening
Distant = small: the pinhole camera model
– View coordinates screen coordinates
David Luebke 04/21/23
Rendering: Transformations
All these transformations involve shifting coordinate systems (i.e., basis sets)
That’s what matrices do… Represent coordinates as vectors, transforms
as matrices
Multiply matrices = concatenate transforms!
Y
X
Y
X
cossin
sincos
David Luebke 04/21/23
Rendering: Transformations
Homogeneous coordinates: represent coordinates in 3 dimensions with a 4-vector– Denoted [x, y, z, w]
Note that typically w = 1 in model coordinates
– To get 3-D coordinates, divide by w:[x’, y’, z’] = [x/w, y/w, z/w]
Transformations are 4x4 matrices Why? To handle translation and projection
David Luebke 04/21/23
Rendering: Transformations
OpenGL caveats:– All modeling transforms and the viewing transform
are concatenated into the modelview matrix– A stack of modelview matrices is kept– The projection transform is stored separately in
the projection matrix
See Chapter 3 of the OpenGL book
David Luebke 04/21/23
The Rendering Pipeline: 3-D
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/21/23
Rendering: Lighting
Illuminating a scene: coloring pixels according to some approximation of lighting– Global illumination: solves for lighting of the whole
scene at once– Local illumination: local approximation, typically
lighting each polygon separately
Interactive graphics (e.g., hardware) does only local illumination at run time
David Luebke 04/21/23
The Rendering Pipeline: 3-D
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/21/23
Rendering: Clipping
Clipping a 3-D primitive returns its intersection with the view frustum:
See Foley & van Dam section 19.1
David Luebke 04/21/23
Rendering: Clipping
Clipping is tricky!
In: 3 verticesIn: 3 verticesOut: 6 verticesOut: 6 vertices
Clip
Clip In: 1 polygonIn: 1 polygonOut: 2 polygonsOut: 2 polygons
David Luebke 04/21/23
The Rendering Pipeline: 3-D
Transform
Illuminate
Transform
Clip
Project
Rasterize
Model & CameraModel & CameraParametersParameters Rendering PipelineRendering Pipeline FramebufferFramebuffer DisplayDisplay
David Luebke 04/21/23
Modeling: The Basics
Common interactive 3-D primitives: points, lines, polygons (i.e., triangles)
Organized into objects– Collection of primitives, other objects– Associated matrix for transformations
Instancing: using same geometry for multiple objects – 4 wheels on a car, 2 arms on a robot
David Luebke 04/21/23
Modeling: The Scene Graph
The scene graph captures transformations and object-object relationships in a DAG
Objects in black; blue arrows indicate instancing and each have a matrix
Robot
BodyHead
ArmTrunkLegEyeMouth
David Luebke 04/21/23
Modeling: The Scene Graph
Traverse the scene graph in depth-first order, concatenating transformations
Maintain a matrix stack of transformations
ArmTrunkLegEyeMouth
Head Body
Robot
Foot
MatrixMatrixStackStack
VisitedVisited
UnvisitedUnvisited
ActiveActive
David Luebke 04/21/23
Modeling: The Camera
Finally: need a model of the virtual camera– Can be very sophisticated
Field of view, depth of field, distortion, chromatic aberration…
– Interactive graphics (OpenGL): Pinhole camera model
Field of view Aspect ratio Near & far clipping planes
Camera pose: position & orientation
David Luebke 04/21/23
Modeling: The Camera
These parameters are encapsulated in a projection matrix– Homogeneous coordinates 4x4 matrix!– See OpenGL Appendix F for the matrix
The projection matrix premultiplies the viewing matrix, which premultiplies the modeling matrices– Actually, OpenGL lumps viewing and modeling
transforms into modelview matrix
David Luebke 04/21/23
Rigid-Body Transforms
Goal: object coordinatesworld coordinates Idea: use only transformations that preserve
the shape of the object– Rigid-body or Euclidean transforms – Includes rotation, translation, and scale
To reiterate: we will represent points as column vectors:
z
y
x
zyx ),,(
David Luebke 04/21/23
Vectors and Matrices
Vector algebra operations can be expressed in this matrix form– Dot product:
– Cross product: Note: use
right-handrule!
z
y
x
zyx
b
b
b
aaaba
0cb
0ca
cba
z
y
x
z
y
x
xy
xz
yz
c
c
c
b
b
b
aa
aa
aa
0
0
0
David Luebke 04/21/23
Translations
For convenience we usually describe objects in relation to their own coordinate system– Solar system example
We can translate or move points to a new position by adding offsets to their coordinates:
– Note that this translates all points uniformly
z
y
x
t
t
t
z
y
x
z
y
x
'
'
'
David Luebke 04/21/23
3-D Rotations
Rotations in 2-D are easy:
3-D is more complicated– Need to specify an axis of rotation
– Common pedagogy: express rotation about this axis as the composition of canonical rotations
Canonical rotations: rotation about X-axis, Y-axis, Z-axis
y
x
y
x
cossin
sincos
'
'
David Luebke 04/21/23
3-D Rotations
Basic idea:– Using rotations about X, Y, Z axes, rotate model until
desired axis of rotation coincides with Z-axis– Perform rotation in the X-Y plane (i.e., about Z-axis)– Reverse the initial rotations to get back into the initial
frame of reference
Objections:– Difficult & error prone– Ambiguous: several combinations about the canonical
axis give the same result– For a different approach, see McMillan’s lecture 12