Graphics Primer Lecture 2 January 14, 2020 Introduction Computer - - PowerPoint PPT Presentation

graphics primer
SMART_READER_LITE
LIVE PREVIEW

Graphics Primer Lecture 2 January 14, 2020 Introduction Computer - - PowerPoint PPT Presentation

CS530 - Spring 2020 Introduction to Scientific Visualization Graphics Primer Lecture 2 January 14, 2020 Introduction Computer Graphics vs. Visualization Visualization methods transform data into primitives that are rendered using CG


slide-1
SLIDE 1

CS530 - Spring 2020

Introduction to Scientific Visualization

Lecture

Graphics Primer

January 14, 2020

2

slide-2
SLIDE 2

CS530 / Spring 2020 : Introduction to Scientific Visualization. Graphics Primer 01/14/2020

Introduction

Computer Graphics vs. Visualization

“Visualization methods transform data into primitives that are rendered using CG techniques”

Today’s objective: understand basic concepts of CG necessary to use a visualization library like VTK

2

slide-3
SLIDE 3

CS530 / Spring 2020 : Introduction to Scientific Visualization. Graphics Primer 01/14/2020

Outline

Graphics Primitives Colors Shading Rasterization Cameras Fundamental Techniques

3

slide-4
SLIDE 4

CS530 / Spring 2020 : Introduction to Scientific Visualization. Graphics Primer 01/14/2020

Points

Positions in space 2D(x,y), 3D(x,y,z) coordinates “0-dimensional” objects

Graphics Primitives

4

slide-5
SLIDE 5

CS530 / Spring 2020 : Introduction to Scientific Visualization. Graphics Primer 01/14/2020

Graphics Primitives

Lines

1-dimensional objects Polygonal description (”polyline”)

piecewise linear

5

slide-6
SLIDE 6

CS530 / Spring 2020 : Introduction to Scientific Visualization. Graphics Primer 01/14/2020

Lines

1-dimensional objects Parametric description

(e.g., splines)

6

Graphics Primitives

P : t 2 I 7! P(t) 2 I Rn P(t)

slide-7
SLIDE 7

CS530 / Spring 2020 : Introduction to Scientific Visualization. Graphics Primer 01/14/2020

Graphics Primitives

Surfaces

2-dimensional objects (in 3D) Polygonal description

Triangle mesh (piecewise linear)

7

slide-8
SLIDE 8

CS530 / Spring 2020 : Introduction to Scientific Visualization. Graphics Primer 01/14/2020

Surfaces

2-dimensional objects Parametric description

bi-quadratic, bi-cubic, Bezier, splines, NURBS...

Graphics Primitives

8

P : (u, v) ⇤ I J ⌅⇥ P(u, v) ⇤ I Rn

slide-9
SLIDE 9

CS530 / Spring 2020 : Introduction to Scientific Visualization. Graphics Primer 01/14/2020

Primitive Attributes

9

Color Normal Texture coordinates Opacity

slide-10
SLIDE 10

CS530 / Spring 2020 : Introduction to Scientific Visualization. Graphics Primer 01/14/2020

Outline

Graphics Primitives Colors Shading Rasterization Cameras Fundamental Techniques

10

slide-11
SLIDE 11

CS530 / Spring 2020 : Introduction to Scientific Visualization. Graphics Primer 01/14/2020

Colors

RGB system

11

Black 0,0,0 White 1,1,1 Red 1,0,0 Green 0,1,0 Blue 0,0,1 Yellow 1,1,0 Cyan 0,1,1 Magenta 1,0,1 Sky Blue 1/2,1/2, 1

slide-12
SLIDE 12

CS530 / Spring 2020 : Introduction to Scientific Visualization. Graphics Primer 01/14/2020

Colors

RGB system encodes colors with 3 scalars Simplified models of human color perception More on the topic next week!

12

slide-13
SLIDE 13

CS530 / Spring 2020 : Introduction to Scientific Visualization. Graphics Primer 01/14/2020

Outline

Graphics Primitives Colors Shading Rasterization Cameras Fundamental Techniques

13

slide-14
SLIDE 14

CS530 / Spring 2020 : Introduction to Scientific Visualization. Graphics Primer 01/14/2020

Shading

Shading reveals the shape of 3D objects through their interaction with light Shading creates colors as a function of:

surface properties surface normals lights

Only covering basics here Surfaces show information, lights show surfaces, shading controls how

14

slide-15
SLIDE 15

CS530 / Spring 2020 : Introduction to Scientific Visualization. Graphics Primer 01/14/2020

