cisc 3620 lecture 12: rendering pipeline revisitedm.mr-pc.org/t/cisc3620/2019sp/lecture12.pdf ·...

123
CISC 3620 Lecture 12: Rendering pipeline revisited Topics : Rendering overview Clipping Polygon rendering Rasterization Display issues

Upload: others

Post on 25-Mar-2021

1 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: CISC 3620 Lecture 12: Rendering pipeline revisitedm.mr-pc.org/t/cisc3620/2019sp/lecture12.pdf · 2019. 5. 1. · 4 Overview At end of the geometric pipeline, vertices have been assembled

CISC 3620 Lecture 12:Rendering pipeline revisited

Topics:

Rendering overviewClipping

Polygon renderingRasterization

Display issues

Page 2: CISC 3620 Lecture 12: Rendering pipeline revisitedm.mr-pc.org/t/cisc3620/2019sp/lecture12.pdf · 2019. 5. 1. · 4 Overview At end of the geometric pipeline, vertices have been assembled

Rendering overview

Page 3: CISC 3620 Lecture 12: Rendering pipeline revisitedm.mr-pc.org/t/cisc3620/2019sp/lecture12.pdf · 2019. 5. 1. · 4 Overview At end of the geometric pipeline, vertices have been assembled

3

Objectives

● Examine what happens between the vertex shader and the fragment shader

● Introduce basic implementation strategies● Clipping ● Rendering

– lines– polygons

● Give a sample algorithm for each

Angel and Shreiner: Interactive Computer Graphics 7E © Addison-Wesley 2015

Page 4: CISC 3620 Lecture 12: Rendering pipeline revisitedm.mr-pc.org/t/cisc3620/2019sp/lecture12.pdf · 2019. 5. 1. · 4 Overview At end of the geometric pipeline, vertices have been assembled

4

Overview

● At end of the geometric pipeline, vertices have been assembled into primitives

● Must clip out primitives that are outside the view frustum– Algorithms based on representing primitives by lists of vertices

● Must find which pixels can be affected by each primitive– Fragment generation– Rasterization or scan conversion

Angel and Shreiner: Interactive Computer Graphics 7E © Addison-Wesley 2015

Page 5: CISC 3620 Lecture 12: Rendering pipeline revisitedm.mr-pc.org/t/cisc3620/2019sp/lecture12.pdf · 2019. 5. 1. · 4 Overview At end of the geometric pipeline, vertices have been assembled

5

Required Tasks

● Clipping● Rasterization or scan conversion● Transformations● Some tasks deferred until fragment processing

– Hidden surface removal – Antialiasing

Angel and Shreiner: Interactive Computer Graphics 7E © Addison-Wesley 2015

Page 6: CISC 3620 Lecture 12: Rendering pipeline revisitedm.mr-pc.org/t/cisc3620/2019sp/lecture12.pdf · 2019. 5. 1. · 4 Overview At end of the geometric pipeline, vertices have been assembled

6

Rasterization Meta Algorithms

● Any rendering method must process every object and assign a color to every pixel

● Think of rendering algorithms as two loops– over objects– over pixels

● The order of these loops defines two strategies– Image-space approach– Object-space approach

Angel and Shreiner: Interactive Computer Graphics 7E © Addison-Wesley 2015

Page 7: CISC 3620 Lecture 12: Rendering pipeline revisitedm.mr-pc.org/t/cisc3620/2019sp/lecture12.pdf · 2019. 5. 1. · 4 Overview At end of the geometric pipeline, vertices have been assembled

7

Object-Space Approach

● For every object, determine which pixels it covers and shade these pixels– Pipeline approach– Must keep track of depths for hidden surface removal– Cannot handle most global lighting calculations– Need entire framebuffer available at all times

Angel and Shreiner: Interactive Computer Graphics 7E © Addison-Wesley 2015

Page 8: CISC 3620 Lecture 12: Rendering pipeline revisitedm.mr-pc.org/t/cisc3620/2019sp/lecture12.pdf · 2019. 5. 1. · 4 Overview At end of the geometric pipeline, vertices have been assembled

8

Image-Space Approach

● For every pixel, determine which object that projects on the pixel is closest to the viewer and compute the shade of this pixel– Ray tracing paradigm– Need all objects available

Angel and Shreiner: Interactive Computer Graphics 7E © Addison-Wesley 2015

Page 9: CISC 3620 Lecture 12: Rendering pipeline revisitedm.mr-pc.org/t/cisc3620/2019sp/lecture12.pdf · 2019. 5. 1. · 4 Overview At end of the geometric pipeline, vertices have been assembled

9

Image-Space Approach:Patch renderers

● Divide framebuffer into small patches● Determine which objects affect each patch● Image-space render each patch separately using

relevant objects● Used in limited power devices such as cell phones

Angel and Shreiner: Interactive Computer Graphics 7E © Addison-Wesley 2015

Page 10: CISC 3620 Lecture 12: Rendering pipeline revisitedm.mr-pc.org/t/cisc3620/2019sp/lecture12.pdf · 2019. 5. 1. · 4 Overview At end of the geometric pipeline, vertices have been assembled

Clipping

Page 11: CISC 3620 Lecture 12: Rendering pipeline revisitedm.mr-pc.org/t/cisc3620/2019sp/lecture12.pdf · 2019. 5. 1. · 4 Overview At end of the geometric pipeline, vertices have been assembled

11

Objectives

● Clipping lines● First implementation of algorithms● Clipping polygons

Angel and Shreiner: Interactive Computer Graphics 7E © Addison-Wesley 2015

Page 12: CISC 3620 Lecture 12: Rendering pipeline revisitedm.mr-pc.org/t/cisc3620/2019sp/lecture12.pdf · 2019. 5. 1. · 4 Overview At end of the geometric pipeline, vertices have been assembled

12

Clipping

● 2D against clipping window● 3D against clipping volume● Easy for line segments, polygons● Hard for curves and text

– Convert to lines and polygons first

Angel and Shreiner: Interactive Computer Graphics 7E © Addison-Wesley 2015

Page 13: CISC 3620 Lecture 12: Rendering pipeline revisitedm.mr-pc.org/t/cisc3620/2019sp/lecture12.pdf · 2019. 5. 1. · 4 Overview At end of the geometric pipeline, vertices have been assembled

13

Clipping 2D Line Segments

● Brute force approach: compute intersections with all sides of clipping window– Inefficient: one division per intersection

● Idea: eliminate as many cases as possible without computing intersections

Angel and Shreiner: Interactive Computer Graphics 7E © Addison-Wesley 2015

Page 14: CISC 3620 Lecture 12: Rendering pipeline revisitedm.mr-pc.org/t/cisc3620/2019sp/lecture12.pdf · 2019. 5. 1. · 4 Overview At end of the geometric pipeline, vertices have been assembled

14

Cohen-Sutherland Algorithm

● Start with four lines that determine the sides of the clipping window

x = xmaxx = xmin

y = ymax

y = ymin

Angel and Shreiner: Interactive Computer Graphics 7E © Addison-Wesley 2015

Page 15: CISC 3620 Lecture 12: Rendering pipeline revisitedm.mr-pc.org/t/cisc3620/2019sp/lecture12.pdf · 2019. 5. 1. · 4 Overview At end of the geometric pipeline, vertices have been assembled

15

Cohen-Sutherland Algorithm

● Start with four lines that determine the sides of the clipping window

● What are the possible line-rectangle interactions?

x = xmaxx = xmin

y = ymax

y = ymin

Angel and Shreiner: Interactive Computer Graphics 7E © Addison-Wesley 2015

Page 16: CISC 3620 Lecture 12: Rendering pipeline revisitedm.mr-pc.org/t/cisc3620/2019sp/lecture12.pdf · 2019. 5. 1. · 4 Overview At end of the geometric pipeline, vertices have been assembled

16

The Cases

● Case 1: both endpoints of line segment inside all four lines– Draw (accept) line segment as is

