the 3d rasterization pipeline€¦ · perspective vs. parallel • perspective projection + size...

74
The 3D Rasterization Pipeline COS 426

Upload: others

Post on 19-Apr-2020

30 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: The 3D Rasterization Pipeline€¦ · Perspective vs. Parallel • Perspective projection + Size varies inversely with distance - looks realistic – Distance and angles are not (in

The 3D Rasterization Pipeline

COS 426

Page 2: The 3D Rasterization Pipeline€¦ · Perspective vs. Parallel • Perspective projection + Size varies inversely with distance - looks realistic – Distance and angles are not (in

3D Rendering Scenarios• Batch

One image generated with as much quality as possiblefor a particular set of rendering parameters Take as much time as is needed (minutes) Useful for photorealistism, movies, etc.

Interactive Images generated in fraction of a second (<1/10)

with user input, animation, varying camera, etc. Achieve highest quality possible in given time Visualization, games, etc.

Page 3: The 3D Rasterization Pipeline€¦ · Perspective vs. Parallel • Perspective projection + Size varies inversely with distance - looks realistic – Distance and angles are not (in

3D Polygon Rendering• Many applications use rendering of 3D polygons

with direct illumination

Bungie

Page 4: The 3D Rasterization Pipeline€¦ · Perspective vs. Parallel • Perspective projection + Size varies inversely with distance - looks realistic – Distance and angles are not (in

3D Polygon Rendering• Many applications use rendering of 3D polygons

with direct illumination

meshview

Page 5: The 3D Rasterization Pipeline€¦ · Perspective vs. Parallel • Perspective projection + Size varies inversely with distance - looks realistic – Distance and angles are not (in

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€¦ · Perspective vs. Parallel • Perspective projection + Size varies inversely with distance - looks realistic – Distance and angles are not (in

3D Polygon Rendering• We can render polygons faster if we take

advantage of spatial coherence

Page 7: The 3D Rasterization Pipeline€¦ · Perspective vs. Parallel • Perspective projection + Size varies inversely with distance - looks realistic – Distance and angles are not (in

3D Polygon Rendering• How?

Page 8: The 3D Rasterization Pipeline€¦ · Perspective vs. Parallel • Perspective projection + Size varies inversely with distance - looks realistic – Distance and angles are not (in

3D Polygon Rendering• How?

Page 9: The 3D Rasterization Pipeline€¦ · Perspective vs. Parallel • Perspective projection + Size varies inversely with distance - looks realistic – Distance and angles are not (in

3D Polygon Rendering• How?

Page 10: The 3D Rasterization Pipeline€¦ · Perspective vs. Parallel • Perspective projection + Size varies inversely with distance - looks realistic – Distance and angles are not (in

3D Rendering Pipeline (for direct illumination)

3D Primitives

ModelingTransformation

ProjectionTransformation

Clipping

Lighting

Image

ViewportTransformation

ScanConversion

ViewingTransformation

This is a pipelinedsequence of operations to draw 3D primitives

into a 2D image

Page 11: The 3D Rasterization Pipeline€¦ · Perspective vs. Parallel • Perspective projection + Size varies inversely with distance - looks realistic – Distance and angles are not (in

3D Rendering 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(1.0, 1.0, 1.0);glVertex3f(0.0, 1.0, 1.0);glEnd();

Page 12: The 3D Rasterization Pipeline€¦ · Perspective vs. Parallel • Perspective projection + Size varies inversely with distance - looks realistic – Distance and angles are not (in

3D Rendering Pipeline (for direct illumination)

3D Primitives

ModelingTransformation

ProjectionTransformation

Clipping

Lighting

Image

ViewportTransformation

ScanConversion

ViewingTransformation

Transform into 3D world coordinate system

Page 13: The 3D Rasterization Pipeline€¦ · Perspective vs. Parallel • Perspective projection + Size varies inversely with distance - looks realistic – Distance and angles are not (in

3D Rendering 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 14: The 3D Rasterization Pipeline€¦ · Perspective vs. Parallel • Perspective projection + Size varies inversely with distance - looks realistic – Distance and angles are not (in

3D Rendering 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 15: The 3D Rasterization Pipeline€¦ · Perspective vs. Parallel • Perspective projection + Size varies inversely with distance - looks realistic – Distance and angles are not (in

3D Rendering 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 16: The 3D Rasterization Pipeline€¦ · Perspective vs. Parallel • Perspective projection + Size varies inversely with distance - looks realistic – Distance and angles are not (in

3D Rendering 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 17: The 3D Rasterization Pipeline€¦ · Perspective vs. Parallel • Perspective projection + Size varies inversely with distance - looks realistic – Distance and angles are not (in

3D Rendering 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€¦ · Perspective vs. Parallel • Perspective projection + Size varies inversely with distance - looks realistic – Distance and angles are not (in

3D Rendering 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€¦ · Perspective vs. Parallel • Perspective projection + Size varies inversely with distance - looks realistic – Distance and angles are not (in

3D Rendering 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€¦ · Perspective vs. Parallel • Perspective projection + Size varies inversely with distance - looks realistic – Distance and angles are not (in

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 CameraCoordinates

3D ObjectCoordinates

x

z

y

Page 21: The 3D Rasterization Pipeline€¦ · Perspective vs. Parallel • Perspective projection + Size varies inversely with distance - looks realistic – Distance and angles are not (in

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€¦ · Perspective vs. Parallel • Perspective projection + Size varies inversely with distance - looks realistic – Distance and angles are not (in

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€¦ · Perspective vs. Parallel • Perspective projection + Size varies inversely with distance - looks realistic – Distance and angles are not (in

Camera Coordinates

Camera right vectormaps to X axis

Camera up vector maps to Y axis

Camera back vectormaps 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€¦ · Perspective vs. Parallel • Perspective projection + Size varies inversely with distance - looks realistic – Distance and angles are not (in

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 =

=

wzyx

ponmlkjihgfedcba

wzyx

''''

cpTwp 1−=

?

Page 25: The 3D Rasterization Pipeline€¦ · Perspective vs. Parallel • Perspective projection + Size varies inversely with distance - looks realistic – Distance and angles are not (in

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!

=

wzyx

EBUREBUREBUREBUR

wzyx

wwww

zzzz

yyyy

xxxx

''''

Page 26: The 3D Rasterization Pipeline€¦ · Perspective vs. Parallel • Perspective projection + Size varies inversely with distance - looks realistic – Distance and angles are not (in

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€¦ · Perspective vs. Parallel • Perspective projection + Size varies inversely with distance - looks realistic – Distance and angles are not (in

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€¦ · Perspective vs. Parallel • Perspective projection + Size varies inversely with distance - looks realistic – Distance and angles are not (in

Taxonomy of Projections

FVFHP Figure 6.10

Page 29: The 3D Rasterization Pipeline€¦ · Perspective vs. Parallel • Perspective projection + Size varies inversely with distance - looks realistic – Distance and angles are not (in

Taxonomy of Projections

FVFHP Figure 6.10

Page 30: The 3D Rasterization Pipeline€¦ · Perspective vs. Parallel • Perspective projection + Size varies inversely with distance - looks realistic – Distance and angles are not (in

Parallel Projection

Angel Figure 5.4

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

DOP

ViewPlane

Page 31: The 3D Rasterization Pipeline€¦ · Perspective vs. Parallel • Perspective projection + Size varies inversely with distance - looks realistic – Distance and angles are not (in

Orthographic Projections

Angel Figure 5.5Top Side

Front

• DOP perpendicular to view plane

Page 32: The 3D Rasterization Pipeline€¦ · Perspective vs. Parallel • Perspective projection + Size varies inversely with distance - looks realistic – Distance and angles are not (in

Parallel Projection Matrix• General parallel projection transformation:

=

1100000000sin100cos01

c

c

c

s

s

s

s

zyx

LL

wzyx

φφ

Page 33: The 3D Rasterization Pipeline€¦ · Perspective vs. Parallel • Perspective projection + Size varies inversely with distance - looks realistic – Distance and angles are not (in

Parallel Projection View Volume

H&B Figure 12.30

Page 34: The 3D Rasterization Pipeline€¦ · Perspective vs. Parallel • Perspective projection + Size varies inversely with distance - looks realistic – Distance and angles are not (in

Taxonomy of Projections

FVFHP Figure 6.10

Page 35: The 3D Rasterization Pipeline€¦ · Perspective vs. Parallel • Perspective projection + Size varies inversely with distance - looks realistic – Distance and angles are not (in

Perspective Projection

Angel Figure 5.9

• Map points onto “view plane” along “projectors” emanating from “center of projection” (COP)

Center ofProjection

View Plane

Page 36: The 3D Rasterization Pipeline€¦ · Perspective vs. Parallel • Perspective projection + Size varies inversely with distance - looks realistic – Distance and angles are not (in

Perspective Projection• Compute 2D coordinates from 3D coordinates

with similar triangles

(0,0,0) z

-y

-z

y

D

(x,y,z)

ViewPlane

-z

What are the coordinatesof the point resulting fromprojection of (x,y,z) ontothe view plane?

Page 37: The 3D Rasterization Pipeline€¦ · Perspective vs. Parallel • Perspective projection + Size varies inversely with distance - looks realistic – Distance and angles are not (in

Perspective Projection• Compute 2D coordinates from 3D coordinates

with similar triangles

(0,0,0) z

-y

-z

y

D

(x,y,z)

ViewPlane

-z

(xD/z, yD/z)

Page 38: The 3D Rasterization Pipeline€¦ · Perspective vs. Parallel • Perspective projection + Size varies inversely with distance - looks realistic – Distance and angles are not (in

Perspective Projection Matrix• 4x4 matrix representation?

=

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

c

c

c

s

s

s

s

zyx

wzyx

1

//

====

s

s

ccs

ccs

wDz

zDyyzDxx

Page 39: The 3D Rasterization Pipeline€¦ · Perspective vs. Parallel • Perspective projection + Size varies inversely with distance - looks realistic – Distance and angles are not (in

Perspective Projection Matrix• 4x4 matrix representation?

=

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

c

c

c

s

s

s

s

zyx

wzyx

1

//

====

s

s

ccs

ccs

wDz

zDyyzDxx

Dzwzzyyxx

c

c

c

c

/''''

====

'/''/''/'

wzzwyywxx

s

s

s

===

Page 40: The 3D Rasterization Pipeline€¦ · Perspective vs. Parallel • Perspective projection + Size varies inversely with distance - looks realistic – Distance and angles are not (in

Perspective Projection Matrix• 4x4 matrix representation?

1

//

====

s

s

ccs

ccs

wDz

zDyyzDxx

=

10/100010000100001

c

c

c

s

s

s

s

zyx

Dwzyx

Dzwzzyyxx

c

c

c

c

/''''

====

'/''/''/'

wzzwyywxx

s

s

s

===

Page 41: The 3D Rasterization Pipeline€¦ · Perspective vs. Parallel • Perspective projection + Size varies inversely with distance - looks realistic – Distance and angles are not (in

Perspective Projection View Volume

H&B Figure 12.30

ViewPlane

Page 42: The 3D Rasterization Pipeline€¦ · Perspective vs. Parallel • Perspective projection + Size varies inversely with distance - looks realistic – Distance and angles are not (in

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 43: The 3D Rasterization Pipeline€¦ · Perspective vs. Parallel • Perspective projection + Size varies inversely with distance - looks realistic – Distance and angles are not (in

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 CameraCoordinates

3D ObjectCoordinates

x

z

y

Page 44: The 3D Rasterization Pipeline€¦ · Perspective vs. Parallel • Perspective projection + Size varies inversely with distance - looks realistic – Distance and angles are not (in

Viewport Transformation• Transform 2D geometric primitives from

screen coordinate system (normalized device coordinates) to image coordinate system (pixels)

ImageScreen

Viewport

Window

Page 45: The 3D Rasterization Pipeline€¦ · Perspective vs. Parallel • Perspective projection + Size varies inversely with distance - looks realistic – Distance and angles are not (in

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 46: The 3D Rasterization Pipeline€¦ · Perspective vs. Parallel • Perspective projection + Size varies inversely with distance - looks realistic – Distance and angles are not (in

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 47: The 3D Rasterization Pipeline€¦ · Perspective vs. Parallel • Perspective projection + Size varies inversely with distance - looks realistic – Distance and angles are not (in

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 48: The 3D Rasterization Pipeline€¦ · Perspective vs. Parallel • Perspective projection + Size varies inversely with distance - looks realistic – Distance and angles are not (in

Clipping• Avoid drawing parts of primitives outside window

Window defines part of scene being viewed Must draw geometric primitives only inside window

ViewingWindow

Page 49: The 3D Rasterization Pipeline€¦ · Perspective vs. Parallel • Perspective projection + Size varies inversely with distance - looks realistic – Distance and angles are not (in

Clipping• Avoid drawing parts of primitives outside window

Points Lines Polygons Circles etc.

ViewingWindow

Page 50: The 3D Rasterization Pipeline€¦ · Perspective vs. Parallel • Perspective projection + Size varies inversely with distance - looks realistic – Distance and angles are not (in

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

Before Clipping

Page 51: The 3D Rasterization Pipeline€¦ · Perspective vs. Parallel • Perspective projection + Size varies inversely with distance - looks realistic – Distance and angles are not (in

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

After Clipping

Page 52: The 3D Rasterization Pipeline€¦ · Perspective vs. Parallel • Perspective projection + Size varies inversely with distance - looks realistic – Distance and angles are not (in

Sutherland Hodgeman Clipping• Clip to each window boundary one at a time

Page 53: The 3D Rasterization Pipeline€¦ · Perspective vs. Parallel • Perspective projection + Size varies inversely with distance - looks realistic – Distance and angles are not (in

Sutherland Hodgeman Clipping• Clip to each window boundary one at a time

Page 54: The 3D Rasterization Pipeline€¦ · Perspective vs. Parallel • Perspective projection + Size varies inversely with distance - looks realistic – Distance and angles are not (in

Sutherland Hodgeman Clipping• Clip to each window boundary one at a time

Page 55: The 3D Rasterization Pipeline€¦ · Perspective vs. Parallel • Perspective projection + Size varies inversely with distance - looks realistic – Distance and angles are not (in

Sutherland Hodgeman Clipping• Clip to each window boundary one at a time

Page 56: The 3D Rasterization Pipeline€¦ · Perspective vs. Parallel • Perspective projection + Size varies inversely with distance - looks realistic – Distance and angles are not (in

Sutherland Hodgeman Clipping• Clip to each window boundary one at a time

Page 57: The 3D Rasterization Pipeline€¦ · Perspective vs. Parallel • Perspective projection + Size varies inversely with distance - looks realistic – Distance and angles are not (in

Clipping to a Boundary• Do inside test for each point in sequence,

Insert new points when cross window boundary, Remove points outside window boundary

OutsideInside

WindowBoundary

P1

P2

P5

P4

P3

Page 58: The 3D Rasterization Pipeline€¦ · Perspective vs. Parallel • Perspective projection + Size varies inversely with distance - looks realistic – Distance and angles are not (in

Clipping to a Boundary• Do inside test for each point in sequence,

Insert new points when cross window boundary, Remove points outside window boundary

OutsideInside

WindowBoundary

P1

P2

P5

P4

P3

Page 59: The 3D Rasterization Pipeline€¦ · Perspective vs. Parallel • Perspective projection + Size varies inversely with distance - looks realistic – Distance and angles are not (in

Clipping to a Boundary• Do inside test for each point in sequence,

Insert new points when cross window boundary, Remove points outside window boundary

OutsideInside

WindowBoundary

P1

P2

P5

P4

P3

Page 60: The 3D Rasterization Pipeline€¦ · Perspective vs. Parallel • Perspective projection + Size varies inversely with distance - looks realistic – Distance and angles are not (in

Clipping to a Boundary• Do inside test for each point in sequence,

Insert new points when cross window boundary, Remove points outside window boundary

OutsideInside

WindowBoundary

P1

P2

P5

P4

P3

Page 61: The 3D Rasterization Pipeline€¦ · Perspective vs. Parallel • Perspective projection + Size varies inversely with distance - looks realistic – Distance and angles are not (in

Clipping to a Boundary• Do inside test for each point in sequence,

Insert new points when cross window boundary, Remove points outside window boundary

OutsideInside

WindowBoundary

P1

P2

P5

P4

P3

P’

Page 62: The 3D Rasterization Pipeline€¦ · Perspective vs. Parallel • Perspective projection + Size varies inversely with distance - looks realistic – Distance and angles are not (in

Clipping to a Boundary• Do inside test for each point in sequence,

Insert new points when cross window boundary, Remove points outside window boundary

OutsideInside

WindowBoundary

P1

P2

P5

P4

P3

P’

Page 63: The 3D Rasterization Pipeline€¦ · Perspective vs. Parallel • Perspective projection + Size varies inversely with distance - looks realistic – Distance and angles are not (in

Clipping to a Boundary• Do inside test for each point in sequence,

Insert new points when cross window boundary, Remove points outside window boundary

OutsideInside

WindowBoundary

P1

P2

P5

P4

P3

P’

Page 64: The 3D Rasterization Pipeline€¦ · Perspective vs. Parallel • Perspective projection + Size varies inversely with distance - looks realistic – Distance and angles are not (in

Clipping to a Boundary• Do inside test for each point in sequence,

Insert new points when cross window boundary, Remove points outside window boundary

OutsideInside

WindowBoundary

P1

P2

P5

P4

P3

P’ P’’

Page 65: The 3D Rasterization Pipeline€¦ · Perspective vs. Parallel • Perspective projection + Size varies inversely with distance - looks realistic – Distance and angles are not (in

Clipping to a Boundary• Do inside test for each point in sequence,

Insert new points when cross window boundary, Remove points outside window boundary

OutsideInside

WindowBoundary

P1

P2

P’ P’’

Page 66: The 3D Rasterization Pipeline€¦ · Perspective vs. Parallel • Perspective projection + Size varies inversely with distance - looks realistic – Distance and angles are not (in

3D Rendering Pipeline (for direct illumination)

ViewingWindow

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 67: The 3D Rasterization Pipeline€¦ · Perspective vs. Parallel • Perspective projection + Size varies inversely with distance - looks realistic – Distance and angles are not (in

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 68: The 3D Rasterization Pipeline€¦ · Perspective vs. Parallel • Perspective projection + Size varies inversely with distance - looks realistic – Distance and angles are not (in

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

AntialiasedScan Conversion

P1

P2

P3

3D Rendering Pipeline (for direct illumination)

Page 69: The 3D Rasterization Pipeline€¦ · Perspective vs. Parallel • Perspective projection + Size varies inversely with distance - looks realistic – Distance and angles are not (in

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 70: The 3D Rasterization Pipeline€¦ · Perspective vs. Parallel • Perspective projection + Size varies inversely with distance - looks realistic – Distance and angles are not (in

Triangle Scan Conversion• Properties of a good algorithm

Symmetric Straight edges No cracks between adjacent primitives (Antialiased edges) FAST!

P1

P2

P3

P4

Page 71: The 3D Rasterization Pipeline€¦ · Perspective vs. Parallel • Perspective projection + Size varies inversely with distance - looks realistic – Distance and angles are not (in

• 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 72: The 3D Rasterization Pipeline€¦ · Perspective vs. Parallel • Perspective projection + Size varies inversely with distance - looks realistic – Distance and angles are not (in

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 73: The 3D Rasterization Pipeline€¦ · Perspective vs. Parallel • Perspective projection + Size varies inversely with distance - looks realistic – Distance and angles are not (in

Triangle Sweep-Line Algorithmvoid 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

dxLdyL

dxRdyR

Page 74: The 3D Rasterization Pipeline€¦ · Perspective vs. Parallel • Perspective projection + Size varies inversely with distance - looks realistic – Distance and angles are not (in

GPU Architecture

GeForce 6 Series Architecture GPU Gems 2, NVIDIA