Rasterization (03) RNDr. Martin Madaras, PhD. - - PowerPoint PPT Presentation

rasterization 03
SMART_READER_LITE
LIVE PREVIEW

Rasterization (03) RNDr. Martin Madaras, PhD. - - PowerPoint PPT Presentation

Principles of Computer Graphics and Image Processing Rasterization (03) RNDr. Martin Madaras, PhD. martin.madaras@stuba.sk Last lessons summary 2 CG reference model 3 Computer Vision/ Computer Graphics Computer Graphics 4 CG reference


slide-1
SLIDE 1

Principles of Computer Graphics and Image Processing

Rasterization (03)

  • RNDr. Martin Madaras, PhD.

martin.madaras@stuba.sk

slide-2
SLIDE 2

2

Last lessons summary

slide-3
SLIDE 3

CG reference model

3

slide-4
SLIDE 4

4

Computer Vision/ Computer Graphics

Computer Graphics

slide-5
SLIDE 5

CG reference model

5

 Geometry space

 continuous  3Dimensional

 Screen space

 discrete  2Dimensional

slide-6
SLIDE 6

3D Scene vs. 2D image

6

slide-7
SLIDE 7

Geometry vs. screen space

7

3D Continuous Parametric Models 2D Discrete Non-parametric Pixels

slide-8
SLIDE 8

3D polygon rendering

8

 Many applications use rendering of 3D polygons with

direct illumination

slide-9
SLIDE 9

3D polygon rendering

9

 Many applications use rendering of 3D polygons with

direct illumination

Quake 3, ID software

slide-10
SLIDE 10

3D polygon rendering

10

 Many applications use rendering of 3D polygons with

direct illumination

CATIA, Dassault Systemes

slide-11
SLIDE 11

3D polygon rendering

11

 What steps are necessary to produce an image of a 3D

scene?

slide-12
SLIDE 12

Ray Casting

12

 One approach is to cast rays from the camera…

slide-13
SLIDE 13

Ray Casting

13

 And find intersections with the scene…  We are going to describe different approach this lesson

slide-14
SLIDE 14

3D polygon rendering

14

 Second approach is called Rasterization  Way how to efficiently draw primitives into screen space

slide-15
SLIDE 15

15

  • Ask questions, please!!!
  • Be communicative
  • www.slido.com #PPGSO03
  • More active you are, the better for you!

How the lectures should look like #1

slide-16
SLIDE 16

16

Rasterization

slide-17
SLIDE 17

3D rendering pipeline

17

3D polygons Modeling Transformation Lighting Viewing Transformation Projection Transformation Clipping Scan Conversion 2D Image

1

slide-18
SLIDE 18

3D rendering pipeline

18

Modeling Transformation Lighting Viewing Transformation Projection Transformation Clipping Scan Conversion 2D Image

1

array of vertex positions x,y,z { 0,1,0, 1,1,0, 1,0,0, 0,0,0}

OpenGL executes steps of the 3D rendering pipeline for each polygon

slide-19
SLIDE 19

3D rendering pipeline

19

3D polygons Modeling Transformation Lighting Viewing Transformation Projection Transformation Clipping Scan Conversion 2D Image

1

Transform into 3D world coordinate system

slide-20
SLIDE 20

3D rendering pipeline

20

3D polygons Modeling Transformation Lighting Viewing Transformation Projection Transformation Clipping Scan Conversion 2D Image

1

Transform into 3D world coordinate system Illuminate according to light

slide-21
SLIDE 21

3D rendering pipeline

21

3D polygons Modeling Transformation Lighting Viewing Transformation Projection Transformation Clipping Scan Conversion 2D Image

1

Transform into 3D world coordinate system Illuminate according to light Transform into 3D camera coordinate system

slide-22
SLIDE 22

3D rendering pipeline

22

3D polygons Modeling Transformation Lighting Viewing Transformation Projection Transformation Clipping Scan Conversion 2D Image

1

Transform into 3D world coordinate system Illuminate according to light Transform into 3D camera coordinate system Transform into 2D camera coordinate system Clip polygons outside of camera’s view Draw pixels

slide-23
SLIDE 23

3D rendering pipeline

23

3D polygons Modeling Transformation Lighting Viewing Transformation Projection Transformation Clipping Scan Conversion 2D Image

1

Transform into 3D world coordinate system Illuminate according to light Transform into 3D camera coordinate system Transform into 2D camera coordinate system Clip polygons outside of camera’s view Draw pixels