● Case 2: both endpoints outside all lines and on same side of a line– Discard (reject) the line segment

x = xmaxx = xmin

y = ymax

y = ymin

Angel and Shreiner: Interactive Computer Graphics 7E © Addison-Wesley 2015

Case 1Case 2

Page 17: CISC 3620 Lecture 12: Rendering pipeline revisitedm.mr-pc.org/t/cisc3620/2019sp/lecture12.pdf · 2019. 5. 1. · 4 Overview At end of the geometric pipeline, vertices have been assembled

17

The Cases

● Case 3: One endpoint inside, one outside– Must do at least one intersection

● Case 4: Both outside– May have part inside (4a)– Must do at least one intersection

x = xmaxx = xmin

y = ymax

Angel and Shreiner: Interactive Computer Graphics 7E © Addison-Wesley 2015

Case 4a

Case 4b

Page 18: CISC 3620 Lecture 12: Rendering pipeline revisitedm.mr-pc.org/t/cisc3620/2019sp/lecture12.pdf · 2019. 5. 1. · 4 Overview At end of the geometric pipeline, vertices have been assembled

18

Classify endpoints with Outcodes

● For each endpoint, define an outcode: b0b1b2b3

– b0 = 1 if y > ymax, 0 otherwise

– b1 = 1 if y < ymin, 0 otherwise

– b2 = 1 if x > xmax, 0 otherwise

– b3 = 1 if x < xmin, 0 otherwise

Angel and Shreiner: Interactive Computer Graphics 7E © Addison-Wesley 2015

Page 19: CISC 3620 Lecture 12: Rendering pipeline revisitedm.mr-pc.org/t/cisc3620/2019sp/lecture12.pdf · 2019. 5. 1. · 4 Overview At end of the geometric pipeline, vertices have been assembled

19

Classify endpoints with Outcodes

● For each endpoint, define an outcode: b0b1b2b3

– b0 = 1 if y > ymax, 0 otherwise

– b1 = 1 if y < ymin, 0 otherwise

– b2 = 1 if x > xmax, 0 otherwise

– b3 = 1 if x < xmin, 0 otherwise

● Outcodes divide space into ____ regions● Computation of outcode requires at most _____

subtractions

Angel and Shreiner: Interactive Computer Graphics 7E © Addison-Wesley 2015

Page 20: CISC 3620 Lecture 12: Rendering pipeline revisitedm.mr-pc.org/t/cisc3620/2019sp/lecture12.pdf · 2019. 5. 1. · 4 Overview At end of the geometric pipeline, vertices have been assembled

20

Classify endpoints with Outcodes

● For each endpoint, define an outcode: b0b1b2b3

– b0 = 1 if y > ymax, 0 otherwise

– b1 = 1 if y < ymin, 0 otherwise

– b2 = 1 if x > xmax, 0 otherwise

– b3 = 1 if x < xmin, 0 otherwise

● Outcodes divide space into 9 regions● Computation of outcode requires at most 4

subtractions

Angel and Shreiner: Interactive Computer Graphics 7E © Addison-Wesley 2015

Page 21: CISC 3620 Lecture 12: Rendering pipeline revisitedm.mr-pc.org/t/cisc3620/2019sp/lecture12.pdf · 2019. 5. 1. · 4 Overview At end of the geometric pipeline, vertices have been assembled

21

Classify endpoints with Outcodes

● For each endpoint, define an outcode: b0b1b2b3

– b0 = 1 if y > ymax, 0 otherwise

– b1 = 1 if y < ymin, 0 otherwise

– b2 = 1 if x > xmax, 0 otherwise

– b3 = 1 if x < xmin, 0 otherwise

● Outcodes divide space into 9 regions● Computation of outcode requires at most 4

subtractions

Angel and Shreiner: Interactive Computer Graphics 7E © Addison-Wesley 2015

Page 22: CISC 3620 Lecture 12: Rendering pipeline revisitedm.mr-pc.org/t/cisc3620/2019sp/lecture12.pdf · 2019. 5. 1. · 4 Overview At end of the geometric pipeline, vertices have been assembled

22

Classify endpoints with Outcodes

● For each endpoint, define an outcode: b0b1b2b3

– b0 = 1 if y > ymax, 0 otherwise

– b1 = 1 if y < ymin, 0 otherwise

– b2 = 1 if x > xmax, 0 otherwise

– b3 = 1 if x < xmin, 0 otherwise

● Outcodes divide space into 9 regions● Computation of outcode requires at most 4

subtractions

Angel and Shreiner: Interactive Computer Graphics 7E © Addison-Wesley 2015

Page 23: CISC 3620 Lecture 12: Rendering pipeline revisitedm.mr-pc.org/t/cisc3620/2019sp/lecture12.pdf · 2019. 5. 1. · 4 Overview At end of the geometric pipeline, vertices have been assembled

23

Using Outcodes

● What are the outcodes for each of these vertices?

Angel and Shreiner: Interactive Computer Graphics 7E © Addison-Wesley 2015

Page 24: CISC 3620 Lecture 12: Rendering pipeline revisitedm.mr-pc.org/t/cisc3620/2019sp/lecture12.pdf · 2019. 5. 1. · 4 Overview At end of the geometric pipeline, vertices have been assembled

24

Using Outcodes

● What are the outcodes for each of these vertices?

Angel and Shreiner: Interactive Computer Graphics 7E © Addison-Wesley 2015

1000

0001

1000

1000

00010000

0000 0010

0000

00100010

0010

Page 25: CISC 3620 Lecture 12: Rendering pipeline revisitedm.mr-pc.org/t/cisc3620/2019sp/lecture12.pdf · 2019. 5. 1. · 4 Overview At end of the geometric pipeline, vertices have been assembled

25

Using Outcodes

● AB: outcode(A) = outcode(B) = 0–

Angel and Shreiner: Interactive Computer Graphics 7E © Addison-Wesley 2015

Page 26: CISC 3620 Lecture 12: Rendering pipeline revisitedm.mr-pc.org/t/cisc3620/2019sp/lecture12.pdf · 2019. 5. 1. · 4 Overview At end of the geometric pipeline, vertices have been assembled

26

Using Outcodes

● AB: outcode(A) = outcode(B) = 0– Accept line segment

Angel and Shreiner: Interactive Computer Graphics 7E © Addison-Wesley 2015

Page 27: CISC 3620 Lecture 12: Rendering pipeline revisitedm.mr-pc.org/t/cisc3620/2019sp/lecture12.pdf · 2019. 5. 1. · 4 Overview At end of the geometric pipeline, vertices have been assembled

27

Using Outcodes

● CD: outcode (C) = 0, outcode(D) 0 0–

Angel and Shreiner: Interactive Computer Graphics 7E © Addison-Wesley 2015

Page 28: CISC 3620 Lecture 12: Rendering pipeline revisitedm.mr-pc.org/t/cisc3620/2019sp/lecture12.pdf · 2019. 5. 1. · 4 Overview At end of the geometric pipeline, vertices have been assembled

28

Using Outcodes

● CD: outcode (C) = 0, outcode(D) 0 0– Compute intersection with edge– Position of 1 in outcode(D) determines which edge to intersect with– Note: if there were a segment from C to a point in a region with 2

ones in outcode, we might have to do two intersection calculations

Angel and Shreiner: Interactive Computer Graphics 7E © Addison-Wesley 2015

Page 29: CISC 3620 Lecture 12: Rendering pipeline revisitedm.mr-pc.org/t/cisc3620/2019sp/lecture12.pdf · 2019. 5. 1. · 4 Overview At end of the geometric pipeline, vertices have been assembled

29

Using Outcodes

● EF: outcode(E) logically ANDed with outcode(F) (bitwise) 0 0–

Angel and Shreiner: Interactive Computer Graphics 7E © Addison-Wesley 2015

Page 30: CISC 3620 Lecture 12: Rendering pipeline revisitedm.mr-pc.org/t/cisc3620/2019sp/lecture12.pdf · 2019. 5. 1. · 4 Overview At end of the geometric pipeline, vertices have been assembled

