34
CPSC 599.64 / 601.64 Illumination and Shading

09-illumination and shadingjungle/599.64/09... · modelling of geometry transformation into world coordinate system placement of cameras and light sources backface ... • speed-up

  • Upload
    others

  • View
    1

  • Download
    0

Embed Size (px)

Citation preview

Page 1: 09-illumination and shadingjungle/599.64/09... · modelling of geometry transformation into world coordinate system placement of cameras and light sources backface ... • speed-up

CPSC 599.64 / 601.64

Illumination and Shading

Page 2: 09-illumination and shadingjungle/599.64/09... · modelling of geometry transformation into world coordinate system placement of cameras and light sources backface ... • speed-up

CPSC 599.64 / 601.64 – Fall 2005 Illumination and ShadingTobias Isenberg

Rendering Pipeline

modelling ofgeometry

transformation intoworld coordinate

system

placement ofcameras andlight sources

backfaceculling

projectionclipping w.r.t.view volume

hidden surfaceremovale (hsr)

rasterizationillumination and

shading

usually in one step

transformation into

camera coordinate

system

Page 3: 09-illumination and shadingjungle/599.64/09... · modelling of geometry transformation into world coordinate system placement of cameras and light sources backface ... • speed-up

CPSC 599.64 / 601.64 – Fall 2005 Illumination and ShadingTobias Isenberg

Overview

• illumination models

– light sources

– light interaction with surfaces

– illumination model by Phong

• shading

– application of illumination models to

rendering polygons

– efficiency vs. quality

– flat, Gouraud, Phong shading

Page 4: 09-illumination and shadingjungle/599.64/09... · modelling of geometry transformation into world coordinate system placement of cameras and light sources backface ... • speed-up

CPSC 599.64 / 601.64 – Fall 2005 Illumination and ShadingTobias Isenberg

Illumination Models

Angel (2000)

• real world:

– surfaces emit, absorb,

reflect, and scatter light

– light intensity and color dependent on surface

position and orientation w.r.t. the light source

– light is usually reflected or

refracted several times

– usually several sources of light

– final intensity/color at a point is

sum of several light paths

ending at that point

Page 5: 09-illumination and shadingjungle/599.64/09... · modelling of geometry transformation into world coordinate system placement of cameras and light sources backface ... • speed-up

CPSC 599.64 / 601.64 – Fall 2005 Illumination and ShadingTobias Isenberg

Illumination Models

• computer graphics world:

– mathematical description necessary

– leads to equation using integrals:

the rendering equation

– it’s usually not solvable

– we need approximation!

• simplifying light sources

• simplifying materials

• simplifying computation

• speed-up

Page 6: 09-illumination and shadingjungle/599.64/09... · modelling of geometry transformation into world coordinate system placement of cameras and light sources backface ... • speed-up

CPSC 599.64 / 601.64 – Fall 2005 Illumination and ShadingTobias Isenberg

Illumination Models

• description of the factors that influence the color and light intensity at a point

• global illumination models:

– considering all objects of a scene to compute

light at a specific point

– e.g., radiosity and raytracing

• local illumination models:

– only object-light interaction, pipeline approach

– heuristic approximation, simpler than global

– Phong illumination model & polygonal shading

Page 7: 09-illumination and shadingjungle/599.64/09... · modelling of geometry transformation into world coordinate system placement of cameras and light sources backface ... • speed-up

CPSC 599.64 / 601.64 – Fall 2005 Illumination and ShadingTobias Isenberg

Light Sources in Computer Graphics

• point light source: has only position and no size, sends light equally in all directions

→ point in 3D & intensity

• spot light source: point light source sending out a cone of light with light intensity decreasing towards cone border

→ point + vector in 3D, angle, attenuation

• directional light source: sends directed, parallel light rays, has no position

→ vector in 3D & intensity

Page 8: 09-illumination and shadingjungle/599.64/09... · modelling of geometry transformation into world coordinate system placement of cameras and light sources backface ... • speed-up

CPSC 599.64 / 601.64 – Fall 2005 Illumination and ShadingTobias Isenberg

Light Sources in Computer Graphics

point light spot light directional light

• spot light intensity defined bycosine function depending onangle from center ray, exponent

Angel (2000)

Page 9: 09-illumination and shadingjungle/599.64/09... · modelling of geometry transformation into world coordinate system placement of cameras and light sources backface ... • speed-up

