computer graphics - week 4feiner/courses/csw4160/slides/s99-4.pdf · computer graphics - week 4...

35
Computer Graphics - Week 4 Computer Graphics - Week 4 Bengt-Olaf Schneider Bengt-Olaf Schneider IBM T.J. Watson Research Center IBM T.J. Watson Research Center © Bengt-Olaf Schneider, 1999 Computer Graphics – Week 4 Questions about Last Week ? Questions about Last Week ? Information about ACIS will be available tomorrow ... Check the newsgroup You should have started to work on the assignment We have fudged the data to make things fit better The universe is mostly empty, after all Tips about the assignment Ellpsis equation ... check out your favorite math book Ellipsis can be generate by non-uniform scaling of circles Caution: Non-uniform scaling of spheres generate ellipsoid Make sure you think about the order of transformations

Upload: others

Post on 21-Sep-2020

0 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Computer Graphics - Week 4feiner/courses/csw4160/slides/S99-4.pdf · Computer Graphics - Week 4 Bengt-Olaf Schneider IBM T.J. Watson Research Center Computer Graphics – Week 4

Computer Graphics - Week 4Computer Graphics - Week 4

Bengt-Olaf SchneiderBengt-Olaf SchneiderIBM T.J. Watson Research CenterIBM T.J. Watson Research Center

© Bengt-Olaf Schneider, 1999Computer Graphics – Week 4

Questions about Last Week ?Questions about Last Week ?

Information about ACIS will be available tomorrow ...Check the newsgroup

You should have started to work on the assignment

We have fudged the data to make things fit betterThe universe is mostly empty, after all

Tips about the assignmentEllpsis equation ... check out your favorite math bookEllipsis can be generate by non-uniform scaling of circlesCaution: Non-uniform scaling of spheres generate ellipsoidMake sure you think about the order of transformations

Page 2: Computer Graphics - Week 4feiner/courses/csw4160/slides/S99-4.pdf · Computer Graphics - Week 4 Bengt-Olaf Schneider IBM T.J. Watson Research Center Computer Graphics – Week 4

© Bengt-Olaf Schneider, 1999Computer Graphics – Week 4

Overview of Week 4Overview of Week 4

Lighting ModelsGeneral lighting conceptsBasic illumination modelsPrinciples of polygon shadingSurface propertiesAdvanced illumination models

OpenGLRendering primitivesOpenGL lighting and shading

© Bengt-Olaf Schneider, 1999Computer Graphics – Week 4

LightingLighting

So far we only considered the effects of the viewpoint on the geometryEven a minimum of realism requires to take into account interactions of light with the scene.

We need models forLightsMaterials and surface propertiesInteraction of lights and material

We will develop several lighting models of increasing complexity and visual accuracy

Page 3: Computer Graphics - Week 4feiner/courses/csw4160/slides/S99-4.pdf · Computer Graphics - Week 4 Bengt-Olaf Schneider IBM T.J. Watson Research Center Computer Graphics – Week 4

© Bengt-Olaf Schneider, 1999Computer Graphics – Week 4

Shading vs. LightingShading vs. Lighting

Lighting models define how to compute the color of a surface point, given a number of parameters:

lighting conditions, e.g. number and positions of light sourcesviewpointsurface properties, e.g. surface orientation or materialathmosperic properties, e.g. fog or smoke

Shading models define when and where a lighting model is evaluated

at every vertex (Gouraud shading)at every pixel (Phong shading)

© Bengt-Olaf Schneider, 1999Computer Graphics – Week 4

Lighting ModelsLighting Models

Different lighting models have been developed to account for various illumination effects

Physically based Lighting ModelsModel one or several physical lighting effects Assumptions are stated explicitely

Empiric Lighting ModelsMany lighting models are not "strictly" based on physicsMany popular ad-hoc methods deliver attractive resultsReasons are computational efficiency

We will discuss various such lighting models

Page 4: Computer Graphics - Week 4feiner/courses/csw4160/slides/S99-4.pdf · Computer Graphics - Week 4 Bengt-Olaf Schneider IBM T.J. Watson Research Center Computer Graphics – Week 4

© Bengt-Olaf Schneider, 1999Computer Graphics – Week 4

Modeling MaterialsModeling Materials

The real problem in computing illumination effect stems from the interaction of light with matterMaterials are characterized by ...

colorglossiness or dullnessreflectivitypolarization of reflected lighttransparencyindex of refraction

These properties result from various physical effectsWe will not try to explain these effects hereHowever, we will try to model / simulate some of them

© Bengt-Olaf Schneider, 1999Computer Graphics – Week 4

Bidirectional Reflection Function (BDRF)Bidirectional Reflection Function (BDRF)