30

Using Outcodes

● EF: outcode(E) logically ANDed with outcode(F) (bitwise) 0 0– Both outcodes have a 1 bit in the same place– Line segment is outside of corresponding side of clipping window– Reject

Angel and Shreiner: Interactive Computer Graphics 7E © Addison-Wesley 2015

Page 31: CISC 3620 Lecture 12: Rendering pipeline revisitedm.mr-pc.org/t/cisc3620/2019sp/lecture12.pdf · 2019. 5. 1. · 4 Overview At end of the geometric pipeline, vertices have been assembled

31

Using Outcodes

● GH and IJ: same outcodes, neither zero but logical AND yields zero–

Angel and Shreiner: Interactive Computer Graphics 7E © Addison-Wesley 2015

Page 32: CISC 3620 Lecture 12: Rendering pipeline revisitedm.mr-pc.org/t/cisc3620/2019sp/lecture12.pdf · 2019. 5. 1. · 4 Overview At end of the geometric pipeline, vertices have been assembled

32

Using Outcodes

● GH and IJ: same outcodes, neither zero but logical AND yields zero– Shorten line segment by intersecting with one of sides of window– Compute outcode of intersection (new endpoint of shortened line segment)– Reexecute algorithm

Angel and Shreiner: Interactive Computer Graphics 7E © Addison-Wesley 2015

Page 33: CISC 3620 Lecture 12: Rendering pipeline revisitedm.mr-pc.org/t/cisc3620/2019sp/lecture12.pdf · 2019. 5. 1. · 4 Overview At end of the geometric pipeline, vertices have been assembled

33

Efficiency

● In many applications, the clipping window is small relative to the size of the entire object database– Most line segments are outside one or more side of the

window and can be eliminated based on their outcodes

● Inefficiency when code has to be reexecuted for line segments that must be shortened in more than one step

Angel and Shreiner: Interactive Computer Graphics 7E © Addison-Wesley 2015

Page 34: CISC 3620 Lecture 12: Rendering pipeline revisitedm.mr-pc.org/t/cisc3620/2019sp/lecture12.pdf · 2019. 5. 1. · 4 Overview At end of the geometric pipeline, vertices have been assembled

34

Cohen Sutherland in 3D

● Use 6-bit outcodes ● When needed, clip line segment against planes

Angel and Shreiner: Interactive Computer Graphics 7E © Addison-Wesley 2015

Page 35: CISC 3620 Lecture 12: Rendering pipeline revisitedm.mr-pc.org/t/cisc3620/2019sp/lecture12.pdf · 2019. 5. 1. · 4 Overview At end of the geometric pipeline, vertices have been assembled

35

Clipping and Normalization

● General clipping in 3D requires intersection of line segments against arbitrary plane

● Example: oblique view

Angel and Shreiner: Interactive Computer Graphics 7E © Addison-Wesley 2015

Page 36: CISC 3620 Lecture 12: Rendering pipeline revisitedm.mr-pc.org/t/cisc3620/2019sp/lecture12.pdf · 2019. 5. 1. · 4 Overview At end of the geometric pipeline, vertices have been assembled

36

Plane-Line Intersections

a=n⋅( po−p1 )

n⋅( p2−p1)

Angel and Shreiner: Interactive Computer Graphics 7E © Addison-Wesley 2015

Page 37: CISC 3620 Lecture 12: Rendering pipeline revisitedm.mr-pc.org/t/cisc3620/2019sp/lecture12.pdf · 2019. 5. 1. · 4 Overview At end of the geometric pipeline, vertices have been assembled

37

Normalized Form

before normalization after normalization

top view

Angel and Shreiner: Interactive Computer Graphics 7E © Addison-Wesley 2015

● Normalization is part of viewing (pre clipping)– but after normalization, we clip against sides of right parallelepiped

● Typical intersection calculation now requires only a floating point subtraction– e.g. is x > xmax ?

Page 38: CISC 3620 Lecture 12: Rendering pipeline revisitedm.mr-pc.org/t/cisc3620/2019sp/lecture12.pdf · 2019. 5. 1. · 4 Overview At end of the geometric pipeline, vertices have been assembled

Polygon Clipping

● Not as simple as line segment clipping– Clipping a line segment yields at most one line segment– Clipping a polygon can yield multiple polygons

38Angel and Shreiner: Interactive Computer Graphics 7E © Addison-Wesley 2015

Page 39: CISC 3620 Lecture 12: Rendering pipeline revisitedm.mr-pc.org/t/cisc3620/2019sp/lecture12.pdf · 2019. 5. 1. · 4 Overview At end of the geometric pipeline, vertices have been assembled

Polygon Clipping

● Not as simple as line segment clipping– Clipping a line segment yields at most one line segment– Clipping a polygon can yield multiple polygons

● However, clipping a convex polygon can yield at most one polygon

39Angel and Shreiner: Interactive Computer Graphics 7E © Addison-Wesley 2015

Page 40: CISC 3620 Lecture 12: Rendering pipeline revisitedm.mr-pc.org/t/cisc3620/2019sp/lecture12.pdf · 2019. 5. 1. · 4 Overview At end of the geometric pipeline, vertices have been assembled

Tessellation and Convexity

● One strategy is to replace nonconvex (concave) polygons with a set of triangular polygons (a tessellation)

● Also makes fill easier● Tessellation through tessellation shaders

40Angel and Shreiner: Interactive Computer Graphics 7E © Addison-Wesley 2015

Page 41: CISC 3620 Lecture 12: Rendering pipeline revisitedm.mr-pc.org/t/cisc3620/2019sp/lecture12.pdf · 2019. 5. 1. · 4 Overview At end of the geometric pipeline, vertices have been assembled

Clipping as a Black Box

● Can consider line segment clipping as a process that takes in two vertices and produces either no vertices or the vertices of a clipped line segment

41Angel and Shreiner: Interactive Computer Graphics 7E © Addison-Wesley 2015

xi=( ymax− y1)x2−x1

y2− y1

Page 42: CISC 3620 Lecture 12: Rendering pipeline revisitedm.mr-pc.org/t/cisc3620/2019sp/lecture12.pdf · 2019. 5. 1. · 4 Overview At end of the geometric pipeline, vertices have been assembled

Pipeline Clipping of Line Segments

● Clipping against each side of window is independent of other sides– Can use four independent clippers in a pipeline

42Angel and Shreiner: Interactive Computer Graphics 7E © Addison-Wesley 2015

Page 43: CISC 3620 Lecture 12: Rendering pipeline revisitedm.mr-pc.org/t/cisc3620/2019sp/lecture12.pdf · 2019. 5. 1. · 4 Overview At end of the geometric pipeline, vertices have been assembled

Pipeline Clipping of Line Segments

● Clipping against each side of window is independent of other sides– Can use four independent clippers in a pipeline

43Angel and Shreiner: Interactive Computer Graphics 7E © Addison-Wesley 2015

Page 44: CISC 3620 Lecture 12: Rendering pipeline revisitedm.mr-pc.org/t/cisc3620/2019sp/lecture12.pdf · 2019. 5. 1. · 4 Overview At end of the geometric pipeline, vertices have been assembled

Pipeline Clipping of Line Segments

● Clipping against each side of window is independent of other sides– Can use four independent clippers in a pipeline

44Angel and Shreiner: Interactive Computer Graphics 7E © Addison-Wesley 2015

Page 45: CISC 3620 Lecture 12: Rendering pipeline revisitedm.mr-pc.org/t/cisc3620/2019sp/lecture12.pdf · 2019. 5. 1. · 4 Overview At end of the geometric pipeline, vertices have been assembled

Pipeline Clipping of Line Segments

● Clipping against each side of window is independent of other sides– Can use four independent clippers in a pipeline

45Angel and Shreiner: Interactive Computer Graphics 7E © Addison-Wesley 2015

