79
The 3D Rasterization Pipeline COS 426, Spring 2020 Felix Heide Princeton University

The 3D Rasterization Pipeline€¦ · Viewport Transformation Scan Conversion Viewing Transformation This is a pipelined sequence of operations to draw 3D primitives into a 2D image

  • Upload
    others

  • View
    12

  • Download
    0

Embed Size (px)

Citation preview

Page 1: The 3D Rasterization Pipeline€¦ · Viewport Transformation Scan Conversion Viewing Transformation This is a pipelined sequence of operations to draw 3D primitives into a 2D image

The 3D Rasterization Pipeline

COS 426, Spring 2020

Felix Heide

Princeton University

Page 2: The 3D Rasterization Pipeline€¦ · Viewport Transformation Scan Conversion Viewing Transformation This is a pipelined sequence of operations to draw 3D primitives into a 2D image

3D Rendering Scenarios

• Offline One image generated with as much quality as possible

for a particular set of rendering parameters

▪ Take as much time as is needed (minutes)

▪ Targets photorealistism, movies, etc.

➢ Interactive Images generated dynamically, in fraction of a second

(e.g., 1/30) as user controls rendering parameters (e.g.,

camera)

▪ Achieve highest quality possible in given time

▪ Visualization, games, etc.

Page 3: The 3D Rasterization Pipeline€¦ · Viewport Transformation Scan Conversion Viewing Transformation This is a pipelined sequence of operations to draw 3D primitives into a 2D image

3D Polygon Rendering

• Many applications use rendering of 3D polygons

with direct illumination Valve

Page 4: The 3D Rasterization Pipeline€¦ · Viewport Transformation Scan Conversion Viewing Transformation This is a pipelined sequence of operations to draw 3D primitives into a 2D image

3D Polygon Rendering

• Many applications use rendering of 3D polygons

with direct illuminationAssignment 2

Page 5: The 3D Rasterization Pipeline€¦ · Viewport Transformation Scan Conversion Viewing Transformation This is a pipelined sequence of operations to draw 3D primitives into a 2D image

Ray Casting Revisited

• For each sample … Construct ray from eye position through view plane

Find first surface intersected by ray through pixel

Compute color of sample based on illumination

Page 6: The 3D Rasterization Pipeline€¦ · Viewport Transformation Scan Conversion Viewing Transformation This is a pipelined sequence of operations to draw 3D primitives into a 2D image

3D Polygon Rasterization

• We can render polygons faster if we take

advantage of spatial coherence

Page 7: The 3D Rasterization Pipeline€¦ · Viewport Transformation Scan Conversion Viewing Transformation This is a pipelined sequence of operations to draw 3D primitives into a 2D image

3D Polygon Rasterization

• How?

Page 8: The 3D Rasterization Pipeline€¦ · Viewport Transformation Scan Conversion Viewing Transformation This is a pipelined sequence of operations to draw 3D primitives into a 2D image

3D Polygon Rasterization

• How?

Page 9: The 3D Rasterization Pipeline€¦ · Viewport Transformation Scan Conversion Viewing Transformation This is a pipelined sequence of operations to draw 3D primitives into a 2D image

Rasterization Pipeline (for direct illumination)

3D Primitives

ModelingTransformation

ProjectionTransformation

Clipping

Lighting

Image

ViewportTransformation

ScanConversion

ViewingTransformation

This is a pipelined

sequence of operations

to draw 3D primitives

into a 2D image

Page 10: The 3D Rasterization Pipeline€¦ · Viewport Transformation Scan Conversion Viewing Transformation This is a pipelined sequence of operations to draw 3D primitives into a 2D image

Rasterization Pipeline (for direct illumination)

3D Primitives

ModelingTransformation

ProjectionTransformation

Clipping

Lighting

Image

ViewportTransformation

ScanConversion

ViewingTransformation

OpenGL executes steps

of 3D rendering pipeline

for each polygon

glBegin(GL_POLYGON);

glVertex3f(0.0, 0.0, 0.0);

glVertex3f(1.0, 0.0, 0.0);

glVertex3f(0.0, 1.0, 0.0);

glEnd();

Page 11: The 3D Rasterization Pipeline€¦ · Viewport Transformation Scan Conversion Viewing Transformation This is a pipelined sequence of operations to draw 3D primitives into a 2D image

