rasterization - 计算机图形学 rasterization.pdf · rasterization •the task of displaying a...

78
Rasterization Teacher: A.prof. Chengying Gao(高成英) E-mail: [email protected] School of Data and Computer Science Computer Graphics

Upload: others

Post on 02-Oct-2020

4 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Rasterization - 计算机图形学 Rasterization.pdf · Rasterization •The task of displaying a world modeled using primitives like lines, polygons, filled/patterned area, etc

Rasterization

Teacher: A.prof. Chengying Gao(高成英)

E-mail: [email protected]

School of Data and Computer Science

Computer Graphics

Page 2: Rasterization - 计算机图形学 Rasterization.pdf · Rasterization •The task of displaying a world modeled using primitives like lines, polygons, filled/patterned area, etc

To make an image, we can...

2Computer Graphics

Drawing

Photography

Page 3: Rasterization - 计算机图形学 Rasterization.pdf · Rasterization •The task of displaying a world modeled using primitives like lines, polygons, filled/patterned area, etc

Two Ways to Render an Image

3Computer Graphics

In CG, drawing is... Photography is...

Ray Tracing

Rasterization

Page 4: Rasterization - 计算机图形学 Rasterization.pdf · Rasterization •The task of displaying a world modeled using primitives like lines, polygons, filled/patterned area, etc

Screen

4Computer Graphics

Page 5: Rasterization - 计算机图形学 Rasterization.pdf · Rasterization •The task of displaying a world modeled using primitives like lines, polygons, filled/patterned area, etc

Sensors

5Computer Graphics

真实物理世界没有颜色的概念,只有频率。颜色只是人的主观感受,不是物体的客观属性,物体只是在发射或反射电磁波。

Page 6: Rasterization - 计算机图形学 Rasterization.pdf · Rasterization •The task of displaying a world modeled using primitives like lines, polygons, filled/patterned area, etc

Rasterization

• The task of displaying a world modeled using primitives like lines, polygons,

filled/patterned area, etc. can be carried out in two steps:

• determine the pixels through which the primitive is visible,

• determine the color value to be assigned to each such pixel

6Computer Graphics

Page 7: Rasterization - 计算机图形学 Rasterization.pdf · Rasterization •The task of displaying a world modeled using primitives like lines, polygons, filled/patterned area, etc

Raster Graphics Packages

• The efficiency of these steps forms the main criteria to

determine the performance of a display

• The raster graphics package is typically a collection of efficient

algorithms for scan converting (rasterization) of the display

primitives

• High performance graphics workstations have most of these

algorithms implemented in hardware

• Comparison of raster graphics editors:

• https://en.wikipedia.org/wiki/Comparison_of_raster_graphics_editors

7Computer Graphics

Page 8: Rasterization - 计算机图形学 Rasterization.pdf · Rasterization •The task of displaying a world modeled using primitives like lines, polygons, filled/patterned area, etc

Rasterization

To convert vector data to raster format

Scan Conversion:Figure out which pixel should to shade.

8Computer Graphics

Page 9: Rasterization - 计算机图形学 Rasterization.pdf · Rasterization •The task of displaying a world modeled using primitives like lines, polygons, filled/patterned area, etc

Scan converting lines

9Computer Graphics

Page 10: Rasterization - 计算机图形学 Rasterization.pdf · Rasterization •The task of displaying a world modeled using primitives like lines, polygons, filled/patterned area, etc

Scan converting lines

10Computer Graphics

Page 11: Rasterization - 计算机图形学 Rasterization.pdf · Rasterization •The task of displaying a world modeled using primitives like lines, polygons, filled/patterned area, etc

Scan converting lines

11Computer Graphics

Page 12: Rasterization - 计算机图形学 Rasterization.pdf · Rasterization •The task of displaying a world modeled using primitives like lines, polygons, filled/patterned area, etc

Scan converting lines

12Computer Graphics

Page 13: Rasterization - 计算机图形学 Rasterization.pdf · Rasterization •The task of displaying a world modeled using primitives like lines, polygons, filled/patterned area, etc

Scan converting lines

13Computer Graphics

Page 14: Rasterization - 计算机图形学 Rasterization.pdf · Rasterization •The task of displaying a world modeled using primitives like lines, polygons, filled/patterned area, etc

Scan converting lines

14Computer Graphics

Page 15: Rasterization - 计算机图形学 Rasterization.pdf · Rasterization •The task of displaying a world modeled using primitives like lines, polygons, filled/patterned area, etc