Page 46: CISC 3620 Lecture 12: Rendering pipeline revisitedm.mr-pc.org/t/cisc3620/2019sp/lecture12.pdf · 2019. 5. 1. · 4 Overview At end of the geometric pipeline, vertices have been assembled

Pipeline Clipping of Line Segments

● Clipping against each side of window is independent of other sides– Can use four independent clippers in a pipeline

46Angel and Shreiner: Interactive Computer Graphics 7E © Addison-Wesley 2015

Page 47: CISC 3620 Lecture 12: Rendering pipeline revisitedm.mr-pc.org/t/cisc3620/2019sp/lecture12.pdf · 2019. 5. 1. · 4 Overview At end of the geometric pipeline, vertices have been assembled

Pipeline Clipping of Polygons

47Angel and Shreiner: Interactive Computer Graphics 7E © Addison-Wesley 2015

● Strategy used in SGI Geometry Engine● Small increase in latency● In three dimensions: add front and back clippers

Page 48: CISC 3620 Lecture 12: Rendering pipeline revisitedm.mr-pc.org/t/cisc3620/2019sp/lecture12.pdf · 2019. 5. 1. · 4 Overview At end of the geometric pipeline, vertices have been assembled

Bounding Boxes

● Rather than doing clipping on a complex polygon, we can use an axis-aligned bounding box or extent– Smallest rectangle aligned with axes that encloses the polygon

– Simple to compute:

48Angel and Shreiner: Interactive Computer Graphics 7E © Addison-Wesley 2015

Page 49: CISC 3620 Lecture 12: Rendering pipeline revisitedm.mr-pc.org/t/cisc3620/2019sp/lecture12.pdf · 2019. 5. 1. · 4 Overview At end of the geometric pipeline, vertices have been assembled

Bounding Boxes

● Rather than doing clipping on a complex polygon, we can use an axis-aligned bounding box or extent– Smallest rectangle aligned with axes that encloses the polygon

– Simple to compute: max and min of x and y

49Angel and Shreiner: Interactive Computer Graphics 7E © Addison-Wesley 2015

Page 50: CISC 3620 Lecture 12: Rendering pipeline revisitedm.mr-pc.org/t/cisc3620/2019sp/lecture12.pdf · 2019. 5. 1. · 4 Overview At end of the geometric pipeline, vertices have been assembled

Bounding boxes

● Can usually determine accept/reject based only on bounding box

50Angel and Shreiner: Interactive Computer Graphics 7E © Addison-Wesley 2015

Page 51: CISC 3620 Lecture 12: Rendering pipeline revisitedm.mr-pc.org/t/cisc3620/2019sp/lecture12.pdf · 2019. 5. 1. · 4 Overview At end of the geometric pipeline, vertices have been assembled

Bounding boxes

● Can usually determine accept/reject based only on bounding box

reject

accept

requires detailed clipping

51Angel and Shreiner: Interactive Computer Graphics 7E © Addison-Wesley 2015

Page 52: CISC 3620 Lecture 12: Rendering pipeline revisitedm.mr-pc.org/t/cisc3620/2019sp/lecture12.pdf · 2019. 5. 1. · 4 Overview At end of the geometric pipeline, vertices have been assembled

Hidden surface removal

Page 53: CISC 3620 Lecture 12: Rendering pipeline revisitedm.mr-pc.org/t/cisc3620/2019sp/lecture12.pdf · 2019. 5. 1. · 4 Overview At end of the geometric pipeline, vertices have been assembled

Clipping and Visibility

● Clipping has much in common with hidden-surface removal

● In both cases, we are trying to remove objects that are not visible to the camera

● Often we can use visibility or occlusion testing early in the process to eliminate as many polygons as possible before going through the entire pipeline

53Angel and Shreiner: Interactive Computer Graphics 7E © Addison-Wesley 2015

Page 54: CISC 3620 Lecture 12: Rendering pipeline revisitedm.mr-pc.org/t/cisc3620/2019sp/lecture12.pdf · 2019. 5. 1. · 4 Overview At end of the geometric pipeline, vertices have been assembled

Hidden Surface Removal

● Object-space approach: use pairwise testing between polygons (objects)

● Worst case complexity O(____) for n polygons

partially obscuring can draw independently

54Angel and Shreiner: Interactive Computer Graphics 7E © Addison-Wesley 2015

Page 55: CISC 3620 Lecture 12: Rendering pipeline revisitedm.mr-pc.org/t/cisc3620/2019sp/lecture12.pdf · 2019. 5. 1. · 4 Overview At end of the geometric pipeline, vertices have been assembled

Hidden Surface Removal

● Object-space approach: use pairwise testing between polygons (objects)

● Worst case complexity O(n2) for n polygons

partially obscuring can draw independently

55Angel and Shreiner: Interactive Computer Graphics 7E © Addison-Wesley 2015

Page 56: CISC 3620 Lecture 12: Rendering pipeline revisitedm.mr-pc.org/t/cisc3620/2019sp/lecture12.pdf · 2019. 5. 1. · 4 Overview At end of the geometric pipeline, vertices have been assembled

Painter’s Algorithm

● Render polygons in back-to-front order so that polygons behind others are simply painted over

● But how do we get back-to-front order?B behind A as seen by viewer Fill B then A

56Angel and Shreiner: Interactive Computer Graphics 7E © Addison-Wesley 2015

Page 57: CISC 3620 Lecture 12: Rendering pipeline revisitedm.mr-pc.org/t/cisc3620/2019sp/lecture12.pdf · 2019. 5. 1. · 4 Overview At end of the geometric pipeline, vertices have been assembled

Depth Sort

● Requires ordering of polygons first – O(n log n) calculation for ordering– Not every polygon is either in front or behind all

other polygons

● Order polygons and deal with easy cases first, harder later

Polygons sorted by distance from center of projection

57Angel and Shreiner: Interactive Computer Graphics 7E © Addison-Wesley 2015

Page 58: CISC 3620 Lecture 12: Rendering pipeline revisitedm.mr-pc.org/t/cisc3620/2019sp/lecture12.pdf · 2019. 5. 1. · 4 Overview At end of the geometric pipeline, vertices have been assembled

Depth Sort

● What are the possible depth relationships between pairs of polygons?

58Angel and Shreiner: Interactive Computer Graphics 7E © Addison-Wesley 2015

Page 59: CISC 3620 Lecture 12: Rendering pipeline revisitedm.mr-pc.org/t/cisc3620/2019sp/lecture12.pdf · 2019. 5. 1. · 4 Overview At end of the geometric pipeline, vertices have been assembled

Easy Cases

● A lies behind all other polygons– Can render

● Polygons overlap in z but not in either x or y– Can render independently

59Angel and Shreiner: Interactive Computer Graphics 7E © Addison-Wesley 2015

Page 60: CISC 3620 Lecture 12: Rendering pipeline revisitedm.mr-pc.org/t/cisc3620/2019sp/lecture12.pdf · 2019. 5. 1. · 4 Overview At end of the geometric pipeline, vertices have been assembled

Hard Cases

Overlap in all directionsbut one is fully on

one side of the other

cyclic overlap

piercing

60Angel and Shreiner: Interactive Computer Graphics 7E © Addison-Wesley 2015

Page 61: CISC 3620 Lecture 12: Rendering pipeline revisitedm.mr-pc.org/t/cisc3620/2019sp/lecture12.pdf · 2019. 5. 1. · 4 Overview At end of the geometric pipeline, vertices have been assembled

Back-Face Removal (Culling)

61Angel and Shreiner: Interactive Computer Graphics 7E © Addison-Wesley 2015

● One way to save rendering is to only render polygons on the side of an object that faces the viewer

● In OpenGL we can simply enable culling– but may not work correctly if we

have nonconvex objects

Page 62: CISC 3620 Lecture 12: Rendering pipeline revisitedm.mr-pc.org/t/cisc3620/2019sp/lecture12.pdf · 2019. 5. 1. · 4 Overview At end of the geometric pipeline, vertices have been assembled