Amount and direction of reflected light for a given direction of incident light.

Bidirectional: αI and αR

Many other ways to describe this relationship

BDRFs for real materials are complex ...

N

II

IR

βαI

αR

Page 5: Computer Graphics - Week 4feiner/courses/csw4160/slides/S99-4.pdf · Computer Graphics - Week 4 Bengt-Olaf Schneider IBM T.J. Watson Research Center Computer Graphics – Week 4

© Bengt-Olaf Schneider, 1999Computer Graphics – Week 4

Reflectance FunctionsReflectance Functions

From A. Glassner, Principles of Image Synthesis

Reflectance function describe the amount of reflected light for given angles of incidence and observation.

Each curve describes the amount of light reflected into various directionsDifferent curves for different angles of incidenceExample:For light coming in at 30O, approx. 50% is reflected into a direction of 45O.

© Bengt-Olaf Schneider, 1999Computer Graphics – Week 4

Reflectance Function for White PaperReflectance Function for White Paper

From A. Glassner, Principles of Image Synthesis

Page 6: Computer Graphics - Week 4feiner/courses/csw4160/slides/S99-4.pdf · Computer Graphics - Week 4 Bengt-Olaf Schneider IBM T.J. Watson Research Center Computer Graphics – Week 4

© Bengt-Olaf Schneider, 1999Computer Graphics – Week 4

Reflectance Function for the MoonReflectance Function for the Moon

From A. Glassner, Principles of Image Synthesis

© Bengt-Olaf Schneider, 1999Computer Graphics – Week 4

Lighting Concepts (1)Lighting Concepts (1)

L RN

Eα α β

Object

ViewpointLight-source

At every surface point we consider several vectors:

Surface normal NLight source vector LVector to the eye EReflected vector R

Also we will take into account various surface properties of the object

Page 7: Computer Graphics - Week 4feiner/courses/csw4160/slides/S99-4.pdf · Computer Graphics - Week 4 Bengt-Olaf Schneider IBM T.J. Watson Research Center Computer Graphics – Week 4

© Bengt-Olaf Schneider, 1999Computer Graphics – Week 4

Lighting Concepts (2)Lighting Concepts (2)Intensity

"Amount" of light along a given direction, i.e. luminous intensityUsually a vector (multiple colors or wavelengths)Can be a scalar (monochromatic light, grey values)We will often use the terms "color" and "intensity" as synonyms

Coefficients kX

Dimensionless scale factors affecting the intensityFor example: absorption, reflectivity, ...If kX is wavelength dependent it describes a color

Example: If only red light is reflected, the object appears redExample: If only red light is reflected, the object appears red

Wavelength DependeceTypically lighting is evaluated for RGB componentsAlthough, a rough approximation, often produces acceptable results

© Bengt-Olaf Schneider, 1999Computer Graphics – Week 4

Lighting Concepts (3)Lighting Concepts (3)

Direct IlluminationLight received directly from a light sourceAll lighting models account for direct illumination

Indirect IlluminationLight received via reflecting/refracting intermediate objectsE.g. mirrors, lenses, fog, ....Many lighting models simulate indirect illumination crudely or not allGlobal illumination models perform more accurate estimation of indirect illumination effects

Page 8: Computer Graphics - Week 4feiner/courses/csw4160/slides/S99-4.pdf · Computer Graphics - Week 4 Bengt-Olaf Schneider IBM T.J. Watson Research Center Computer Graphics – Week 4

© Bengt-Olaf Schneider, 1999Computer Graphics – Week 4

Directional vs. Point Light SourcesDirectional vs. Point Light Sources

Directional light sourceLight source is at infinityAll light rays are parallel

Point light sourceLight source at finite positionLight rays radiate in all directionsIntersect surface at different angles with normal

Similar for eye positioinInfinite ViewerFinite Viewer

L

© Bengt-Olaf Schneider, 1999Computer Graphics – Week 4

Empirical Lighting ModelsEmpirical Lighting Models

EmissionAmbient LightDiffuse ReflectionSpecular ReflectionLight AttenuationAthmospheric Effects

Page 9: Computer Graphics - Week 4feiner/courses/csw4160/slides/S99-4.pdf · Computer Graphics - Week 4 Bengt-Olaf Schneider IBM T.J. Watson Research Center Computer Graphics – Week 4

© Bengt-Olaf Schneider, 1999Computer Graphics – Week 4

The simplest lighting model is NO lighting modelAssigns a constant color to the entire objectIgnores any lights in the environmentNo discernable surface featuresUseful to model luminous (i.e. light-emitting) objects

Emitted LightEmitted Light

I k i=

© Bengt-Olaf Schneider, 1999Computer Graphics – Week 4