Phong lighting model (1975): Light reflected by

surface is combination of:

Specular reflection Diffuse reflection Ambient reflection

15

Shading

slide-16
SLIDE 16

CS530 / Spring 2020 : Introduction to Scientific Visualization. Graphics Primer 01/14/2020

Phong lighting model (1975): Light reflected by

surface is combination of:

Specular reflection Diffuse reflection Ambient reflection

15

Shading

slide-17
SLIDE 17

CS530 / Spring 2020 : Introduction to Scientific Visualization. Graphics Primer 01/14/2020

Phong lighting model (1975): Light reflected by

surface is combination of:

Specular reflection Diffuse reflection Ambient reflection

15

Shading

slide-18
SLIDE 18

CS530 / Spring 2020 : Introduction to Scientific Visualization. Graphics Primer 01/14/2020

Phong lighting model (1975): Light reflected by

surface is combination of:

Specular reflection Diffuse reflection Ambient reflection

15

Shading

http://en.wikipedia.org/wiki/Phong_shading

slide-19
SLIDE 19

CS530 / Spring 2020 : Introduction to Scientific Visualization. Graphics Primer 01/14/2020

Phong lighting model: Ambient reflection

16

Shading

slide-20
SLIDE 20

CS530 / Spring 2020 : Introduction to Scientific Visualization. Graphics Primer 01/14/2020

Phong lighting model: Ambient reflection

I = ksIs + kdId + kaIa

Light intensity per light source and per color channel

16

Shading

slide-21
SLIDE 21

CS530 / Spring 2020 : Introduction to Scientific Visualization. Graphics Primer 01/14/2020

Phong lighting model: Ambient reflection

I = ksIs + kdId + kaIa

Light intensity per light source and per color channel

16

Shading

relative contributions (material specific)

slide-22
SLIDE 22

CS530 / Spring 2020 : Introduction to Scientific Visualization. Graphics Primer 01/14/2020

Phong lighting model: Ambient reflection

I = ksIs + kdId + kaIa

Light intensity per light source and per color channel

16

Shading

relative contributions (material specific)

slide-23
SLIDE 23

CS530 / Spring 2020 : Introduction to Scientific Visualization. Graphics Primer 01/14/2020

Shading

Phong lighting model: Specular Reflection

mirror-like surfaces Specular reflection depends on position of the observer relative to light source and surface normal

17

⇥ l

⇥ n ⇥ r

⇥ v

θ θ

γ

slide-24
SLIDE 24

CS530 / Spring 2020 : Introduction to Scientific Visualization. Graphics Primer 01/14/2020

Shading

Phong lighting model: Specular Reflection

  • 18

⇥ l

⇥ n ⇥ r

⇥ v

θ θ

γ

Is = Ii cosn = Ii cosn < r, v >

slide-25
SLIDE 25

CS530 / Spring 2020 : Introduction to Scientific Visualization. Graphics Primer 01/14/2020

Shading

Phong lighting model: Diffuse Reflection

Non-shiny surfaces Diffuse reflection depends only on relative position of light source and surface normal.

19

⇥ l

⇥ n

θ

slide-26
SLIDE 26

CS530 / Spring 2020 : Introduction to Scientific Visualization. Graphics Primer 01/14/2020

Shading

Phong lighting model: Diffuse Reflection

20

Id = Ii cos = Ii cos < l, n >

⇥ l

⇥ n

θ

Id = Ii cos ✓ = Ii (~ l · ~ n)

slide-27
SLIDE 27

CS530 / Spring 2020 : Introduction to Scientific Visualization. Graphics Primer 01/14/2020

Phong lighting model

21

Shading

⇥ l

⇥ n ⇥ r

⇥ v

θ θ

γ

sum over all light sources ambient light

per color channel

I = kaIa +

N

X

i=1

Ii (kd cos(θ) + ks cosn(γ))

diffuse specular

slide-28
SLIDE 28

CS530 / Spring 2020 : Introduction to Scientific Visualization. Graphics Primer 01/14/2020

Outline

Graphics Primitives Colors Shading Rasterization Cameras Fundamental Techniques

22

slide-29
SLIDE 29

CS530 / Spring 2020 : Introduction to Scientific Visualization. Graphics Primer 01/14/2020

Rasterization

Putting shaded polygons on screen

Transform geometric primitives into pixels

Lowest level: scan conversion

Bresenham, midpoint algorithms

23

slide-30
SLIDE 30

