Presentation is loading. Please wait.

Presentation is loading. Please wait.

Rasterization CENG 477 Introduction to Computer Graphics Slides from Steve Marschner, CS4620, 2008 Cornell University.

Similar presentations


Presentation on theme: "Rasterization CENG 477 Introduction to Computer Graphics Slides from Steve Marschner, CS4620, 2008 Cornell University."— Presentation transcript:

1 Rasterization CENG 477 Introduction to Computer Graphics Slides from Steve Marschner, CS4620, 2008 Cornell University

2

3

4 Primitives Graphic SW and HW provide subroutines to describe a scene in terms of basic geometric structures called output primitives. Output primitives are combined to form complex structures Simplest primitives Point (pixel) Line segment

5

6 Rasterization Converting output primitives into frame buffer updates. Choose which pixels contain which intensity value. Constraints Straight lines should appear as a straight line primitives should start and end accurately Primitives should have a consistent brightness along their length They should be drawn rapidly

7

8 OpenGL Point Functions glBegin (GL_POINTS); glVertex2i(50, 100); glVertex2i(75, 150); glVertex2i(100, 200); glEnd();

9 OpenGL Line Functions glBegin (GL_LINES); glVertex2iv(p1); glVertex2iv(p2); glVertex2iv(p3); glVertex2iv(p4); glVertex2iv(p5); glEnd(); p5 p3 p1 p4 p2

10 OpenGL Line Functions glBegin (GL_LINE_STRIP); glVertex2iv(p1); glVertex2iv(p2); glVertex2iv(p3); glVertex2iv(p4); glVertex2iv(p5); glEnd(); p5 p3 p1 p4 p2

11 OpenGL Line Functions glBegin (GL_LINE_LOOP); glVertex2iv(p1); glVertex2iv(p2); glVertex2iv(p3); glVertex2iv(p4); glVertex2iv(p5); glEnd(); p5 p3 p1 p4 p2

12 Line Drawing Algorithms Simple approach: sample a line at discrete positions at one coordinate from start point to end point, calculate the other coordinate value from line equation (slope-intercept line equation). If m>1, increment y uniformly and find x If m ≤1, increment x uniformly and find y Is this correct?

13

14 Digital Differential Analyzer Simple approach: too many floating point operations and repeated calculations Calculate from for a value

15

16

17 DDA Algorithm

18 DDA Is faster than directly implementing y=mx+b. No floating point multiplications. We have floating point additions only at each step. But what about round-off errors? Can we get rid of floating point operations completely?

19 Bresenham's Line Algorithm DDA: Still floating point operations x k+1 xkxk ykyk yk+1yk+1 y=mx+b d upper d lower x k+2 x k+3

20 at step k+1: 0 if p k was negative1 if p k was positive to calculate p 0 at the starting pixel position (x 0,y 0 )

21 Bresenham’s Line-Drawing Algorithm

22 Midpoint algorithm from the book Implicit line equation: Incremental computation: Evaluation of line equation at midpoint: What does this mean?

23 Midpoint algorithm from the book

24 Example Using Bresenham’s algorithm digitize the line with endpoints (20,10) and (30,18)

25 Example continued... 2021302225 10 18

26 Plotted pixels 2021302225 10 18

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41 Computing the Barycentric Coordinates

42 Triangle rasterization algorithm Combine this with incremental linear interpolation

43

44

45

46


Download ppt "Rasterization CENG 477 Introduction to Computer Graphics Slides from Steve Marschner, CS4620, 2008 Cornell University."

Similar presentations


Ads by Google