slide-24
SLIDE 24

3D rendering pipeline

24

3D polygons Modeling Transformation Lighting Viewing Transformation Projection Transformation Clipping Scan Conversion 2D Image

1

Transform into 3D world coordinate system Illuminate according to light Transform into 3D camera coordinate system Transform into 2D camera coordinate system Clip polygons outside of camera’s view Draw pixels

slide-25
SLIDE 25

3D rendering pipeline

25

3D polygons Modeling Transformation Lighting Viewing Transformation Projection Transformation Clipping Scan Conversion 2D Image

1

 Model transformation

 local → global coordinates

 View transformation

 global → camera

 Projection transformation

 camera → screen

 Clipping, rasterization,

texturing & Lighting

 might take place earlier

slide-26
SLIDE 26

Transformations

26

3D polygons Modeling Transformation Lighting Viewing Transformation Projection Transformation Clipping Scan Conversion 2D Image

1

Transform into 3D world coordinate system Illuminate according to light Transform into 3D camera coordinate system Transform into 2D camera coordinate system Clip polygons outside of camera’s view Draw pixels

slide-27
SLIDE 27

Transformations

27 P(x, y, z)

3D Object coordinates

Modeling Transformation

3D World coordinates

Viewing Transformation

3D Camera coordinates

Projection Transformation

2D Camera coordinates

Window to Viewport Transformation

2D Image coordinates

P’(x’, y’)

Transformations map points from one coordinate system to another

slide-28
SLIDE 28

Camera coordinates

28

 Canonical coordinate system

 Convention is right-handed (looking down -z)  Convenient for projection, clipping etc.

slide-29
SLIDE 29

Coordinate systems

29

 DirectX <= 9, left handed only

slide-30
SLIDE 30

Local coordinates

30

 Each object has its own coordinate system

slide-31
SLIDE 31

Global coordinates

31

 One system for the whole scene

slide-32
SLIDE 32

Local → Global coordinates

