•the graphics pipeline: illumination and shading · 2018-07-20 · 1 graphics lecture 3: slide 1...

14
1 Graphics Lecture 3: Slide 1 Interactive Computer Graphics • The Graphics Pipeline: Illumination and Shading Some slides adopted from F. Durand and B. Cutler, MIT Graphics Lecture 3: Slide 2 The Graphics Pipeline Modelling Transformations Illumination (Shading) Viewing Transformation (Perspective / Orthographic) Clipping Projection (to Screen Space) Scan Conversion (Rasterization) Visibility / Display Output: 2D image for framebuffer display Input: - geometric model - illumination model - camera model - viewport Graphics Lecture 3: Slide 3 Modelling Transformations Illumination (Shading) Viewing Transformation (Perspective / Orthographic) Clipping Projection (to Screen Space) Scan Conversion (Rasterization) Visibility / Display The Graphics Pipeline 3D models are defined in their own coordinate system Modeling transformations orient the models within a common coordinate frame (world coordinates) Graphics Lecture 3: Slide 4 Modelling Transformations Illumination (Shading) Viewing Transformation (Perspective / Orthographic) Clipping Projection (to Screen Space) Scan Conversion (Rasterization) Visibility / Display The Graphics Pipeline Vertices are lit (shaded) according to material properties, surface properties and light sources Uses a local lighting model

Upload: others

Post on 26-Jul-2020

3 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: •The Graphics Pipeline: Illumination and Shading · 2018-07-20 · 1 Graphics Lecture 3: Slide 1 Interactive Computer Graphics •The Graphics Pipeline: Illumination and Shading

1

Graphics Lecture 3: Slide 1

Interactive Computer Graphics

• The Graphics Pipeline: Illumination and Shading

Some slides adopted from F. Durand and B. Cutler, MIT

Graphics Lecture 3: Slide 2

The Graphics PipelineModelling

Transformations

Illumination(Shading)

Viewing Transformation(Perspective / Orthographic)

Clipping

Projection(to Screen Space)

Scan Conversion(Rasterization)

Visibility / Display Output: 2D imagefor framebuffer display

Input:- geometric model- illumination model- camera model- viewport

Graphics Lecture 3: Slide 3

Modelling Transformations

Illumination(Shading)

Viewing Transformation(Perspective / Orthographic)

Clipping

Projection(to Screen Space)

Scan Conversion(Rasterization)

Visibility / Display

The Graphics Pipeline

• 3D models are defined in theirown coordinate system

• Modeling transformationsorient the models within acommon coordinate frame(world coordinates)

Graphics Lecture 3: Slide 4

Modelling Transformations

Illumination(Shading)

Viewing Transformation(Perspective / Orthographic)

Clipping

Projection(to Screen Space)

Scan Conversion(Rasterization)

Visibility / Display

The Graphics Pipeline

• Vertices are lit (shaded)according to materialproperties, surface propertiesand light sources

• Uses a local lighting model

Page 2: •The Graphics Pipeline: Illumination and Shading · 2018-07-20 · 1 Graphics Lecture 3: Slide 1 Interactive Computer Graphics •The Graphics Pipeline: Illumination and Shading

2

Graphics Lecture 3: Slide 5

Modelling Transformations

Illumination(Shading)

Viewing Transformation(Perspective / Orthographic)

Clipping

Projection(to Screen Space)

Scan Conversion(Rasterization)

Visibility / Display

The Graphics Pipeline

• Maps world space to eye(camera) space

• Viewing position istransformed to origin andviewing direction is orientedalong some axis (typically z)

Graphics Lecture 3: Slide 6

Modelling Transformations

Illumination(Shading)

Viewing Transformation(Perspective / Orthographic)

Clipping

Projection(to Screen Space)

Scan Conversion(Rasterization)

Visibility / Display

The Graphics Pipeline

• Transforms to Normalized DeviceCoordinates

• Portions of the scene outside theviewing volume (view frustum) areremoved (clipped)

Eye space NDC

Graphics Lecture 3: Slide 7

Modelling Transformations

Illumination(Shading)

Viewing Transformation(Perspective / Orthographic)

Clipping

Projection(to Screen Space)

Scan Conversion(Rasterization)

Visibility / Display

The Graphics Pipeline

• The objects are projected tothe 2D imaging plane (screenspace)

NDC Screen Space

Graphics Lecture 3: Slide 8

Modelling Transformations

Illumination(Shading)

Viewing Transformation(Perspective / Orthographic)

Clipping

Projection(to Screen Space)

Scan Conversion(Rasterization)

Visibility / Display

The Graphics Pipeline

• Rasterizes objects into pixels• Interpolate values inside

objects (color, depth, etc.)

Page 3: •The Graphics Pipeline: Illumination and Shading · 2018-07-20 · 1 Graphics Lecture 3: Slide 1 Interactive Computer Graphics •The Graphics Pipeline: Illumination and Shading