Ambient LightAmbient Light

Light with equal intensity in the entire scene: IA

No preferred direction to light rays Independent of object and viewer positionApproximates background light in a scene as light bounces off multiple objects before it reaches a given surface pointBackground light is a crude simplification of indirect illuminationSoftens boundaries between lit and unlit regions

Objects reflect certain percentage of ambient light: kA

I I kA A= ⋅

Page 10: Computer Graphics - Week 4feiner/courses/csw4160/slides/S99-4.pdf · Computer Graphics - Week 4 Bengt-Olaf Schneider IBM T.J. Watson Research Center Computer Graphics – Week 4

© Bengt-Olaf Schneider, 1999Computer Graphics – Week 4

Diffuse ReflectionDiffuse Reflection

Lambertian ReflectionDiffuse surfaces appear equally bright from all viewing directionsBrightness depends on the angle between surface normal and light

I I k I kL D L D= ⋅ ⋅ = ⋅ ⋅ ⋅cosα N L

L RN

Eα α β

Object

ViewpointLight-source

1kD

© Bengt-Olaf Schneider, 1999Computer Graphics – Week 4

Specular Reflection (1)Specular Reflection (1)

"Shiny" surfaces reflect light distributed around the direction of ideal reflection.

Intensity maximal along direction of ideal reflection

L RN

Eα α β

Object

ViewpointLight-source

I I k I kL Sn

L Sn= ⋅ ⋅ = ⋅ ⋅ ⋅cos β R Eb g

1

kS

Page 11: Computer Graphics - Week 4feiner/courses/csw4160/slides/S99-4.pdf · Computer Graphics - Week 4 Bengt-Olaf Schneider IBM T.J. Watson Research Center Computer Graphics – Week 4

© Bengt-Olaf Schneider, 1999Computer Graphics – Week 4

Specular Reflection (2)Specular Reflection (2)

Intensity depends on position of viewer and light source

Color of specular reflection depends on materialPlastics reflect the color of the light source, kλsame for a λMetals reflect the material color, kλdifferent for different λOther materials, combination of light and material color

© Bengt-Olaf Schneider, 1999Computer Graphics – Week 4

Specular Reflection (3)Specular Reflection (3)

1.1

0

cos α( )

cos α( )2

cos α( )8

cos α( )16

π2

0 α

Glossiness coefficient n determines extent of the highlights

Exponentiation of Cosine roll-off is purely empirical

Result look attractiveDue to Bui-Tuong Phong

Page 12: Computer Graphics - Week 4feiner/courses/csw4160/slides/S99-4.pdf · Computer Graphics - Week 4 Bengt-Olaf Schneider IBM T.J. Watson Research Center Computer Graphics – Week 4

© Bengt-Olaf Schneider, 1999Computer Graphics – Week 4

Specular Reflection (4)Specular Reflection (4)

Computing the reflected vectorCalculate projection of incident ray L onto surface normal NCompute vector from incident ray to projection: SReflected ray is L+2S

Reflected vector must recomputed if N (or L) changes

NSS

RL NL

α

R L SL NL N L

NL N LN L

= += + ⋅ −= ⋅ −= ⋅ −

22

22

( )

cosα

© Bengt-Olaf Schneider, 1999Computer Graphics – Week 4

Specular Reflection (5)Specular Reflection (5)

Avoid computing RSimplification due to BlinnHalfway vector H bisects angle between L and EMaximum intensity if H = NFor directional light and infinite viewer, H is constant and does not depend on N

L HN

Eα α

β

Object

ViewpointLight-source

I I k I kL Sn

L Sn= ⋅ ⋅ = ⋅ ⋅ ⋅cos β N Hb g

Page 13: Computer Graphics - Week 4feiner/courses/csw4160/slides/S99-4.pdf · Computer Graphics - Week 4 Bengt-Olaf Schneider IBM T.J. Watson Research Center Computer Graphics – Week 4

© Bengt-Olaf Schneider, 1999Computer Graphics – Week 4

Specular Reflection (6)Specular Reflection (6)

Both Phong and Blinn model are strictly empiricalResults do not match any real materialsSimulate plastic fairly well

Phong and Blinn model are not identicalSimilar resultsBoth are approximations anyway

© Bengt-Olaf Schneider, 1999Computer Graphics – Week 4

Multiple Light SourcesMultiple Light Sources

Light from different light sources can be superimposedIgnores interference effectsAssume incoherent light

I I ii

= ∑ b g

Page 14: Computer Graphics - Week 4feiner/courses/csw4160/slides/S99-4.pdf · Computer Graphics - Week 4 Bengt-Olaf Schneider IBM T.J. Watson Research Center Computer Graphics – Week 4