Scan converting lines

15Computer Graphics

Page 16: Rasterization - 计算机图形学 Rasterization.pdf · Rasterization •The task of displaying a world modeled using primitives like lines, polygons, filled/patterned area, etc

Scan converting lines

16Computer Graphics

Page 17: Rasterization - 计算机图形学 Rasterization.pdf · Rasterization •The task of displaying a world modeled using primitives like lines, polygons, filled/patterned area, etc

Equation of Line

17Computer Graphics

Page 18: Rasterization - 计算机图形学 Rasterization.pdf · Rasterization •The task of displaying a world modeled using primitives like lines, polygons, filled/patterned area, etc

Digital Differential Analyzer (DDA, 数值微分法)

18Computer Graphics

Page 19: Rasterization - 计算机图形学 Rasterization.pdf · Rasterization •The task of displaying a world modeled using primitives like lines, polygons, filled/patterned area, etc

Digital Differential Analyzer (DDA, 数值微分法)

19Computer Graphics

Page 20: Rasterization - 计算机图形学 Rasterization.pdf · Rasterization •The task of displaying a world modeled using primitives like lines, polygons, filled/patterned area, etc

Digital Differential Analyzer (DDA, 数值微分法)

20Computer Graphics

Page 21: Rasterization - 计算机图形学 Rasterization.pdf · Rasterization •The task of displaying a world modeled using primitives like lines, polygons, filled/patterned area, etc

Digital Differential Analyzer (DDA)

21Computer Graphics

Page 22: Rasterization - 计算机图形学 Rasterization.pdf · Rasterization •The task of displaying a world modeled using primitives like lines, polygons, filled/patterned area, etc

Digital Differential Analyzer (DDA)

22Computer Graphics

Page 23: Rasterization - 计算机图形学 Rasterization.pdf · Rasterization •The task of displaying a world modeled using primitives like lines, polygons, filled/patterned area, etc

Digital Differential Analyzer (DDA)

23Computer Graphics

Page 24: Rasterization - 计算机图形学 Rasterization.pdf · Rasterization •The task of displaying a world modeled using primitives like lines, polygons, filled/patterned area, etc

Digital Differential Analyzer (DDA)

24Computer Graphics

Page 25: Rasterization - 计算机图形学 Rasterization.pdf · Rasterization •The task of displaying a world modeled using primitives like lines, polygons, filled/patterned area, etc

Digital Differential Analyzer (DDA)

25Computer Graphics

Page 26: Rasterization - 计算机图形学 Rasterization.pdf · Rasterization •The task of displaying a world modeled using primitives like lines, polygons, filled/patterned area, etc

Digital Differential Analyzer (DDA)

26Computer Graphics

y += 1, x += 1/m

Page 27: Rasterization - 计算机图形学 Rasterization.pdf · Rasterization •The task of displaying a world modeled using primitives like lines, polygons, filled/patterned area, etc

Digital Differential Analyzer (DDA)

27Computer Graphics

y += 1, x += 1/m

Page 28: Rasterization - 计算机图形学 Rasterization.pdf · Rasterization •The task of displaying a world modeled using primitives like lines, polygons, filled/patterned area, etc

Digital Differential Analyzer (DDA)

28Computer Graphics

y += 1, x += 1/m

Page 29: Rasterization - 计算机图形学 Rasterization.pdf · Rasterization •The task of displaying a world modeled using primitives like lines, polygons, filled/patterned area, etc

Digital Differential Analyzer (DDA)

29Computer Graphics

y += 1, x += 1/m

Page 30: Rasterization - 计算机图形学 Rasterization.pdf · Rasterization •The task of displaying a world modeled using primitives like lines, polygons, filled/patterned area, etc

Digital Differential Analyzer (DDA)

30Computer Graphics

y += 1, x += 1/m

Page 31: Rasterization - 计算机图形学 Rasterization.pdf · Rasterization •The task of displaying a world modeled using primitives like lines, polygons, filled/patterned area, etc

Digital Differential Analyzer (DDA)

31Computer Graphics

y += 1, x += 1/m

Divide and conquer!

Page 32: Rasterization - 计算机图形学 Rasterization.pdf · Rasterization •The task of displaying a world modeled using primitives like lines, polygons, filled/patterned area, etc

DDA Algorithm

32Computer Graphics

