Top Banner
Computer Graphics (fall 2009) School of Computer Science University of Seoul
65

School of Computer Science University of Seoul. Graphics pipeline Algorithms for the tasks in the pipeline.

Dec 17, 2015

Download

Documents

Hannah Davis
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: School of Computer Science University of Seoul. Graphics pipeline Algorithms for the tasks in the pipeline.

Computer Graphics(fall 2009)

School of Computer ScienceUniversity of Seoul

Page 2: School of Computer Science University of Seoul. Graphics pipeline Algorithms for the tasks in the pipeline.

Topics

Graphics pipeline Algorithms for the tasks in the pipeline

Page 3: School of Computer Science University of Seoul. Graphics pipeline Algorithms for the tasks in the pipeline.

Chap 7: From Vertices to Fragments

1. Basic Implementation Strategies2. Four Major Tasks3. Clipping4. Line-Segment Clipping5. Polygon Clipping6. Clipping of Other Primitives7. Clipping in Three Dimensions8. Rasterization9. Bresenham’s Algorithm10. Polygon Rasterization11. Hidden-Surface Removal12. Antialiasing13. Display Considerations

Page 4: School of Computer Science University of Seoul. Graphics pipeline Algorithms for the tasks in the pipeline.

7.1 Basic Implementation Strategies

Page 5: School of Computer Science University of Seoul. Graphics pipeline Algorithms for the tasks in the pipeline.

Big Picture

Input Geometric objects Attributes: color, material, normal, etc. Lights Camera specifications Etc.

Output Arrays of colored pixels in the framebuffer

Page 6: School of Computer Science University of Seoul. Graphics pipeline Algorithms for the tasks in the pipeline.

Big Picture (cont’d)

Tasks by graphics system Transformations Clipping Shading Hidden-surface removal Rasterization

Page 7: School of Computer Science University of Seoul. Graphics pipeline Algorithms for the tasks in the pipeline.

Object-Oriented Approach

for(each_object) render(object);

Pipeline renderer Same operation on every primitive (inde-

pendently, in arbitrary order) SIMD (Single Instruction, Multiple Data)

Cannot handle global calculations (excep-tion: hidden-surface removal)

Page 8: School of Computer Science University of Seoul. Graphics pipeline Algorithms for the tasks in the pipeline.

Image-Oriented Approach

for(each_pixel) assign_a_color(pixel);

To determine which geometric primitives can contribute to its color

Coherency incremental implementation Complex data structure Can handle global effects Example: raytracing

Page 9: School of Computer Science University of Seoul. Graphics pipeline Algorithms for the tasks in the pipeline.

7.2 Four Major Tasks

Page 10: School of Computer Science University of Seoul. Graphics pipeline Algorithms for the tasks in the pipeline.

Four Major Tasks

1. Modeling2. Geometry processing3. Rasterization4. Fragment processing

Page 11: School of Computer Science University of Seoul. Graphics pipeline Algorithms for the tasks in the pipeline.

1. Modeling

Output: set of vertices

Page 12: School of Computer Science University of Seoul. Graphics pipeline Algorithms for the tasks in the pipeline.

2. Geometry Processing

1. Model-view transformation To camera (eye) coordinate

2. Projection transformation To a normalized view volume Vertices represented in clip coordinate

3. Primitive assembly4. Clipping5. Shading

Modified Phong model

6. Perspective division

Page 13: School of Computer Science University of Seoul. Graphics pipeline Algorithms for the tasks in the pipeline.

3. Rasterization

A.k.a. scan conversion “How to approximate a line segment with

pixels?” “Which pixels lie inside a 2D polygon?” Viewport transformation Fragments in window coordinates

Vs. screen coordinates?

Page 14: School of Computer Science University of Seoul. Graphics pipeline Algorithms for the tasks in the pipeline.

4. Rasterization

Color assigned by linear interpolation Hidden-surface removal on a fragment-by-

fragment basis Blending Antialiasing

Page 15: School of Computer Science University of Seoul. Graphics pipeline Algorithms for the tasks in the pipeline.

7.3 Clipping

Page 16: School of Computer Science University of Seoul. Graphics pipeline Algorithms for the tasks in the pipeline.

Clipping

Before perspective division Normalized device coordinates

Page 17: School of Computer Science University of Seoul. Graphics pipeline Algorithms for the tasks in the pipeline.

