Docsity

3D Computer Graphics: Triangle Scan Conversion and Shading, Study notes of Computer Systems Networking and Telecommunications

Toggle sidebar
bg1
1
Greg Humphreys
CS445: Intro Graphics
University of Virginia, Fall 2004
Polygon Scan Conversion
& Shading
3D Rendering Pipeline (for direct illumination)
3D Primitives
Modeling
Transformation
Projection
Transformation
Clipping
Lighting
Image
Viewport
Transformation
Scan
Conversion
2D Image Coordinates
3D Modeling Coordinates
3D World Coordinates
3D Camera Coordinates
2D Screen Coordinates
2D Screen Coordinates
Viewing
Transformation
3D World Coordinates
2D Image Coordinates
Scan Conversion
& Shading
P1
P2
P3
Overview
• Scan conversion
Figure out which pixels to fill
• Shading
Determine a color for each filled pixel
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)
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)
Triangle Scan Conversion
• Properties of a good algorithm
Symmetric
Straight edges
Antialiased edges
No cracks between adjacent primitives
MUST BE FAST!
P1
P2
P3
P4
pf3
pf4
pf5
pf8

Partial preview of the text

Download 3D Computer Graphics: Triangle Scan Conversion and Shading and more Study notes Computer Systems Networking and Telecommunications in PDF only on Docsity!

Greg Humphreys

CS445: Intro Graphics

University of Virginia, Fall 2004

Polygon Scan Conversion

& Shading

3D Rendering Pipeline (for direct illumination)

3D Primitives Transformation^ Modeling Transformation^ Projection Clipping Lighting Image Transformation^ Viewport Conversion^ Scan 2D Image Coordinates 3D Modeling Coordinates 3D World Coordinates 3D Camera Coordinates 2D Screen Coordinates 2D Screen Coordinates Transformation^ Viewing 3D World Coordinates 2D Image Coordinates

Scan Conversion

& Shading

P 1

P 2

P 3

Overview

• Scan conversion

 Figure out which pixels to fill

• Shading

 Determine a color for each filled pixel

Scan Conversion

• Render an image of a geometric primitive

by setting pixel colors

• Example: Filling the inside of a triangle

P 1

P 2

P 3

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

Scan Conversion

• Render an image of a geometric primitive

by setting pixel colors

• Example: Filling the inside of a triangle

P 1

P 2

P 3

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

Triangle Scan Conversion

• Properties of a good algorithm

 Symmetric

 Straight edges

 Antialiased edges

 No cracks between adjacent primitives

 MUST BE FAST!

P 1

P 2

P 3

P 4

Triangle Scan Conversion

  • Properties of a good algorithm

 Symmetric

 Straight edges

 Antialiased edges

 No cracks between adjacent primitives

 MUST BE FAST!

P 1 P 2 P 3 P 4 Simple Algorithm P 1 P 2 P 3 void ScanTriangle(Triangle T, Color rgba){ for each pixel P at (x,y){ if (Inside(T, P)) SetPixel(x, y, rgba); } }

  • Color all pixels inside triangle P 1 P 2 Line defines two halfspaces
  • Implicit equation for a line

 On line: ax + by + c = 0

 On right: ax + by + c < 0

 On left: ax + by + c > 0

L Inside Triangle Test

  • A point is inside a triangle if it is in the positive halfspace of all three boundary lines

 Triangle vertices are ordered counter-clockwise

 Point must be on the left side of every boundary line

P L 1 L 2 L 3 Inside Triangle Test Boolean Inside(Triangle T, Point P) { for each boundary line L of T { Scalar d = L.aP.x + L.bP.y + L.c; if (d < 0.0) return FALSE; } return TRUE; }** L 1 L 2 L 3 Simple Algorithm P 1 P 2 P 3 void ScanTriangle(Triangle T, Color rgba){ for each pixel P at (x,y){ if (Inside(T, P)) SetPixel(x, y, rgba); } }

  • What is bad about this algorithm?

Polygon Sweep-Line Algorithm

  • Incremental algorithm to find spans, and determine insideness with odd parity rule

 Takes advantage of scanline coherence

xL xR

Triangle Polygon

Polygon Sweep-Line Algorithm void ScanPolygon(Triangle T, Color rgba){ sort edges by maxy make empty “active edge list” for each scanline (top-to-bottom) { insert/remove edges from “active edge list” update x coordinate of every active edge sort active edges by x coordinate for each pair of active edges (left-to-right) SetPixels(xi, xi+1, y, rgba); } } Hardware Scan Conversion

  • Convert everything into triangles

 Scan convert the triangles

Hardware Antialiasing

  • Supersample pixels

 Multiple samples per pixel

 Average subpixel intensities (box filter)

 Trades intensity resolution for spatial resolution

P 1 P 2 P 3 Overview

  • Scan conversion

 Figure out which pixels to fill

  • Shading

 Determine a color for each filled pixel

Shading

  • How do we choose a color for each filled pixel?

 Each illumination calculation for a ray from the eyepoint

through the view plane provides a radiance sample

» How do we choose where to place samples?

» How do we filter samples to reconstruct image?

Angel Figure 6.

Emphasis on methods that can

be implemented in hardware

Ray Casting

• Simplest shading approach is to perform

independent lighting calculation for every pixel

 When is this unnecessary?

I = IE + KAIAL +! i ( KD ( N • Li ) Ii + KS ( V • R i )^ nIi )

Polygon Shading

• Can take advantage of spatial coherence

 Illumination calculations for pixels covered by same

primitive are related to each other

I = IE + KAIAL +! i ( KD ( N • Li ) Ii + KS ( V • R i )^ nIi )

Polygon Shading Algorithms

• Flat Shading

• Gouraud Shading

• Phong Shading

Polygon Shading Algorithms

• Flat Shading

• Gouraud Shading

• Phong Shading

Flat Shading

• What if a faceted object is illuminated only by

directional light sources and is either diffuse or

viewed from infinitely far away

I = IE + KAIAL +! i ( KD ( N • Li ) Ii + KS ( V • R i )^ nIi )

Flat Shading

• One illumination calculation per polygon

 Assign all pixels inside each polygon the same color

N

Gouraud Shading

• Produces smoothly shaded polygonal mesh

 Piecewise linear approximation

 Need fine mesh to capture subtle lighting effects

Flat Shading Gouraud Shading

Polygon Shading Algorithms

• Flat Shading

• Gouraud Shading

• Phong Shading

Phong Shading

• What if polygonal mesh is too coarse to capture

illumination effects in polygon interiors?

I = IE + KAIAL +! i ( KD ( N • Li ) Ii + KS ( V • R i )^ nIi )

Phong Shading

• Method 2: One lighting calculation per pixel

 Approximate surface normals for points inside polygons by

bilinear interpolation of normals from vertices

Phong Shading

• Bilinearly interpolate surface normals at vertices

down and across scan lines

Polygon Shading Algorithms

Gouraud Phong

Wireframe Flat

Watt Plate 7

Shading Issues

  • Problems with interpolated shading:

 Polygonal silhouettes

 Perspective distortion

 Orientation dependence (due to bilinear interpolation)

 Problems computing shared vertex normals

 Problems at T-vertices

Summary

  • 2D polygon scan conversion

 Paint pixels inside primitive

 Sweep-line algorithm for polygons

  • Polygon Shading Algorithms

 Flat

 Gouraud

 Phong

 Ray casting

  • Key ideas:

 Sampling and reconstruction

 Spatial coherence

Less expensive

More accurate