© Bengt-Olaf Schneider, 1999Computer Graphics – Week 4

Putting it all together: Phong LightingPutting it all together: Phong Lighting

I k I k I k IA A D i ii

l

S in

i

l

= ⋅ + ⋅ ⋅ ⋅ + ⋅ ⋅= =∑ ∑N L R Eb g b g

0 0

Useful empirical lighting modelStraight-forward to computeAcceptable resultsUsed in many APIs and some hardware implementations

© Bengt-Olaf Schneider, 1999Computer Graphics – Week 4

DemoDemo

Also: check out glaze from E+Shttp://www.es.com/Products/Workstation/download.html

Page 15: Computer Graphics - Week 4feiner/courses/csw4160/slides/S99-4.pdf · Computer Graphics - Week 4 Bengt-Olaf Schneider IBM T.J. Watson Research Center Computer Graphics – Week 4

© Bengt-Olaf Schneider, 1999Computer Graphics – Week 4

Computing Surface Normals (1)Computing Surface Normals (1)

Surface normalUnit length (same goes for all other vectors !!)Non-unit vectors will result in false lightingPerpendicular to surface

Perpendicular vectors are computed using the vector cross product V1

V = V VV V V

3 1 2

3 1 2

x | | = | | | | sin α

V2α

u ve e e

e e eX Y Z

X Y Z× = = − − − + − =−−−

FHGG

IKJJu u u

v v vu v u v u v u v u v u v

u v u vu v u vu v u v

X Y Z

X Y Z

Y Z Z Y X Z Z X X Y Y X

Y Z Z Y

X Z Z X

X Y Y X

b g b g b g

© Bengt-Olaf Schneider, 1999Computer Graphics – Week 4

Computing Surface Normals (2)Computing Surface Normals (2)

For polygons: Compute normal from 2 edgesEdges must not be collinearNumerical problems for almost collinear edgesOnly triangles are guaranteed to be planar

P1

P2

P3NN

P P P PP P P P

3 1 2 1

3 1 2 1

= − × −− × −

( ) ( )( ) ( )

Page 16: Computer Graphics - Week 4feiner/courses/csw4160/slides/S99-4.pdf · Computer Graphics - Week 4 Bengt-Olaf Schneider IBM T.J. Watson Research Center Computer Graphics – Week 4

© Bengt-Olaf Schneider, 1999Computer Graphics – Week 4

Computing Surface Normals (3)Computing Surface Normals (3)

Polygon meshes approximate smooth surfacesVertex normals are computed by averaging adjacent surface normals

Phong Shading: Interior normals are computed as interpolation of vertex normals

© Bengt-Olaf Schneider, 1999Computer Graphics – Week 4

Computing Surface Normals (4)Computing Surface Normals (4)

Averaging surface normals to obtain vertex normals is a linear approximation

Apparent curvature depends on size of participating polygonsInterior surface feature may be missed

Page 17: Computer Graphics - Week 4feiner/courses/csw4160/slides/S99-4.pdf · Computer Graphics - Week 4 Bengt-Olaf Schneider IBM T.J. Watson Research Center Computer Graphics – Week 4

© Bengt-Olaf Schneider, 1999Computer Graphics – Week 4

Transforming Normal Vectors (1)Transforming Normal Vectors (1)

Normals are often defined in the local coordinates together with the geometryNormals must therefore also be transformed by modeling and viewing transformations

X X

Y Y

© Bengt-Olaf Schneider, 1999Computer Graphics – Week 4

Transforming Normal Vectors (2)Transforming Normal Vectors (2)

Rigid body transformations work fineUniform Scaling

Vectors must be renormalizedGeneral transformations

Normals do not remain perpendicular to the associated surface

X X

Y Y

Page 18: Computer Graphics - Week 4feiner/courses/csw4160/slides/S99-4.pdf · Computer Graphics - Week 4 Bengt-Olaf Schneider IBM T.J. Watson Research Center Computer Graphics – Week 4

© Bengt-Olaf Schneider, 1999Computer Graphics – Week 4

Transforming Normal Vectors (3)Transforming Normal Vectors (3)

Scaling distorts the normal vector, thereby changing its orientation to the surface

The scaling operation distorts surfaces and normals in opposite directions ...... not surprising given that normals are rotated 90O with respect to the surface .

N' M N= ⋅

© Bengt-Olaf Schneider, 1999Computer Graphics – Week 4

Transforming Normal Vectors (4)Transforming Normal Vectors (4)

Let's try to tackle this a bit more formally:

Looking at two transformed vectors N' and V'.

All vectors V' lie in a planeN' perpendicular to this plane

We assert that they are perpendicular after the transformation with the matrix M.

N' V'