CPSC 599.64 / 601.64 – Fall 2005 Illumination and ShadingTobias Isenberg

Light Sources in Computer Graphics

• results from simplification to point light sources?

– sharp contrast between light and shade,

no gradual change (penumbra)

– aerial light sources have

to be approximated by

several point lights to

have a penumbra

Angel (2000)

Page 10: 09-illumination and shadingjungle/599.64/09... · modelling of geometry transformation into world coordinate system placement of cameras and light sources backface ... • speed-up

CPSC 599.64 / 601.64 – Fall 2005 Illumination and ShadingTobias Isenberg

Light Sources in Computer Graphics

• light attenuation

– light intensity reduces with growing distance

– theoretically: I ~ 1/d²

– reality does not follow exactly this – why?

– CG: I ~ 1/(a+bd+cd²), often only linear: a,c = 0

• light color

– heuristic: color modeled using RGB values

– approximation because light behavior

depends on wave length – examples?

Page 11: 09-illumination and shadingjungle/599.64/09... · modelling of geometry transformation into world coordinate system placement of cameras and light sources backface ... • speed-up

CPSC 599.64 / 601.64 – Fall 2005 Illumination and ShadingTobias Isenberg

Light Interaction with Surfaces

• angle θ between L & Ndetermines diffusereflection

• reflection angle equals θ

• angle Φ between R & Vdetermines perceivedbrightness

• maximal reflection ifR = V (Φ = 0)

L

N

V

R

L – vector to light sourceN – surface normal vectorR – reflected light rayV – vector to viewer/observer

θΦ

Page 12: 09-illumination and shadingjungle/599.64/09... · modelling of geometry transformation into world coordinate system placement of cameras and light sources backface ... • speed-up

CPSC 599.64 / 601.64 – Fall 2005 Illumination and ShadingTobias Isenberg

Light Interaction with Surfaces

• directed reflection: reflection only for small Φ: smooth surfaces – examples?

• physical reality

– non-symmetric reflection around R

– materials with anisotropic reflection

(reflection depends on angle Φ AND

direction of L w.r.t. surface)

L

N

V

R

Φ

Page 13: 09-illumination and shadingjungle/599.64/09... · modelling of geometry transformation into world coordinate system placement of cameras and light sources backface ... • speed-up

CPSC 599.64 / 601.64 – Fall 2005 Illumination and ShadingTobias Isenberg

Light Interaction with Surfaces

• light attenuation depending on angle between R and V: shininess

• modeled using cosine function and exponent: I ~ cos (Φ)e

• metals: e ≈100

L

N

V

R

Angel (2000)

e=1

e=2

e=5

Φ

Page 14: 09-illumination and shadingjungle/599.64/09... · modelling of geometry transformation into world coordinate system placement of cameras and light sources backface ... • speed-up

CPSC 599.64 / 601.64 – Fall 2005 Illumination and ShadingTobias Isenberg

Light Interaction with Surfaces

• diffuse reflection: equal reflection in all directions on rough surfaces, depends only on θ and not observer – examples?

• due to light scattering on rough surfaces on randomly oriented microscopic facets

Angel (2000)

Page 15: 09-illumination and shadingjungle/599.64/09... · modelling of geometry transformation into world coordinate system placement of cameras and light sources backface ... • speed-up

CPSC 599.64 / 601.64 – Fall 2005 Illumination and ShadingTobias Isenberg

Light Interaction with Surfaces

• diffuse reflection modeled according to Lambert’s law by cosine function:I ~ cos θ = L • N for normalized L, N

because lightdistributesover larger area

θ = 0º → max. intensityθ = 90º → 0 intensity

L

N

V

Angel (2000)

Page 16: 09-illumination and shadingjungle/599.64/09... · modelling of geometry transformation into world coordinate system placement of cameras and light sources backface ... • speed-up

CPSC 599.64 / 601.64 – Fall 2005 Illumination and ShadingTobias Isenberg

Light Interaction with Surfaces

• combined effects of diffuse and directed reflection make up material properties

• in reality very complex function, can be captured with BRDFs (Bidirectional Reflectance Distribution Function)

Bender/Brill (2003)

Page 17: 09-illumination and shadingjungle/599.64/09... · modelling of geometry transformation into world coordinate system placement of cameras and light sources backface ... • speed-up

CPSC 599.64 / 601.64 – Fall 2005 Illumination and ShadingTobias Isenberg