7.4 Line-Segment Clipping

Page 18: School of Computer Science University of Seoul. Graphics pipeline Algorithms for the tasks in the pipeline.

Clipper

Clipper accepts, rejects (or culls), or clips primitives against the view volume

Before rasterization Four cases in 2D Two algorithms

Cohen-Sutherland clipping Liang-Barsky clipping

Page 19: School of Computer Science University of Seoul. Graphics pipeline Algorithms for the tasks in the pipeline.

Cohen-Sutherland Clipping

Intersection calculation replaced by membership test Intersection calculation: FP mul & div Membership test: FP sub & bit operations

Intersection calculation only when needed The whole 2D space decomposed into 9 regions

Membership test against each plane outcodes computed “0000” for inside of the volume

otherwise0

if1 max0

yyb

Page 20: School of Computer Science University of Seoul. Graphics pipeline Algorithms for the tasks in the pipeline.

Cohen-Sutherland Clipping (cont’d)

Four cases associated with the outcodes of endpoints o1==o2==0: both inside (AB) o1<>0, o2==0 (or vide versa): one inside and the

other outsideintersection calculation required (CD)

o1&o2<>0: outside of the common plane(edge)can be discarded (EF)

o1&o2==0: outside of the different planemore computation required (GH & IJ)

Page 21: School of Computer Science University of Seoul. Graphics pipeline Algorithms for the tasks in the pipeline.

Cohen-Sutherland Clipping (cont’d)

Works best when many line segments are discarded

Can be extended to three dimension Must be recursive

Page 22: School of Computer Science University of Seoul. Graphics pipeline Algorithms for the tasks in the pipeline.

Liang-Barsky Clipping

Parametric form of line segment

Four parameter values computed associated with the intersections with four planes

Example 1:bottom, 2: left, 3: top, 4: right (a) 0<1< 2< 3< 4<1 (b) 0<1< 3< 2< 4<1

10,1 21 ppp

Page 23: School of Computer Science University of Seoul. Graphics pipeline Algorithms for the tasks in the pipeline.

Liang-Barsky Clipping (cont’d)

Intersection calculation (against top plane)

Simpler form used for clipping decision

FP div only when required Multiple shortening not required Not extend to three dimension

12

1max

yy

yy

max1max12 yyyyyy

Page 24: School of Computer Science University of Seoul. Graphics pipeline Algorithms for the tasks in the pipeline.

More on Line Clipping

Line clipping by Wikipedia

Page 25: School of Computer Science University of Seoul. Graphics pipeline Algorithms for the tasks in the pipeline.

7.5 Polygon Clipping

Page 26: School of Computer Science University of Seoul. Graphics pipeline Algorithms for the tasks in the pipeline.

Applications

Non-rectangular window Shadow generation Hidden-surface removal Antialiasing

Page 27: School of Computer Science University of Seoul. Graphics pipeline Algorithms for the tasks in the pipeline.

Concave & Convex Polygons

Clipping concave polygon is complex

Clipping convex polygon is easysingle clipped polygon

Concave polygon is tessellated into convex polygons

Page 28: School of Computer Science University of Seoul. Graphics pipeline Algorithms for the tasks in the pipeline.

Algorithm

Sutherland-Hodgeman Any line segment clipper can be applied blackboxed

Convex polygon (including rectangle) as the intersection of half-spaces

Intersection test against each plane

max3

12

121max13

yy

yy

xxyyxx

Page 29: School of Computer Science University of Seoul. Graphics pipeline Algorithms for the tasks in the pipeline.

Algorithm (cont’d)

Pipelined

Page 30: School of Computer Science University of Seoul. Graphics pipeline Algorithms for the tasks in the pipeline.

7.6 Clipping of Other Primi-tives

Page 31: School of Computer Science University of Seoul. Graphics pipeline Algorithms for the tasks in the pipeline.

Bounding Volume

Early clipping can improve performancebounding boxes & volumes AABB (Axis-Aligned Bounding Box) Bounding sphere OBB (Oriented Bounding Box) DOP (Discrete Oriented Polytop) Convex hull …and many more

Page 32: School of Computer Science University of Seoul. Graphics pipeline Algorithms for the tasks in the pipeline.

Bounding Volume (cont’d)