Rasterization Pipeline (for direct illumination)

3D Primitives

ModelingTransformation

ProjectionTransformation

Clipping

Lighting

Image

ViewportTransformation

ScanConversion

ViewingTransformation

Transform into 3D world coordinate system

Page 12: The 3D Rasterization Pipeline€¦ · Viewport Transformation Scan Conversion Viewing Transformation This is a pipelined sequence of operations to draw 3D primitives into a 2D image

Rasterization Pipeline (for direct illumination)

3D Primitives

ModelingTransformation

ProjectionTransformation

Clipping

Lighting

Image

ViewportTransformation

ScanConversion

ViewingTransformation

Transform into 3D world coordinate system

Illuminate according to lighting and reflectance

Page 13: The 3D Rasterization Pipeline€¦ · Viewport Transformation Scan Conversion Viewing Transformation This is a pipelined sequence of operations to draw 3D primitives into a 2D image

Rasterization Pipeline (for direct illumination)

3D Primitives

ModelingTransformation

ProjectionTransformation

Clipping

Lighting

Image

ViewportTransformation

ScanConversion

ViewingTransformation

Transform into 3D world coordinate system

Transform into 3D camera coordinate system

Illuminate according to lighting and reflectance

Page 14: The 3D Rasterization Pipeline€¦ · Viewport Transformation Scan Conversion Viewing Transformation This is a pipelined sequence of operations to draw 3D primitives into a 2D image

Rasterization Pipeline (for direct illumination)

3D Primitives

ModelingTransformation

ProjectionTransformation

Clipping

Lighting

Image

ViewportTransformation

ScanConversion

ViewingTransformation

Transform into 3D world coordinate system

Transform into 3D camera coordinate system

Transform into 2D camera coordinate system

Illuminate according to lighting and reflectance

Page 15: The 3D Rasterization Pipeline€¦ · Viewport Transformation Scan Conversion Viewing Transformation This is a pipelined sequence of operations to draw 3D primitives into a 2D image

Rasterization Pipeline (for direct illumination)

3D Primitives

ModelingTransformation

ProjectionTransformation

Clipping

Lighting

Image

ViewportTransformation

ScanConversion

ViewingTransformation

Transform into 3D world coordinate system

Transform into 3D camera coordinate system

Clip primitives outside camera’s view

Transform into 2D camera coordinate system

Illuminate according to lighting and reflectance

Page 16: The 3D Rasterization Pipeline€¦ · Viewport Transformation Scan Conversion Viewing Transformation This is a pipelined sequence of operations to draw 3D primitives into a 2D image

Rasterization Pipeline (for direct illumination)

3D Primitives

ModelingTransformation

ProjectionTransformation

Clipping

Lighting

Image

ViewportTransformation

ScanConversion

ViewingTransformation

Transform into 3D world coordinate system

Transform into 3D camera coordinate system

Clip primitives outside camera’s view … in clip space

Transform into 2D camera coordinate system

Illuminate according to lighting and reflectance

Page 17: The 3D Rasterization Pipeline€¦ · Viewport Transformation Scan Conversion Viewing Transformation This is a pipelined sequence of operations to draw 3D primitives into a 2D image

Rasterization Pipeline (for direct illumination)

3D Primitives

ModelingTransformation

ProjectionTransformation

Clipping

Lighting

Image

ViewportTransformation

ScanConversion

ViewingTransformation

Transform into 3D world coordinate system

Transform into 3D camera coordinate system

Clip primitives outside camera’s view

Transform into 2D camera coordinate system

Illuminate according to lighting and reflectance

Transform into image coordinate system

Page 18: The 3D Rasterization Pipeline€¦ · Viewport Transformation Scan Conversion Viewing Transformation This is a pipelined sequence of operations to draw 3D primitives into a 2D image

Rasterization Pipeline (for direct illumination)

3D Primitives

ModelingTransformation

ProjectionTransformation

Clipping

Lighting

Image

ViewportTransformation

ScanConversion

ViewingTransformation

Transform into 3D world coordinate system

Transform into 3D camera coordinate system

Draw pixels (includes texturing, hidden surface, ...)

Clip primitives outside camera’s view