N' M V

N' M V

N' M V

M N' V

⋅ =⋅ • =• • =• • =

• • =

0

0

0

0

0

b gb g

c h

T

T T T

T T

Page 19: Computer Graphics - Week 4feiner/courses/csw4160/slides/S99-4.pdf · Computer Graphics - Week 4 Bengt-Olaf Schneider IBM T.J. Watson Research Center Computer Graphics – Week 4

© Bengt-Olaf Schneider, 1999Computer Graphics – Week 4

Transforming Normal Vectors (5)Transforming Normal Vectors (5)

M N' V

N M N'

N' M N

N' M N

T T

T

T

T

• • =

= •

= •

= •

c h

c hc h

0

1

1

We require that N be perpendicular to any V lying in the given plane

Therefore: N*V = 0

Comparing coefficients yields ...

Normals are transformed by the transpose of the inverse of the transformation matrix.

© Bengt-Olaf Schneider, 1999Computer Graphics – Week 4

Transforming Normal Vectors (6)Transforming Normal Vectors (6)

Normals are transformed by the transpose of the inverse of the transformation matrix.

Special cases:Rotation:

Vectors and points are rotated the same way.

Scaling:

Scaling is accomplished by transforming vectors with the inverse of the transformation matrix.

Translations do not affect the transformation of vectors (W = 0 !). Therefore, we can transform vectors and points the same way.

M M M M− −= ⇒ =1 1T T c h

M M− −=1 1c hT

Page 20: Computer Graphics - Week 4feiner/courses/csw4160/slides/S99-4.pdf · Computer Graphics - Week 4 Bengt-Olaf Schneider IBM T.J. Watson Research Center Computer Graphics – Week 4

© Bengt-Olaf Schneider, 1999Computer Graphics – Week 4

Front and Back Faces (1)Front and Back Faces (1)

Light from a given direction affects only one side of a surface, i.e. the surface is self-occluding.

This requires that normals are consistent across the surfaces, e.g. all normals point outward (or inward).

By convention, for front-facing polygons the vertices are oriented counter-clockwise (mathematically positive).For front-facing polygons, the normal vector points toward the viewer

© Bengt-Olaf Schneider, 1999Computer Graphics – Week 4

Front and Back Faces (2)Front and Back Faces (2)

Different materials properties can be assigned to front and back faces to distinguish front and back faces

Different interior and exterior colors for solid objectsVisual differentiation of top and bottom of a surface

Page 21: Computer Graphics - Week 4feiner/courses/csw4160/slides/S99-4.pdf · Computer Graphics - Week 4 Bengt-Olaf Schneider IBM T.J. Watson Research Center Computer Graphics – Week 4

© Bengt-Olaf Schneider, 1999Computer Graphics – Week 4

Front and Back Faces (3)Front and Back Faces (3)

For solid models, back-facing polygons are always hidden if the viewpoint is outside of the solid.Then, no need to process back-facing polygons.

Back-face cullingOnly process front-facing polygons.Discard back-facing polygons.

After modeling and viewing transformation, check surface normal to identify back-facing polygonsSaves unnecessary work for lighting, clipping, and rasterization

© Bengt-Olaf Schneider, 1999Computer Graphics – Week 4

Light AttenuationLight Attenuation

The light intensity dimishes with increased distance from the light source.We model this with an attenuation factor: fatt(d)

For true point lights, the intensity falls off with square of the distance: fatt(d) = 1 / d2

Inspite of physics, the results do not appear natural: objects close to the light appear too bright, distant objects appear too dark.

Apparent harshness in contrast becasue true point light sources are rare in realityApparent harshness in contrast becasue true point light sources are rare in reality

An empirical model accounts for these shortcomings, using user-defined coefficients for constant, linear and quadratic fall-off:

f dc c d c datt ( ) =

+ +1

1 2 32

Page 22: Computer Graphics - Week 4feiner/courses/csw4160/slides/S99-4.pdf · Computer Graphics - Week 4 Bengt-Olaf Schneider IBM T.J. Watson Research Center Computer Graphics – Week 4

© Bengt-Olaf Schneider, 1999Computer Graphics – Week 4

Athmospheric Effects (1)Athmospheric Effects (1)

Athmospheric effects account for changes to the light as it travels from the object to the viewer: depth cueing

Typically involves a shift in the color valueHaze (grey), fog (white), smoke (black), water (blue or green)The farther the object, the less dominant the object color

The color shift is modeled by linearly blending between object color and depth-cue color:

I s I s I DC' ( )= ⋅ + − ⋅1

© Bengt-Olaf Schneider, 1999Computer Graphics – Week 4

Athmospheric Effects (2)Athmospheric Effects (2)