Phong Illumination Model

• most common CG model for illuminationIPhong = Ia + Id + Is

• ambient light: base illumination of scene

– simulates light scattering on objects

– necessary because repeated diffuse reflection

is not considered in local illumination model

– depends on color of all objects in scene

– should always be kept very small

• diffuse light: light from diffuse reflection

• specular light: light from directed reflection

Page 18: 09-illumination and shadingjungle/599.64/09... · modelling of geometry transformation into world coordinate system placement of cameras and light sources backface ... • speed-up

CPSC 599.64 / 601.64 – Fall 2005 Illumination and ShadingTobias Isenberg

Phong Illumination Model

(((( ))))e

ssddaaPhong V)(RkLN)(LkLcdbda

kLI ⋅⋅⋅⋅++++⋅⋅⋅⋅++++++++

++++====2

1

L

N

V

R

L – vector to light sourceN – surface normal vectorR – reflected light rayV – vector to viewer/observer

has to be evaluated for all light sources and for each of the base colors

Page 19: 09-illumination and shadingjungle/599.64/09... · modelling of geometry transformation into world coordinate system placement of cameras and light sources backface ... • speed-up

CPSC 599.64 / 601.64 – Fall 2005 Illumination and ShadingTobias Isenberg

Phong Illumination Model

• ideally specular, mixed, and ideally diffuse

• imperfect specular and ideally diffuse reflection as 3D functions

Bender/Brill (2003)

Angel (2000)

Page 20: 09-illumination and shadingjungle/599.64/09... · modelling of geometry transformation into world coordinate system placement of cameras and light sources backface ... • speed-up

CPSC 599.64 / 601.64 – Fall 2005 Illumination and ShadingTobias Isenberg

Phong Illumination Model

• 3D reflection functions for θ=10°, 45°, 70°

Bender/Brill (2003)

Page 21: 09-illumination and shadingjungle/599.64/09... · modelling of geometry transformation into world coordinate system placement of cameras and light sources backface ... • speed-up

CPSC 599.64 / 601.64 – Fall 2005 Illumination and ShadingTobias Isenberg

Phong Illumination Model

• 3D reflection functions for different specular exponents: e = 2, 20, 100

Bender/Brill (2003)

Page 22: 09-illumination and shadingjungle/599.64/09... · modelling of geometry transformation into world coordinate system placement of cameras and light sources backface ... • speed-up

CPSC 599.64 / 601.64 – Fall 2005 Illumination and ShadingTobias Isenberg

Shading of Polygonal Models

• status: we can approximate color at a point

• goal: we want to render the whole model

• constraint: efficiency and quality

• approach: shade all pixel of a triangle based on color computation at a few points

• three techniques:

– flat shading

– Gouraud shading

– Phong shading (≠ Phong illumination)

Page 23: 09-illumination and shadingjungle/599.64/09... · modelling of geometry transformation into world coordinate system placement of cameras and light sources backface ... • speed-up

CPSC 599.64 / 601.64 – Fall 2005 Illumination and ShadingTobias Isenberg

Flat Shading

• no interpolation

• all pixels same color

• two methods:

– one point per

triangle/quad

– average of

triangle’s/quad’s vertices

• low quality: single primitives easily visible

• fast computation & easy implementation

Page 24: 09-illumination and shadingjungle/599.64/09... · modelling of geometry transformation into world coordinate system placement of cameras and light sources backface ... • speed-up

CPSC 599.64 / 601.64 – Fall 2005 Illumination and ShadingTobias Isenberg

Flat Shading: Edge Perception

• discontinuities easily visible and distracting

– reason in human perception

– contrast are enhanced by visual system

(remember the saber tooth tigers ;-)

– perceived brightness differences are bigger

than the physical reality

Angel (2000)Mach band effect

Page 25: 09-illumination and shadingjungle/599.64/09... · modelling of geometry transformation into world coordinate system placement of cameras and light sources backface ... • speed-up

CPSC 599.64 / 601.64 – Fall 2005 Illumination and ShadingTobias Isenberg

Gouraud Shading

• computation of colorsat all vertices

• linear interpolation ofcolors over primitive

• more computation butbetter quality than flat shading

• usually implemented in graphics hardware

• problem:

highlights in the middle of triangles

Page 26: 09-illumination and shadingjungle/599.64/09... · modelling of geometry transformation into world coordinate system placement of cameras and light sources backface ... • speed-up

CPSC 599.64 / 601.64 – Fall 2005 Illumination and ShadingTobias Isenberg

Gouraud Shading: Vertex Normals

• prerequisite: normal vectors at vertices

• need to be interpolated from face normals

• requires data structure supporting cross-referencing of vertices, normals, faces etc.

• otherwise (no normal interpolation)?

4321

4321

nnnn

nnnnn

++++++++++++

++++++++++++====

Page 27: 09-illumination and shadingjungle/599.64/09... · modelling of geometry transformation into world coordinate system placement of cameras and light sources backface ... • speed-up

CPSC 599.64 / 601.64 – Fall 2005 Illumination and ShadingTobias Isenberg

Phong Shading

• linear interpolation ofnormals for each pixel

• color computation foreach pixel separately

• best quality but compu-tationally more expensive,highlights are shown correctly

• problems:– polygons still visible at silhouettes

(image above is no real Phong shading)

– typically not implemented in hardware

Page 28: 09-illumination and shadingjungle/599.64/09... · modelling of geometry transformation into world coordinate system placement of cameras and light sources backface ... • speed-up

CPSC 599.64 / 601.64 – Fall 2005 Illumination and ShadingTobias Isenberg

Phong Shading: Normal Interpolation

• first: normal vector interpolation along edges on per-scanline basis

• second: normal vector interpolation between edges along scanlineson per-pixel basis

Angel (2003)

Page 29: 09-illumination and shadingjungle/599.64/09... · modelling of geometry transformation into world coordinate system placement of cameras and light sources backface ... • speed-up

CPSC 599.64 / 601.64 – Fall 2005 Illumination and ShadingTobias Isenberg

Phong Shading: Normal Interpolation

• alternative: quadratic inter-polation (van Overveldand Wyvill, 1997)

Page 30: 09-illumination and shadingjungle/599.64/09... · modelling of geometry transformation into world coordinate system placement of cameras and light sources backface ... • speed-up

CPSC 599.64 / 601.64 – Fall 2005 Illumination and ShadingTobias Isenberg

Polygonal Shading

• when in the pipeline?

• typically last step together with rasterization and z-buffering

• problem:

– normals would be perspectively projected

– normals not perpendicular to surface anymore

– light position w.r.t. surface may change

• determine illumination before projection!

• shading after projection

Page 31: 09-illumination and shadingjungle/599.64/09... · modelling of geometry transformation into world coordinate system placement of cameras and light sources backface ... • speed-up

CPSC 599.64 / 601.64 – Fall 2005 Illumination and ShadingTobias Isenberg

Polygonal Shading: Comparison

• comparison on a by-pixel basis:

Gouraud shading Phong shadingflat shading

Page 32: 09-illumination and shadingjungle/599.64/09... · modelling of geometry transformation into world coordinate system placement of cameras and light sources backface ... • speed-up

CPSC 599.64 / 601.64 – Fall 2005 Illumination and ShadingTobias Isenberg

Polygonal Shading: Comparison

vertex normals interpolated and one color value per pixel

one color value per vertex & interpolation inside

one color value for entire polygon

PhongGouraudFlat

N

IN1

I1

N3

N2

I3

I2

N1

I1

N3

N2

I3

I2

Page 33: 09-illumination and shadingjungle/599.64/09... · modelling of geometry transformation into world coordinate system placement of cameras and light sources backface ... • speed-up

CPSC 599.64 / 601.64 – Fall 2005 Illumination and ShadingTobias Isenberg

Summary

• Phong illumination model: heuristic to compute color at one surface point

– ambient, diffuse, and specular components

– only computes direct (local) illumination

• three shading methods to color polygons

– flat, Gouraud, and Phong shading

– not physically based

– speed vs. quality tradeoff

– illumination computation in world coordinates

(before projection)!

Page 34: 09-illumination and shadingjungle/599.64/09... · modelling of geometry transformation into world coordinate system placement of cameras and light sources backface ... • speed-up

CPSC 599.64 / 601.64 – Fall 2005 Illumination and ShadingTobias Isenberg

Sources:

• Computer Graphics I lecture by BerhardPreim, Department of Simulation and Graphics, Otto-von-Guericke University of Magdeburg, Germany

• CPSC 407 and CPSC 453 lectures by Brian Wyvill, Department of Computer Science, University of Calgary, Canada