Transform into 2D camera coordinate system

Illuminate according to lighting and reflectance

Transform into image coordinate system

Page 19: The 3D Rasterization Pipeline€¦ · Viewport Transformation Scan Conversion Viewing Transformation This is a pipelined sequence of operations to draw 3D primitives into a 2D image

Rasterization Pipeline (for direct illumination)

3D Primitives

ModelingTransformation

ProjectionTransformation

Clipping

Lighting

Image

ViewportTransformation

ScanConversion

ViewingTransformation

Transform into 3D world coordinate system

Transform into 3D camera coordinate system

Draw pixels (includes texturing, hidden surface, ...)

Clip primitives outside camera’s view

Transform into 2D camera coordinate system

Illuminate according to lighting and reflectance

Transform into image coordinate system

Page 20: The 3D Rasterization Pipeline€¦ · Viewport Transformation Scan Conversion Viewing Transformation This is a pipelined sequence of operations to draw 3D primitives into a 2D image

Transformations

ModelingTransformation

ViewingTransformation

2D Image Coordinates

ProjectionTransformation

ViewportTransformation

3D Object Coordinates

3D World Coordinates

3D Camera Coordinates

2D Screen Coordinates

Transformations map points from

one coordinate system to another

p(x,y,z)

p’(x’,y’)

3D World

Coordinates

3D Camera

Coordinates

3D Object

Coordinatesx

z

y

Page 21: The 3D Rasterization Pipeline€¦ · Viewport Transformation Scan Conversion Viewing Transformation This is a pipelined sequence of operations to draw 3D primitives into a 2D image

Viewing Transformations

ModelingTransformation

ViewingTransformation

2D Image Coordinates

ProjectionTransformation

ViewportTransformation

3D Object Coordinates

3D World Coordinates

3D Camera Coordinates

2D Screen Coordinates

p(x,y,z)

p’(x’,y’)

Viewing Transformations

Page 22: The 3D Rasterization Pipeline€¦ · Viewport Transformation Scan Conversion Viewing Transformation This is a pipelined sequence of operations to draw 3D primitives into a 2D image

Review: Viewing Transformation

• Mapping from world to camera coordinates Eye position maps to origin

Right vector maps to X axis

Up vector maps to Y axis

Back vector maps to Z axis

x

y

z

World

rightup

back

Camera

View plane

Page 23: The 3D Rasterization Pipeline€¦ · Viewport Transformation Scan Conversion Viewing Transformation This is a pipelined sequence of operations to draw 3D primitives into a 2D image

Review: Camera Coordinates

Camera right vector

maps to X axis

Camera up vector

maps to Y axis

Camera back vector

maps to Z axis

(pointing out of page)

• Canonical coordinate system Convention is right-handed (looking down -z axis)

Convenient for projection, clipping, etc.

x

y

z

Page 24: The 3D Rasterization Pipeline€¦ · Viewport Transformation Scan Conversion Viewing Transformation This is a pipelined sequence of operations to draw 3D primitives into a 2D image

Finding the Viewing Transformation

• Trick: map from camera coordinates to world Origin maps to eye position

Z axis maps to Back vector

Y axis maps to Up vector

X axis maps to Right vector

• This matrix is T-1 so we invert it to get T … easy!

=

w

z

y

x

EBUR

EBUR

EBUR

EBUR

w

z

y

x

wwww

zzzz

yyyy

xxxx

'

'

'

'

Page 25: The 3D Rasterization Pipeline€¦ · Viewport Transformation Scan Conversion Viewing Transformation This is a pipelined sequence of operations to draw 3D primitives into a 2D image

Finding the viewing transformation

• We have the camera (in world coordinates)

• We want T taking objects from world to camera

• Trick: find T-1 taking objects in camera to world

wpTcp =

cpTwp 1−=

Page 26: The 3D Rasterization Pipeline€¦ · Viewport Transformation Scan Conversion Viewing Transformation This is a pipelined sequence of operations to draw 3D primitives into a 2D image

Viewing Transformations

ModelingTransformation

ViewingTransformation

2D Image Coordinates

ProjectionTransformation

ViewportTransformation

3D Object Coordinates

3D World Coordinates

3D Camera Coordinates

2D Screen Coordinates

