Top Banner
Review 2: Illumination, Shading, Texturing and Anti- aliasing Jian Huang, CS594, Spring 2002
54

Review 2: Illumination, Shading, Texturing and Anti-aliasing Jian Huang, CS594, Spring 2002.

Dec 27, 2015

Download

Documents

Allison Edwards
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Review 2: Illumination, Shading, Texturing and Anti-aliasing Jian Huang, CS594, Spring 2002.

Review 2: Illumination, Shading, Texturing and Anti-aliasing

Jian Huang, CS594, Spring 2002

Page 2: Review 2: Illumination, Shading, Texturing and Anti-aliasing Jian Huang, CS594, Spring 2002.

Illumination Vs. Shading

Illumination (lighting) model: determine the color of a surface point by simulating some light attributes.

Shading model: applies the illumination models at a set of points and colors the whole image.

Page 3: Review 2: Illumination, Shading, Texturing and Anti-aliasing Jian Huang, CS594, Spring 2002.

Local illumination

• Only consider the light, the observer position, and the object material properties

Page 4: Review 2: Illumination, Shading, Texturing and Anti-aliasing Jian Huang, CS594, Spring 2002.

Basic Illumination Model

• Simple and fast method for calculating surface intensity at a given point

• Lighting calculating are based on:– The background lighting conditions– The light source specification: color, position– Optical properties of surfaces:

• Glossy OR matte• Opaque OR transparent (control refection and

absorption)

Page 5: Review 2: Illumination, Shading, Texturing and Anti-aliasing Jian Huang, CS594, Spring 2002.

Ambient light (background light)

• The light that is the result from the light reflecting off other surfaces in the environment

• A general level of brightness for a scene that is independent of the light positions or surface directions -> ambient light

• Has no direction• Each light source has an ambient light contribution, Ia• For a given surface, we can specify how much

ambient light the surface can reflect using an ambient reflection coefficient : Ka (0 < Ka < 1)

Page 6: Review 2: Illumination, Shading, Texturing and Anti-aliasing Jian Huang, CS594, Spring 2002.

Ambient Light

• So the amount of light that the surface reflect is therefore

Iamb = Ka * Ia

Page 7: Review 2: Illumination, Shading, Texturing and Anti-aliasing Jian Huang, CS594, Spring 2002.

Diffuse Light

• The illumination that a surface receives from a light source and reflects equally in all directions

• This type of reflection is called Lambertian Reflection (thus, Lambertian surfaces)

• The brightness of the surface is indepenent of the observer position (since the light is reflected in all direction equally)

Page 8: Review 2: Illumination, Shading, Texturing and Anti-aliasing Jian Huang, CS594, Spring 2002.

Lambert’s Law• How much light the surface receives from a

light source depends on the angle between its angle and the vector from the surface point to the light (light vector)

• Lambert’s law: the radiant energy ’Id’ from a small surface da for a given light source is:

Id = IL * cos)IL : the intensity of the light source is the angle between the surface normal (N) and light vector (L)

Page 9: Review 2: Illumination, Shading, Texturing and Anti-aliasing Jian Huang, CS594, Spring 2002.

The Diffuse Component

• Surface’s material property: assuming that the surface can reflect Kd (0<Kd<1), diffuse reflection

coefficient) amount of diffuse light:

Idiff = Kd * IL * cos)

If N and L are normalized, cos) = N*L

Idiff = Kd * IL * (N*L)

• The total diffuse reflection = ambient + diffuse

Idiff = Ka * Ia + Kd * IL * (N*L)

Page 10: Review 2: Illumination, Shading, Texturing and Anti-aliasing Jian Huang, CS594, Spring 2002.

Examples

Sphere diffusely lighted from various angles !

Page 11: Review 2: Illumination, Shading, Texturing and Anti-aliasing Jian Huang, CS594, Spring 2002.

Specular Light

These are the bright spots on objects (such as polished metal, apple ...)

Light reflected from the surface unequally to all directions.

The result of near total reflection of the incident light in a concentrated region around the specular reflection angle