Back-Face Removal (Culling)

62Angel and Shreiner: Interactive Computer Graphics 7E © Addison-Wesley 2015

● Face is visible iff _______

Page 63: CISC 3620 Lecture 12: Rendering pipeline revisitedm.mr-pc.org/t/cisc3620/2019sp/lecture12.pdf · 2019. 5. 1. · 4 Overview At end of the geometric pipeline, vertices have been assembled

Back-Face Removal (Culling)

63Angel and Shreiner: Interactive Computer Graphics 7E © Addison-Wesley 2015

● Face is visible iff (equivalently):– 90 -90 -90 -90– cos 0 -90– v • n 0 -90

● Plane of face has form ax + by +cz +d =0– Can be written as p • n = 0

where p = (x y z 1)T

– after normalization v = ( 0 0 1 0)T

● So __________

Page 64: CISC 3620 Lecture 12: Rendering pipeline revisitedm.mr-pc.org/t/cisc3620/2019sp/lecture12.pdf · 2019. 5. 1. · 4 Overview At end of the geometric pipeline, vertices have been assembled

Back-Face Removal (Culling)

64Angel and Shreiner: Interactive Computer Graphics 7E © Addison-Wesley 2015

● Face is visible iff (equivalently):– 90 -90 -90 -90– cos 0 -90– v • n 0 -90

● Plane of face has form ax + by +cz +d =0– Can be written as p • n = 0

where p = (x y z 1)T

– after normalization v = ( 0 0 1 0)T

● So need only test the sign of c

Page 65: CISC 3620 Lecture 12: Rendering pipeline revisitedm.mr-pc.org/t/cisc3620/2019sp/lecture12.pdf · 2019. 5. 1. · 4 Overview At end of the geometric pipeline, vertices have been assembled

Image Space Approach

● Look at each projector (nm for an n x m frame buffer) and find closest of k polygons

● Complexity O(nmk)● Can implement with z-buffer● Ray tracing

65Angel and Shreiner: Interactive Computer Graphics 7E © Addison-Wesley 2015

Page 66: CISC 3620 Lecture 12: Rendering pipeline revisitedm.mr-pc.org/t/cisc3620/2019sp/lecture12.pdf · 2019. 5. 1. · 4 Overview At end of the geometric pipeline, vertices have been assembled

z-Buffer Algorithm

● Use a buffer called the z or depth buffer to store the depth of the closest object at each pixel found so far

● As we render each polygon, compare the depth of each pixel to depth in z buffer

● If less, place shade of pixel in color buffer and update z buffer

66Angel and Shreiner: Interactive Computer Graphics 7E © Addison-Wesley 2015

Page 67: CISC 3620 Lecture 12: Rendering pipeline revisitedm.mr-pc.org/t/cisc3620/2019sp/lecture12.pdf · 2019. 5. 1. · 4 Overview At end of the geometric pipeline, vertices have been assembled

Efficiency

● If we work scan line by scan line as we move across a scan line, the depth changes satisfy ax+by+cz=0

Along scan line

y = 0z = - x

c

a

In screen space x = 1

67Angel and Shreiner: Interactive Computer Graphics 7E © Addison-Wesley 2015

Page 68: CISC 3620 Lecture 12: Rendering pipeline revisitedm.mr-pc.org/t/cisc3620/2019sp/lecture12.pdf · 2019. 5. 1. · 4 Overview At end of the geometric pipeline, vertices have been assembled

Scan-Line Algorithm

● Can combine shading and culling through scan line algorithm

● scan line i: no need for depth information, can only be in no or one polygon

● scan line j: need depth information only when in more than one polygon

68Angel and Shreiner: Interactive Computer Graphics 7E © Addison-Wesley 2015

Page 69: CISC 3620 Lecture 12: Rendering pipeline revisitedm.mr-pc.org/t/cisc3620/2019sp/lecture12.pdf · 2019. 5. 1. · 4 Overview At end of the geometric pipeline, vertices have been assembled

Implementation

● Need a data structure to store– Flag for each polygon (inside/outside)– Incremental structure for scan lines that stores which

edges are encountered – Parameters for planes

69Angel and Shreiner: Interactive Computer Graphics 7E © Addison-Wesley 2015

Page 70: CISC 3620 Lecture 12: Rendering pipeline revisitedm.mr-pc.org/t/cisc3620/2019sp/lecture12.pdf · 2019. 5. 1. · 4 Overview At end of the geometric pipeline, vertices have been assembled

Visibility Testing● In many realtime applications, such as games, we want to eliminate as

many objects as possible within the application– Reduce burden on pipeline– Reduce traffic on bus

● Partition space with Binary Spatial Partition (BSP) Tree

70Angel and Shreiner: Interactive Computer Graphics 7E © Addison-Wesley 2015

Page 71: CISC 3620 Lecture 12: Rendering pipeline revisitedm.mr-pc.org/t/cisc3620/2019sp/lecture12.pdf · 2019. 5. 1. · 4 Overview At end of the geometric pipeline, vertices have been assembled

Simple Example

consider 6 parallel polygons

top view

The plane of A separates B and C from D, E and F

71Angel and Shreiner: Interactive Computer Graphics 7E © Addison-Wesley 2015

Page 72: CISC 3620 Lecture 12: Rendering pipeline revisitedm.mr-pc.org/t/cisc3620/2019sp/lecture12.pdf · 2019. 5. 1. · 4 Overview At end of the geometric pipeline, vertices have been assembled

BSP Tree

● Can continue recursively – Plane of C separates B from A– Plane of D separates E and F

● Can put this information in a BSP tree– Use for visibility and

occlusion testing

72Angel and Shreiner: Interactive Computer Graphics 7E © Addison-Wesley 2015

Page 73: CISC 3620 Lecture 12: Rendering pipeline revisitedm.mr-pc.org/t/cisc3620/2019sp/lecture12.pdf · 2019. 5. 1. · 4 Overview At end of the geometric pipeline, vertices have been assembled

Rasterization

Page 74: CISC 3620 Lecture 12: Rendering pipeline revisitedm.mr-pc.org/t/cisc3620/2019sp/lecture12.pdf · 2019. 5. 1. · 4 Overview At end of the geometric pipeline, vertices have been assembled

Objectives

● Survey Line Drawing Algorithms– DDA– Bresenham’s Algorithm

● Aliasing and Antialiasing

Page 75: CISC 3620 Lecture 12: Rendering pipeline revisitedm.mr-pc.org/t/cisc3620/2019sp/lecture12.pdf · 2019. 5. 1. · 4 Overview At end of the geometric pipeline, vertices have been assembled

Rasterization

● Rasterization (scan conversion)– Determine which pixels are inside primitive specified by a

set of vertices– Produces a set of fragments– Fragments have a location (pixel location) and other

attributes such color and texture coordinates that are determined by interpolating values at vertices

● Pixel colors determined later using color, texture, and other vertex properties

Page 76: CISC 3620 Lecture 12: Rendering pipeline revisitedm.mr-pc.org/t/cisc3620/2019sp/lecture12.pdf · 2019. 5. 1. · 4 Overview At end of the geometric pipeline, vertices have been assembled

Scan Conversion of Line Segments

● Start with line segment in window coordinates with integer values for endpoints

● Assume implementation has a write_pixel function

y = mx + h

x

ym

Page 77: CISC 3620 Lecture 12: Rendering pipeline revisitedm.mr-pc.org/t/cisc3620/2019sp/lecture12.pdf · 2019. 5. 1. · 4 Overview At end of the geometric pipeline, vertices have been assembled

DDA Algorithm

● Digital Differential Analyzer– DDA was a mechanical device for numerical solution of differential equations– Line y=mx+ h satisfies differential equation

dy/dx = m = y/x = y2-y1/x2-x1

● Along scan line x = 1for(x=x1; x<=x2; x++) {

y += m;

write_pixel(x, round(y), line_color)

}