p(x,y,z)

p’(x’,y’)

Viewing Transformations

Page 27: The 3D Rasterization Pipeline€¦ · Viewport Transformation Scan Conversion Viewing Transformation This is a pipelined sequence of operations to draw 3D primitives into a 2D image

Projection

• General definition: Transform points in n-space to m-space (m<n)

• In computer graphics: Map 3D camera coordinates to 2D screen coordinates

Page 28: The 3D Rasterization Pipeline€¦ · Viewport Transformation Scan Conversion Viewing Transformation This is a pipelined sequence of operations to draw 3D primitives into a 2D image

Taxonomy of Projections

FVFHP Figure 6.10

Page 29: The 3D Rasterization Pipeline€¦ · Viewport Transformation Scan Conversion Viewing Transformation This is a pipelined sequence of operations to draw 3D primitives into a 2D image

Taxonomy of Projections

FVFHP Figure 6.10

Page 30: The 3D Rasterization Pipeline€¦ · Viewport Transformation Scan Conversion Viewing Transformation This is a pipelined sequence of operations to draw 3D primitives into a 2D image

Parallel Projection

Angel Figure 5.4

• Center of projection is at infinity Direction of projection (DOP) same for all points

DOP

View

Plane

Page 31: The 3D Rasterization Pipeline€¦ · Viewport Transformation Scan Conversion Viewing Transformation This is a pipelined sequence of operations to draw 3D primitives into a 2D image

Orthographic Projections

Angel Figure 5.5Top Side

Front

• DOP perpendicular to view plane

Page 32: The 3D Rasterization Pipeline€¦ · Viewport Transformation Scan Conversion Viewing Transformation This is a pipelined sequence of operations to draw 3D primitives into a 2D image

Parallel Projection Matrix

Page 33: The 3D Rasterization Pipeline€¦ · Viewport Transformation Scan Conversion Viewing Transformation This is a pipelined sequence of operations to draw 3D primitives into a 2D image

Parallel Projection Matrix

• General parallel projection transformation:

=

11000

0000

0sin10

0cos01

c

c

c

s

s

s

s

z

y

x

L

L

w

z

y

x

Page 34: The 3D Rasterization Pipeline€¦ · Viewport Transformation Scan Conversion Viewing Transformation This is a pipelined sequence of operations to draw 3D primitives into a 2D image

Parallel Projection View Volume

H&B Figure 12.30

Page 35: The 3D Rasterization Pipeline€¦ · Viewport Transformation Scan Conversion Viewing Transformation This is a pipelined sequence of operations to draw 3D primitives into a 2D image

Taxonomy of Projections

FVFHP Figure 6.10

Page 36: The 3D Rasterization Pipeline€¦ · Viewport Transformation Scan Conversion Viewing Transformation This is a pipelined sequence of operations to draw 3D primitives into a 2D image

Return to Perspective Projection

Angel Figure 5.9

• Map points onto “view plane” along “projectors”

emanating from “center of projection” (COP)

Center of

ProjectionView

Plane

Page 37: The 3D Rasterization Pipeline€¦ · Viewport Transformation Scan Conversion Viewing Transformation This is a pipelined sequence of operations to draw 3D primitives into a 2D image

Perspective Projection

• Compute 2D coordinates from 3D coordinates

with similar triangles

(0,0,0) z

-y

-z

y

D

(x,y,z)

View

Plane

-z

What are the coordinates

of the point resulting from

projection of (x,y,z) onto

the view plane?

Page 38: The 3D Rasterization Pipeline€¦ · Viewport Transformation Scan Conversion Viewing Transformation This is a pipelined sequence of operations to draw 3D primitives into a 2D image

Perspective Projection

• Compute 2D coordinates from 3D coordinates

with similar triangles

(0,0,0) z

-y

-z

y

D

(x,y,z)

View

Plane

-z

(xD/z, yD/z)

Page 39: The 3D Rasterization Pipeline€¦ · Viewport Transformation Scan Conversion Viewing Transformation This is a pipelined sequence of operations to draw 3D primitives into a 2D image

Perspective Projection Matrix

• 4x4 matrix representation?

=

1????????????????

c

c

c

s

s

s

s

z

y

x

w

z

y

x

1

//

====

s

