Shading and Lighting (04) RNDr. Martin Madaras, PhD. - - PowerPoint PPT Presentation

shading and lighting 04
SMART_READER_LITE
LIVE PREVIEW

Shading and Lighting (04) RNDr. Martin Madaras, PhD. - - PowerPoint PPT Presentation

Fundamentals of Computer Graphics and Image Processing Shading and Lighting (04) RNDr. Martin Madaras, PhD. madaras@skeletex.xyz Overview Direct Illumination Emission at light sources Scattering at surfaces Gouraud shading


slide-1
SLIDE 1

Fundamentals of Computer Graphics and Image Processing

Shading and Lighting (04)

  • RNDr. Martin Madaras, PhD.

madaras@skeletex.xyz

slide-2
SLIDE 2

Overview

2

 Direct Illumination

 Emission at light sources  Scattering at surfaces  Gouraud shading

 Global Illumination

 Shadows  Refractions  Inter-object reflections

slide-3
SLIDE 3

3

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

How the lectures should look like #1

slide-4
SLIDE 4

Overview

4

 𝐽𝑀(𝑦, 𝑧, 𝑨, 𝜄, 𝜒, 𝜇)

 describes intensity of energy,  leaving a light source, ...  arriving at location (x,y,z), ...  from direction (θ,φ), ...  with wavelength λ

slide-5
SLIDE 5

Light Source types

5

 Omnidirectional  Spotlight  Area  Directional  Object

  • what are the differences?
slide-6
SLIDE 6

Light Source Models

6

 Simple mathematical models  OpenGL support

 Point light  Directional light  Spot light

slide-7
SLIDE 7

Point Light Source

7

 Models omni-directional source

 intensity (𝐽0),  position (𝑦, 𝑧, 𝑨),  factors (𝑙𝑑, 𝑙𝑚, 𝑙𝑟) for attenuation with distance (𝑒)

slide-8
SLIDE 8

Directional Light Source

8

 Models point light source at infinity

 intensity (𝐽0),  direction (𝑒𝑦, 𝑒𝑧, 𝑒𝑨),  no attenuation with distance

slide-9
SLIDE 9

Spot Light Source

9

 Models point light source with direction

 intensity (𝐽0),  position (𝑦, 𝑧, 𝑨),  direction (𝑒),  attenuation 𝑙𝑑, 𝑙𝑚, 𝑙𝑟 .

slide-10
SLIDE 10

Overview

10

 Direct Illumination

 Emission at light sources  Scattering at surfaces  Gouraud shading

 Global Illumination

 Shadows  Refractions  Inter-object reflections

slide-11
SLIDE 11

Elementary theory

11

 Light-surface interaction  Reflection  Refraction

 Snell’s law

 Surface normal

vector

 Real world is a bit different

slide-12
SLIDE 12

Surface types

12

 Reflective  Diffuse – Lambertian  Both

slide-13
SLIDE 13

Surface types

13

Mirror Matte directional indirectional component component

slide-14
SLIDE 14

Light models

14

 Empiric – e.g. Phong lighting model

 cheap computation  physically incorrect  visually plausible

 Physically-based

 energy transfer, light propagation  closer to real-world physics  expensive

slide-15
SLIDE 15

Local illumination models

15

 Fast but inaccurate  Empirical (no physical background)  Many physical effects are impossible to achieve  Computer games, real-time rendering

slide-16
SLIDE 16

Modeling Surface Reflectance

16

 Rs(θ,φ,γ,ψ,λ) ...

 describes the amount of incident energy, ...  arriving from direction (θ,φ), ...  leaving in direction (γ,ψ), ...  with wavelength λ

slide-17
SLIDE 17

OpenGL Reflectance Model

17

 Simple empirical model:

 diffuse reflection +  specular reflection +  emission +  “ambient”  Bui Tuong Phong, 1973

slide-18
SLIDE 18

OpenGL Reflectance Model

18

 Simple empirical model:

 diffuse reflection +  specular reflection +  emission +  “ambient”

slide-19
SLIDE 19

Diffuse Reflection

19

 Assume surface reflects equally in all directions

 Examples: chalk, clay

slide-20
SLIDE 20