Often, athmosperic attenuation of the objet color is limited to a certain depth range:

Distance must be measure in eye coordinates or normalizeddevice coordinates.

s

s

s z zs sz z

s

z z zz

F

B BF B

F B

B

F B= + − −−

RS||T||

> >>

b g forz > z

z

F

B

z

s

sF

sB

zF zB

Page 23: Computer Graphics - Week 4feiner/courses/csw4160/slides/S99-4.pdf · Computer Graphics - Week 4 Bengt-Olaf Schneider IBM T.J. Watson Research Center Computer Graphics – Week 4

© Bengt-Olaf Schneider, 1999Computer Graphics – Week 4

Spotlights (1)Spotlights (1)

Spotlights do not emit light into all directions

ConeCone specifies direction and angle of emitted lightLight distribution across either uniform or fall-off towards perimeter

Flaps ("barn doors")Limit light to range for each coordinate axisOnly points within those coordinate ranges receive light

© Bengt-Olaf Schneider, 1999Computer Graphics – Week 4

Spotlights (2)Spotlights (2)

Warn lighting modelReflect a virtual light through a specular reflector into the sceneThe light distribution is that of a specular reflection with ks=1

L’

N

L

L’

Virtual Surface

γ

I I Lp= ⋅' cos γ

Page 24: Computer Graphics - Week 4feiner/courses/csw4160/slides/S99-4.pdf · Computer Graphics - Week 4 Bengt-Olaf Schneider IBM T.J. Watson Research Center Computer Graphics – Week 4

© Bengt-Olaf Schneider, 1999Computer Graphics – Week 4

Managing Maximum IntensityManaging Maximum Intensity

None of the lighting models discussed attempted to limit the amount of light in the scene

Intensity may be oversaturated, i.e. > 100%Graphics hardware clamps color components to 100%, resulting in color shift towards white and loss of color differentiation

Therefore, intensities must be adjustedScale back all color channels to maintain color valueAttempt to prescale light intensities so that intensity cannot saturate

consider color emission and maximum reflectance in all material propertiesconsider color emission and maximum reflectance in all material properties

Store true intensities in off-screen area and rescale intensities

© Bengt-Olaf Schneider, 1999Computer Graphics – Week 4

Physically-based Lighting Models (1)Physically-based Lighting Models (1)

Empirical model discussed so far, are approximations of illumination effects that are not derived from physics

Most shortcomings are related to the specular reflection

Empirical models are adequate for small angles of incidenceReal BDRFs show very different behavior for large angles of incidence

Reflectivity increases for larger angles of incidenceHighlight is shifted off the specular peak, i.e. off RColor shifts due to interactions of light with the material are not modelled at all by Phong lighting

Page 25: Computer Graphics - Week 4feiner/courses/csw4160/slides/S99-4.pdf · Computer Graphics - Week 4 Bengt-Olaf Schneider IBM T.J. Watson Research Center Computer Graphics – Week 4

© Bengt-Olaf Schneider, 1999Computer Graphics – Week 4

Physically-based Lighting Models (2)Physically-based Lighting Models (2)

Torrance-Sparrow Lighting ModelPhysics-based surface model or microscopic, ideal mirrorsMirrors are inclined towards the surface normal, forming V-shaped grooves across the surfaceOrientation of these micro-grooves is given by statistical distributionThis distribution determines how much incident and reflected light is shadowed by the other mirrors

N NH HL LV

V

© Bengt-Olaf Schneider, 1999Computer Graphics – Week 4

Lighting as Part of the Rendering PipelineLighting as Part of the Rendering Pipeline

ClippingLightingCalculations

ModelingTransforms

ViewingTransforms

Geometric Operations

Image Generation

SetupCalculations

ScreenRefresh

FrameBufferRasterization Pixel

Processing

Perspective+ Viewport

Lighting is often part of the geometry pipelineLit vertices are sent to the rasterization stagePhong shading moves lighting into the pixel processing step

Lighting occurs in world coordinates (or equiv.)

Page 26: Computer Graphics - Week 4feiner/courses/csw4160/slides/S99-4.pdf · Computer Graphics - Week 4 Bengt-Olaf Schneider IBM T.J. Watson Research Center Computer Graphics – Week 4

© Bengt-Olaf Schneider, 1999Computer Graphics – Week 4

Shading (1)Shading (1)

Shading specifies when and where the lighting model is evaluated.

Gouraud ShadingEvaluate lighting model at vertices to compute vertex colorInterpolate color across polygonLighting calculations in world/eye coordinate

Phong ShadingInterpolate surface normal across polygonEvaluate lighting model at every pixelLighting calculations starting in screen coordinates

© Bengt-Olaf Schneider, 1999Computer Graphics – Week 4

