lighting and shading spring 2003 cal state san marcos

81
Spring 2003 Cal State San Marcos Lighting and Shading

Upload: darren-evans

Post on 19-Jan-2018

215 views

Category:

Documents


0 download

DESCRIPTION

Lighting and Shading Illumination Lighting Shading The flux of light energy from light sources to objects in the scene via direct and indirect paths Lighting The process of computing the luminous intensity reflected from a specified 3-D point Shading The process of assigning a colors to a pixel Spring 2003 Cal State San Marcos

TRANSCRIPT

Page 1: Lighting and Shading Spring 2003 Cal State San Marcos

Spring 2003 Cal State San Marcos

Lighting and Shading

Page 2: Lighting and Shading Spring 2003 Cal State San Marcos

Spring 2003 Cal State San Marcos

Lighting and ShadingIllumination

The flux of light energy from light sources to objects in the scene via direct and indirect paths

LightingThe process of computing the luminous intensity reflected from a specified 3-D point

ShadingThe process of assigning a colors to a pixel

Page 3: Lighting and Shading Spring 2003 Cal State San Marcos

Spring 2003 Cal State San Marcos

Energy and Power of Light Light is a form of energy

measured in Joules (J) Power: energy per unit time

Measured in Joules/sec = Watts (W) Also known as Radiant Flux ( )

Page 4: Lighting and Shading Spring 2003 Cal State San Marcos

Spring 2003 Cal State San Marcos

Point Light Source Total radiant flux in Watts

Energy emitted in unit time How to define angular

dependence? Use solid angle

Define power per unit solid angle: Radiant Intensity (I) Measured in Watts per

steradian (W/sr)

Page 5: Lighting and Shading Spring 2003 Cal State San Marcos

Spring 2003 Cal State San Marcos

Light Emitted from a Surface Radiance (L): Power per

unit area per unit solid angle Measured in W/m2sr dA is projected area –

perpendicular to given direction

Radiosity (B): Radiance integrated over all directions

Power from per unit area, measured in W/m2