3

Graphics Lecture 3: Slide 9

Modelling Transformations

Illumination(Shading)

Viewing Transformation(Perspective / Orthographic)

Clipping

Projection(to Screen Space)

Scan Conversion(Rasterization)

Visibility / Display

The Graphics Pipeline

• Handles occlusions• Determines which objects are

closest and therefore visible

Graphics Lecture 3: Slide 10

The Physics of shading

• If we look at a point on an object we perceive acolour and a shading intensity that depends on thevarious characteristics of the object and the lightsources that illuminate it.

• For the time being we will consider only thebrightness at each point. We will extend the treatmentto colour later.

Graphics Lecture 3: Slide 11

The Physics of shading

• Object properties:– Looking at a point on an object we see the reflection of the

light that falls on it. This reflection is governed by:1. The position of the object relative to the light sources2. The surface normal vector3. The albedo of the surface (ability to adsorb light energy)4. The reflectivity of the surface

• Light source properties:– The important properties of the light source are1. Intensity of the emitted light2. The distance to the point on the surface

Graphics Lecture 3: Slide 12

Radiometry

• Energy of a photon

• Radiant Energy of n photons

• Radiation flux (electromagnetic flux, radiant flux)Units: Watts

dt

dQ=!

sm csJhhc

e /103 1063.6 834

!"!!"=#

$$

!=

=n

i i

hcQ

1 "

Page 4: •The Graphics Pipeline: Illumination and Shading · 2018-07-20 · 1 Graphics Lecture 3: Slide 1 Interactive Computer Graphics •The Graphics Pipeline: Illumination and Shading

4

Graphics Lecture 3: Slide 13

Radiometry

!"!

ddA

dL