Shading (2)Shading (2)

Why is Phong shading "better"Interior highlights are missed by Gouraud shading

Phong Gouraud

Highlight

Page 27: Computer Graphics - Week 4feiner/courses/csw4160/slides/S99-4.pdf · Computer Graphics - Week 4 Bengt-Olaf Schneider IBM T.J. Watson Research Center Computer Graphics – Week 4

© Bengt-Olaf Schneider, 1999Computer Graphics – Week 4

Shading (3)Shading (3)

Why is Phong shading expensiveInterpolation of normal vectors generates non-unit vectors

Scanline

Surface

α

N0 N1N

© Bengt-Olaf Schneider, 1999Computer Graphics – Week 4

Rendering Primitives (1)Rendering Primitives (1)

The basic rendering primitive in most raster graphics systems is the triangleOther primitives:

Triangle-stripQuadQuad-meshPolygonLinePoly-line

Page 28: Computer Graphics - Week 4feiner/courses/csw4160/slides/S99-4.pdf · Computer Graphics - Week 4 Bengt-Olaf Schneider IBM T.J. Watson Research Center Computer Graphics – Week 4

© Bengt-Olaf Schneider, 1999Computer Graphics – Week 4

Rendering Primitives (2)Rendering Primitives (2)

All rendering primitives are based on verticesE.g. polygons are defined as a list of vertices

Primitives are processed by processing their verticesTransformed primitives are the collection of transformed verticesExploits the property of affine transformations that lines are mapped into lines (or points)Lighting is applied to the vertices (Gouraud shading)

© Bengt-Olaf Schneider, 1999Computer Graphics – Week 4

Rendering Primitives (3)Rendering Primitives (3)Triangles

Linear functions are naturally defined over triangles

Depth varies linearly, e.g. for color, Depth varies linearly, e.g. for color, texture, alpha, ...texture, alpha, ...

Triangle Strips and FansConnected trianglesNeighboring triangles share 2 vertices, don't need to be redefined for every triangle3-deep queue of verticesStrips: Use prev. 2 verticesFans: Reference first and previous vertices Proper traversal to ensure consistent normals

V6

V7

V1

V5V4

V2

V3

V6

V7

V1

V5

V4V2

V3

Page 29: Computer Graphics - Week 4feiner/courses/csw4160/slides/S99-4.pdf · Computer Graphics - Week 4 Bengt-Olaf Schneider IBM T.J. Watson Research Center Computer Graphics – Week 4

© Bengt-Olaf Schneider, 1999Computer Graphics – Week 4

Rendering Primitives (4)Rendering Primitives (4)

Quadrilaterals (Quads)4 verticesNot necessarily planar, convex or simple

V1

V2

V4

V3

V6

V5

V7

V8

Quad-stripsConnected quadsNeighboring quads share 2 vertices4-deep queue of vertices

© Bengt-Olaf Schneider, 1999Computer Graphics – Week 4

Rendering Primitives (5)Rendering Primitives (5)

General polygonsPlanarConvex vs. ConcaveSelf-intersectingHoles

Page 30: Computer Graphics - Week 4feiner/courses/csw4160/slides/S99-4.pdf · Computer Graphics - Week 4 Bengt-Olaf Schneider IBM T.J. Watson Research Center Computer Graphics – Week 4

© Bengt-Olaf Schneider, 1999Computer Graphics – Week 4

Rendering Primitives (6)Rendering Primitives (6)

Higher-order primitivesQuadrics, e.g. spheres, cylinders, cones etc.Freeform surfaces, e.g. splines, Bezier patches, NURBS

TesselationUsually, higher order primitives are approximated with polygonsThe finer the subdivision, the better the approximation

© Bengt-Olaf Schneider, 1999Computer Graphics – Week 4

OpenGLOpenGL

OpenGL implements the Phong lighting model with light attenutation and depth cueing

Page 31: Computer Graphics - Week 4feiner/courses/csw4160/slides/S99-4.pdf · Computer Graphics - Week 4 Bengt-Olaf Schneider IBM T.J. Watson Research Center Computer Graphics – Week 4

© Bengt-Olaf Schneider, 1999Computer Graphics – Week 4

OpenGL: LightsOpenGL: Lights

glLight()At least 8 lights supportedEach parameter of the lighting model is set separatelyParameters:

Ambient, diffuse, specular intensityAmbient, diffuse, specular intensityGlossiness coefficientGlossiness coefficientPosition or DirectionPosition or DirectionSpotlight parameters (direction, exponent, angle)Spotlight parameters (direction, exponent, angle)Attenuation (constant, linear and quadratic coefficients)Attenuation (constant, linear and quadratic coefficients)

