David Luebke1/10/2016 CS 551 / 645: Introductory Computer Graphics David Luebke...
-
Upload
brett-collins -
Category
Documents
-
view
224 -
download
0
Transcript of David Luebke1/10/2016 CS 551 / 645: Introductory Computer Graphics David Luebke...
![Page 1: David Luebke1/10/2016 CS 551 / 645: Introductory Computer Graphics David Luebke cs551@cs.virginia.edu cs551.](https://reader035.fdocuments.in/reader035/viewer/2022062309/5697c0221a28abf838cd31ce/html5/thumbnails/1.jpg)
David Luebke 04/21/23
CS 551 / 645: Introductory Computer Graphics
David Luebke
http://www.cs.virginia.edu/~cs551
![Page 2: David Luebke1/10/2016 CS 551 / 645: Introductory Computer Graphics David Luebke cs551@cs.virginia.edu cs551.](https://reader035.fdocuments.in/reader035/viewer/2022062309/5697c0221a28abf838cd31ce/html5/thumbnails/2.jpg)
David Luebke 04/21/23
Side Note
Shifts versus additions
![Page 3: David Luebke1/10/2016 CS 551 / 645: Introductory Computer Graphics David Luebke cs551@cs.virginia.edu cs551.](https://reader035.fdocuments.in/reader035/viewer/2022062309/5697c0221a28abf838cd31ce/html5/thumbnails/3.jpg)
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
![Page 4: David Luebke1/10/2016 CS 551 / 645: Introductory Computer Graphics David Luebke cs551@cs.virginia.edu cs551.](https://reader035.fdocuments.in/reader035/viewer/2022062309/5697c0221a28abf838cd31ce/html5/thumbnails/4.jpg)
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
![Page 5: David Luebke1/10/2016 CS 551 / 645: Introductory Computer Graphics David Luebke cs551@cs.virginia.edu cs551.](https://reader035.fdocuments.in/reader035/viewer/2022062309/5697c0221a28abf838cd31ce/html5/thumbnails/5.jpg)
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
![Page 6: David Luebke1/10/2016 CS 551 / 645: Introductory Computer Graphics David Luebke cs551@cs.virginia.edu cs551.](https://reader035.fdocuments.in/reader035/viewer/2022062309/5697c0221a28abf838cd31ce/html5/thumbnails/6.jpg)
David Luebke 04/21/23
The Display You Know
Transform
Illuminate
Transform
Clip
Project
Rasterize
Model & CameraModel & CameraParametersParameters Rendering PipelineRendering Pipeline FramebufferFramebuffer DisplayDisplay
![Page 7: David Luebke1/10/2016 CS 551 / 645: Introductory Computer Graphics David Luebke cs551@cs.virginia.edu cs551.](https://reader035.fdocuments.in/reader035/viewer/2022062309/5697c0221a28abf838cd31ce/html5/thumbnails/7.jpg)
David Luebke 04/21/23
The Framebuffer You Know
Transform
Illuminate
Transform
Clip
Project
Rasterize
Model & CameraModel & CameraParametersParameters Rendering PipelineRendering Pipeline FramebufferFramebuffer DisplayDisplay
![Page 8: David Luebke1/10/2016 CS 551 / 645: Introductory Computer Graphics David Luebke cs551@cs.virginia.edu cs551.](https://reader035.fdocuments.in/reader035/viewer/2022062309/5697c0221a28abf838cd31ce/html5/thumbnails/8.jpg)
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?
![Page 9: David Luebke1/10/2016 CS 551 / 645: Introductory Computer Graphics David Luebke cs551@cs.virginia.edu cs551.](https://reader035.fdocuments.in/reader035/viewer/2022062309/5697c0221a28abf838cd31ce/html5/thumbnails/9.jpg)
David Luebke 04/21/23
2-D Rendering You Know
Transform
Illuminate
Transform
Clip
Project
Rasterize
Model & CameraModel & CameraParametersParameters Rendering PipelineRendering Pipeline FramebufferFramebuffer DisplayDisplay
![Page 10: David Luebke1/10/2016 CS 551 / 645: Introductory Computer Graphics David Luebke cs551@cs.virginia.edu cs551.](https://reader035.fdocuments.in/reader035/viewer/2022062309/5697c0221a28abf838cd31ce/html5/thumbnails/10.jpg)
David Luebke 04/21/23
Edge Equations You Know
V2
V1
V0 Find edge
equations
![Page 11: David Luebke1/10/2016 CS 551 / 645: Introductory Computer Graphics David Luebke cs551@cs.virginia.edu cs551.](https://reader035.fdocuments.in/reader035/viewer/2022062309/5697c0221a28abf838cd31ce/html5/thumbnails/11.jpg)
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
![Page 12: David Luebke1/10/2016 CS 551 / 645: Introductory Computer Graphics David Luebke cs551@cs.virginia.edu cs551.](https://reader035.fdocuments.in/reader035/viewer/2022062309/5697c0221a28abf838cd31ce/html5/thumbnails/12.jpg)
David Luebke 04/21/23
Edge Equations You Know
V2
V1
V0 Find edge
equations
![Page 13: David Luebke1/10/2016 CS 551 / 645: Introductory Computer Graphics David Luebke cs551@cs.virginia.edu cs551.](https://reader035.fdocuments.in/reader035/viewer/2022062309/5697c0221a28abf838cd31ce/html5/thumbnails/13.jpg)
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
![Page 14: David Luebke1/10/2016 CS 551 / 645: Introductory Computer Graphics David Luebke cs551@cs.virginia.edu cs551.](https://reader035.fdocuments.in/reader035/viewer/2022062309/5697c0221a28abf838cd31ce/html5/thumbnails/14.jpg)
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
![Page 15: David Luebke1/10/2016 CS 551 / 645: Introductory Computer Graphics David Luebke cs551@cs.virginia.edu cs551.](https://reader035.fdocuments.in/reader035/viewer/2022062309/5697c0221a28abf838cd31ce/html5/thumbnails/15.jpg)
David Luebke 04/21/23
Edge Equations You Know
V2
V1
V0 All enabled
processors evaluate linear expressions for triangle color, depth, etc.
![Page 16: David Luebke1/10/2016 CS 551 / 645: Introductory Computer Graphics David Luebke cs551@cs.virginia.edu cs551.](https://reader035.fdocuments.in/reader035/viewer/2022062309/5697c0221a28abf838cd31ce/html5/thumbnails/16.jpg)
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
![Page 17: David Luebke1/10/2016 CS 551 / 645: Introductory Computer Graphics David Luebke cs551@cs.virginia.edu cs551.](https://reader035.fdocuments.in/reader035/viewer/2022062309/5697c0221a28abf838cd31ce/html5/thumbnails/17.jpg)
David Luebke 04/21/23
The Rendering Pipeline: 3-D
Transform
Illuminate
Transform
Clip
Project
Rasterize
Model & CameraModel & CameraParametersParameters Rendering PipelineRendering Pipeline FramebufferFramebuffer DisplayDisplay
![Page 18: David Luebke1/10/2016 CS 551 / 645: Introductory Computer Graphics David Luebke cs551@cs.virginia.edu cs551.](https://reader035.fdocuments.in/reader035/viewer/2022062309/5697c0221a28abf838cd31ce/html5/thumbnails/18.jpg)
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
![Page 19: David Luebke1/10/2016 CS 551 / 645: Introductory Computer Graphics David Luebke cs551@cs.virginia.edu cs551.](https://reader035.fdocuments.in/reader035/viewer/2022062309/5697c0221a28abf838cd31ce/html5/thumbnails/19.jpg)
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
![Page 20: David Luebke1/10/2016 CS 551 / 645: Introductory Computer Graphics David Luebke cs551@cs.virginia.edu cs551.](https://reader035.fdocuments.in/reader035/viewer/2022062309/5697c0221a28abf838cd31ce/html5/thumbnails/20.jpg)
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
![Page 21: David Luebke1/10/2016 CS 551 / 645: Introductory Computer Graphics David Luebke cs551@cs.virginia.edu cs551.](https://reader035.fdocuments.in/reader035/viewer/2022062309/5697c0221a28abf838cd31ce/html5/thumbnails/21.jpg)
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
![Page 22: David Luebke1/10/2016 CS 551 / 645: Introductory Computer Graphics David Luebke cs551@cs.virginia.edu cs551.](https://reader035.fdocuments.in/reader035/viewer/2022062309/5697c0221a28abf838cd31ce/html5/thumbnails/22.jpg)
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
![Page 23: David Luebke1/10/2016 CS 551 / 645: Introductory Computer Graphics David Luebke cs551@cs.virginia.edu cs551.](https://reader035.fdocuments.in/reader035/viewer/2022062309/5697c0221a28abf838cd31ce/html5/thumbnails/23.jpg)
David Luebke 04/21/23
Rendering: Transformations
Projection transform– Apply perspective foreshortening
Distant = small: the pinhole camera model
– View coordinates screen coordinates
![Page 24: David Luebke1/10/2016 CS 551 / 645: Introductory Computer Graphics David Luebke cs551@cs.virginia.edu cs551.](https://reader035.fdocuments.in/reader035/viewer/2022062309/5697c0221a28abf838cd31ce/html5/thumbnails/24.jpg)
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
![Page 25: David Luebke1/10/2016 CS 551 / 645: Introductory Computer Graphics David Luebke cs551@cs.virginia.edu cs551.](https://reader035.fdocuments.in/reader035/viewer/2022062309/5697c0221a28abf838cd31ce/html5/thumbnails/25.jpg)
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
![Page 26: David Luebke1/10/2016 CS 551 / 645: Introductory Computer Graphics David Luebke cs551@cs.virginia.edu cs551.](https://reader035.fdocuments.in/reader035/viewer/2022062309/5697c0221a28abf838cd31ce/html5/thumbnails/26.jpg)
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
![Page 27: David Luebke1/10/2016 CS 551 / 645: Introductory Computer Graphics David Luebke cs551@cs.virginia.edu cs551.](https://reader035.fdocuments.in/reader035/viewer/2022062309/5697c0221a28abf838cd31ce/html5/thumbnails/27.jpg)
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
![Page 28: David Luebke1/10/2016 CS 551 / 645: Introductory Computer Graphics David Luebke cs551@cs.virginia.edu cs551.](https://reader035.fdocuments.in/reader035/viewer/2022062309/5697c0221a28abf838cd31ce/html5/thumbnails/28.jpg)
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
![Page 29: David Luebke1/10/2016 CS 551 / 645: Introductory Computer Graphics David Luebke cs551@cs.virginia.edu cs551.](https://reader035.fdocuments.in/reader035/viewer/2022062309/5697c0221a28abf838cd31ce/html5/thumbnails/29.jpg)
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
![Page 30: David Luebke1/10/2016 CS 551 / 645: Introductory Computer Graphics David Luebke cs551@cs.virginia.edu cs551.](https://reader035.fdocuments.in/reader035/viewer/2022062309/5697c0221a28abf838cd31ce/html5/thumbnails/30.jpg)
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
![Page 31: David Luebke1/10/2016 CS 551 / 645: Introductory Computer Graphics David Luebke cs551@cs.virginia.edu cs551.](https://reader035.fdocuments.in/reader035/viewer/2022062309/5697c0221a28abf838cd31ce/html5/thumbnails/31.jpg)
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
![Page 32: David Luebke1/10/2016 CS 551 / 645: Introductory Computer Graphics David Luebke cs551@cs.virginia.edu cs551.](https://reader035.fdocuments.in/reader035/viewer/2022062309/5697c0221a28abf838cd31ce/html5/thumbnails/32.jpg)
David Luebke 04/21/23
The Rendering Pipeline: 3-D
Transform
Illuminate
Transform
Clip
Project
Rasterize
Model & CameraModel & CameraParametersParameters Rendering PipelineRendering Pipeline FramebufferFramebuffer DisplayDisplay
![Page 33: David Luebke1/10/2016 CS 551 / 645: Introductory Computer Graphics David Luebke cs551@cs.virginia.edu cs551.](https://reader035.fdocuments.in/reader035/viewer/2022062309/5697c0221a28abf838cd31ce/html5/thumbnails/33.jpg)
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
![Page 34: David Luebke1/10/2016 CS 551 / 645: Introductory Computer Graphics David Luebke cs551@cs.virginia.edu cs551.](https://reader035.fdocuments.in/reader035/viewer/2022062309/5697c0221a28abf838cd31ce/html5/thumbnails/34.jpg)
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
![Page 35: David Luebke1/10/2016 CS 551 / 645: Introductory Computer Graphics David Luebke cs551@cs.virginia.edu cs551.](https://reader035.fdocuments.in/reader035/viewer/2022062309/5697c0221a28abf838cd31ce/html5/thumbnails/35.jpg)
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
![Page 36: David Luebke1/10/2016 CS 551 / 645: Introductory Computer Graphics David Luebke cs551@cs.virginia.edu cs551.](https://reader035.fdocuments.in/reader035/viewer/2022062309/5697c0221a28abf838cd31ce/html5/thumbnails/36.jpg)
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
![Page 37: David Luebke1/10/2016 CS 551 / 645: Introductory Computer Graphics David Luebke cs551@cs.virginia.edu cs551.](https://reader035.fdocuments.in/reader035/viewer/2022062309/5697c0221a28abf838cd31ce/html5/thumbnails/37.jpg)
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
![Page 38: David Luebke1/10/2016 CS 551 / 645: Introductory Computer Graphics David Luebke cs551@cs.virginia.edu cs551.](https://reader035.fdocuments.in/reader035/viewer/2022062309/5697c0221a28abf838cd31ce/html5/thumbnails/38.jpg)
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 ),,(
![Page 39: David Luebke1/10/2016 CS 551 / 645: Introductory Computer Graphics David Luebke cs551@cs.virginia.edu cs551.](https://reader035.fdocuments.in/reader035/viewer/2022062309/5697c0221a28abf838cd31ce/html5/thumbnails/39.jpg)
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
![Page 40: David Luebke1/10/2016 CS 551 / 645: Introductory Computer Graphics David Luebke cs551@cs.virginia.edu cs551.](https://reader035.fdocuments.in/reader035/viewer/2022062309/5697c0221a28abf838cd31ce/html5/thumbnails/40.jpg)
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
'
'
'
![Page 41: David Luebke1/10/2016 CS 551 / 645: Introductory Computer Graphics David Luebke cs551@cs.virginia.edu cs551.](https://reader035.fdocuments.in/reader035/viewer/2022062309/5697c0221a28abf838cd31ce/html5/thumbnails/41.jpg)
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
'
'
![Page 42: David Luebke1/10/2016 CS 551 / 645: Introductory Computer Graphics David Luebke cs551@cs.virginia.edu cs551.](https://reader035.fdocuments.in/reader035/viewer/2022062309/5697c0221a28abf838cd31ce/html5/thumbnails/42.jpg)
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