Page 33: Rasterization - 计算机图形学 Rasterization.pdf · Rasterization •The task of displaying a world modeled using primitives like lines, polygons, filled/patterned area, etc

Bresenham’s algorithm (布兰森汉姆算法)

• Introduced in 1967 by J. Bresenham of IBM

• Best-fit approximation under some conditions

• In DDA, only yi is used to compute yi+1, the information for

selecting the pixel is neglected

• Bresenham algorithm employs the information to constrain the

position of the next pixel

33Computer Graphics

Page 34: Rasterization - 计算机图形学 Rasterization.pdf · Rasterization •The task of displaying a world modeled using primitives like lines, polygons, filled/patterned area, etc

Notations

34Computer Graphics

• The line segment is from to

• Denote

• Assume that slope

• Like DDA algorithm, Bresenham Algorithm also starts from

and increases x coordinate by 1 each time

• Suppose the i-th point is

• Then the next point can only be one of the following two

Page 35: Rasterization - 计算机图形学 Rasterization.pdf · Rasterization •The task of displaying a world modeled using primitives like lines, polygons, filled/patterned area, etc

Criteria(判别标准)

• We will choose one which distance to the following intersection is shorter

35Computer Graphics

Page 36: Rasterization - 计算机图形学 Rasterization.pdf · Rasterization •The task of displaying a world modeled using primitives like lines, polygons, filled/patterned area, etc

Computation of Criteria

• The distances are respectively

36Computer Graphics

Page 37: Rasterization - 计算机图形学 Rasterization.pdf · Rasterization •The task of displaying a world modeled using primitives like lines, polygons, filled/patterned area, etc

Computation of Criteria

37Computer Graphics

division operation

Page 38: Rasterization - 计算机图形学 Rasterization.pdf · Rasterization •The task of displaying a world modeled using primitives like lines, polygons, filled/patterned area, etc

Restatement of the Criteria

38Computer Graphics

Page 39: Rasterization - 计算机图形学 Rasterization.pdf · Rasterization •The task of displaying a world modeled using primitives like lines, polygons, filled/patterned area, etc

Recursive for computation of pi

39Computer Graphics

Page 40: Rasterization - 计算机图形学 Rasterization.pdf · Rasterization •The task of displaying a world modeled using primitives like lines, polygons, filled/patterned area, etc

Summary of Bresenham Algorithm

40Computer Graphics

Page 41: Rasterization - 计算机图形学 Rasterization.pdf · Rasterization •The task of displaying a world modeled using primitives like lines, polygons, filled/patterned area, etc

Example

• Draw line segment (3,4)-(8,7)

41Computer Graphics

Page 42: Rasterization - 计算机图形学 Rasterization.pdf · Rasterization •The task of displaying a world modeled using primitives like lines, polygons, filled/patterned area, etc

2 3 4 5 6 7 8

8

7

6

5

4

3

2

0 1 (4,5)

1 -3 (5,5)

2 3 (6,6)

3 -1 (7,6)

4 5 (8,7)

注:

(Continued)

Page 43: Rasterization - 计算机图形学 Rasterization.pdf · Rasterization •The task of displaying a world modeled using primitives like lines, polygons, filled/patterned area, etc

More Raster Line Issues

• The coordinates of endpoints are not integer

• Generalize to draw other primitives: circles, ellipsoids

• Line pattern and thickness?

44Computer Graphics

Page 44: Rasterization - 计算机图形学 Rasterization.pdf · Rasterization •The task of displaying a world modeled using primitives like lines, polygons, filled/patterned area, etc

3D Bresenham algorithm

45Computer Graphics

Page 45: Rasterization - 计算机图形学 Rasterization.pdf · Rasterization •The task of displaying a world modeled using primitives like lines, polygons, filled/patterned area, etc

What Makes a Good Line?

• Not too jaggy

• Uniform thickness of lines at different angles

• Symmetry, Line(P,Q) = Line(Q,P)

• A good line algorithm should be fast.

46Computer Graphics

Page 46: Rasterization - 计算机图形学 Rasterization.pdf · Rasterization •The task of displaying a world modeled using primitives like lines, polygons, filled/patterned area, etc

Line Attributes

• line width

• dash patterns

• end caps: butt, round, square

47Computer Graphics

Page 47: Rasterization - 计算机图形学 Rasterization.pdf · Rasterization •The task of displaying a world modeled using primitives like lines, polygons, filled/patterned area, etc