(image courtesy of http://www.ray-tracing.ru)

Page 33: School of Computer Science University of Seoul. Graphics pipeline Algorithms for the tasks in the pipeline.

Curves, Surfaces and Texts

Approximated with line segments (or trian-gles/quads)

“Convex hull property” for parametric curves & surfaces

Texts Texts as bit patterns clipping in framebuffer Texts as geometric objects polygon clipping OpenGL allows both

Scissoring: clipping in the framebuffer

Page 34: School of Computer Science University of Seoul. Graphics pipeline Algorithms for the tasks in the pipeline.

7.7 Clipping in Three Dimen-sions

Page 35: School of Computer Science University of Seoul. Graphics pipeline Algorithms for the tasks in the pipeline.

3D Clipping

Clipping against 3D view volume

Extension of Cohen-Sutherland

Page 36: School of Computer Science University of Seoul. Graphics pipeline Algorithms for the tasks in the pipeline.

3D Clipping (cont’d)

Extension of Liang-Barsky

Intersection calculation is simple due to normal-ization

Additional clipping planes with arbitrary orien-tations supported

0

1

0

21

ppn

ppp

12

10

ppn

ppn

Page 37: School of Computer Science University of Seoul. Graphics pipeline Algorithms for the tasks in the pipeline.

7.8 Rasterization

Page 38: School of Computer Science University of Seoul. Graphics pipeline Algorithms for the tasks in the pipeline.

Pixels

Square-shaped Integer coordinates In OpenGL center is located at the halfway

between integers

Page 39: School of Computer Science University of Seoul. Graphics pipeline Algorithms for the tasks in the pipeline.

DDA Algorithm

Rasterization of line segment

Only for small slopes

FP addition for each pixel

xmyx

y

xx

yym

12

12

Page 40: School of Computer Science University of Seoul. Graphics pipeline Algorithms for the tasks in the pipeline.

7.9 Bresenham’s Algorithm

Page 41: School of Computer Science University of Seoul. Graphics pipeline Algorithms for the tasks in the pipeline.

Bresenham’s Algorithm

No FP calculation! Standard algorithm For integer endpoints (x1,y1)-(x2,y2)

Page 42: School of Computer Science University of Seoul. Graphics pipeline Algorithms for the tasks in the pipeline.

Bresenham’s Algorithm (cont’d)

How it works: With slope 0<=m<=1 Assume we just colored the pixel (i+1/2,j+1/2) We need to color either (i+3/2,j+1/2) or

(i+3/2,j+3/2) depending on d=a-b (x2-x1)(a-b) is integer simpler calculation d can be computed incrementally

(next page)

Page 43: School of Computer Science University of Seoul. Graphics pipeline Algorithms for the tasks in the pipeline.

Bresenham’s Algorithm (cont’d)

d can be computed incrementally If a_k > b_k (left)

a_{k+1}+m=a_k a_{k+1}=a_k-m b_k = b_{k+1}-m b_{k+1}=b_k+m

If a_k<b_k (right) 1+a_k=a_{k+1}+m a_{k+1}=a_k-(m-1) 1-b_k=m-b_{k+1} b_{k+1}=b_k+(m-1)

.2

;0 if21 otherwisexy

dydd kkk

Page 44: School of Computer Science University of Seoul. Graphics pipeline Algorithms for the tasks in the pipeline.

7.10 Polygon Rasterization

Page 45: School of Computer Science University of Seoul. Graphics pipeline Algorithms for the tasks in the pipeline.

Polygon Rasterization

Inside-outside testing Crossing (or odd-even test) Winding test – how to compute?

Page 46: School of Computer Science University of Seoul. Graphics pipeline Algorithms for the tasks in the pipeline.

Tessellation

Supported by GLU functions Triangles generated based on given contour Different tessellation depending on the winding

number (gluTessProperty)

Page 47: School of Computer Science University of Seoul. Graphics pipeline Algorithms for the tasks in the pipeline.

Polygon Fill

“How to fill the interior of a polygon?” Three algorithms

Flood fill – starts with “seed point” Scanline fill Odd-Even fill

Singularity1. Handle separately2. Perturb the position3. Different values for pixels and vertices

Page 48: School of Computer Science University of Seoul. Graphics pipeline Algorithms for the tasks in the pipeline.

7.11 Hidden-Surface Removal

Page 49: School of Computer Science University of Seoul. Graphics pipeline Algorithms for the tasks in the pipeline.

Hidden-Surface Removal

Object-space approach For each object, determine & render the visible

parts Pairwise comparison O(k^2)

Image-space approach For each pixel, determine the closest polygon O(k)

Page 50: School of Computer Science University of Seoul. Graphics pipeline Algorithms for the tasks in the pipeline.

Scanline Algorithm

“Spans” processed independently for light-ing and depth calculations

Overhead to generate spans y-x algorithm

Page 51: School of Computer Science University of Seoul. Graphics pipeline Algorithms for the tasks in the pipeline.

Back-Face Removal

A.k.a. Culling Fast calculation in normalized view volume OpenGL back-face culling

glCullFace(face) & glEnable(GL_CULL_FACE) Culling by signed area in window coordinates

(WHY?)

Page 52: School of Computer Science University of Seoul. Graphics pipeline Algorithms for the tasks in the pipeline.

The z-Buffer Algorithm

Most widely used (including OpenGL) Works in image space Depth information for each fragment

stored in the “depth buffer” (or “z-buffer”) Inaccurate depth for perspective after nor-

malization, but ordering preserved Depth can be computed incrementally

xc

az

Page 53: School of Computer Science University of Seoul. Graphics pipeline Algorithms for the tasks in the pipeline.

The z-Buffer Algorithm (cont’d)

Scan conversion with the z-buffer:three tasks simutaneously Orthographic projection Hidden-surface removal Shading

Page 54: School of Computer Science University of Seoul. Graphics pipeline Algorithms for the tasks in the pipeline.

Depth Sort & Painter’s Algorithm

? ?

Page 55: School of Computer Science University of Seoul. Graphics pipeline Algorithms for the tasks in the pipeline.

7.12 Antialiasing

Page 56: School of Computer Science University of Seoul. Graphics pipeline Algorithms for the tasks in the pipeline.

Antialiasing

Shades each pixel by the percentage of the ideal line that crosses it antialiasing by area averaging

Polygons sharing a pixel can be handled using accumulation buffer

Page 57: School of Computer Science University of Seoul. Graphics pipeline Algorithms for the tasks in the pipeline.

Antialiasing

Time-domain (temporal) aliasing Small moving objects can be missed More and one ray per pixel

Page 58: School of Computer Science University of Seoul. Graphics pipeline Algorithms for the tasks in the pipeline.

7.13 Display Considerations

Page 59: School of Computer Science University of Seoul. Graphics pipeline Algorithms for the tasks in the pipeline.

Problems with Display

Range of colors (gamut) they display differ How they map SW-defined colors to the val-

ues of the primaries for the display differ The mapping between brightness values de-

fined by the program and what is displayed is nonlinear

Page 60: School of Computer Science University of Seoul. Graphics pipeline Algorithms for the tasks in the pipeline.

Color Systems

Basic assumption: three color values that we determine for each pixel correspond to the tristimulus values RGB system

Problem with RGB system Range of displayable colors (color gamut) is dif-

ferent for each medium (film or CRT) device independent graphics

Color-conversion matrixSupported by OpenGL

Page 61: School of Computer Science University of Seoul. Graphics pipeline Algorithms for the tasks in the pipeline.

Color Systems (cont’d)

Problems with color-conversion approach Color gamut of different systems may not be the

same Conversion between RGB and CMYK is hard Distance between colors in the color cube is not

a measure of how far apart the colors are per-ceptually

Page 62: School of Computer Science University of Seoul. Graphics pipeline Algorithms for the tasks in the pipeline.

Chromaticity Coordinates

Fraction of each color in the three primaries t1+t2+t3=1 the last value is implicit can

be plotted in 2D T1+T2+T3 is the intensity

Page 63: School of Computer Science University of Seoul. Graphics pipeline Algorithms for the tasks in the pipeline.

HLS System

Hue-Saturation-Lightness Hue: color vector direction Saturation: how far the given color is from the

diagonal Lightness: how far the given color is from the

origin RGB color in polar coordinates

Page 64: School of Computer Science University of Seoul. Graphics pipeline Algorithms for the tasks in the pipeline.

Gamma Correction

Human visual system perceives intensity in a logarithmic manner

For uniformly spaced brightness, the inten-sities needs to be assigned exponentially

Page 65: School of Computer Science University of Seoul. Graphics pipeline Algorithms for the tasks in the pipeline.

Dithering and Halftoning

Trade-off between spatial resolution with grayscale (or color) precision

Dithering may introduce Moire