glEnable() / glDisable()GL_LIGHTING

Performs lighting calculations or use vertex colorsPerforms lighting calculations or use vertex colors

GL_LIGHTi, i = 0, 1, 2, ...

© Bengt-Olaf Schneider, 1999Computer Graphics – Week 4

OpenGL: LightingOpenGL: Lighting

glLightModel() specifiesglobal ambient lightwhether to support local or only infinite viewerwhether to apply lighting to front and back faces

glShadeModel()GL_FLAT: Single color for the entire polygon

Color specified by one of the vertices in the polygon (see Reference Manual)Color specified by one of the vertices in the polygon (see Reference Manual)

GL_SMOOTH: Interpolate vertex colors across the polygon

Page 32: Computer Graphics - Week 4feiner/courses/csw4160/slides/S99-4.pdf · Computer Graphics - Week 4 Bengt-Olaf Schneider IBM T.J. Watson Research Center Computer Graphics – Week 4

© Bengt-Olaf Schneider, 1999Computer Graphics – Week 4

OpenGL: Material PropertiesOpenGL: Material Properties

glMaterial()Separate material for front face, back face or bothEach material parameter is set separatelyParameters:

Ambient, diffuse, specular reflectanceAmbient, diffuse, specular reflectanceGlossiness coefficientGlossiness coefficient

Material applies to all surfaces defined after call to glMaterial()

glColorMaterial()Material properties are tracking active colorMore efficient than using glMaterial()Activate parameter tracking w/ glEnable(GL_COLOR_MATERIAL)

© Bengt-Olaf Schneider, 1999Computer Graphics – Week 4

OpenGL: Normal VectorsOpenGL: Normal Vectors

Lighting calculations require surface normals

glNormal()Specifies normal vector in active coordinate system

glEnable (GL_NORMALIZE)Vectors specified by glNormal() are scaled to unit lengthRequires extra computation

glFrontFace()Specifies whether front faces are defined by clockwise or counter-clockwise orientation of vertices

glCullFace() and glEnable(GL_CULL_FACE)Discard front-facing (or back-facing) polygons from processing

Page 33: Computer Graphics - Week 4feiner/courses/csw4160/slides/S99-4.pdf · Computer Graphics - Week 4 Bengt-Olaf Schneider IBM T.J. Watson Research Center Computer Graphics – Week 4

© Bengt-Olaf Schneider, 1999Computer Graphics – Week 4

OpenGL: Depth CueingOpenGL: Depth Cueing

glFog()Specifies depth range of depth cueingInterpolation between object and fog color

LinearLinearExponential (default)Exponential (default)Squared-exponentialSquared-exponential

© Bengt-Olaf Schneider, 1999Computer Graphics – Week 4

OpenGL: Rendering PrimitivesOpenGL: Rendering Primitives

Definition of rendering primitives bracketed by glBegin() and glEnd()

Argument to glBegin() determines primitive typeGL_POINTS, GL_LINES, GL_LINE_STRIP, GL_LINE_LOOP, GL_TRIANGLES, GL_TRIANGLE_STRIP, GL_TRIANGL_FAN, GL_QUADS, GL_QUAD_STRIP, GL_POLYGONMore complex primitives like quadrics, concave polygons, teapot and NURBS are supported by Glu and Glut libraries

Page 34: Computer Graphics - Week 4feiner/courses/csw4160/slides/S99-4.pdf · Computer Graphics - Week 4 Bengt-Olaf Schneider IBM T.J. Watson Research Center Computer Graphics – Week 4

© Bengt-Olaf Schneider, 1999Computer Graphics – Week 4

SummarySummary

Lighting model versus shading ModelLighting models for ambient, diffuse, specular illumination

Phong and Blinn lighting modelLight attenuation and athomspheric effectsComputation and transformation of normal vectors

Rendering Primitives

© Bengt-Olaf Schneider, 1999Computer Graphics – Week 4

HomeworkHomework

Foley et al., Chapter 3.11-13, 19.1

Page 35: Computer Graphics - Week 4feiner/courses/csw4160/slides/S99-4.pdf · Computer Graphics - Week 4 Bengt-Olaf Schneider IBM T.J. Watson Research Center Computer Graphics – Week 4

© Bengt-Olaf Schneider, 1999Computer Graphics – Week 4

Next Week ...Next Week ...

Clip Volume Clip Volume

Polygon ClippedPolygon

Line:

P

P P t P P

ax by cz d

abcd

xyz

V P

L = + ⋅ −

+ + +⇒

=

F

H

GGGG

I

K

JJJJ•

F

H

GGGG

I

K

JJJJ= •

1 2 1

0

1

( )

lane: 0 =

Clipping