Line Attributes

• Joins: round, bevel, miter

48Computer Graphics

Page 48: Rasterization - 计算机图形学 Rasterization.pdf · Rasterization •The task of displaying a world modeled using primitives like lines, polygons, filled/patterned area, etc

Scan conversion of circles

49Computer Graphics

Page 49: Rasterization - 计算机图形学 Rasterization.pdf · Rasterization •The task of displaying a world modeled using primitives like lines, polygons, filled/patterned area, etc

Polygon Rasterization

50Computer Graphics

Page 50: Rasterization - 计算机图形学 Rasterization.pdf · Rasterization •The task of displaying a world modeled using primitives like lines, polygons, filled/patterned area, etc

Scan conversion of polygon

• Polygon representation

51Computer Graphics

Polygon filling: vertex representation lattice representation

Page 51: Rasterization - 计算机图形学 Rasterization.pdf · Rasterization •The task of displaying a world modeled using primitives like lines, polygons, filled/patterned area, etc

Polygon filling

• fill a polygonal area --> test every pixel in the raster to see if it

lies inside the polygon.

52Computer Graphics

Page 52: Rasterization - 计算机图形学 Rasterization.pdf · Rasterization •The task of displaying a world modeled using primitives like lines, polygons, filled/patterned area, etc

Inside Check

53Computer Graphics

Page 53: Rasterization - 计算机图形学 Rasterization.pdf · Rasterization •The task of displaying a world modeled using primitives like lines, polygons, filled/patterned area, etc

Scan-line Methods

54Computer Graphics

• Makes use of the coherence properties

• Spatial coherence : Except at the boundary edges, adjacent pixels

are likely to have the same characteristics

• Scan line coherence : Pixels in the adjacent scan lines are likely to

have the same characteristics

• Uses intersections between area boundaries and scan lines to

identify pixels that are inside the area

Page 54: Rasterization - 计算机图形学 Rasterization.pdf · Rasterization •The task of displaying a world modeled using primitives like lines, polygons, filled/patterned area, etc

Scan Line Method

• Proceeding from left to right the intersections are paired and intervening

pixels are set to the specified intensity

• Algorithm

• Find the intersections of the scan line with all the edges in the polygon

• Sort the intersections by increasing X-coordinates

• Fill the pixels between pair of intersections

55Computer Graphics

From top to down

Discussion : How to speed up, or how to avoid calculating intersection

Page 55: Rasterization - 计算机图形学 Rasterization.pdf · Rasterization •The task of displaying a world modeled using primitives like lines, polygons, filled/patterned area, etc

Efficiency Issues Scan-line Methods

56Computer Graphics

Page 56: Rasterization - 计算机图形学 Rasterization.pdf · Rasterization •The task of displaying a world modeled using primitives like lines, polygons, filled/patterned area, etc

Special cases for Scan-line Methods

57Computer Graphics

Page 57: Rasterization - 计算机图形学 Rasterization.pdf · Rasterization •The task of displaying a world modeled using primitives like lines, polygons, filled/patterned area, etc

Advantages of Scan Line method

• The algorithm is efficient

• Each pixel is visited only once

• Shading algorithms could be easily integrated with this method

to obtain shaded area

• Efficient could be further improved if polygons are convex

• Much better if they are only triangles

58Computer Graphics

Page 58: Rasterization - 计算机图形学 Rasterization.pdf · Rasterization •The task of displaying a world modeled using primitives like lines, polygons, filled/patterned area, etc

What is Convex?

59Computer Graphics

Page 59: Rasterization - 计算机图形学 Rasterization.pdf · Rasterization •The task of displaying a world modeled using primitives like lines, polygons, filled/patterned area, etc

Convex Polygon Rasterization

60Computer Graphics

Page 60: Rasterization - 计算机图形学 Rasterization.pdf · Rasterization •The task of displaying a world modeled using primitives like lines, polygons, filled/patterned area, etc

Triangle Rasterization

61Computer Graphics

Page 61: Rasterization - 计算机图形学 Rasterization.pdf · Rasterization •The task of displaying a world modeled using primitives like lines, polygons, filled/patterned area, etc

Edge Walking

62Computer Graphics

Page 62: Rasterization - 计算机图形学 Rasterization.pdf · Rasterization •The task of displaying a world modeled using primitives like lines, polygons, filled/patterned area, etc

Edge Walking

63Computer Graphics