Page 12: Review 2: Illumination, Shading, Texturing and Anti-aliasing Jian Huang, CS594, Spring 2002.

Phong’s Model for Specular

• How much reflection light you can see depends on where you are

Page 13: Review 2: Illumination, Shading, Texturing and Anti-aliasing Jian Huang, CS594, Spring 2002.

Phong Illumination Curves

Specular exponents are much larger than 1;

Values of 100 are not uncommon.

n : glossiness, rate of falloff

Page 14: Review 2: Illumination, Shading, Texturing and Anti-aliasing Jian Huang, CS594, Spring 2002.

Specular Highlights

• Shiny surfaces change appearance when viewpoint is changed• Specularities are caused by microscopically smooth surfaces.• A mirror is a perfect specular reflector

Page 15: Review 2: Illumination, Shading, Texturing and Anti-aliasing Jian Huang, CS594, Spring 2002.

Phong Illumination

Moving Light

Change n

Page 16: Review 2: Illumination, Shading, Texturing and Anti-aliasing Jian Huang, CS594, Spring 2002.

Putting It All Together

• Single Light (white light source)

Page 17: Review 2: Illumination, Shading, Texturing and Anti-aliasing Jian Huang, CS594, Spring 2002.

Flat Shading

Page 18: Review 2: Illumination, Shading, Texturing and Anti-aliasing Jian Huang, CS594, Spring 2002.

Smooth Shading

• Need to have per-vertex normals• Gouraud Shading

– Interpolate color across triangles– Fast, supported by most of the graphics

accelerator cards

• Phong Shading – Interpolate normals across triangles– More accurate, but slow. Not widely supported by

hardware

Page 19: Review 2: Illumination, Shading, Texturing and Anti-aliasing Jian Huang, CS594, Spring 2002.

Gouraud Shading

• Normals are computed at the polygon vertices• If we only have per-face normals, the normal at each

vertex is the average of the normals of its adjacent faces

• Intensity interpolation: linearly interpolate the pixel intensity (color) across a polygon surface

Page 20: Review 2: Illumination, Shading, Texturing and Anti-aliasing Jian Huang, CS594, Spring 2002.

Gouraud Shading

Page 21: Review 2: Illumination, Shading, Texturing and Anti-aliasing Jian Huang, CS594, Spring 2002.

Phong Shading Model Gouraud shading does not properly handle specular

highlights, specially when the n parameter is large (small highlight).

Reason: colors are interpolated.

Solution: (Phong Shading Model)

1. Compute averaged normal at vertices.

2. Interpolate normals along edges and scan-lines. (component by component)

3. Compute per-pixel illumination.

Page 22: Review 2: Illumination, Shading, Texturing and Anti-aliasing Jian Huang, CS594, Spring 2002.

Phong Shading

Page 23: Review 2: Illumination, Shading, Texturing and Anti-aliasing Jian Huang, CS594, Spring 2002.

What Dreams May Come

Page 24: Review 2: Illumination, Shading, Texturing and Anti-aliasing Jian Huang, CS594, Spring 2002.

How to efficiently add graphics detail?

• Solution - (its really a cheat!!)

• How?

MAP surface detail from a predefined (easy to model) table (“texture”) to a simple polygon

Page 25: Review 2: Illumination, Shading, Texturing and Anti-aliasing Jian Huang, CS594, Spring 2002.

Texture Mapping

• Problem #1– Fitting a square peg in a round hole– We deal with non-linear

transformations– Which parts map where?

Page 26: Review 2: Illumination, Shading, Texturing and Anti-aliasing Jian Huang, CS594, Spring 2002.

Texture Mapping

• Problem #2– Mapping from a pixel to a “texel”– Aliasing is a huge problem!

Page 27: Review 2: Illumination, Shading, Texturing and Anti-aliasing Jian Huang, CS594, Spring 2002.

What is a Texture?

• Given the (texture/image index) (u,v), want:– FF(u,v) ==> a continuous reconstruction

• = { R(u,v), G(u,v), B(u,v) }• = { I(u,v) }• = { index(u,v) }• = { alpha(u,v) }• = { normals(u,v) }• = { surface_height(u,v) }• = ...