Diffuse Reflection

20

 How is light reflected ?

 Depends on an angle of incident light

slide-21
SLIDE 21

Diffuse Reflection

21

 How is light reflected ?

 Depends on an angle of incident light

slide-22
SLIDE 22

Diffuse Reflection

22

 Lambertian model

 cosine law (dot product)

slide-23
SLIDE 23

OpenGL Reflectance Model

23

 Simple empirical model:

 diffuse reflection +  specular reflection +  emission +  “ambient”

slide-24
SLIDE 24

Specular Reflection

24

 Reflection is strongest near mirror angle

 Examples: Mirrors, Metals

slide-25
SLIDE 25

Specular Reflection

25

 How much light is seen ?  Depends on:

 angle of incident light  angle of viewer

slide-26
SLIDE 26

Specular Reflection

26

 Phong Model

 cos(α)n This is a physically motivated hack!

slide-27
SLIDE 27

OpenGL Reflectance Model

27

 Simple empirical model:

 diffuse reflection +  specular reflection +  emission +  “ambient”

slide-28
SLIDE 28

Emission

28

 Represents light emitted directly from surface

slide-29
SLIDE 29

OpenGL Reflectance Model

29

 Simple empirical model:

 diffuse reflection +  specular reflection +  emission +  “ambient”

slide-30
SLIDE 30

Ambient term

30

 Represents reflection of all indirect illumination  This is a total hack

 (avoids complexity of global illumination)!

slide-31
SLIDE 31

OpenGL Reflectance Model

31

 Simple empirical model:

 diffuse reflection +  specular reflection +  emission +  “ambient”

slide-32
SLIDE 32

OpenGL Reflectance Model

32

 Simple empirical model:

 diffuse reflection +  specular reflection +  emission +  “ambient”

slide-33
SLIDE 33

OpenGL Reflectance Model

33

 Simple empirical model:

 diffuse reflection +  specular reflection +  emission +  “ambient”

slide-34
SLIDE 34

Diffuse light

34

slide-35
SLIDE 35

Ambient light

35

slide-36
SLIDE 36

Diffuse + Ambient light

36

slide-37
SLIDE 37

Specular + Diffuse + Ambient light

37

slide-38
SLIDE 38

Phong lighting model

38

 Ambient + Diffuse + Specular components  Simulates global light scattered in the scene and reflected

from other objects

without ambient with ambient

slide-39
SLIDE 39

Other lighting models

39

 Blinn-Phong

 generalization of Phong’s model

 Cook-Torrance

 microfacets

 Oren-Nayar

 rough surfaces

 Anisotropic microfacet distribution

slide-40
SLIDE 40

Direct Illumination

40

 Single light source example

slide-41
SLIDE 41

Direct Illumination

41

 Multiple light source example

slide-42
SLIDE 42

3D rendering pipeline

42

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

1

Draw pixels

slide-43
SLIDE 43

Ray Casting

43

 Independent lighting calculation for each pixel

 Computationally expensive

slide-44
SLIDE 44

Polygon Shading

44

 Can take advantage of spatial coherence

 Illumination calculations of pixels of a triangle are related  Scanline rasterization

slide-45
SLIDE 45

Surface normal vector

45

 Perpendicular to the surface at the point  Computation:

 Usually from tangent vectors  Vector cross product  Depends on the

  • bject representation

 Vector

normalization

v u n     = n n n   = ˆ u  v  n 

slide-46
SLIDE 46

Tangent vectors

46

 Parametric representation

 X = x(u,v)  Y = y(u,v)  Z = z(u,v)

 Partial derivation by u,v → vectors tu, tv

 Polygonal representation

 Tangent vectors are edge vectors  Mind the orientation!

slide-47
SLIDE 47

Overview

47

 Global Illumination

 Shadows  Refractions  Inter-object reflections

 Shading

 Flat  Gouraud  Phong

slide-48
SLIDE 48

Flat Shading

48

 Fill triangles using single calculated color

slide-49
SLIDE 49

Flat Shading

49

 One Illumination calculation per polygon  Assign all pixels of each polygon the same color

slide-50
SLIDE 50

Flat Shading