cos)(

2#

=

steradianmeter

WattUnits

:

2

• Radiance – radiant flux per unit solid angle per unitprojected area

– Number of photons arriving per time at a small area from a particular direction

Graphics Lecture 3: Slide 14

Radiometry

• Irradiance – differential flux falling onto differentialarea

• Irradiance can be seen as a density of the incident fluxfalling onto a surface.

• It can be also obtained by integrating the radianceover the solid angle.

dA

dE

!=

2:meter

WattUnits

Graphics Lecture 3: Slide 15

Light Emission

• Light sources: sun, fire, light bulbs etc.• Consider a point light source that emits light

uniformly in all directions

Surface

θ

n

sourcelight the todistance

sourcelight theofpower

4

4

cos22

!

!"

"=

"=

d

dL

dE

s

ss

##

$

Graphics Lecture 3: Slide 16

Reflection & Reflectance

• Reflection - the process by which electromagnetic fluxincident on a surface leaves the surface without a change infrequency.

• Reflectance – a fraction of the incident flux that is reflected• We do not consider:

– absorption, transmission, fluorescence– diffraction

Page 5: •The Graphics Pipeline: Illumination and Shading · 2018-07-20 · 1 Graphics Lecture 3: Slide 1 Interactive Computer Graphics •The Graphics Pipeline: Illumination and Shading

5

Graphics Lecture 3: Slide 17

Reflectance

• Bidirectional Reflectance Distribution Function (BRDF)

θiθr

φi φr

),(

),(),,,(

iii

rrrrriir

dE

dLf

!"

!"!"!" =

steradianUnits

1:

LiLr

Graphics Lecture 3: Slide 18

Isotropic BRDFs

• Rotation along surface normal does not change reflectance

θiθr

φd

),(

),(),,(),,(

dii

drrdririrrir

dE

dLff

!"

!"!""!!"" ==#

LiLr

Graphics Lecture 3: Slide 19

Anisotropic BRDFs

• Surfaces with strongly oriented microgeometry elements• Examples:

– brushed metals,– hair, fur, cloth, velvet

Source: Westin et.al 92

Graphics Lecture 3: Slide 20

Properties of BRDFs

• Non-negativity

• Energy Conservation

• Reciprocity

),( allfor 1),(),,,( iirrrriir df !"!"µ!"!" #$%

),,,(),,,( iirrrrriir ff !"!"!"!" =

0),,,( !rriirf "#"#

Page 6: •The Graphics Pipeline: Illumination and Shading · 2018-07-20 · 1 Graphics Lecture 3: Slide 1 Interactive Computer Graphics •The Graphics Pipeline: Illumination and Shading

6

Graphics Lecture 3: Slide 21

Reflectance

• Bidirectional scattering-surface distribution Function(BSSRDF)

Surface

Jensen et al. SIGGRAPH 2001A Practical Model for Subsurface Light Transport

Graphics Lecture 3: Slide 22

How to compute reflected radiance?

• Continuous version

• Discrete version – n point light sources

iiiirir

iirirrr

dndLf

dEfL

!!!!!

!!!!

)cos()( ),(

)(),()(

"=

==

#

#

$

$

21

1

4

cos),(

),()(

j

sj

j

n

j

rijr

j

n

j

rijrrr

df

EfL

!"##

###

$=

==

%

%

=

=

),( !"# =

Graphics Lecture 3: Slide 23

Ideal Diffuse Reflectance

• Assume surface reflects equally in all directions.• An ideal diffuse surface is, at the microscopic level, a

very rough surface.– Example: chalk, clay, some paints

Surface

Graphics Lecture 3: Slide 24

Ideal Diffuse Reflectance

• BRDF value is constant

Surface

θi

dB

dA

!

Lr("r) = f r(" i,"r )#

$ dEi(" i) =

n

!

= fr dEi(" i)#

$ =

!

= frEi

Page 7: •The Graphics Pipeline: Illumination and Shading · 2018-07-20 · 1 Graphics Lecture 3: Slide 1 Interactive Computer Graphics •The Graphics Pipeline: Illumination and Shading

7

Graphics Lecture 3: Slide 25

• Ideal diffuse reflectors reflect light according to Lambert'scosine law.

Ideal Diffuse Reflectance

Graphics Lecture 3: Slide 26

Ideal Diffuse Reflectance

• Single Point Light Source– kd: The diffuse reflection coefficient.– n: Surface normal.– l: Light direction.

Surface

θl

n

Graphics Lecture 3: Slide 27

Ideal Diffuse Reflectance – More Details

• If n and l are facing away from each other, n • lbecomes negative.

• Using max((n • l), 0) makes sure that the result iszero.

– From now on, we mean max() when we write •.

Do not forget to normalize your vectors forthe dot product!

Graphics Lecture 3: Slide 28

Ideal Specular Reflectance

• Reflection is only at mirror angle.– View dependent– Microscopic surface elements are usually oriented in the

same direction as the surface itself.– Examples: mirrors, highly polished metals.

Surface

θl

n

Page 8: •The Graphics Pipeline: Illumination and Shading · 2018-07-20 · 1 Graphics Lecture 3: Slide 1 Interactive Computer Graphics •The Graphics Pipeline: Illumination and Shading

8

Graphics Lecture 3: Slide 29

Ideal Specular Reflectance

• Special case of Snell’s Law– The incoming ray, the surface normal, and the reflected ray

all lie in a common plane.

Surface

θl l

n

rθr

Graphics Lecture 3: Slide 30

Non-ideal Reflectors

• Snell’s law applies only to ideal mirror reflectors.• Real materials tend to deviate significantly from ideal

mirror reflectors.• They are not ideal diffuse surfaces either …

Graphics Lecture 3: Slide 31

Non-ideal Reflectors

• Simple Empirical Model:– We expect most of the reflected light to travel in the

direction of the ideal ray.– However, because of microscopic surface variations we

might expect some of the light to be reflected just slightlyoffset from the ideal reflected ray.

– As we move farther and farther, in the angular sense, fromthe reflected ray we expect to see less light reflected.

Graphics Lecture 3: Slide 32

Incident

Light

Perfectly Matt surface

The reflected intensity is the same in all directions

Incident

Light

Reflected

Direction

Slightly specular (shiny) surface

Slightly higher intensity in the reflected direction

Incident

Light

Reflected

Direction

Highly specular (shiny) surface

High intensity in the reflected direction

Incident

Light

Reflected

Direction

Perfect Mirror

All light re-admitted in the reflected direction

Non-ideal Reflectors: Surface Characteristics

Page 9: •The Graphics Pipeline: Illumination and Shading · 2018-07-20 · 1 Graphics Lecture 3: Slide 1 Interactive Computer Graphics •The Graphics Pipeline: Illumination and Shading

9

Graphics Lecture 3: Slide 33

The Phong Model

• How much light is reflected?– Depends on the angle between the ideal reflection direction

and the viewer direction α.

Surface

θl

nr

θCamera

v

α

Graphics Lecture 3: Slide 34

The Phong Model

• Parameters– ks: specular reflection coefficient– q : specular reflection exponent

Surface

θl

nr

θCamera

v

α

Graphics Lecture 3: Slide 35

The Phong Model

• Effect of the q coefficient

Graphics Lecture 3: Slide 36

The Phong Model

Surface

θl

n

θr

r

Page 10: •The Graphics Pipeline: Illumination and Shading · 2018-07-20 · 1 Graphics Lecture 3: Slide 1 Interactive Computer Graphics •The Graphics Pipeline: Illumination and Shading

10

Graphics Lecture 3: Slide 37

Blinn-Phong Variation

• Uses the halfway vector h between l and v.

Surface

l

n

Camerav

h

β

Graphics Lecture 3: Slide 38

Phong vs Blinn-Phong

• The following spheres illustrate specular reflections as thedirection of the light source and the coefficient of shininess isvaried.

Graphics Lecture 3: Slide 39

The Phong Model

• Sum of three components:diffuse reflection + specular reflection + ambient.

Surface

Graphics Lecture 3: Slide 40

Ambient Illumination

• Represents the reflection of all indirect illumination.• This is a total hack!• Avoids the complexity of global illumination.

Page 11: •The Graphics Pipeline: Illumination and Shading · 2018-07-20 · 1 Graphics Lecture 3: Slide 1 Interactive Computer Graphics •The Graphics Pipeline: Illumination and Shading

11

Graphics Lecture 3: Slide 41

Putting it all together

• Phong Illumination Model

Graphics Lecture 3: Slide 42

Putting it all together

• Phong Illumination Model

Graphics Lecture 3: Slide 43

Adding color

• Diffuse coefficients:– kd-red, kd-green, kd-blue

• Specular coefficients:– ks-red, ks-green, ks-blue

• Specular exponent:q

Graphics Lecture 3: Slide 44

Inverse Square Law

• It is well known that light falls off according to aninverse square law. Thus, if we have light sourcesclose to our polygons we should model this effect.

where d is the distance from the light source to theobject

Page 12: •The Graphics Pipeline: Illumination and Shading · 2018-07-20 · 1 Graphics Lecture 3: Slide 1 Interactive Computer Graphics •The Graphics Pipeline: Illumination and Shading

12

Graphics Lecture 3: Slide 45

Heuristic Law

• Although physically correct the inverse square lawdoes not produce the best results.

• Instead the following is often used:

where s is an heuristic constant.• One might be tempted to think that light intensity falls

off with the distance to the viewpoint, but it doesn’t!• Why not?

Graphics Lecture 3: Slide 46

Questions?

Graphics Lecture 3: Slide 47

Using Shading

• There are three levels at which shading can be appliedin polygon based systems:

Flat ShadingGouraud ShadingPhong Shading

• They provide increasing realism at highercomputational cost

Interpolation Shading

Graphics Lecture 3: Slide 48

Using Shading

• Flat Shading:– Each polygon is shaded uniformly over its surface.– The shade is computed by taking a point in the centre and the surface

normal vector. (Equivalent to a light source at infinity)– Usually only diffuse and ambient components are used.

• Interpolation Shading:– A more accurate way to render a shaded polygon is to compute an

independent shade value at each point.– This is done quickly by interpolation:1. Compute a shade value at each vertex2. Interpolate to find the shade value at the boundary3. Interpolate to find the shade values in the middle

Page 13: •The Graphics Pipeline: Illumination and Shading · 2018-07-20 · 1 Graphics Lecture 3: Slide 1 Interactive Computer Graphics •The Graphics Pipeline: Illumination and Shading

13

Graphics Lecture 3: Slide 49

Calculating the shades at the edges

d1

d2

L = (d1L3+d2L1) / (d1+d2)

L3

L2

L1

Graphics Lecture 3: Slide 50

Calculating the internal shades

d1 d2

L = (d1LB+d2LA) / (d1+d2)

L3

L2

L1

LBLA

Graphics Lecture 3: Slide 51

Interpolating over polygons

• In addition to interpolating shades over polygons, wecan interpolate them over groups of polygons tocreate the impression of a smooth surface.

• The idea is to create at each vertex an averagedintensity from all the polygons that meet at thatvertex.

Graphics Lecture 3: Slide 52

nave =(n1 + n2 + n3 + n4)/4

n1

n2

n3

n4

Gouraud Shading

(Object Space)

nave

Computing an average normal vector at a vertex

Page 14: •The Graphics Pipeline: Illumination and Shading · 2018-07-20 · 1 Graphics Lecture 3: Slide 1 Interactive Computer Graphics •The Graphics Pipeline: Illumination and Shading

14

Graphics Lecture 3: Slide 53

Smooth Shading

• Need to have per-vertex normals• Gouraud Shading

– Interpolate color across triangles– Fast, supported by most of the graphics accelerator cards– Can’t model specular components accurately, since we do

not have the normal vector at each point on a polygon.

• Phong Shading– Interpolate normals across triangles– More accurate modelling of specular compoents, but

slower.

Graphics Lecture 3: Slide 54

Interpolation of the 3D normals

• We may express any point for this facet in parametricform:

P = V1 + µ1(V2 - V1) + µ2(V3-V1)• The average normal vector at the same point may be

calculated as the vector a:a = n1 + µ1(n2 - n1) + µ2(n3-n1)

and thennaverage = a / | a |

Graphics Lecture 3: Slide 55

2D or 3D

• The interpolation calculations may be done in either2D or 3D

• For specular reflections the calculation of thereflected vector and viewpoint vector must be done in3D.