david luebke11/14/2015 cs 551 / 645: introductory computer graphics david luebke...

32
David Luebke 06/23/22 CS 551 / 645: Introductory Computer Graphics David Luebke [email protected] http://www.cs.virginia.edu/~cs551

Upload: mildred-campbell

Post on 04-Jan-2016

228 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: David Luebke11/14/2015 CS 551 / 645: Introductory Computer Graphics David Luebke cs551@cs.virginia.edu cs551

David Luebke 04/20/23

CS 551 / 645: Introductory Computer Graphics

David Luebke

[email protected]

http://www.cs.virginia.edu/~cs551

Page 2: David Luebke11/14/2015 CS 551 / 645: Introductory Computer Graphics David Luebke cs551@cs.virginia.edu cs551

David Luebke 04/20/23

Administrivia

Office hours today: 4:30-5:30

Page 3: David Luebke11/14/2015 CS 551 / 645: Introductory Computer Graphics David Luebke cs551@cs.virginia.edu cs551

David Luebke 04/20/23

Recap: Rigid-Body Transforms

Goal: object coordinatesworld coordinates Rigid-body transforms

– Translation– Rotation– Scale– Shear

Page 4: David Luebke11/14/2015 CS 551 / 645: Introductory Computer Graphics David Luebke cs551@cs.virginia.edu cs551

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

Page 5: David Luebke11/14/2015 CS 551 / 645: Introductory Computer Graphics David Luebke cs551@cs.virginia.edu cs551

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

Page 6: David Luebke11/14/2015 CS 551 / 645: Introductory Computer Graphics David Luebke cs551@cs.virginia.edu cs551

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

Page 7: David Luebke11/14/2015 CS 551 / 645: Introductory Computer Graphics David Luebke cs551@cs.virginia.edu cs551

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

Page 8: David Luebke11/14/2015 CS 551 / 645: Introductory Computer Graphics David Luebke cs551@cs.virginia.edu cs551

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

Page 9: David Luebke11/14/2015 CS 551 / 645: Introductory Computer Graphics David Luebke cs551@cs.virginia.edu cs551

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

Page 10: David Luebke11/14/2015 CS 551 / 645: Introductory Computer Graphics David Luebke cs551@cs.virginia.edu cs551

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

'

'

'

'

Page 11: David Luebke11/14/2015 CS 551 / 645: Introductory Computer Graphics David Luebke cs551@cs.virginia.edu cs551

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

'

'

'

'

Page 12: David Luebke11/14/2015 CS 551 / 645: Introductory Computer Graphics David Luebke cs551@cs.virginia.edu cs551

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

'

'

'

'

Page 13: David Luebke11/14/2015 CS 551 / 645: Introductory Computer Graphics David Luebke cs551@cs.virginia.edu cs551

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

Page 14: David Luebke11/14/2015 CS 551 / 645: Introductory Computer Graphics David Luebke cs551@cs.virginia.edu cs551

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

Page 15: David Luebke11/14/2015 CS 551 / 645: Introductory Computer Graphics David Luebke cs551@cs.virginia.edu cs551

David Luebke 04/20/23

Perspective Projection

In the real world, objects exhibit perspective foreshortening: distant objects appear smaller

The basic situation:

Page 16: David Luebke11/14/2015 CS 551 / 645: Introductory Computer Graphics David Luebke cs551@cs.virginia.edu cs551

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?

Page 17: David Luebke11/14/2015 CS 551 / 645: Introductory Computer Graphics David Luebke cs551@cs.virginia.edu cs551

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’ = ?

Page 18: David Luebke11/14/2015 CS 551 / 645: Introductory Computer Graphics David Luebke cs551@cs.virginia.edu cs551

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

,','

',

'

Page 19: David Luebke11/14/2015 CS 551 / 645: Introductory Computer Graphics David Luebke cs551@cs.virginia.edu cs551

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

Page 20: David Luebke11/14/2015 CS 551 / 645: Introductory Computer Graphics David Luebke cs551@cs.virginia.edu cs551

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,,

Page 21: David Luebke11/14/2015 CS 551 / 645: Introductory Computer Graphics David Luebke cs551@cs.virginia.edu cs551

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

Page 22: David Luebke11/14/2015 CS 551 / 645: Introductory Computer Graphics David Luebke cs551@cs.virginia.edu cs551

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 ?)

Page 23: David Luebke11/14/2015 CS 551 / 645: Introductory Computer Graphics David Luebke cs551@cs.virginia.edu cs551

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

Page 24: David Luebke11/14/2015 CS 551 / 645: Introductory Computer Graphics David Luebke cs551@cs.virginia.edu cs551

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

Page 25: David Luebke11/14/2015 CS 551 / 645: Introductory Computer Graphics David Luebke cs551@cs.virginia.edu cs551

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

Page 26: David Luebke11/14/2015 CS 551 / 645: Introductory Computer Graphics David Luebke cs551@cs.virginia.edu cs551

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

Page 27: David Luebke11/14/2015 CS 551 / 645: Introductory Computer Graphics David Luebke cs551@cs.virginia.edu cs551

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

Page 28: David Luebke11/14/2015 CS 551 / 645: Introductory Computer Graphics David Luebke cs551@cs.virginia.edu cs551

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

Page 29: David Luebke11/14/2015 CS 551 / 645: Introductory Computer Graphics David Luebke cs551@cs.virginia.edu cs551

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

Page 30: David Luebke11/14/2015 CS 551 / 645: Introductory Computer Graphics David Luebke cs551@cs.virginia.edu cs551

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

Page 31: David Luebke11/14/2015 CS 551 / 645: Introductory Computer Graphics David Luebke cs551@cs.virginia.edu cs551

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

Page 32: David Luebke11/14/2015 CS 551 / 645: Introductory Computer Graphics David Luebke cs551@cs.virginia.edu cs551

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