Page 78: CISC 3620 Lecture 12: Rendering pipeline revisitedm.mr-pc.org/t/cisc3620/2019sp/lecture12.pdf · 2019. 5. 1. · 4 Overview At end of the geometric pipeline, vertices have been assembled

DDA Algorithm

● Digital Differential Analyzer– DDA was a mechanical device for numerical solution of differential equations– Line y=mx+ h satisfies differential equation

dy/dx = m = y/x = y2-y1/x2-x1

● Along scan line x = 1for(x=x1; x<=x2; x++) {

y += m;

write_pixel(x, round(y), line_color)

}

● Try for m = 0.2, x1 = 0, x2 = 10● Try for m = 5.0, x1 = 0, x2 = 10

Page 79: CISC 3620 Lecture 12: Rendering pipeline revisitedm.mr-pc.org/t/cisc3620/2019sp/lecture12.pdf · 2019. 5. 1. · 4 Overview At end of the geometric pipeline, vertices have been assembled

Problem

● DDA = for each x plot pixel at closest y– Problems for steep lines

Page 80: CISC 3620 Lecture 12: Rendering pipeline revisitedm.mr-pc.org/t/cisc3620/2019sp/lecture12.pdf · 2019. 5. 1. · 4 Overview At end of the geometric pipeline, vertices have been assembled

Using Symmetry

● Use for 1 m 0 -90 -90● For m > 1, swap role of x and y

– For each y, plot closest x

Page 81: CISC 3620 Lecture 12: Rendering pipeline revisitedm.mr-pc.org/t/cisc3620/2019sp/lecture12.pdf · 2019. 5. 1. · 4 Overview At end of the geometric pipeline, vertices have been assembled

Bresenham’s Algorithm

● DDA requires one floating point addition per step● We can eliminate all floating point math through Bresenham’s

algorithm● Consider only 1 m 0 -90 -90

– Other cases by symmetry

● Assume pixel centers are at half integer coordinates● If we start at a pixel that has been written, there are only two

candidates for the next pixel to be written into the frame buffer

Page 82: CISC 3620 Lecture 12: Rendering pipeline revisitedm.mr-pc.org/t/cisc3620/2019sp/lecture12.pdf · 2019. 5. 1. · 4 Overview At end of the geometric pipeline, vertices have been assembled

Candidate Pixels

1 -90 m -90 0

previous pixel

candidates

Note that line could havepassed through anypart of this pixel

-

Page 83: CISC 3620 Lecture 12: Rendering pipeline revisitedm.mr-pc.org/t/cisc3620/2019sp/lecture12.pdf · 2019. 5. 1. · 4 Overview At end of the geometric pipeline, vertices have been assembled

Decision Variable

-

d = x(b-a)

d is an integerd > 0 use upper pixeld < 0 use lower pixel

Page 84: CISC 3620 Lecture 12: Rendering pipeline revisitedm.mr-pc.org/t/cisc3620/2019sp/lecture12.pdf · 2019. 5. 1. · 4 Overview At end of the geometric pipeline, vertices have been assembled

Incremental Form

● More efficient if we look at dk, the value of the decision variable at x = k

dk+1= dk –2y, if dk <0

dk+1= dk –2(y - x), otherwise

● For each x, we need do only an integer addition and a test

● Single instruction on graphics chips

Page 85: CISC 3620 Lecture 12: Rendering pipeline revisitedm.mr-pc.org/t/cisc3620/2019sp/lecture12.pdf · 2019. 5. 1. · 4 Overview At end of the geometric pipeline, vertices have been assembled

As pseudocode

plotLine(x0,y0, x1,y1)

dx = x1 - x0

dy = y1 - y0

D = 2*dy - dx

y = y0

for x from x0 to x1

plot(x,y)

if D > 0

y = y + 1

D = D - 2*dx

end if

D = D + 2*dy

● Try for m = 0.2, x1 = 0, x2 = 10

● https://en.wikipedia.org/wiki/Bresenham%27s_line_algorithm#Algorithm_for_integer_arithmetic

Page 86: CISC 3620 Lecture 12: Rendering pipeline revisitedm.mr-pc.org/t/cisc3620/2019sp/lecture12.pdf · 2019. 5. 1. · 4 Overview At end of the geometric pipeline, vertices have been assembled

Polygon Scan Conversion

● Scan Conversion = Fill● How to tell inside from outside

– Convex easy– Nonsimple difficult– Odd even test

● Count edge crossings

– Winding number

odd-even fill

Page 87: CISC 3620 Lecture 12: Rendering pipeline revisitedm.mr-pc.org/t/cisc3620/2019sp/lecture12.pdf · 2019. 5. 1. · 4 Overview At end of the geometric pipeline, vertices have been assembled

Winding Number

● Count clockwise encirclements of point

● Alternate definition of inside:

inside if winding number 0 0

winding number = ?

winding number = ?

Page 88: CISC 3620 Lecture 12: Rendering pipeline revisitedm.mr-pc.org/t/cisc3620/2019sp/lecture12.pdf · 2019. 5. 1. · 4 Overview At end of the geometric pipeline, vertices have been assembled

Winding Number

● Count clockwise encirclements of point

● Alternate definition of inside:

inside if winding number 0 0

winding number = 2

winding number = 1

Page 89: CISC 3620 Lecture 12: Rendering pipeline revisitedm.mr-pc.org/t/cisc3620/2019sp/lecture12.pdf · 2019. 5. 1. · 4 Overview At end of the geometric pipeline, vertices have been assembled

Filling in the Frame Buffer

● Fill at end of pipeline– Convex Polygons only– Nonconvex polygons assumed to have been tessellated– Shades (colors) have been computed for vertices

(Gouraud shading)– Combine with z-buffer algorithm

● March across scan lines interpolating shades● Incremental work easy

Page 90: CISC 3620 Lecture 12: Rendering pipeline revisitedm.mr-pc.org/t/cisc3620/2019sp/lecture12.pdf · 2019. 5. 1. · 4 Overview At end of the geometric pipeline, vertices have been assembled

Using Interpolation

span

C1

C3

C2

C5

C4

scan line

● C1 C2 C3 specified by glColor or by vertex shading● C4 determined by interpolating between C1 and C2● C5 determined by interpolating between C2 and C3● interpolate between C4 and C5 along span

Page 91: CISC 3620 Lecture 12: Rendering pipeline revisitedm.mr-pc.org/t/cisc3620/2019sp/lecture12.pdf · 2019. 5. 1. · 4 Overview At end of the geometric pipeline, vertices have been assembled

Flood Fill● Fill can be done recursively if we know a seed point located inside (WHITE)● Scan convert edges into buffer in edge/inside color (BLACK)

flood_fill(int x, int y) { if(read_pixel(x,y) == WHITE) { write_pixel(x,y,BLACK); flood_fill(x-1, y); flood_fill(x+1, y); flood_fill(x, y+1); flood_fill(x, y-1); } }

By André Karwath aka Aka - Own work, CC BY-SA 2.5, https://commons.wikimedia.org/w/index.php?curid=481651

Page 92: CISC 3620 Lecture 12: Rendering pipeline revisitedm.mr-pc.org/t/cisc3620/2019sp/lecture12.pdf · 2019. 5. 1. · 4 Overview At end of the geometric pipeline, vertices have been assembled

Scan Line Fill

● Can also fill by maintaining a data structure of all intersections of polygons with scan lines– Sort by scan line– Fill each span

vertex order generated by vertex list desired order

Page 93: CISC 3620 Lecture 12: Rendering pipeline revisitedm.mr-pc.org/t/cisc3620/2019sp/lecture12.pdf · 2019. 5. 1. · 4 Overview At end of the geometric pipeline, vertices have been assembled

Scan Line Fill

● Can also fill by maintaining a data structure of all intersections of polygons with scan lines– Sort by scan line– Fill each span

vertex order generated by vertex list desired order