32

 Translation

            = 1 1 1 ) 1 , , ( ) 1 , ' , ' ( y t x t y x y x

slide-33
SLIDE 33

Local → Global coordinates

33

 Rotation

          − = 1 cos sin sin cos ) 1 , , ( ) 1 , ' , ' (     y x y x

slide-34
SLIDE 34

Local → Global coordinates

34

 All transformations combined

slide-35
SLIDE 35

Transformations

35

 Transformation from one coordinate system to another

  • ne is a composition of partial transformations:

 Translation  Rotation  Scaling

slide-36
SLIDE 36

All transformations

36

 Model transformation

 Unify coordinates by transforming local

to global coordinates

 View transformation

 Transform global coordinates so that they are

aligned with camera coordinates

 T

  • make projection computable
slide-37
SLIDE 37

Model transformation

37

 Transformation local → global  Combination of rotate, translate, scale  Matrix multiplication

slide-38
SLIDE 38

Model transformation

38

 Translation, rotation, scaling

          − 1 cos sin sin cos               1 y s x s

            1 1 1 y t x t

slide-39
SLIDE 39

Camera coordinates

39

 XY of screen + Z as direction of view

slide-40
SLIDE 40

Global→camera coordinates

40

 T * Ry * Rx

 Translation, rotation, rotation

 T * Ry * Rx * Rz

 if the camera is rolled

 Projection P

 orthogonal, perspective, isometric ...

slide-41
SLIDE 41

Viewing Transformation

41

 Mapping from world to camera coordinates

 Eye position maps to origin  Right vector maps to X axis  Up vector maps to

Y axis

 Back vector maps to Z axis

slide-42
SLIDE 42

Finding the Viewing Transformation

42

 We have the camera (in world coordinates)  We want T taking objects from world to camera

𝑞𝐷 = 𝑈𝑞𝑋

 Trick: find T taking objects in camera to world

𝑞𝑋 = 𝑈−1𝑞𝐷 𝑦′ 𝑧′ 𝑨′ 𝑥′ = 𝑏 𝑐 𝑑 𝑒 𝑓 𝑔 𝑕 ℎ 𝑗 𝑘 𝑙 𝑚 𝑛 𝑜 𝑝 𝑞 𝑦 𝑧 𝑨 𝑥

slide-43
SLIDE 43

Finding the Viewing Transformation

43

 Trick: Map from camera coordinates to world

 Origin maps to eye position  z axis maps to Back vector  y axis maps to Up vector  x axis maps to Right vector  T

  • get 𝑈−1we just need to invert 𝑈

𝑦′ 𝑧′ 𝑨′ 𝑥′ =

𝑠

𝑦

𝑣𝑦 𝑐𝑦 𝑓𝑌 𝑠

𝑧

𝑣𝑧 𝑐𝑧 𝑓𝑧 𝑠

𝑨

𝑣𝑨 𝑐𝑨 𝑓𝑨 𝑠

𝑥

𝑣𝑥 𝑐𝑥 𝑓𝑥

𝑦 𝑧 𝑨 𝑥

slide-44
SLIDE 44

Finding the Viewing Transformation

44

 Trick: Map from camera coordinates to world

 Origin maps to eye position  z axis maps to Back vector  y axis maps to Up vector  x axis maps to Right vector  T

  • get 𝑈−1we just need to invert 𝑈

𝑦′ 𝑧′ 𝑨′ 𝑥′ =

𝑠

𝑦

𝑣𝑦 𝑐𝑦 𝑓𝑌 𝑠

𝑧

𝑣𝑧 𝑐𝑧 𝑓𝑧 𝑠

𝑨

𝑣𝑨 𝑐𝑨 𝑓𝑨 𝑠

𝑥

𝑣𝑥 𝑐𝑥 𝑓𝑥

𝑦 𝑧 𝑨 𝑥

slide-45
SLIDE 45

Vectors vs Positions

45

 There is a fundamental difference between vectors and

positions in homogeneous coordinates!

 Position

 In homogeneous coordinates p = {x, y, z, 1}  Can be moved so translation will apply

 Vector

 In homogenous coordinates v = {x, y, z, 0}  Cannot be moved, its just direction

slide-46
SLIDE 46

46

Projections summary

slide-47
SLIDE 47

Projection types

47

 Orthogonal

slide-48
SLIDE 48

Projection types

48

 Parallel

slide-49
SLIDE 49

Projection types

49

 Isometric (parallel but not orthogonal)

slide-50
SLIDE 50

Projection types

50

 Perspective

slide-51
SLIDE 51

Projection types

51

 Perspective

slide-52
SLIDE 52

52

Viewport transformation

slide-53
SLIDE 53

Viewport transformation

53

 Global coordinates

e.g. (-50..50 cm, -50..50 cm, -50..50 cm)

 Camera coordinates

 e.g. (-1..1, -1..1, -1..1)

 Viewport (window)

 e.g. (0..1200 px, 0..800 px)

slide-54
SLIDE 54

Viewport transformation

54

          + − + − = 1 ) 1 , , ( ) 1 , , (

min min min min

yv yc s xv xc s s s y x y x

y x y x p p v v

min max min max

xc xc xv xv sx − − =

min max min max

yc yc yv yv sy − − =

slide-55
SLIDE 55

3D rendering pipeline

55

3D polygons Modeling Transformation Lighting Viewing Transformation Projection Transformation Clipping Scan Conversion 2D Image

1

Transform into 3D world coordinate system Illuminate according to light Transform into 3D camera coordinate system Transform into 2D camera coordinate system Clip polygons outside of camera’s view Draw pixels

slide-56
SLIDE 56

3D rendering pipeline

56

3D polygons Modeling Transformation Lighting Viewing Transformation Projection Transformation Clipping Scan Conversion 2D Image

1

Transform into 3D world coordinate system Illuminate according to light Transform into 3D camera coordinate system Transform into 2D camera coordinate system Clip polygons outside of camera’s view Draw pixels

slide-57
SLIDE 57

3D polygon rendering

57

 Closed sequence of lines

slide-58
SLIDE 58

General problem

58

 Given a continuous

geometric representation

  • f an object

 Decide which pixels

are occupied by the object

slide-59
SLIDE 59

General problem

59

slide-60
SLIDE 60

Digital Differential Analyzer

60

 dd = (y2 – y1) / (x2 – x1)

: float

slide-61
SLIDE 61

Digital Differential Analyzer

61

Pseudocode:

y = y1 for x = x1 to x2 begin setpixel (x, round(y)) y = y + dd end

slide-62
SLIDE 62

Digital Differential Analyzer

62

slide-63
SLIDE 63

Watch for line slope

63

 if abs(dd) > 1  exchange x↔y

in algorithm

slide-64
SLIDE 64

Bresenham algorithm

64

 DDA requires floating point  Bresenham works with integers only  main idea: for each x there are only 2 possible y values,

pick the one with the smaller error. accumulate error

  • ver iterations.

 modify for other slopes and

  • rientations
slide-65
SLIDE 65

Circle, ellipse rasterization

65

 Bresenham for circles (midpoint algorithm)  Can be modified for ellipses

slide-66
SLIDE 66

Polygon rasterization

66

Scanline algorithm: For each scan line:

  • 1. Find the intersections of polygon and the scan line
  • 2. Sort the intersections by x coordinate
  • 3. Fill the pixels between subsequent pairs of intersections
slide-67
SLIDE 67

Scan-line algorithm

67

slide-68
SLIDE 68

Scan-line algorithm

68

 (works also for non-convex polygons)

slide-69
SLIDE 69

Filled polygon

69

 How to draw all pixels inside a polygon?

slide-70
SLIDE 70

Filled polygon

70

 We need to determine INSIDE / OUTSIDE

slide-71
SLIDE 71

Filled polygon

71

 We need to determine INSIDE / OUTSIDE

slide-72
SLIDE 72

Filled polygon

72

 We need to determine INSIDE / OUTSIDE

slide-73
SLIDE 73

Filled polygon

73

 We need to determine INSIDE / OUTSIDE

slide-74
SLIDE 74

Filled polygon

74

 We need to determine INSIDE / OUTSIDE

slide-75
SLIDE 75

Filled polygon

75

 We need to determine INSIDE / OUTSIDE

slide-76
SLIDE 76

Filled polygon

76

 We need to determine INSIDE / OUTSIDE

slide-77
SLIDE 77

Filled polygon

77

 If convex / concave vertices are handled correctly

slide-78
SLIDE 78

Filled triangle

78

 Polygons defined using triangles  Lets draw triangles instead

slide-79
SLIDE 79

Filled triangle

79

 Split triangle horizontally into two parts  Use linear interpolation to draw lines

slide-80
SLIDE 80

Filled triangle

80

 Fill using horizontal lines

A B C

slide-81
SLIDE 81

Filled triangle

81

 Fill using horizontal lines

𝑌 = 𝑚𝑓𝑠𝑞(𝐵, 𝐷, 𝑢1) 𝑍 = 𝑚𝑓𝑠𝑞(𝐶, 𝐷, 𝑢1) 𝑎 = 𝑚𝑓𝑠𝑞(𝑌, 𝑍, 𝑢2)

A B C X Y Z 𝑢1 𝑢2

slide-82
SLIDE 82

Rasterization alias

82

slide-83
SLIDE 83

Aliasing

83

 continuous → discrete, artifacts might appear  rasterization alias – jagged edges  sampling

 creating

  • bservation of

continuous phenomenon in discrete intervals

 sampling frequency

 pixel density

slide-84
SLIDE 84

Forms of alias

84

 spatial alias

 jaggy edges  moiré  texture

distortion

 temporal

 “wagon wheel”

slide-85
SLIDE 85

Anti-aliasing

85

 general (global) anti-aliasing - supersampling

 works on all objects

 object (local) anti-aliasing

 line anti-aliasing  silhouette anti-aliasing  texture anti-aliasing

slide-86
SLIDE 86

Super-sampling

86

 For each pixel perform multiple

sub-pixel observations and combine the results

Regular (grid) Random (stochastic) Poisson Jitter

slide-87
SLIDE 87

Super-sampling

87

slide-88
SLIDE 88

Super-sampling

88

slide-89
SLIDE 89

Super-sampling

89

slide-90
SLIDE 90

Next lessons

90

3D polygons Modeling Transformation Lighting Viewing Transformation Projection Transformation Clipping Scan Conversion 2D Image

1

Shading and Lighting (06)

slide-91
SLIDE 91

Rest of rendering pipeline - next lessons

91

3D polygons Modeling Transformation Lighting Viewing Transformation Projection Transformation Clipping Scan Conversion 2D Image

1

Visibility, Culling, Cropping (07)

slide-92
SLIDE 92

92

Shading and Lighting

Next Week

slide-93
SLIDE 93

93

Acknowledgements

 Thanks to all the people, whose work is shown here and whose

slides were used as a material for creation of these slides:

Matej Novotný, GSVM lectures at FMFI UK Peter Drahoš, PPGSO lectures at FIIT STU

slide-94
SLIDE 94

94

www.slido.com #PPGSO03 martin.madaras@stuba.sk

Questions ?!