s

ccs

ccs

wDz

zDyyzDxx

Page 40: The 3D Rasterization Pipeline€¦ · Viewport Transformation Scan Conversion Viewing Transformation This is a pipelined sequence of operations to draw 3D primitives into a 2D image

Perspective Projection Matrix

• 4x4 matrix representation?

=

1????????????????

c

c

c

s

s

s

s

z

y

x

w

z

y

x

1

//

====

s

s

ccs

ccs

wDz

zDyyzDxx

Dzwzzyyxx

c

c

c

c

/''''

====

'/''/''/'

wzzwyywxx

s

s

s

===

Page 41: The 3D Rasterization Pipeline€¦ · Viewport Transformation Scan Conversion Viewing Transformation This is a pipelined sequence of operations to draw 3D primitives into a 2D image

Perspective Projection Matrix

• 4x4 matrix representation?

1

//

====

s

s

ccs

ccs

wDz

zDyyzDxx

=

10/100010000100001

c

c

c

s

s

s

s

z

y

x

Dw

z

y

x

Dzwzzyyxx

c

c

c

c

/''''

====

'/''/''/'

wzzwyywxx

s

s

s

===

Page 42: The 3D Rasterization Pipeline€¦ · Viewport Transformation Scan Conversion Viewing Transformation This is a pipelined sequence of operations to draw 3D primitives into a 2D image

• In practice, want to compute a value related to

depth to include in z-buffer

Perspective Projection Matrix

1///

=−=

==

s

cs

ccs

ccs

wzDzzDyyzDxx

−=

10/100

1000

0010

0001

c

c

c

s

s

s

s

z

y

x

Dw

z

y

x

Dzwz

yyxx

c

c

c

/'1'

''

=−=

==

'/''/''/'

wzzwyywxx

s

s

s

===

Page 43: The 3D Rasterization Pipeline€¦ · Viewport Transformation Scan Conversion Viewing Transformation This is a pipelined sequence of operations to draw 3D primitives into a 2D image

Perspective Projection View Volume

H&B Figure 12.30

View

Plane

Page 44: The 3D Rasterization Pipeline€¦ · Viewport Transformation Scan Conversion Viewing Transformation This is a pipelined sequence of operations to draw 3D primitives into a 2D image

Perspective vs. Parallel

• Perspective projection+ Size varies inversely with distance - looks realistic

– Distance and angles are not (in general) preserved

– Parallel lines do not (in general) remain parallel

• Parallel projection+ Good for exact measurements

+ Parallel lines remain parallel

– Angles are not (in general) preserved

– Less realistic looking

Page 45: The 3D Rasterization Pipeline€¦ · Viewport Transformation Scan Conversion Viewing Transformation This is a pipelined sequence of operations to draw 3D primitives into a 2D image

Transformations

ModelingTransformation

ViewingTransformation

2D Image Coordinates

ProjectionTransformation

ViewportTransformation

3D Object Coordinates

3D World Coordinates

3D Camera Coordinates

2D Screen Coordinates

Transformations map points from

one coordinate system to another

p(x,y,z)

p’(x’,y’)

3D World

Coordinates

3D Camera

Coordinates

3D Object

Coordinatesx

z

y

Page 46: The 3D Rasterization Pipeline€¦ · Viewport Transformation Scan Conversion Viewing Transformation This is a pipelined sequence of operations to draw 3D primitives into a 2D image

Viewport Transformation

• Transform 2D geometric primitives from

screen coordinate system (normalized device

coordinates) to image coordinate system (pixels)

ImageScreen

Viewport

Window

Page 47: The 3D Rasterization Pipeline€¦ · Viewport Transformation Scan Conversion Viewing Transformation This is a pipelined sequence of operations to draw 3D primitives into a 2D image

Viewport Transformation

vx1 vx2vy1

vy2

wx1 wx2wy1

wy2Window Viewport

Screen Coordinates Image Coordinates

(wx,wy) (vx,vy)

vx = vx1 + (wx - wx1) * (vx2 - vx1) / (wx2 - wx1);

vy = vy1 + (wy - wy1) * (vy2 - vy1) / (wy2 - wy1);

• Window-to-viewport mapping