Page 94: CISC 3620 Lecture 12: Rendering pipeline revisitedm.mr-pc.org/t/cisc3620/2019sp/lecture12.pdf · 2019. 5. 1. · 4 Overview At end of the geometric pipeline, vertices have been assembled

Data Structure

Page 95: CISC 3620 Lecture 12: Rendering pipeline revisitedm.mr-pc.org/t/cisc3620/2019sp/lecture12.pdf · 2019. 5. 1. · 4 Overview At end of the geometric pipeline, vertices have been assembled

Aliasing

● Ideal rasterized line should be 1 pixel wide

● Choosing best y for each x (or visa versa) produces aliased raster lines

Page 96: CISC 3620 Lecture 12: Rendering pipeline revisitedm.mr-pc.org/t/cisc3620/2019sp/lecture12.pdf · 2019. 5. 1. · 4 Overview At end of the geometric pipeline, vertices have been assembled

Antialiasing by Area Averaging

● Color multiple pixels for each x depending on coverage by ideal line

original antialiased

magnified

Page 97: CISC 3620 Lecture 12: Rendering pipeline revisitedm.mr-pc.org/t/cisc3620/2019sp/lecture12.pdf · 2019. 5. 1. · 4 Overview At end of the geometric pipeline, vertices have been assembled

Polygon Aliasing

● Aliasing problems can be serious for polygons– Jaggedness of edges– Small polygons

neglected– Need compositing so

color of one polygon does not totally determine color of pixel

All three polygons should contribute to color

Page 98: CISC 3620 Lecture 12: Rendering pipeline revisitedm.mr-pc.org/t/cisc3620/2019sp/lecture12.pdf · 2019. 5. 1. · 4 Overview At end of the geometric pipeline, vertices have been assembled

Display issues

Page 99: CISC 3620 Lecture 12: Rendering pipeline revisitedm.mr-pc.org/t/cisc3620/2019sp/lecture12.pdf · 2019. 5. 1. · 4 Overview At end of the geometric pipeline, vertices have been assembled

99

Objectives

● Consider perceptual issues related to displays● Introduce chromaticity space

Color systems Color transformations

● Standard Color Systems

Angel and Shreiner: Interactive Computer Graphics 7E © Addison-Wesley 2015

Page 100: CISC 3620 Lecture 12: Rendering pipeline revisitedm.mr-pc.org/t/cisc3620/2019sp/lecture12.pdf · 2019. 5. 1. · 4 Overview At end of the geometric pipeline, vertices have been assembled

No Display Can Be Perfect

● An analog display device such as a CRT takes digital input (pixels) and outputs a small spot of color

● A Digital display such as a LCD display outputs discrete spots

● The eye merges (filters) these spots● Sampling theory shows this process cannot be

done perfectly

100Angel and Shreiner: Interactive Computer Graphics 7E © Addison-Wesley 2015

Page 101: CISC 3620 Lecture 12: Rendering pipeline revisitedm.mr-pc.org/t/cisc3620/2019sp/lecture12.pdf · 2019. 5. 1. · 4 Overview At end of the geometric pipeline, vertices have been assembled

101

Perception Review

● Light is the part of the electromagnetic spectrum between ~350-750 nm

● A color C() is a distribution of energies within this range

● The human visual system has three types of cones on the retina, each with its own spectral sensitivity

● Consequently, only three values, the tristimulus values, are “seen” by the brain

Angel and Shreiner: Interactive Computer Graphics 7E © Addison-Wesley 2015

Page 102: CISC 3620 Lecture 12: Rendering pipeline revisitedm.mr-pc.org/t/cisc3620/2019sp/lecture12.pdf · 2019. 5. 1. · 4 Overview At end of the geometric pipeline, vertices have been assembled

102

Tristimulus Values

● The human visual center has three cones with sensitivity curves S1(), S2(), and S3()

● For a color C(), the cones output the tristimulus values