Page 63: Rasterization - 计算机图形学 Rasterization.pdf · Rasterization •The task of displaying a world modeled using primitives like lines, polygons, filled/patterned area, etc

Edge Walking Triangle

64Computer Graphics

Page 64: Rasterization - 计算机图形学 Rasterization.pdf · Rasterization •The task of displaying a world modeled using primitives like lines, polygons, filled/patterned area, etc

12

Page 65: Rasterization - 计算机图形学 Rasterization.pdf · Rasterization •The task of displaying a world modeled using primitives like lines, polygons, filled/patterned area, etc

Edge Walking

66Computer Graphics

Page 66: Rasterization - 计算机图形学 Rasterization.pdf · Rasterization •The task of displaying a world modeled using primitives like lines, polygons, filled/patterned area, etc

Edge Equations

67Computer Graphics

Page 67: Rasterization - 计算机图形学 Rasterization.pdf · Rasterization •The task of displaying a world modeled using primitives like lines, polygons, filled/patterned area, etc

Edge Equations

68Computer Graphics

Page 68: Rasterization - 计算机图形学 Rasterization.pdf · Rasterization •The task of displaying a world modeled using primitives like lines, polygons, filled/patterned area, etc

Edge Equations

69Computer Graphics

Page 69: Rasterization - 计算机图形学 Rasterization.pdf · Rasterization •The task of displaying a world modeled using primitives like lines, polygons, filled/patterned area, etc

Aliasing

70Computer Graphics

Page 70: Rasterization - 计算机图形学 Rasterization.pdf · Rasterization •The task of displaying a world modeled using primitives like lines, polygons, filled/patterned area, etc

Aliasing

• A classic part of the computer graphics curriculum

• Input:

• Line segment definition

• (x1, y1), (x2, y2)

• Output:

• List of pixels

71Computer Graphics

(x1, y1)

(x2, y2)

Page 71: Rasterization - 计算机图形学 Rasterization.pdf · Rasterization •The task of displaying a world modeled using primitives like lines, polygons, filled/patterned area, etc

Aliasing

• How Do They Look?

• So now we know how to draw lines

• But they don’t look very good:

72Computer Graphics

Page 72: Rasterization - 计算机图形学 Rasterization.pdf · Rasterization •The task of displaying a world modeled using primitives like lines, polygons, filled/patterned area, etc

Antialiasing

73Computer Graphics

Page 73: Rasterization - 计算机图形学 Rasterization.pdf · Rasterization •The task of displaying a world modeled using primitives like lines, polygons, filled/patterned area, etc

Anti-aliasing

• Application of techniques to reduce/eliminate aliasing

artifacts.

• Essentially 3 techniques:

• Super-sampling vs. filter

• We discussed a simple averaging filter

• Compute the fraction of a line that should be applied to a pixel

• Ratio method

• Area Simpling

74Computer Graphics

Page 74: Rasterization - 计算机图形学 Rasterization.pdf · Rasterization •The task of displaying a world modeled using primitives like lines, polygons, filled/patterned area, etc

Anti-aliasing: Super-sampling

• Technique:

1. Create an image 2x (or 4x, or 8x) bigger than the real image

2. Scale the line endpoints accordingly

3. Draw the line as before

• No change to line drawing algorithm

4. Average each 2x2 (or 4x4, or 8x8) block into a single pixel

75Computer Graphics

Page 75: Rasterization - 计算机图形学 Rasterization.pdf · Rasterization •The task of displaying a world modeled using primitives like lines, polygons, filled/patterned area, etc

Anti-aliasing: Super-sampling

76Computer Graphics

No antialiasing 2x2 SupersampledDownsampled to

original size

1/42/41/4

1/42/4

Page 76: Rasterization - 计算机图形学 Rasterization.pdf · Rasterization •The task of displaying a world modeled using primitives like lines, polygons, filled/patterned area, etc

Anti-aliasing: Ratios

77Computer Graphics

Page 77: Rasterization - 计算机图形学 Rasterization.pdf · Rasterization •The task of displaying a world modeled using primitives like lines, polygons, filled/patterned area, etc

Anti-aliasing: Ratios

78Computer Graphics

Page 78: Rasterization - 计算机图形学 Rasterization.pdf · Rasterization •The task of displaying a world modeled using primitives like lines, polygons, filled/patterned area, etc

Anti-aliasing (Area Sampling)

79Computer Graphics