Page 28: Review 2: Illumination, Shading, Texturing and Anti-aliasing Jian Huang, CS594, Spring 2002.

RGB Textures

• Places an image on the object• “Typical” texture mapping

Page 29: Review 2: Illumination, Shading, Texturing and Anti-aliasing Jian Huang, CS594, Spring 2002.

Opacity Textures

• A binary mask, really redefines the geometry.

Page 30: Review 2: Illumination, Shading, Texturing and Anti-aliasing Jian Huang, CS594, Spring 2002.

Bump Mapping

• This modifies the surface normals.

• More on this later.

Page 31: Review 2: Illumination, Shading, Texturing and Anti-aliasing Jian Huang, CS594, Spring 2002.

Displacement Mapping

• Modifies the surface position in the direction of the surface normal.

Page 32: Review 2: Illumination, Shading, Texturing and Anti-aliasing Jian Huang, CS594, Spring 2002.

Texture and Texel

• Each pixel in a texture map is called a Texel• Each Texel is associated with a (u,v) 2D

texture coordinate• The range of u, v is [0.0,1.0]

Page 33: Review 2: Illumination, Shading, Texturing and Anti-aliasing Jian Huang, CS594, Spring 2002.

(u,v) tuple

• For any (u,v) in the range of (0-1, 0-1), we can find the corresponding value in the texture using some interpolation

Page 34: Review 2: Illumination, Shading, Texturing and Anti-aliasing Jian Huang, CS594, Spring 2002.

Two-Stage Mapping

1. Model the mapping: (x,y,z) -> (u,v)

2. Do the mapping

Page 35: Review 2: Illumination, Shading, Texturing and Anti-aliasing Jian Huang, CS594, Spring 2002.

Image space scan

For each yFor each x

compute u(x,y) and v(x,y)copy texture(u,v) to image(x,y)

• Samples the warped texture at the appropriate image pixels.

• inverse mapping

Page 36: Review 2: Illumination, Shading, Texturing and Anti-aliasing Jian Huang, CS594, Spring 2002.

Texture

Image space scan

• Problems:– Finding the inverse mapping

• Use one of the analytical mappings• Bi-linear or triangle inverse mapping

– May miss parts of the texture map

Image

Page 37: Review 2: Illumination, Shading, Texturing and Anti-aliasing Jian Huang, CS594, Spring 2002.

Inverse Mapping

• Need to transform back to world space to do the interpolation

• Orientation in 3D image space

• Foreshortening

(.5,1) (.8,1)

(.1,.6)

(.6,.2)

(.5,.7)

Page 38: Review 2: Illumination, Shading, Texturing and Anti-aliasing Jian Huang, CS594, Spring 2002.

Texture space scan

For each vFor each u

compute x(u,v) and y(u,v)copy texture(u,v) to image(x,y)

• Places each texture sample to the mapped image pixel.

• Forward mapping

Page 39: Review 2: Illumination, Shading, Texturing and Anti-aliasing Jian Huang, CS594, Spring 2002.

Texture space scan

• Problems:– May not fill image– Forward mapping needed

ImageTexture

Page 40: Review 2: Illumination, Shading, Texturing and Anti-aliasing Jian Huang, CS594, Spring 2002.

Texture Mapping

• Mapping to a 3D Plane– Simple Affine transformation

• rotate• scale• translate z

y

x

u

v

Page 41: Review 2: Illumination, Shading, Texturing and Anti-aliasing Jian Huang, CS594, Spring 2002.

Texture Mapping

• Mapping to a Cylinder– Rotate, translate and scale in the uv-plane

– u -> – v -> z– x = r cos(), y = r sin()

u

v

Page 42: Review 2: Illumination, Shading, Texturing and Anti-aliasing Jian Huang, CS594, Spring 2002.

Texture Mapping

• Mapping to Sphere– Impossible!!!!– Severe distortion at the poles– u -> – v -> – x = r sin() cos()– y = r sin() sin()– z = r cos()

Page 43: Review 2: Illumination, Shading, Texturing and Anti-aliasing Jian Huang, CS594, Spring 2002.