dLB cos),(

Page 6: Lighting and Shading Spring 2003 Cal State San Marcos

Spring 2003 Cal State San Marcos

Light Falling on a Surface Power falling on per

unit area – Irradiance (E) Measured in W/m2 Depends on

Distance from the light source: inverse square law E ~ 1/r2

Incident direction: cosine law E ~ n.l

Page 7: Lighting and Shading Spring 2003 Cal State San Marcos

Spring 2003 Cal State San Marcos

Irradiance The irradiance (E) is an integral of all incident radiance.

iii dLE cos

Page 8: Lighting and Shading Spring 2003 Cal State San Marcos

Spring 2003 Cal State San Marcos

ReflectionThe amount of reflected radiance is proportional to the incident radiance.

iLrL

( , , , )r r r i i iL E

Page 9: Lighting and Shading Spring 2003 Cal State San Marcos

Spring 2003 Cal State San Marcos

BRDF is called Bidirectional Reflectance

Distribution Function (BRDF) Is a surface property Relates energy in to energy out Depends on incoming and outgoing directions

),,,( iirr

Page 10: Lighting and Shading Spring 2003 Cal State San Marcos

Spring 2003 Cal State San Marcos

Local Illumination

Phong illumination model approximates the BRDF with combination of diffuse and specular components.

iiiiirrr dLL cos),(

Page 11: Lighting and Shading Spring 2003 Cal State San Marcos

Spring 2003 Cal State San Marcos

Energy Balance Equation The total light leaving a point is given by the sum

of two major terms: Emitted from the point Incoming light from other sources reflected at the point

dLLL ioobdooeoo cos),,(),,,,(),,(),,( xxxx

Light leaving

Emission Sum BRDF Incominglight

Incoming light reflected at the point

Page 12: Lighting and Shading Spring 2003 Cal State San Marcos

Spring 2003 Cal State San Marcos

Rendering Equation

L is the radiance from a point on a surface in a given direction ω E is the emitted radiance from a point: E is non-zero only if x’ is emissive V is the visibility term: 1 when the surfaces are unobstructed along the direction ω, 0 otherwise G is the geometry term, which depends on the geometric relationship between the two surfaces x and x’It’s very hard to directly solve this equation. Have to use some approximations.

( ) ( ) ( ) ( ) ( ) ( ), , , ,s

L x E x x L x G x x V x x dAw r w¢ ¢ ¢ ¢ ¢ ¢= +òr r

Page 13: Lighting and Shading Spring 2003 Cal State San Marcos

Spring 2003 Cal State San Marcos

Fast and Dirty Approximations (OpenGL) Use red, green, and blue instead of full spectrum

Roughly follows the eye's sensitivity Forego such complex surface behavior as metals

Use finite number of point light sources instead of full hemisphere Integration changes to summation Forego such effects as soft shadows and color bleeding

BRDF behaves independently on each color Treat red, green, and blue as three separate computations Forego such effects as iridescence and refraction

BRDF split into three approximate effects Ambient: constant, non-directional, background light Diffuse: light reflected uniformly in all directions Specular: light of higher intensity in mirror-reflection direction

Radiance L replaced by simple ``intensity'' I No pretense of being physically true

Page 14: Lighting and Shading Spring 2003 Cal State San Marcos

Spring 2003 Cal State San Marcos

Approximate Intensity Equation (single light source)

cos( )l

( )lW

l

cos( ) ( ) ( )o e a a d l l s l l lI I k I k I k I W S

lI

                                                                 •   stands for each of red, green, blue •    is the intensity of the light source (modified for distance) •         accounts for the angle of the incoming light •the k are between 0 and 1 and represent absorption factors •        accounts for any highlight effects that depend on the incoming direction

•use         or constant if there is nothing special •    is the mirror reflection angle for the light

•the angle between the view direction and the mirror reflection direction

•       accounts for highlights in the mirror reflection direction •the superscripts e, a, d, s stand for emitted, ambient, diffuse, specular respectively •sum over each light l if there are more one

( )lS

cos( )l

Page 15: Lighting and Shading Spring 2003 Cal State San Marcos

Spring 2003 Cal State San Marcos

OpenGL Lighting Model Local illumination model

Only depends relationship to the light source. Don’t consider light reflected or refracted from other

objects. Don’t model shadow (can be faked)

A point is lighted only if it can see the light source. It’s difficult to compute visibility to light sources in

complex scenes. OpenGL only tests if the polygon faces to the light source. For a point P on a polygon with norm n, P is lighted by

the light source Q only if 0)( nPQ

Page 16: Lighting and Shading Spring 2003 Cal State San Marcos

Spring 2003 Cal State San Marcos

Ambient Light Source An object is lighted by the ambient light even if it is not visible to any light source. Ambient light

no spatial or directional characteristics.

The amount of ambient light incident on each object is a constant for all surfaces in the scene.

A ambient light can have a color. The amount of ambient light that is reflected by an object is independent of the object's position or orientation. Surface properties are used to determine how much ambient light is reflected.

Page 17: Lighting and Shading Spring 2003 Cal State San Marcos

Spring 2003 Cal State San Marcos

Directional Light Sources All of the rays from a directional light source have a common direction, and no point of origin.

It is as if the light source was infinitely far away from the surface that it is illuminating.

Sunlight is an example of a directional light source.

The direction from a surface to a light source is important for computing the light reflected from the surface. A directional light source has a constant direction for every surface. A directional light source can be colored.

Page 18: Lighting and Shading Spring 2003 Cal State San Marcos

Spring 2003 Cal State San Marcos

Point Light SourcesThe point light source emits rays in radial directions from its source. A point light source is a fair approximation to a local light source such as a light bulb.

The direction of the light to each point on a surface changes when a point light source is used. Thus, a normalized vector to the light emitter must be computed for each point that is illuminated.

lplpd

Page 19: Lighting and Shading Spring 2003 Cal State San Marcos

Spring 2003 Cal State San Marcos

Other Light SourcesSpotlights

Restricting the shape of light emitted by a point light to a cone.

Requires a color, a point, a direction, and a cutoff angle to define the cone.

Area Light Sources Light source occupies a 2-D area (usually

a polygon or disk) Generates soft shadows

Extended Light Sources Spherical Light Source Generates soft shadows

Page 20: Lighting and Shading Spring 2003 Cal State San Marcos

Spring 2003 Cal State San Marcos

OpenGL Specifications Available light models in OpenGL

Ambient lights Point lights Directional lights Spot lights

Attenuation Physical attenuation: OpenGL attenuation:

Default a = 1, b=0, c=0

2

)()(QPQIPI

2

)()(cdbda

QIPI

Page 21: Lighting and Shading Spring 2003 Cal State San Marcos

Spring 2003 Cal State San Marcos

Example of OpenGL Light Setting up a simple lighting situation

GLfloat ambientIntensity[4] = {0.1, 0.1, 0.1, 1.0}; GLfloat diffuseIntensity[4] = {1.0, 0.0, 0.0, 1.0}; GLfloat position[4] = {2.0, 4.0, 5.0, 1.0}; glEnable(GL_LIGHTING); // enable lighting glEnable(GL_LIGHT0); // enable light 0 // set up light 0 properties glLightfv(GL_LIGHT0, GL_AMBIENT, ambientIntensity); glLightfv(GL_LIGHT0, GL_DIFFUSE, diffuseIntensity); glLightfv(GL_LIGHT0, GL_POSITION, position);

Page 22: Lighting and Shading Spring 2003 Cal State San Marcos

Spring 2003 Cal State San Marcos

Ideal Diffuse ReflectionIdeal Diffuse Reflection: an incoming ray of light is equally likely to be reflected in any direction over the hemisphere.

An ideal diffuse surface is, at the microscopic level a very rough surface. Chalk is a good approximation to an ideal diffuse surface.

The reflected intensity is independent of the viewing direction. The intensity does however depend on the light source's orientation relative to the surface.

Page 23: Lighting and Shading Spring 2003 Cal State San Marcos

Spring 2003 Cal State San Marcos

Computing Diffuse Reflection

Angle of incidence: The angle between the surface normal and the incoming light ray Lambert's law states that the reflected energy from a small surface area in a particular direction is proportional to cosine of the angle of incidence.

Page 24: Lighting and Shading Spring 2003 Cal State San Marcos

Spring 2003 Cal State San Marcos

Diffuse Lighting Examples We need only consider angles from 0 to 90 degrees. Greater angles (where the dot product is negative) are blocked by the surface, and the reflected energy is 0. Below are several examples of a spherical diffuse reflector with a varying lighting angles.

Page 25: Lighting and Shading Spring 2003 Cal State San Marcos

Spring 2003 Cal State San Marcos

Specular Reflection

A specular reflector is necessary to model a shiny surface, such as polished metal or a glossy car finish. We see a highlight, or bright spot on those surfaces. Where this bright spot appears on the surface is a function of where the surface is seen from. This type of reflectance is view dependent. At the microscopic level a specular reflecting surface is very smooth, and usually these microscopic surface elements are oriented in the same direction as the surface itself. Specular reflection is merely the mirror reflection of the light source in a surface. An ideal mirror is a purely specular reflector.

Page 26: Lighting and Shading Spring 2003 Cal State San Marcos

Spring 2003 Cal State San Marcos

Reflection The incoming ray, the surface normal, and the reflected ray all lie in a common plane. According to Snell’s Law, The incident angle is equal to the reflection on a perfect reflective surface.

l rq q=

Page 27: Lighting and Shading Spring 2003 Cal State San Marcos

Spring 2003 Cal State San Marcos

Non-ideal Reflectors Snell's law, however, applies only to ideal mirror reflectors. Real materials tend to deviate significantly from ideal reflectors. At this point we will introduce an empirical model that is consistent with our experience, at least to a crude approximation. In general, 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 slightly offset from the ideal reflected ray. As we move farther and farther, in the angular sense, from the reflected ray we expect to see less light reflected.

Page 28: Lighting and Shading Spring 2003 Cal State San Marcos

Spring 2003 Cal State San Marcos

Phong Illumination One function that approximates this fall off is called the Phong Illumination model. This model has no physical basis, yet it is one of the most commonly used illumination models in computer graphics. The cosine term is maximum when the surface is viewed from the mirror direction and falls off to 0 when viewed at 90 degrees away from it. The scalar nshiny controls the rate of this fall off.

shinyspecular light cosn

sI k I f=

Page 29: Lighting and Shading Spring 2003 Cal State San Marcos

Spring 2003 Cal State San Marcos

Effect of the nshiny coefficientThe diagram below shows the how the reflectance drops off in a Phong illumination model. For a large value of the nshiny coefficient, the reflectance decreases rapidly with increasing viewing angle.

Page 30: Lighting and Shading Spring 2003 Cal State San Marcos

Spring 2003 Cal State San Marcos

Computing Phong Illumination

The V vector is the unit vector in the direction of the viewer and the R vector is the mirror reflectance direction. The vector R can be computed from the incoming light direction and the surface normal:

( ) shiny

specular light ˆ ˆ n

sI k I V R= ×

( )ˆ ˆ ˆ ˆ2R N L N L= × -

Page 31: Lighting and Shading Spring 2003 Cal State San Marcos

Spring 2003 Cal State San Marcos

Blinn & Torrance Variation

( ) shiny

specular light ˆ ˆ n

sI k I N H= ×

Jim Blinn introduced another approach for computing Phong-like illumination based on the work of Ken Torrance. His illumination function uses the following equation:

In this equation the angle of specular dispersion is computed by how far the surface's normal is from a vector bisecting the incoming light direction and the viewing direction. On your own you should consider how this approach and the previousone differ. OpenGL implements thismodel.

Page 32: Lighting and Shading Spring 2003 Cal State San Marcos

Spring 2003 Cal State San Marcos

Phong Examples The following spheres illustrate specular reflections as the direction of the light source and the coefficient of shininess is varied.

Page 33: Lighting and Shading Spring 2003 Cal State San Marcos

Spring 2003 Cal State San Marcos

Putting it all togetherPhong Illumination Model

nshinysdlightambientatotal RVKLNKIIKI )()(

Page 34: Lighting and Shading Spring 2003 Cal State San Marcos

Spring 2003 Cal State San Marcos

Colored Lights and Surfaces

for each light Ii for each color component reflectance coefficients kd, ks, and ka scalars between 0 and

1 may or may not vary with color nshiny scalar integer: 1 for diffuse surface, 100 for metallic

shiny surfaces

lights

i

n

sdlilambientaltotalshinyRVKLNKIIKI

1,,,

Page 35: Lighting and Shading Spring 2003 Cal State San Marcos

Spring 2003 Cal State San Marcos

Where do we Illuminate?

To this point we have discussed how to compute an illumination model at a point on a surface. But, at which points on the surface is the illumination model applied? Where and how often it is applied has a noticeable effect on the result. Lighting can be a costly process involving the computation of and normalizing of vectors to multiple light sources and the viewer. For models defined by collections of polygonal facets or triangles:

Each facet has a common surface normal If the light is directional then the diffuse contribution is constant

across the facet. Why? If the eye is infinitely far away and the light is directional then the

specular contribution is constant across the facet. Why?

Page 36: Lighting and Shading Spring 2003 Cal State San Marcos

Spring 2003 Cal State San Marcos

Flat Shading The simplest shading method applies only one illumination calculation for each primitive. This technique is called constant or flat shading. It is often used on polygonal primitives.

Drawbacks: the direction to the light source varies over the facet the direction to the eye varies over the facet

Nonetheless, often illumination is computed for only a single point on the facet. Usually the centroid.

Page 37: Lighting and Shading Spring 2003 Cal State San Marcos

Spring 2003 Cal State San Marcos

Even when the illumination equation is applied at each point of the facet, the polygonal nature is still apparent.

To overcome this limitation normals are introduced at each vertex.

different than the polygon normal for shading only (not backface culling or other computations) better approximates smooth surfaces

Facet Shading

Page 38: Lighting and Shading Spring 2003 Cal State San Marcos

Spring 2003 Cal State San Marcos

Vertex Normals If vertex normals are not provided they can often be approximated by averaging the normals of the facets which share the vertex.

This only works if the polygons reasonably approximate the underlying surface.

1

ki

vi i

nnn=

= årr r

Page 39: Lighting and Shading Spring 2003 Cal State San Marcos

Spring 2003 Cal State San Marcos

Gouraud Shading

The Gouraud shading method applies the illumination model at each vertex and the colors in the triangles interior are linearly interpolated from these vertex values.

Implemented in OpenGL as Smooth Shading. Notice that facet artifacts are still visible.

Page 40: Lighting and Shading Spring 2003 Cal State San Marcos

Spring 2003 Cal State San Marcos

Phong Shading In Phong shading (not to be confused with the Phong illumination model), the surface normal is linearly interpolated across polygonal facets, and the Illumination model is applied at every point. A Phong shader assumes the same input as a Gouraud shader, which means that it expects a normal for every vertex. The illumination model is applied at every point on the surface being rendered, where the normal at each point is the result of linearly interpolating the vertex normals defined at each vertex of the triangle.

Phong shading will usually result in a very smooth appearance, however, evidence of the polygonal model can usually be seen along silhouettes.

Page 41: Lighting and Shading Spring 2003 Cal State San Marcos

Spring 2003 Cal State San Marcos

Gouraud and Phong Shading

Page 42: Lighting and Shading Spring 2003 Cal State San Marcos

Spring 2003 Cal State San Marcos

OpenGL Specifications Each light has ambient, diffuse, and specular

component. Each light can be a point light, directional light, or

spot light. Directional light is a point light positioned at infinity

Shading Models: flat and smooth glShadeModel() GL_FLAT, GL_SMOOTH Smooth model uses Gouraud shading

Page 43: Lighting and Shading Spring 2003 Cal State San Marcos

Spring 2003 Cal State San Marcos

OpenGL Examples We have shown how to set up lights in OpenGL Set surface material properties

glMaterialf(GLenum face, GLenum pname, GLfloat param) glMaterialfv(GLenum face,GLenum pname,GLfloat* param) Face can be GL_FRONT, GL_BACK, or L_FRONT_AND_BACK Pname can be GL_AMBIENT, GL_DIFFUSE, GL_SPECULAR,

GL_SHINESS, and GL_EMISSION …GLfloat mat_specular[] = { 1.0, 1.0, 1.0, 1.0 }; GLfloat low_shininess[] = { 5.0 }; glMaterialfv(GL_FRONT, GL_SPECULAR, mat_specular);glMaterialfv(GL_FRONT, GL_SHININESS,low_shininess);

Nonzero GL_EMISSION makes an object appear to be giving off light of that color

Refer to OpenGL programming guide for more details

Page 44: Lighting and Shading Spring 2003 Cal State San Marcos

Spring 2003 Cal State San Marcos

Triangle Normals Surface normals are the most important geometric surface characteristic used in computing illumination models. They are used in computing both the diffuse and specular components of reflection. On a faceted planar surface vectors in the tangent plane can be computed using surface points as follows.

Normal is always orthogonal to the tangent space at a point. Thus, given two tangent vectors we can compute the normal as follows:

This normal is perpendicular to both of these tangent vectors.

1 1 0 2 2 0, t p p t p p= - = -r rr r r r

1 2n t t= ´r rr

1 2 0n t n t× = × =r rr r

Page 45: Lighting and Shading Spring 2003 Cal State San Marcos

Spring 2003 Cal State San Marcos

Normals of Curved SurfacesNot all surfaces are given as planar facets. A common example of such a surface a parametric surface. For a parametric surface the three-space coordinates are determined by functions of two parameters u and v.

The tangent vectors are computed with partial derivatives and the normal with a cross product:

( , )( , ) ( , )

( , )

X u vS u v Y u v

Z u v

é ùê úê ú= ê úê úë û

1 2 1 2, ,

X Xu vY Yt t n t tu v

ZZvu

é ù é ù¶ ¶ê ú ê úê ú ê ú¶ ¶ê ú ê ú¶ ¶ê ú ê ú= = = ´ê ú ê ú¶ ¶ê ú ê úê ú ê ú¶¶ê ú ê úê ú ê ú¶¶ ê úê ú ë ûë û

r r r rr

Page 46: Lighting and Shading Spring 2003 Cal State San Marcos

Spring 2003 Cal State San Marcos

Normals of Implicit Surfaces Normals of implicit surfaces S are even simpler:

This is often called the gradient vector

{ }If ( , , ) ( , , ) 0 thenS x y z F x y z

FxFnyFz

= =é ù¶ê úê ú¶ê ú¶ê ú= ê ú¶ê úê ú¶ê úê úê ú¶ë û

r

Page 47: Lighting and Shading Spring 2003 Cal State San Marcos

Spring 2003 Cal State San Marcos

Texture Mappings

Page 48: Lighting and Shading Spring 2003 Cal State San Marcos

Spring 2003 Cal State San Marcos

Mapping Techniques Consider the problem of rendering a sphere in the

examples The geometry is very simple - a sphere But the color changes rapidly With the local shading model, so far, the only place to

specify color is at the vertices To get color details, would need thousands of polygons for

a simple shape Same things goes for an orange: simple shape but

complex normal vectors Solution: Mapping techniques use simple geometry

modified by a mapping of some type

Page 49: Lighting and Shading Spring 2003 Cal State San Marcos

Spring 2003 Cal State San Marcos

texturesThe concept is very simple!

Page 50: Lighting and Shading Spring 2003 Cal State San Marcos

Spring 2003 Cal State San Marcos

Texture Mapping Texture mapping associates the color of a point with

the color in an image: the texture Each point on the sphere gets the color of mapped pixel of

the texture Question to address: Which point of the texture do

we use for a given point on the surface? Establish a mapping from surface points to image

points Different mappings are common for different shapes We will, for now, just look at triangles (polygons)

Page 51: Lighting and Shading Spring 2003 Cal State San Marcos

Spring 2003 Cal State San Marcos

Basic Mapping The texture lives in a 2D space

Parameterize points in the texture with 2 coordinates: (s,t) These are just what we would call (x,y) if we were talking about

an image, but we wish to avoid confusion with the world (x,y,z) Define the mapping from (x,y,z) in world space to (s,t) in texture

space To find the color in the texture, take an (x,y,z) point on the

surface, map it into texture space, and use it to look up the color of the texture

With polygons: Specify (s,t) coordinates at vertices Interpolate (s,t) for other points based on given vertices

Page 52: Lighting and Shading Spring 2003 Cal State San Marcos

Spring 2003 Cal State San Marcos

Texture Interpolation Specify where the

vertices in world space are mapped to in texture space

Linearly interpolate the mapping for other points in world space Straight lines in world

space go to straight lines in texture space

Texture maps

t

Triangle in world space

Page 53: Lighting and Shading Spring 2003 Cal State San Marcos

Spring 2003 Cal State San Marcos

Textures Two-dimensional texture pattern T(s, t) It is stored in texture memory as an n*m array

of texture elements (texels) Due to the nature of rendering process, which

works on a pixel-to-pixel base, we are more interested in the inverse map from screen coordinates to the texture coordinates

Page 54: Lighting and Shading Spring 2003 Cal State San Marcos

Spring 2003 Cal State San Marcos

Computing Color in Texture mapping Associate texture with polygon Map pixel onto polygon and then into texture map Use weighted average of covered texture to compute color.

Page 55: Lighting and Shading Spring 2003 Cal State San Marcos

Spring 2003 Cal State San Marcos

Basic OpenGL Texturing Specify texture coordinates for the polygon:

Use glTexCoord2f(s,t) before each vertex: Eg: glTexCoord2f(0,0); glVertex3f(x,y,z);

Create a texture object and fill it with texture data: glGenTextures(num, &indices) to get identifiers for the

objects glBindTexture(GL_TEXTURE_2D, identifier) to bind the

texture Following texture commands refer to the bound texture

glTexParameteri(GL_TEXTURE_2D, …, …) to specify parameters to use when applying the texture

glTexImage2D(GL_TEXTURE_2D, ….) to specify the texture data (the image itself) MORE…

Page 56: Lighting and Shading Spring 2003 Cal State San Marcos

Spring 2003 Cal State San Marcos

Basic OpenGL Texturing (cont) Enable texturing: glEnable(GL_TEXTURE_2D) State how the texture will be used:

glTexEnvf(…) Texturing is done after lighting

Page 57: Lighting and Shading Spring 2003 Cal State San Marcos

Spring 2003 Cal State San Marcos

Controlling Different Parameters The “texels” in the texture map may be interpreted

as many different things. For example: As colors in RGB or RGBA format As grayscale intensity As alpha values only

The data can be applied to the polygon in many different ways: Replace: Replace the polygon color with the texture color Modulate: Multiply the polygon color with the texture color

or intensity Similar to compositing: Composite texture with base color

using operator

Page 58: Lighting and Shading Spring 2003 Cal State San Marcos

Spring 2003 Cal State San Marcos

Texture Stuffs Texture must be in fast memory - it is accessed for every pixel

drawn If you exceed it, performance will degrade horribly There are functions for managing texture memory Skilled artists can pack textures for different objects into one

map Texture memory is typically limited, so a range of functions are

available to manage it Specifying texture coordinates can be annoying, so there are

functions to automate it Sometimes you want to apply multiple textures to the same

point: Multitexturing is now in some hardware

Page 59: Lighting and Shading Spring 2003 Cal State San Marcos

Spring 2003 Cal State San Marcos

Yet More Texture Stuff There is a texture matrix in OpenGL: apply a matrix

transformation to texture coordinates before indexing texture

There are “image processing” operations that can be applied to the pixels coming out of the texture

There are 1D and 3D textures Mapping works essentially the same 3D used in visualization applications, such a visualizing

MRI or other medical data 1D saves memory if the texture is inherently 1D, like

stripes

Page 60: Lighting and Shading Spring 2003 Cal State San Marcos

Spring 2003 Cal State San Marcos

Procedural Texture Mapping Instead of looking up an image, pass the texture

coordinates to a function that computes the texture value on the fly Renderman, the Pixar rendering language, does this Available in a limited form with vertex shaders on current

generation hardware Advantages:

Near-infinite resolution with small storage cost Has the disadvantage of being slow in many cases

Page 61: Lighting and Shading Spring 2003 Cal State San Marcos

Spring 2003 Cal State San Marcos

Other Types of Mapping Bump-mapping computes an offset to the normal

vector at each rendered pixel No need to put bumps in geometry, but silhouette

looks wrong Displacement mapping adds an offset to the surface at

each point Like putting bumps on geometry, but simpler to model

All are available in software renderers like RenderMan compliant renderers

All these are becoming available in hardware

Page 62: Lighting and Shading Spring 2003 Cal State San Marcos

Spring 2003 Cal State San Marcos

Bump MappingTextures can be used to alter the surface normal of an object. This does not change the actual shape of the surface -- we are only shading it as if it were a different shape! This technique is called bump mapping. The texture map is treated as a single-valued height function. The value of the function is not actually used, just its partial derivatives. The partial derivatives tell how to alter the true surface normal at each point on the surface to make the object appear as if it were deformed by the height function.

Since the actual shape of the object does not change, the silhouette edge of the object will not change. Bump Mapping also assumes that the Illumination model is applied at every pixel (as in Phong Shading or ray tracing).

Sphere w/Diffuse Texture

Swirly Bump Map

Sphere w/Diffuse Texture & Bump Map

Page 63: Lighting and Shading Spring 2003 Cal State San Marcos

Spring 2003 Cal State San Marcos

Bump Map Examples

Cylinder w/Diffuse Texture Map

Bump Map

Cylinder w/Texture Map & Bump Map

Page 64: Lighting and Shading Spring 2003 Cal State San Marcos

Spring 2003 Cal State San Marcos

Displacement MappingWe use the texture map to actually move the surface point. This is called displacement mapping. How is this fundamentally different than bump mapping?

The geometry must be displaced before visibility is determined.

Page 65: Lighting and Shading Spring 2003 Cal State San Marcos

Spring 2003 Cal State San Marcos

Readings Textbook 16.1-16.3 OpenGL Programming Guide Chapter 5 and

Chap 9.

Page 66: Lighting and Shading Spring 2003 Cal State San Marcos

Spring 2003 Cal State San Marcos

Better Illumination ModelsBlinn-Torrance-Sparrow (1977)

isotropic collection of planar microscopic facets Cook-Torrance (1982)

Add wavelength dependent Fresnel term He-Torrance-Sillion-Greenberg (1991)

adds polarization, statistical microstructure, self-reflectance Very little of this work has made its way into graphics H/W.

Page 67: Lighting and Shading Spring 2003 Cal State San Marcos

Spring 2003 Cal State San Marcos

Cook-Torrance Illumination

Iλ,a - Ambient light intensityka - Ambient surface reflectanceIλ,i - Luminous intensity of light source i ks - percentage of light reflected specularly (notice terms sum to one) kd - Diffuse reflectivity li - vector to light source n - average surface normal at point D - the distribution of microfacet orientationsG - the masking and shadowing effects between the microfacetsFλ(θi) - Fresnel conductance term related to material’s index of refractionv - vector to viewer

( ) ( )( ) , ,

1ˆ ˆ ˆˆ

lightsi

a a i d i si

DGFI k I I k l n k

v nl

l l lq

p=

é ùê ú= + × +ê ú×ê úë ûå

Page 68: Lighting and Shading Spring 2003 Cal State San Marcos

Spring 2003 Cal State San Marcos

Microfacet Distribution Function2ˆˆtan( )

2 4 ˆˆ4 cos ( )

n hmeD

m n h

æ ö× ÷ç ÷ç- ÷ç ÷÷çè ø=

×

• Statistical model of the microfacet variation in normal direction • Based on a Beckman distribution function • Consistent with the surface variations of rough surfaces • m - the root-mean-square slope of the microfacets

• Small m (e.g., 0.2) : pretty smooth surface• Large m (e.g., 0.7) : pretty rough surface

Page 69: Lighting and Shading Spring 2003 Cal State San Marcos

Spring 2003 Cal State San Marcos

Beckman's Distribution

Page 70: Lighting and Shading Spring 2003 Cal State San Marcos

Spring 2003 Cal State San Marcos

Geometric Attenuation Factor The geometric attenuation factor G accounts for microfacet shadowing.

in the range from 0 (total shadowing) to 1 (no shadowing). There are many different ways that an incoming beam of light can interact with the surface locally. The entire beam can simply reflect.

Page 71: Lighting and Shading Spring 2003 Cal State San Marcos

Spring 2003 Cal State San Marcos

Blocked ReflectionA portion of the out-going beam can be blocked.This is called masking.

Page 72: Lighting and Shading Spring 2003 Cal State San Marcos

Spring 2003 Cal State San Marcos

Blocked Beam A portion of the incoming beam can be blocked. Cook called this self-shadowing.

Page 73: Lighting and Shading Spring 2003 Cal State San Marcos

Spring 2003 Cal State San Marcos

Geometric Attenuation FactorIn each case, the geometric configurations can be analyzed to compute the percentage of light that actually escapes from the surface. The geometric factor, chooses the smallest amount of lost light.

( )( )

( )( ){ }

blocked

facet

masking

shadowing

masking shadowing

1

2

2

min 1, ,

lGl

n h n vG

v hn h n l

Gv h

G G G

= -

× ×=

×× ×

=

rr r rrr

r rr rrr

Page 74: Lighting and Shading Spring 2003 Cal State San Marcos

Spring 2003 Cal State San Marcos

Fresnel Effect

At a very sharp angle surfaces like a book, a wood table top, concrete and plastic can almost become mirrors.

Page 75: Lighting and Shading Spring 2003 Cal State San Marcos

Spring 2003 Cal State San Marcos

Fresnel ReflectionThe Fresnel term results from a complete analysis of the reflection process while considering light as an electromagnetic wave. The behavior of reflection depend on how the incoming electric field is oriented relative to the surface at the point where the field makes contact.

Page 76: Lighting and Shading Spring 2003 Cal State San Marcos

Spring 2003 Cal State San Marcos

Fresnel ReflectionThe Fresnel effect is wavelength dependent. It behavior is determined by the index-of-refraction of the material The Fresnel effect accounts for the color change of the specular highlight as a function of the angle of incidence of the light source, particularly on metals (conductors). It also explains why most surfaces approximate mirror reflectors when when the light strikes them at a grazing angle.

( ) ( )( )

( )( )( )( )

22

2 2

2 2

11 12 1

cos1

i

i

c g cg cF

g c c g c

c l h

g n c

l

l

q

q

æ ö+ - ÷ç- ÷ç ÷= +ç ÷ç ÷+ ç - + ÷çè ø= = ×= + -

r r

Page 77: Lighting and Shading Spring 2003 Cal State San Marcos

Spring 2003 Cal State San Marcos

Reflectance of Metal

Page 78: Lighting and Shading Spring 2003 Cal State San Marcos

Spring 2003 Cal State San Marcos

Reflectance of Dielectrics Non conducting material, e.g., glass, plastics.

Page 79: Lighting and Shading Spring 2003 Cal State San Marcos

Spring 2003 Cal State San Marcos

Schlick Approximation To calculate F for every angle, we can use

measurements of F0, the value of F at normal incidence.

50 0(1 cos ) (1 )F F F

Page 80: Lighting and Shading Spring 2003 Cal State San Marcos

Spring 2003 Cal State San Marcos

Index of RefractionMedium Index of

refractionVaccum 1Air 1.0003Water 1.33Fused Quartz 1.46Glass, crown 1.52Glass, dense flint

1.66

Diamond 2.42Metal 200

Page 81: Lighting and Shading Spring 2003 Cal State San Marcos

Spring 2003 Cal State San Marcos

Remaining Hard ProblemsReflective Diffraction Effects

thin films feathers of a blue jay

Anisotropy brushed metals strands pulled materials satin and velvet cloths