Page 48: The 3D Rasterization Pipeline€¦ · Viewport Transformation Scan Conversion Viewing Transformation This is a pipelined sequence of operations to draw 3D primitives into a 2D image

Summary of Transformations

ModelingTransformation

ViewingTransformation

2D Image Coordinates

ProjectionTransformation

ViewportTransformation

3D Object Coordinates

3D World Coordinates

3D Camera Coordinates

2D Screen Coordinates

p(x,y,z)

p’(x’,y’)

Viewing transformations

Modeling transformation

Viewport transformation

Page 49: The 3D Rasterization Pipeline€¦ · Viewport Transformation Scan Conversion Viewing Transformation This is a pipelined sequence of operations to draw 3D primitives into a 2D image

3D Rendering Pipeline (for direct illumination)

3D Primitives

ModelingTransformation

ProjectionTransformation

Clipping

Lighting

Image

ViewportTransformation

ScanConversion

2D Image Coordinates

3D Modeling Coordinates

3D World Coordinates

3D Camera Coordinates

2D Screen Coordinates

2D Screen Coordinates

ViewingTransformation

3D World Coordinates

2D Image Coordinates

Page 50: The 3D Rasterization Pipeline€¦ · Viewport Transformation Scan Conversion Viewing Transformation This is a pipelined sequence of operations to draw 3D primitives into a 2D image

Clipping

• Avoid drawing parts of primitives outside window Window defines part of scene being viewed

Must draw geometric primitives only inside window

Viewing

Window

Page 51: The 3D Rasterization Pipeline€¦ · Viewport Transformation Scan Conversion Viewing Transformation This is a pipelined sequence of operations to draw 3D primitives into a 2D image

Polygon Clipping

• Find the part of a polygon inside the clip window?

Before Clipping

Page 52: The 3D Rasterization Pipeline€¦ · Viewport Transformation Scan Conversion Viewing Transformation This is a pipelined sequence of operations to draw 3D primitives into a 2D image

Polygon Clipping

• Find the part of a polygon inside the clip window?

After Clipping

Page 53: The 3D Rasterization Pipeline€¦ · Viewport Transformation Scan Conversion Viewing Transformation This is a pipelined sequence of operations to draw 3D primitives into a 2D image

Sutherland Hodgeman Clipping

• Clip to each window boundary one at a time

(for convex polygons)

Page 54: The 3D Rasterization Pipeline€¦ · Viewport Transformation Scan Conversion Viewing Transformation This is a pipelined sequence of operations to draw 3D primitives into a 2D image

Sutherland Hodgeman Clipping

• Clip to each window boundary one at a time

Page 55: The 3D Rasterization Pipeline€¦ · Viewport Transformation Scan Conversion Viewing Transformation This is a pipelined sequence of operations to draw 3D primitives into a 2D image

Sutherland Hodgeman Clipping

• Clip to each window boundary one at a time

Page 56: The 3D Rasterization Pipeline€¦ · Viewport Transformation Scan Conversion Viewing Transformation This is a pipelined sequence of operations to draw 3D primitives into a 2D image

Sutherland Hodgeman Clipping

• Clip to each window boundary one at a time

Page 57: The 3D Rasterization Pipeline€¦ · Viewport Transformation Scan Conversion Viewing Transformation This is a pipelined sequence of operations to draw 3D primitives into a 2D image

Sutherland Hodgeman Clipping

• Clip to each window boundary one at a time

Page 58: The 3D Rasterization Pipeline€¦ · Viewport Transformation Scan Conversion Viewing Transformation This is a pipelined sequence of operations to draw 3D primitives into a 2D image

Clipping to a Boundary

• Do inside test for each point in sequence,

Insert new points when cross window boundary,

Remove points outside window boundary

Outside

Inside

Window

Boundary

P1

P2

P5

P4

P3

Page 59: The 3D Rasterization Pipeline€¦ · Viewport Transformation Scan Conversion Viewing Transformation This is a pipelined sequence of operations to draw 3D primitives into a 2D image

Clipping to a Boundary

• Do inside test for each point in sequence,

Insert new points when cross window boundary,

Remove points outside window boundary

Outside

Inside

Window

Boundary

P1

P2

P5

P4

P3