CS530 / Spring 2020 : Introduction to Scientific Visualization. Graphics Primer 01/14/2020

Rasterization

Putting shaded polygons on screen

Transform geometric primitives into pixels

Lowest level: scan conversion

Bresenham, midpoint algorithms

23

slide-31
SLIDE 31

CS530 / Spring 2020 : Introduction to Scientific Visualization. Graphics Primer 01/14/2020

Rasterization

Putting shaded polygons on screen

Transform geometric primitives into pixels

Lowest level: scan conversion

Bresenham, midpoint algorithms

23

slide-32
SLIDE 32

CS530 / Spring 2020 : Introduction to Scientific Visualization. Graphics Primer 01/14/2020

Rasterization

Putting shaded polygons on screen

Transform geometric primitives into pixels

Lowest level: scan conversion

Bresenham, midpoint algorithms

23

slide-33
SLIDE 33

CS530 / Spring 2020 : Introduction to Scientific Visualization. Graphics Primer 01/14/2020

Rasterization

Putting shaded polygons on screen

Transform geometric primitives into pixels

Lowest level: scan conversion

Bresenham, midpoint algorithms

23

slide-34
SLIDE 34

CS530 / Spring 2020 : Introduction to Scientific Visualization. Graphics Primer 01/14/2020

Rasterization

Putting shaded polygons on screen

Transform geometric primitives into pixels

OpenGL (graphics library) takes care of such operations (under the hood in VTK)

24

slide-35
SLIDE 35

CS530 / Spring 2020 : Introduction to Scientific Visualization. Graphics Primer 01/14/2020

Back to Shading

Flat shading

25

(Color constant per polygon)

slide-36
SLIDE 36

CS530 / Spring 2020 : Introduction to Scientific Visualization. Graphics Primer 01/14/2020

Back to Shading

Gouraud shading (1971)

Shade vertices first, then interpolate* colors

26

(*) More on interpolation in the coming weeks...

slide-37
SLIDE 37

CS530 / Spring 2020 : Introduction to Scientific Visualization. Graphics Primer 01/14/2020

Back to Shading

Phong shading

Interpolate normals and shade every pixel separately

Note: Phong lighting model ≠ Phong shading

27

slide-38
SLIDE 38

CS530 / Spring 2020 : Introduction to Scientific Visualization. Graphics Primer 01/14/2020

Outline

Graphics Primitives Colors Shading Rasterization Cameras Fundamental Techniques

28

slide-39
SLIDE 39

CS530 / Spring 2020 : Introduction to Scientific Visualization. Graphics Primer 01/14/2020

Projections

Perspective projection

parallel lines do not necessarily remain parallel

  • bjects get larger as

they get closer fly-through realism

29

slide-40
SLIDE 40

CS530 / Spring 2020 : Introduction to Scientific Visualization. Graphics Primer 01/14/2020

Camera

30

View angle Front clipping plane Back clipping plane Focal point Camera position View up Direction of projection Image plane

Only primitives located between front and back clipping planes will be rendered.

slide-41
SLIDE 41

CS530 / Spring 2020 : Introduction to Scientific Visualization. Graphics Primer 01/14/2020

Camera

Degrees of freedom

31

Roll Focal Point Azimuth Elevation Direction of projection

slide-42
SLIDE 42

CS530 / Spring 2020 : Introduction to Scientific Visualization. Graphics Primer 01/14/2020

Outline

Graphics Primitives Colors Shading Rasterization Cameras Fundamental Techniques

32

slide-43
SLIDE 43

CS530 / Spring 2020 : Introduction to Scientific Visualization. Graphics Primer 01/14/2020

Fundamental Techniques

Backface culling Z-buffer Alpha blending Depth peeling

33

slide-44
SLIDE 44

CS530 / Spring 2020 : Introduction to Scientific Visualization. Graphics Primer 01/14/2020

Fundamental Techniques

Back-face culling

Determine whether a polygon is visible (i.e., should be rendered) Check polygon normal against camera viewing direction: remove polygons that are

34

< ⌃ v,⌃ n >> 0?

slide-45
SLIDE 45

CS530 / Spring 2020 : Introduction to Scientific Visualization. Graphics Primer 01/14/2020

Fundamental Techniques

Back-face culling

Determine whether a polygon is visible (i.e., should be rendered) Check polygon normal against camera viewing direction: remove polygons that are

34

< ⌃ v,⌃ n >> 0?

slide-46
SLIDE 46

CS530 / Spring 2020 : Introduction to Scientific Visualization. Graphics Primer 01/14/2020