Sampling

• What we have in computer graphics is a point sampling of our scene, or:– I(x) = f(x)•ST(x)

• What we would like is more of an integration across the pixel (or larger area):– I(x) = f(x) h(x)

• What should h(x) be?

Page 44: Review 2: Illumination, Shading, Texturing and Anti-aliasing Jian Huang, CS594, Spring 2002.

Sampling Theorem

• The Shannon Sampling TheoremA band-limited signal f(x), with a cutoff

frequency of , that is sampled with a sampling spacing of T may be perfectly reconstructed from the discrete values f[nT] by convolution with the sinc(x) function, provided:

is called the Nyquist limit.

T2

1

Page 45: Review 2: Illumination, Shading, Texturing and Anti-aliasing Jian Huang, CS594, Spring 2002.

Sampling and Anti-aliasing

• If don’t have Nyquist rate, then aliasing artifacts.

Page 46: Review 2: Illumination, Shading, Texturing and Anti-aliasing Jian Huang, CS594, Spring 2002.

Two possible solutions

• So far we just mapped one point, results in bad aliasing (resampling problems)

• Two possible solutions:– Super-sampling: not very good (slow!)– Low-pass filtering: popular

approaches – mipmaps, SAT

Page 47: Review 2: Illumination, Shading, Texturing and Anti-aliasing Jian Huang, CS594, Spring 2002.

Quality considerations

• Pixel area maps to “weird” (warped) shape in texture space

pixel

u

v

xs

ys

Page 48: Review 2: Illumination, Shading, Texturing and Anti-aliasing Jian Huang, CS594, Spring 2002.

Quality considerations

• We need to:– Calculate (or approximate) the

integral of the texture function under this area

– Approximate:• Convolve with a wide filter around the

center of this area• Calculate the integral for a similar (but

simpler) area.

Page 49: Review 2: Illumination, Shading, Texturing and Anti-aliasing Jian Huang, CS594, Spring 2002.

Quality considerations

• the area is typically approxiated by a rectangular region (found to be good enough for most applications)

• filter is typically a box/averaging filter - other possibilities

• how can we pre-compute this?

Page 50: Review 2: Illumination, Shading, Texturing and Anti-aliasing Jian Huang, CS594, Spring 2002.

Summed Area Table (SAT)

• Determining the rectangle:– Find bounding box and calculate its aspect ratio

pixel

u

v

xs

ys

Page 51: Review 2: Illumination, Shading, Texturing and Anti-aliasing Jian Huang, CS594, Spring 2002.

Summed Area Table (SAT)

• Determine the rectangle with the same aspect ratio as the bounding box and the same area as the pixel mapping.

pixel

u

v

xs

ys

Page 52: Review 2: Illumination, Shading, Texturing and Anti-aliasing Jian Huang, CS594, Spring 2002.

Summed Area Table (SAT)

• Center this rectangle around the bounding box center.

• Formula:• Area = aspect_ratio*x*x

• Solve for x – the width of the rectangle

• Other derivations are also possible using the aspects of the diagonals, …

Page 53: Review 2: Illumination, Shading, Texturing and Anti-aliasing Jian Huang, CS594, Spring 2002.

Summed Area Table (SAT)

• Calculating the color– We want the average of the texel colors within

this rectangle

u

v+

+ -

-

(u3,v3)

(u2,v2)(u1,v1)

(u4,v4)

+ -

+-

Page 54: Review 2: Illumination, Shading, Texturing and Anti-aliasing Jian Huang, CS594, Spring 2002.

Summed Area Table (SAT)

• To get the average, we need to divide by the number of texels falling in the rectangle.– Color = SAT(u3,v3)-SAT(u4,v4)-SAT(u2,v2)+SAT(u1,v1)– Color = Color / ( (u3-u1)*(v3-v1) )

• This implies that the values for each texel may be very large:– For 8-bit colors, we could have a maximum SAT value of

255*nx*ny– 32-bit pixels would handle a 4kx4k texture with 8-bit values.– RGB images imply 12-bytes per pixel.