Page 60: The 3D Rasterization Pipeline€¦ · Viewport Transformation Scan Conversion Viewing Transformation This is a pipelined sequence of operations to draw 3D primitives into a 2D image

Clipping to a Boundary

• Do inside test for each point in sequence,

Insert new points when cross window boundary,

Remove points outside window boundary

Outside

Inside

Window

Boundary

P1

P2

P5

P4

P3

Page 61: The 3D Rasterization Pipeline€¦ · Viewport Transformation Scan Conversion Viewing Transformation This is a pipelined sequence of operations to draw 3D primitives into a 2D image

Clipping to a Boundary

• Do inside test for each point in sequence,

Insert new points when cross window boundary,

Remove points outside window boundary

Outside

Inside

Window

Boundary

P1

P2

P5

P4

P3

Page 62: The 3D Rasterization Pipeline€¦ · Viewport Transformation Scan Conversion Viewing Transformation This is a pipelined sequence of operations to draw 3D primitives into a 2D image

P’

Clipping to a Boundary

• Do inside test for each point in sequence,

Insert new points when cross window boundary,

Remove points outside window boundary

Outside

Inside

Window

Boundary

P1

P2

P5

P4

P3

Page 63: The 3D Rasterization Pipeline€¦ · Viewport Transformation Scan Conversion Viewing Transformation This is a pipelined sequence of operations to draw 3D primitives into a 2D image

P’

Clipping to a Boundary

• Do inside test for each point in sequence,

Insert new points when cross window boundary,

Remove points outside window boundary

Outside

Inside

Window

Boundary

P1

P2

P5

P4

P3

Page 64: The 3D Rasterization Pipeline€¦ · Viewport Transformation Scan Conversion Viewing Transformation This is a pipelined sequence of operations to draw 3D primitives into a 2D image

P’

Clipping to a Boundary

• Do inside test for each point in sequence,

Insert new points when cross window boundary,

Remove points outside window boundary

Outside

Inside

Window

Boundary

P1

P2

P5

P4

P3

Page 65: The 3D Rasterization Pipeline€¦ · Viewport Transformation Scan Conversion Viewing Transformation This is a pipelined sequence of operations to draw 3D primitives into a 2D image

P’’P’

Clipping to a Boundary

• Do inside test for each point in sequence,

Insert new points when cross window boundary,

Remove points outside window boundary

Outside

Inside

Window

Boundary

P1

P2

P5

P4

P3

Page 66: The 3D Rasterization Pipeline€¦ · Viewport Transformation Scan Conversion Viewing Transformation This is a pipelined sequence of operations to draw 3D primitives into a 2D image

P’’P’

Clipping to a Boundary

• Do inside test for each point in sequence,

Insert new points when cross window boundary,

Remove points outside window boundary

Outside

Inside

Window

Boundary

P1

P2

Page 67: The 3D Rasterization Pipeline€¦ · Viewport Transformation Scan Conversion Viewing Transformation This is a pipelined sequence of operations to draw 3D primitives into a 2D image

Sutherland Hodgeman Failure

• Concave Polygons

Page 68: The 3D Rasterization Pipeline€¦ · Viewport Transformation Scan Conversion Viewing Transformation This is a pipelined sequence of operations to draw 3D primitives into a 2D image

3D Rendering Pipeline (for direct illumination)

Viewing

Window

3D Primitives

ModelingTransformation

ProjectionTransformation

Clipping

Lighting

Image

ViewportTransformation

ScanConversion

2D Image Coordinates

3D Modeling Coordinates

3D World Coordinates

3D Camera Coordinates

2D Screen Coordinates

2D Screen Coordinates

ViewingTransformation

3D World Coordinates

2D Image Coordinates

Page 69: The 3D Rasterization Pipeline€¦ · Viewport Transformation Scan Conversion Viewing Transformation This is a pipelined sequence of operations to draw 3D primitives into a 2D image

3D Primitives

ModelingTransformation

ProjectionTransformation

Clipping

Lighting

Image

ViewportTransformation

ScanConversion

2D Image Coordinates

3D Modeling Coordinates

3D World Coordinates

3D Camera Coordinates

2D Screen Coordinates

2D Screen Coordinates

ViewingTransformation

3D World Coordinates

2D Image Coordinates

Standard (aliased)

Scan Conversion

P1