dCST )()(11 dCST )()(22 dCST )()(33

C()

T1, T2, T3cones

optic nerve

Angel and Shreiner: Interactive Computer Graphics 7E © Addison-Wesley 2015

Page 103: CISC 3620 Lecture 12: Rendering pipeline revisitedm.mr-pc.org/t/cisc3620/2019sp/lecture12.pdf · 2019. 5. 1. · 4 Overview At end of the geometric pipeline, vertices have been assembled

103

Three Color Theory

● Any two colors with the same tristimulus values are perceived to be identical

● Thus a display (CRT, LCD, film) must only produce the correct tristimulus values to match a color

● Is this possible? Not always Different primaries (different sensitivity curves) in

different systems

Angel and Shreiner: Interactive Computer Graphics 7E © Addison-Wesley 2015

Page 104: CISC 3620 Lecture 12: Rendering pipeline revisitedm.mr-pc.org/t/cisc3620/2019sp/lecture12.pdf · 2019. 5. 1. · 4 Overview At end of the geometric pipeline, vertices have been assembled

104

The Problem

● The sensitivity curves of the human are not the same as those of physical devices

● Human: curves centered in blue, green, and green-yellow

● CRT: RGB● Print media: CMY or CMYK● Which colors can we match and, if we cannot

match, how close can we come?

Angel and Shreiner: Interactive Computer Graphics 7E © Addison-Wesley 2015

Page 105: CISC 3620 Lecture 12: Rendering pipeline revisitedm.mr-pc.org/t/cisc3620/2019sp/lecture12.pdf · 2019. 5. 1. · 4 Overview At end of the geometric pipeline, vertices have been assembled

105

Representing Colors

● Consider a color C()● It generates tristimulus values T1, T2, T3

Write C = (T1, T2, T3 )

Conventionally,we assume 1 -90 T1, T2, T3 -90 0 because there is a maximum brightness we can produce and energy is nonnegative

C is a point in color solid

C1

11

T1

T2

T3

Angel and Shreiner: Interactive Computer Graphics 7E © Addison-Wesley 2015

Page 106: CISC 3620 Lecture 12: Rendering pipeline revisitedm.mr-pc.org/t/cisc3620/2019sp/lecture12.pdf · 2019. 5. 1. · 4 Overview At end of the geometric pipeline, vertices have been assembled

106

Producing Colors

● Consider a device such as a CRT with RGB primaries and sensitivity curves

● Tristimulus values

dCRT )()(1 dCGT )()(2 dCBT )()(3

Angel and Shreiner: Interactive Computer Graphics 7E © Addison-Wesley 2015

Page 107: CISC 3620 Lecture 12: Rendering pipeline revisitedm.mr-pc.org/t/cisc3620/2019sp/lecture12.pdf · 2019. 5. 1. · 4 Overview At end of the geometric pipeline, vertices have been assembled

107

Matching

● This T1, T2, T3 is dependent on the particular device

● If we use another device, we will get different values and these values will not match those of the human cone curves

● Need a way of matching and a way of normalizing

Angel and Shreiner: Interactive Computer Graphics 7E © Addison-Wesley 2015

Page 108: CISC 3620 Lecture 12: Rendering pipeline revisitedm.mr-pc.org/t/cisc3620/2019sp/lecture12.pdf · 2019. 5. 1. · 4 Overview At end of the geometric pipeline, vertices have been assembled

108

Color Systems

● Various color systems are used Based on real primaries:

• NTSC RGB• UVW• CMYK• HLS

Theoretical• XYZ

● Prefer to separate brightness (luminance) from color (chromatic) information Reduce to two dimensions

Angel and Shreiner: Interactive Computer Graphics 7E © Addison-Wesley 2015

Page 109: CISC 3620 Lecture 12: Rendering pipeline revisitedm.mr-pc.org/t/cisc3620/2019sp/lecture12.pdf · 2019. 5. 1. · 4 Overview At end of the geometric pipeline, vertices have been assembled

109

Tristimulus Coordinates

TTTTt

321

11

TTTTt

321

22

For any set of primaries, define

TTTTt

321

33

1ttt 321 0,,1 ttt 321

-90 -90Note

Angel and Shreiner: Interactive Computer Graphics 7E © Addison-Wesley 2015

Page 110: CISC 3620 Lecture 12: Rendering pipeline revisitedm.mr-pc.org/t/cisc3620/2019sp/lecture12.pdf · 2019. 5. 1. · 4 Overview At end of the geometric pipeline, vertices have been assembled

110

Maxwell Triangle

Project onto 2D: chromaticity space

1

1T1 + T2+T3 =1

1

color solid

t1

t2

1

1

t1 +

t2 =1 possible colors

Angel and Shreiner: Interactive Computer Graphics 7E © Addison-Wesley 2015

Page 111: CISC 3620 Lecture 12: Rendering pipeline revisitedm.mr-pc.org/t/cisc3620/2019sp/lecture12.pdf · 2019. 5. 1. · 4 Overview At end of the geometric pipeline, vertices have been assembled

111

NTSC RGB

1

1

r

g

r+g+b=1

r+g=1

Angel and Shreiner: Interactive Computer Graphics 7E © Addison-Wesley 2015

Page 112: CISC 3620 Lecture 12: Rendering pipeline revisitedm.mr-pc.org/t/cisc3620/2019sp/lecture12.pdf · 2019. 5. 1. · 4 Overview At end of the geometric pipeline, vertices have been assembled

112

Producing Other Colors

● However colors producible on one system (its color gamut) is not necessarily producible on any other

● Not that if we produce all the pure spectral colors in the 350-750 nm range, we can produce all others by adding spectral colors

● With real systems (CRT, film), we cannot produce the pure spectral colors

● We can project the color solid of each system into chromaticity space (of some system) to see how close we can get

Angel and Shreiner: Interactive Computer Graphics 7E © Addison-Wesley 2015

Page 113: CISC 3620 Lecture 12: Rendering pipeline revisitedm.mr-pc.org/t/cisc3620/2019sp/lecture12.pdf · 2019. 5. 1. · 4 Overview At end of the geometric pipeline, vertices have been assembled

113

Color Gamuts

spectral colorsprinter colors

CRT colors

350 nm

750 nm

600 nm

producible color on CRT but not on printer

producible color on both CRT and printer

unproducible color

Angel and Shreiner: Interactive Computer Graphics 7E © Addison-Wesley 2015

Page 114: CISC 3620 Lecture 12: Rendering pipeline revisitedm.mr-pc.org/t/cisc3620/2019sp/lecture12.pdf · 2019. 5. 1. · 4 Overview At end of the geometric pipeline, vertices have been assembled

114

XYZ

● Reference system in which all visible pure spectral colors can be produced

● Theoretical systems as

there are no corresponding

physical primaries● Standard reference system

Angel and Shreiner: Interactive Computer Graphics 7E © Addison-Wesley 2015

Page 115: CISC 3620 Lecture 12: Rendering pipeline revisitedm.mr-pc.org/t/cisc3620/2019sp/lecture12.pdf · 2019. 5. 1. · 4 Overview At end of the geometric pipeline, vertices have been assembled

115

Color Systems

● Most correspond to real primaries

National Television Systems Committee (NTSC) RGB matches phosphors in CRTs

● Film both additive (RGB) and subtractive (CMY) for positive and negative film

● Print industry CMYK (K = black) K used to produce sharp crisp blacks Example: ink jet printers

Angel and Shreiner: Interactive Computer Graphics 7E © Addison-Wesley 2015

Page 116: CISC 3620 Lecture 12: Rendering pipeline revisitedm.mr-pc.org/t/cisc3620/2019sp/lecture12.pdf · 2019. 5. 1. · 4 Overview At end of the geometric pipeline, vertices have been assembled

116

Color Transformations

● Each additive color system is a linear transformation of another

R

R’

GG’

B

B’

C = (T1, T2, T3) = (T’1, T’2, T’3)

in RGB system

in R’G’B’system

Angel and Shreiner: Interactive Computer Graphics 7E © Addison-Wesley 2015

Page 117: CISC 3620 Lecture 12: Rendering pipeline revisitedm.mr-pc.org/t/cisc3620/2019sp/lecture12.pdf · 2019. 5. 1. · 4 Overview At end of the geometric pipeline, vertices have been assembled

117

RGB, CMY, CMYK

● Assuming 1 is max of a primary

C = 1 – R

M = 1 – G

Y = 1 – B● Convert CMY to CMYK by

K = min(C, M, Y)

C’ = C – K

M’ = M – K

Y’ = Y - K

Angel and Shreiner: Interactive Computer Graphics 7E © Addison-Wesley 2015

Page 118: CISC 3620 Lecture 12: Rendering pipeline revisitedm.mr-pc.org/t/cisc3620/2019sp/lecture12.pdf · 2019. 5. 1. · 4 Overview At end of the geometric pipeline, vertices have been assembled

118

Color Matrix

● Exists a 3 x 3 matrix to convert from representation in one system to representation in another

● Example: XYZ to NTSC RGB find in colorimetry references

● Can take a color in XYZ and find out if it is producible by transforming and then checking if resulting tristimulus values lie in (0,1)

TTT

T'T'T'

3

2

1

3

2

1

M

Angel and Shreiner: Interactive Computer Graphics 7E © Addison-Wesley 2015

Page 119: CISC 3620 Lecture 12: Rendering pipeline revisitedm.mr-pc.org/t/cisc3620/2019sp/lecture12.pdf · 2019. 5. 1. · 4 Overview At end of the geometric pipeline, vertices have been assembled

119

YIQ

● NTSC Transmission Colors● Here Y is the luminance

Arose from need to separate brightness from chromatic information in TV broadcasting

● Note luminance shows high green sensitivity

B

G

R

0.3110.523-0.212

0.321-0.275-0.596

0.1140.5870.299

Q

I

Y

Angel and Shreiner: Interactive Computer Graphics 7E © Addison-Wesley 2015

Page 120: CISC 3620 Lecture 12: Rendering pipeline revisitedm.mr-pc.org/t/cisc3620/2019sp/lecture12.pdf · 2019. 5. 1. · 4 Overview At end of the geometric pipeline, vertices have been assembled

120

Other Color Systems

● UVW: equal numerical errors are closer to equal perceptual errors

● HLS: perceptual color (hue, saturation, lightness)

Polar representation of color space Single and double cone versions

Angel and Shreiner: Interactive Computer Graphics 7E © Addison-Wesley 2015

Page 121: CISC 3620 Lecture 12: Rendering pipeline revisitedm.mr-pc.org/t/cisc3620/2019sp/lecture12.pdf · 2019. 5. 1. · 4 Overview At end of the geometric pipeline, vertices have been assembled

121

Gamma

● Intensity vs CRT voltage is nonlinear

I = cV

● Can use a lookup table to correct● Human brightness response is logarithmic

Equal steps in gray levels are not perceived equally

Can use lookup table● CRTs cannot produce a full black

Limits contrast ratio

Angel and Shreiner: Interactive Computer Graphics 7E © Addison-Wesley 2015

Page 122: CISC 3620 Lecture 12: Rendering pipeline revisitedm.mr-pc.org/t/cisc3620/2019sp/lecture12.pdf · 2019. 5. 1. · 4 Overview At end of the geometric pipeline, vertices have been assembled

sRGB

● Standard for Internet● Adjust colors to match standard gamma of

panels match gamma over most of the range enhance less bright colors

● OpenGL (soon WebGL?) can input sRGB and convert to RGB for processing and then back to sRGB

122Angel and Shreiner: Interactive Computer Graphics 7E © Addison-Wesley 2015

Page 123: CISC 3620 Lecture 12: Rendering pipeline revisitedm.mr-pc.org/t/cisc3620/2019sp/lecture12.pdf · 2019. 5. 1. · 4 Overview At end of the geometric pipeline, vertices have been assembled

Summary

● Rendering overview● Clipping● Polygon rendering● Rasterization● Display issues