Fundamental Techniques

Back-face culling

Determine whether a polygon is visible (i.e., should be rendered) Check polygon normal against camera viewing direction: remove polygons that are

34

< ⌃ v,⌃ n >> 0?

slide-47
SLIDE 47

CS530 / Spring 2020 : Introduction to Scientific Visualization. Graphics Primer 01/14/2020

Fundamental Techniques

Back-face culling

Determine whether a polygon is visible (i.e., should be rendered) Check polygon normal against camera viewing direction: remove polygons that are

34

< ⌃ v,⌃ n >> 0?

If some objects do not show up/are black in your visualization: check your normals!

slide-48
SLIDE 48

CS530 / Spring 2020 : Introduction to Scientific Visualization. Graphics Primer 01/14/2020

Fundamental Techniques

Z-buffer algorithm

Maintain a z-buffer of same resolution as frame buffer During scan conversion compare z- coord of pixel to be stored with z- coord of current pixel in z-buffer

35

slide-49
SLIDE 49

CS530 / Spring 2020 : Introduction to Scientific Visualization. Graphics Primer 01/14/2020

Fundamental Techniques

Z-buffer algorithm

36

gray value indicates distance to image plane

slide-50
SLIDE 50

CS530 / Spring 2020 : Introduction to Scientific Visualization. Graphics Primer 01/14/2020

Fundamental Techniques

Alpha blending / compositing

Approximate visual appearance of semi-transparent object in front of another object Implemented with OVER operator

37

slide-51
SLIDE 51

CS530 / Spring 2020 : Introduction to Scientific Visualization. Graphics Primer 01/14/2020

Fundamental Techniques

Alpha blending / compositing

Approximate visual appearance of semi-transparent object in front of another object Implemented with OVER operator

37

cb = (1,0,0) ab = 0.9 cf = (0,1,0) af = 0.4 c = af*cf + (1 - af)*ab*cb a = af + (1 - af)*ab c = (0.54,0.4,0) a = 0.94

slide-52
SLIDE 52

CS530 / Spring 2020 : Introduction to Scientific Visualization. Graphics Primer 01/14/2020

Fundamental Techniques

Alpha blending / compositing

Approximate visual appearance of semi-transparent object in front of another object Implemented with OVER operator

37

cb = (1,0,0) ab = 0.9 cf = (0,1,0) af = 0.4 c = af*cf + (1 - af)*ab*cb a = af + (1 - af)*ab c = (0.54,0.4,0) a = 0.94

Alpha blending is used in volume rendering and depth peeling. More on this later...

slide-53
SLIDE 53

CS530 / Spring 2020 : Introduction to Scientific Visualization. Graphics Primer 01/14/2020

Fundamental Techniques

Depth Peeling

Order-independent transparency Use 2 z-buffers and multiple rendering passes

38

slide-54
SLIDE 54

CS530 / Spring 2020 : Introduction to Scientific Visualization. Graphics Primer 01/14/2020

1 1

Fundamental Techniques

Depth Peeling

39

slide-55
SLIDE 55

CS530 / Spring 2020 : Introduction to Scientific Visualization. Graphics Primer 01/14/2020

1 1

Fundamental Techniques

Depth Peeling

39

2 2

slide-56
SLIDE 56

CS530 / Spring 2020 : Introduction to Scientific Visualization. Graphics Primer 01/14/2020

1 1

Fundamental Techniques

Depth Peeling

39

2 2 3 3

slide-57
SLIDE 57

CS530 / Spring 2020 : Introduction to Scientific Visualization. Graphics Primer 01/14/2020

1 1

Fundamental Techniques

Depth Peeling

39

2 2 3 3 4 4

slide-58
SLIDE 58

CS530 / Spring 2020 : Introduction to Scientific Visualization. Graphics Primer 01/14/2020

1 1

Fundamental Techniques

Depth Peeling

39

2 2 3 3 4 4

Depth peeling is the only way to get correct transparency results in VTK. Make sure to use it!

slide-59
SLIDE 59

CS530 / Spring 2020 : Introduction to Scientific Visualization. Graphics Primer 01/14/2020

Fundamental Algorithms

Ray-tracing algorithm

Send ray from pixel into view volume Determine which surface is struck first Combined with lighting algorithm

40

slide-60
SLIDE 60

CS530 / Spring 2020 : Introduction to Scientific Visualization. Graphics Primer 01/14/2020

Homework

  • Install VTK

41

https://www.cs.purdue.edu/homes/cs530/projects/project0.html