P2

P3

3D Rendering Pipeline (for direct illumination)

Page 70: The 3D Rasterization Pipeline€¦ · Viewport Transformation Scan Conversion Viewing Transformation This is a pipelined sequence of operations to draw 3D primitives into a 2D image

3D Primitives

ModelingTransformation

ProjectionTransformation

Clipping

Lighting

Image

ViewportTransformation

ScanConversion

2D Image Coordinates

3D Modeling Coordinates

3D World Coordinates

3D Camera Coordinates

2D Screen Coordinates

2D Screen Coordinates

ViewingTransformation

3D World Coordinates

2D Image Coordinates

Antialiased

Scan Conversion

P1

P2

P3

3D Rendering Pipeline (for direct illumination)

Page 71: The 3D Rasterization Pipeline€¦ · Viewport Transformation Scan Conversion Viewing Transformation This is a pipelined sequence of operations to draw 3D primitives into a 2D image

Scan Conversion

• Render an image of a geometric primitive

by setting pixel colors

• Example: Filling the inside of a triangle

P1

P2

P3

void SetPixel(int x, int y, Color rgba)

Page 72: The 3D Rasterization Pipeline€¦ · Viewport Transformation Scan Conversion Viewing Transformation This is a pipelined sequence of operations to draw 3D primitives into a 2D image

Triangle Scan Conversion

• Properties of a good algorithm Symmetric

Straight edges

No cracks between adjacent primitives

(Antialiased edges)

FAST!

P1

P2

P3

P4

Page 73: The 3D Rasterization Pipeline€¦ · Viewport Transformation Scan Conversion Viewing Transformation This is a pipelined sequence of operations to draw 3D primitives into a 2D image

• Color all pixels inside triangle

Simple Algorithm

P1

P2

P3

void ScanTriangle(Triangle T, Color rgba){for each pixel P in bbox(T){

if (Inside(T, P)) SetPixel(P.x, P.y, rgba);

}}

Page 74: The 3D Rasterization Pipeline€¦ · Viewport Transformation Scan Conversion Viewing Transformation This is a pipelined sequence of operations to draw 3D primitives into a 2D image

Triangle Sweep-Line Algorithm

• Take advantage of spatial coherence Compute which pixels are inside using horizontal spans

Process horizontal spans in scan-line order

• Take advantage of edge linearity Use edge slopes to update coordinates incrementally

dxdy

Page 75: The 3D Rasterization Pipeline€¦ · Viewport Transformation Scan Conversion Viewing Transformation This is a pipelined sequence of operations to draw 3D primitives into a 2D image

Triangle Sweep-Line Algorithm

void ScanTriangle(Triangle T, Color rgba){for each edge pair {

initialize xL, xR;compute dxL/dyL and dxR/dyR;for each scanline at y

for (int x = xL; x <= xR; x++) SetPixel(x, y, rgba);

xL += dxL/dyL;xR += dxR/dyR;

}}

xL xR

dxL

dyL

dxR

dyR

Page 76: The 3D Rasterization Pipeline€¦ · Viewport Transformation Scan Conversion Viewing Transformation This is a pipelined sequence of operations to draw 3D primitives into a 2D image

Triangle Sweep-Line Algorithm

void ScanTriangle(Triangle T, Color rgba){for each edge pair {

initialize xL, xR;compute dxL/dyL and dxR/dyR;for each scanline at y

for (int x = xL; x <= xR; x++) SetPixel(x, y, rgba);

xL += dxL/dyL;xR += dxR/dyR;

}}

xL xR

dxL

dyL

dxR

dyRMinimize computation

in inner loops

Page 77: The 3D Rasterization Pipeline€¦ · Viewport Transformation Scan Conversion Viewing Transformation This is a pipelined sequence of operations to draw 3D primitives into a 2D image

GPU Architecture

Page 78: The 3D Rasterization Pipeline€¦ · Viewport Transformation Scan Conversion Viewing Transformation This is a pipelined sequence of operations to draw 3D primitives into a 2D image

GPU Architecture

Page 79: The 3D Rasterization Pipeline€¦ · Viewport Transformation Scan Conversion Viewing Transformation This is a pipelined sequence of operations to draw 3D primitives into a 2D image

GPU Architecture