50

 Objects look like they are composed of polygons  Ok for polyhedral objects  Not so good for smooth surfaces

slide-51
SLIDE 51

Gouraud Shading

51

 One lighting calculation per vertex  Assign pixels inside polygon by interpolating colors

computed at vertices

slide-52
SLIDE 52

Gouraud Shading

52

 Bilinearly interpolate colors of triangle across scan line

slide-53
SLIDE 53

Gouraud Shading

53

 Smooth shading over adjacent polygons

 Curved surfaces  Illumination highlights

 Produces smoothly shaded polygonal mesh

 Fast linear approximation  Needs fine mesh to capture subtle lighting effects

slide-54
SLIDE 54

Gouraud Shading

54

slide-55
SLIDE 55

Phong Shading

55

 NOT Phong lighting model  One lighting calculation per pixel

 Approximate surface normals inside polygon using bilinear

interpolation of normals from vertices

slide-56
SLIDE 56

Phong Shading

56

 Bilinearly interpolate surface normals at vertices down

and across scan lines

slide-57
SLIDE 57

Polygon Shading Algorithms

57

slide-58
SLIDE 58

Example: Wireframe scene

58

slide-59
SLIDE 59

Example: Ambient only

59

slide-60
SLIDE 60

Example: Flat shading with Diffuse

60

slide-61
SLIDE 61

Example: Gouraud shading with Diffuse

61

slide-62
SLIDE 62

Example: Gouraud shading with Specular

62

slide-63
SLIDE 63

Example: Phong shading with Specular

63

slide-64
SLIDE 64

Shading Issues

64

 Problems with interpolated shading

 Problems computing shared vertex normals  Perspective distortion  Problems at T

  • vertices
slide-65
SLIDE 65

Shading Benefits

65

 Good performance and quality of output

 Excellent for hardware  Works well with subdivision surfaces

slide-66
SLIDE 66

66

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

How the lectures should look like #2

slide-67
SLIDE 67

Overview

67

 Advanced Shading and Mapping

 Deferred Shading  Shadow Mapping  Normal Mapping  Displacement Mapping  Vector Displacement Mapping

slide-68
SLIDE 68

Deferred Shading

68

 Compute Lighting in Screen-Space  Two pass approach  Decoupling of geometry and lighting  G-Buffer stores positions, normals, materials …  Lighting is a per-pixel operation  Problems with transparency and G-buffer size  O(objects+lights)

slide-69
SLIDE 69

Deferred Shading

69

Diffuse Color Z Buffer Surface Normals Final Composition

slide-70
SLIDE 70

Shadow Mapping

70

 Two pass technique  Obtain Light view depth buffer  Compare each pixel rendered to with light depth  Pixels further away are in shadow  Needs margin of error for lit pixels  Implementation usually has artifacts

slide-71
SLIDE 71

Shadow Mapping

71

slide-72
SLIDE 72

Normal Mapping

72

 Fake lighting of bumps and dents  “Dot3 bump mapping”  Add lighting details without additional geometry  Store normals from high-polygon object in texture  Encode X,Y,Z as R,G,B color information

slide-73
SLIDE 73

Normal Mapping

73

slide-74
SLIDE 74

Normal Mapping

74

a)

Normal map

(encoded in object space)

b)

Original high-res model

c)

Rendered low-res model

d)

Applied normal map

slide-75
SLIDE 75

Displacement Mapping

75

 Move geometry as specified in texture  Displacement in direction of surface normal  Can add additional detail to a subdivided model  Relies on dense geometry  Usually used with adaptive tessellation techniques

slide-76
SLIDE 76

Displacement Mapping

76

slide-77
SLIDE 77

Vector Displacement Mapping

77

 Displace geometry in any direction  Generalization of displacement mapping  Possible to store detailed geometry in textures  Excellent for sculpting purposes (Z-Brush)

slide-78
SLIDE 78

Vector Displacement Mapping

78

slide-79
SLIDE 79

79

Visibility, Culling

Next Week

slide-80
SLIDE 80

80

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 Output of all the publications and great team work Very best data from 3D cameras

slide-81
SLIDE 81

81

www.skeletex.xyz madaras@skeletex.xyz

Questions ?!