shading, surfaces & textures. outline polygon shading models constant, interpolated, polygon...

65
Shading, Surfaces & Textures

Post on 22-Dec-2015

250 views

Category:

Documents


4 download

TRANSCRIPT

Page 1: Shading, Surfaces & Textures. Outline  Polygon shading models  Constant, interpolated, polygon mesh, Lambert, Gouraud, Phong  Lighting models  Lambert,

Shading, Surfaces & Textures

Page 2: Shading, Surfaces & Textures. Outline  Polygon shading models  Constant, interpolated, polygon mesh, Lambert, Gouraud, Phong  Lighting models  Lambert,

Outline

Polygon shading models Constant, interpolated, polygon mesh, Lambert,

Gouraud, Phong Lighting models

Lambert, Phong, Blinn Surfaces properties Surface mapping

Texture Bump Displacement …

Page 3: Shading, Surfaces & Textures. Outline  Polygon shading models  Constant, interpolated, polygon mesh, Lambert, Gouraud, Phong  Lighting models  Lambert,

Lighting algorithms Most algorithms use the polygon or surface

normal (vector that is perpendicular to the polygon)

The amount of light reflected depends on the angle of the incident light, e.g. for diffuse reflection:

NL

Page 4: Shading, Surfaces & Textures. Outline  Polygon shading models  Constant, interpolated, polygon mesh, Lambert, Gouraud, Phong  Lighting models  Lambert,

Constant shading

Also known as Lambert, faceted and flat shading Calculates a single intensity value for each polygon Valid if following assumptions are true:

Light source is at infinity (i.e. angle between light and surface is constant)

Viewer is at infinity (i.e. angle between viewer and surface is constant)

Polygon is not an approximation of a curved surface

Page 5: Shading, Surfaces & Textures. Outline  Polygon shading models  Constant, interpolated, polygon mesh, Lambert, Gouraud, Phong  Lighting models  Lambert,

Interpolated shading

Shading is linearly interpolated across polygon

Faster than calculating each pixel, better than flat shading

Still assumes that polygon represents the true surface

Page 6: Shading, Surfaces & Textures. Outline  Polygon shading models  Constant, interpolated, polygon mesh, Lambert, Gouraud, Phong  Lighting models  Lambert,

Polygon mesh shading

Many sets of polygons actually are approximations to curved surfaces

Shading the polygons to realistically simulate the surface is therefore important

Several methods exist to achieve this, the most important of which are Gouraud and Phong shading.

Page 7: Shading, Surfaces & Textures. Outline  Polygon shading models  Constant, interpolated, polygon mesh, Lambert, Gouraud, Phong  Lighting models  Lambert,

Gouraud shading This is a form of intensity interpolation shading Starts from knowing the normal of the surface

at each vertex of the polygon These may be stored with the mesh or may be

averaged from the adjacent polygons

Next step is to calculate the vertex intensities This will use the vertex

normal and the illumination algorithm

(Henri Gouraud, PhD 1971)

Page 8: Shading, Surfaces & Textures. Outline  Polygon shading models  Constant, interpolated, polygon mesh, Lambert, Gouraud, Phong  Lighting models  Lambert,

Gouraud shading (2) The polygon is then shaded by:

Interpolating the intensities along each edge Interpolating across the polygon between the

edges along each scan line

I1

I2

I3

IP

Page 9: Shading, Surfaces & Textures. Outline  Polygon shading models  Constant, interpolated, polygon mesh, Lambert, Gouraud, Phong  Lighting models  Lambert,

Gouraud algorithm

Compute SA, SB, SC for triangle ABC. Si = shade of point i.

For a scanline XY, compute SX, SY by interpolating e.g. tAB = |AX| / |AB|.

SA = tAB* SA + (1-tAB)*SB

Compute SP

By interpolating between SX and SY

scanline

A

B

C

SX

X Y

SY

P

SP

Page 11: Shading, Surfaces & Textures. Outline  Polygon shading models  Constant, interpolated, polygon mesh, Lambert, Gouraud, Phong  Lighting models  Lambert,

Phong shading

This is a form of normal-vector interpolation shading

Starts from the normal vector at each vertex again, but interpolates the vector rather than the intensity

(Bui-Tong Phong, PhD 1975)

Page 12: Shading, Surfaces & Textures. Outline  Polygon shading models  Constant, interpolated, polygon mesh, Lambert, Gouraud, Phong  Lighting models  Lambert,

Phong shading (2)

In general, this yields much more realistic results, especially for specular surfaces Gouraud shading may miss specular highlights

It is several orders of magnitude slower than Gouraud

Page 13: Shading, Surfaces & Textures. Outline  Polygon shading models  Constant, interpolated, polygon mesh, Lambert, Gouraud, Phong  Lighting models  Lambert,

Problems with interpolated shading

Polygonal silhouette Perspective distortion Orientation dependence Shared vertices Unrepresentative vertex normals

Page 14: Shading, Surfaces & Textures. Outline  Polygon shading models  Constant, interpolated, polygon mesh, Lambert, Gouraud, Phong  Lighting models  Lambert,

Polygonal silhouette

Approximation is polygonal, so no matter how good the shading algorithm the silhouette will be faceted

Can be improved by increasing the polygon count at expense of processing time

Page 15: Shading, Surfaces & Textures. Outline  Polygon shading models  Constant, interpolated, polygon mesh, Lambert, Gouraud, Phong  Lighting models  Lambert,

Perspective distortion Because the interpolation is based on

the scan lines, the number of interpolation increments per polygon depends on the angle of the polygon to the viewer

Steep angle = few increments Shallow angle = more increments

Page 16: Shading, Surfaces & Textures. Outline  Polygon shading models  Constant, interpolated, polygon mesh, Lambert, Gouraud, Phong  Lighting models  Lambert,

Orientation dependence

Because interpolation occurs between vertices and along scan lines, result depends on orientation of polygon relative to scan lines

Page 17: Shading, Surfaces & Textures. Outline  Polygon shading models  Constant, interpolated, polygon mesh, Lambert, Gouraud, Phong  Lighting models  Lambert,

Shared vertices

Problems occur when adjacent polygons do not share vertices

This can lead to discontinuities in shading

Page 18: Shading, Surfaces & Textures. Outline  Polygon shading models  Constant, interpolated, polygon mesh, Lambert, Gouraud, Phong  Lighting models  Lambert,

Unrepresentative vertex normals

Vertices may not adequately represent the surface geometry

Usually can be solved by further subdividing surface

Page 19: Shading, Surfaces & Textures. Outline  Polygon shading models  Constant, interpolated, polygon mesh, Lambert, Gouraud, Phong  Lighting models  Lambert,

Surfaces

Definition of visual characteristics of a surface

Often defined by a ‘shader’ or ‘material’

Specifies colour, how shiny it is, etc.

Page 20: Shading, Surfaces & Textures. Outline  Polygon shading models  Constant, interpolated, polygon mesh, Lambert, Gouraud, Phong  Lighting models  Lambert,

Surface parameters

Colour usually defined by RGB values or via GUI Ambient is a false parameter that defines how

‘ambient’ light is treated Diffuse parameter specifies how much light in

total is evenly reflected Specularity defines how shiny a surface is (a high

value will have highlights like a billiard ball) May also have controls for highlight size and

colour

Page 21: Shading, Surfaces & Textures. Outline  Polygon shading models  Constant, interpolated, polygon mesh, Lambert, Gouraud, Phong  Lighting models  Lambert,

Advanced surface parameters

Reflectivity defines how much of the surrounding environment is reflected by the surface (like a mirror)

Transparency defines of the background is visible through the surface

Translucency defines how much light is transmitted through the surface

Refractivity defines how much light is bent as it enters and leaves the material

Page 22: Shading, Surfaces & Textures. Outline  Polygon shading models  Constant, interpolated, polygon mesh, Lambert, Gouraud, Phong  Lighting models  Lambert,

Surfaces in Maya

Basic materials: Lambert Phong Phong E Blinn

Special materials: Anisotropic, Layered Shader, Ocean Shader,

Ramp Shader, Shading Map, Surface Shader, Use Background

Page 23: Shading, Surfaces & Textures. Outline  Polygon shading models  Constant, interpolated, polygon mesh, Lambert, Gouraud, Phong  Lighting models  Lambert,

Lambert

This is the simplest material It creates a matt surface with diffuse and

ambient components but no highlights The shading interpolates between

adjacent polygon normals so the surface appears smooth

It uses Lambert’s cosine law

Page 24: Shading, Surfaces & Textures. Outline  Polygon shading models  Constant, interpolated, polygon mesh, Lambert, Gouraud, Phong  Lighting models  Lambert,

Lambert’s Cosine Law

“The reflected luminous intensity in any direction from a perfectly diffusing surface varies as the cosine of the angle between the direction of incident light and the normal vector of the surface”

Johann Lambert, 1728-1777.

Page 25: Shading, Surfaces & Textures. Outline  Polygon shading models  Constant, interpolated, polygon mesh, Lambert, Gouraud, Phong  Lighting models  Lambert,

Ideal diffuse surfaces obey this cosine law Often called Lambertian surfaces.

Id = kd Iincident cos = kd Iincident (N·L).

where kd is the diffuse reflectanceof the material.

Wavelength dependent, so usually specified as a colour.

Lambert’s Cosine Law

Page 26: Shading, Surfaces & Textures. Outline  Polygon shading models  Constant, interpolated, polygon mesh, Lambert, Gouraud, Phong  Lighting models  Lambert,

Maya Lambert properties

Page 27: Shading, Surfaces & Textures. Outline  Polygon shading models  Constant, interpolated, polygon mesh, Lambert, Gouraud, Phong  Lighting models  Lambert,

Phong This lighting model includes specularity This takes into account that the amount of light you see depends on

the viewer’s angle to the surface as well as the light’s angle His original formula for the specular term:

W(i)(cos s )n s is the angle between the view and specular reflection

directions. “W(i) is a function which gives the ratio of the specular reflected

light and the incident light as a function of the the incident angle i.”

Ranges from 10 to 80 percent. “n is a power which models the specular reflected light for each

material.” Ranges from 1 to 10.

(Bui-Tong Phong, 1975)

Page 28: Shading, Surfaces & Textures. Outline  Polygon shading models  Constant, interpolated, polygon mesh, Lambert, Gouraud, Phong  Lighting models  Lambert,

Phong lighting model More recent formulations are slightly

different Replace W(i) with a constant ks,

independent of the incident direction Is= ks Iincident cosn

= ks Iincident (V·R)n. V is the view direction. R is the specular reflection direction L

N

RV

Page 29: Shading, Surfaces & Textures. Outline  Polygon shading models  Constant, interpolated, polygon mesh, Lambert, Gouraud, Phong  Lighting models  Lambert,

Variation of n

Page 30: Shading, Surfaces & Textures. Outline  Polygon shading models  Constant, interpolated, polygon mesh, Lambert, Gouraud, Phong  Lighting models  Lambert,

Maya Phong properties

Page 31: Shading, Surfaces & Textures. Outline  Polygon shading models  Constant, interpolated, polygon mesh, Lambert, Gouraud, Phong  Lighting models  Lambert,

Maya’s ‘Phong E’

Uses a simplified model, faster to render than pure Phong

Page 32: Shading, Surfaces & Textures. Outline  Polygon shading models  Constant, interpolated, polygon mesh, Lambert, Gouraud, Phong  Lighting models  Lambert,

Maya’s Blinn

Based on Blinn-Phong shading (an adaptation of Phong)

Offers great control over specularity but in general will not look as ‘shiny’ as a Phong material

(Jim Blinn, 1977)

Page 33: Shading, Surfaces & Textures. Outline  Polygon shading models  Constant, interpolated, polygon mesh, Lambert, Gouraud, Phong  Lighting models  Lambert,

Maya Blinn properties

II

Page 34: Shading, Surfaces & Textures. Outline  Polygon shading models  Constant, interpolated, polygon mesh, Lambert, Gouraud, Phong  Lighting models  Lambert,

2D texture mapping

A ‘cheap’ way of enhancing the the surface definition

So far, surfaces have been defined with a plain colour

In real life, many surfaces are multi-coloured E.g. Wood looks ‘wooden’ because of many

different colour variations in the grain

Page 35: Shading, Surfaces & Textures. Outline  Polygon shading models  Constant, interpolated, polygon mesh, Lambert, Gouraud, Phong  Lighting models  Lambert,

2D texture mapping (2)

2D texture mapping involves applying a 2D image to the surface of a 3D object In this case the term ‘texture’ applies to the

image rather than the more traditional ‘feel’ of the surface

Textures may be ‘real’ (e.g. scanned), manually generated (e.g. with a paint program) or procedurally generated (e.g. by a computer program)

Page 36: Shading, Surfaces & Textures. Outline  Polygon shading models  Constant, interpolated, polygon mesh, Lambert, Gouraud, Phong  Lighting models  Lambert,

2D texture mapping (3)

The process of applying the texture is the ‘mapping’

The two mapping processes: Projecting the image onto the surface Stretching the image to fit on the

surface

Page 37: Shading, Surfaces & Textures. Outline  Polygon shading models  Constant, interpolated, polygon mesh, Lambert, Gouraud, Phong  Lighting models  Lambert,

Projection mapping

In projection mapping the image is projected through space

Wherever it ‘hits’ the surface the surface becomes the colour of the texture

The purest form of this is planar projection

Page 38: Shading, Surfaces & Textures. Outline  Polygon shading models  Constant, interpolated, polygon mesh, Lambert, Gouraud, Phong  Lighting models  Lambert,
Page 39: Shading, Surfaces & Textures. Outline  Polygon shading models  Constant, interpolated, polygon mesh, Lambert, Gouraud, Phong  Lighting models  Lambert,

Cylindrical projection

Image is bent into a cylinder before projection takes place

Object is then placed ‘in’ the cylinder

Page 40: Shading, Surfaces & Textures. Outline  Polygon shading models  Constant, interpolated, polygon mesh, Lambert, Gouraud, Phong  Lighting models  Lambert,
Page 41: Shading, Surfaces & Textures. Outline  Polygon shading models  Constant, interpolated, polygon mesh, Lambert, Gouraud, Phong  Lighting models  Lambert,

Spherical projection

Image bent onto an imaginary sphere before projection

Object placed ‘in’ sphere

Page 42: Shading, Surfaces & Textures. Outline  Polygon shading models  Constant, interpolated, polygon mesh, Lambert, Gouraud, Phong  Lighting models  Lambert,
Page 43: Shading, Surfaces & Textures. Outline  Polygon shading models  Constant, interpolated, polygon mesh, Lambert, Gouraud, Phong  Lighting models  Lambert,

Limitations

Unless mapping on a perfect flat surface, cylinder or sphere, all projection methods will have a tendency to ‘streak’

Parameterised texture mapping offers a solution to this problem

Page 44: Shading, Surfaces & Textures. Outline  Polygon shading models  Constant, interpolated, polygon mesh, Lambert, Gouraud, Phong  Lighting models  Lambert,

Parameterised (UV) mapping Imagine printing the texture image onto

thin transparent film Then stretch the film over the surface This is the principle of parameterised

texture mapping

Page 45: Shading, Surfaces & Textures. Outline  Polygon shading models  Constant, interpolated, polygon mesh, Lambert, Gouraud, Phong  Lighting models  Lambert,

Parameterised mapping (2)

The 2D texture image is (obviously) an array of rectangular pixels

These can be referenced by Cartesian coordinates, usually with the lower left pixel being (0,0) (and for a 512 x 512 image the top right being (511,511))

Each pixel rectangle is then mapped to a corresponding area of the 3D surface

Page 46: Shading, Surfaces & Textures. Outline  Polygon shading models  Constant, interpolated, polygon mesh, Lambert, Gouraud, Phong  Lighting models  Lambert,

Parameterised mapping (3)

You therefore have to divide the surface into the same number of steps

The surface patch is defined to use the coordinate system U and V to specify locations on it

The area defined by (0,0) on the surface has the colour applied to it from the image pixel at (0,0)

Page 47: Shading, Surfaces & Textures. Outline  Polygon shading models  Constant, interpolated, polygon mesh, Lambert, Gouraud, Phong  Lighting models  Lambert,
Page 48: Shading, Surfaces & Textures. Outline  Polygon shading models  Constant, interpolated, polygon mesh, Lambert, Gouraud, Phong  Lighting models  Lambert,
Page 49: Shading, Surfaces & Textures. Outline  Polygon shading models  Constant, interpolated, polygon mesh, Lambert, Gouraud, Phong  Lighting models  Lambert,
Page 50: Shading, Surfaces & Textures. Outline  Polygon shading models  Constant, interpolated, polygon mesh, Lambert, Gouraud, Phong  Lighting models  Lambert,

Procedural textures

Textures can be generated by procedures rather than using predefined images

This is good for regular patterns (e.g. brickwork) or (semi-)random patterns (e.g. noise)

Page 51: Shading, Surfaces & Textures. Outline  Polygon shading models  Constant, interpolated, polygon mesh, Lambert, Gouraud, Phong  Lighting models  Lambert,

Maya procedural textures

Page 52: Shading, Surfaces & Textures. Outline  Polygon shading models  Constant, interpolated, polygon mesh, Lambert, Gouraud, Phong  Lighting models  Lambert,

Got to here!Other types of mapping

So far, all examples have used the colour of the image to affect the colour of the surface - this is colour texture mapping

Other options are transparency mapping, bump mapping and displacement mapping

Page 53: Shading, Surfaces & Textures. Outline  Polygon shading models  Constant, interpolated, polygon mesh, Lambert, Gouraud, Phong  Lighting models  Lambert,

Transparency mapping

Use pixel value to define transparency of object

Usually uses grey values, white = opaque & black = transparent

Page 54: Shading, Surfaces & Textures. Outline  Polygon shading models  Constant, interpolated, polygon mesh, Lambert, Gouraud, Phong  Lighting models  Lambert,
Page 55: Shading, Surfaces & Textures. Outline  Polygon shading models  Constant, interpolated, polygon mesh, Lambert, Gouraud, Phong  Lighting models  Lambert,

Bump mapping

Uses pixel values to ‘perturb’ the surface normals

Used to model tiny variations in surface contour

Actual surface doesn’t change geometry, but appears to because normal is shifted

Good for ‘orange peel’ like effects, but outline is still smooth

Page 56: Shading, Surfaces & Textures. Outline  Polygon shading models  Constant, interpolated, polygon mesh, Lambert, Gouraud, Phong  Lighting models  Lambert,
Page 57: Shading, Surfaces & Textures. Outline  Polygon shading models  Constant, interpolated, polygon mesh, Lambert, Gouraud, Phong  Lighting models  Lambert,
Page 58: Shading, Surfaces & Textures. Outline  Polygon shading models  Constant, interpolated, polygon mesh, Lambert, Gouraud, Phong  Lighting models  Lambert,

Displacement mapping

Uses the intensity of the pixel to actually shift part of the surface up (for white) or down (for black)

Used to model surface irregularity, but unlike bump mapping the surface geometry actually changes

Page 59: Shading, Surfaces & Textures. Outline  Polygon shading models  Constant, interpolated, polygon mesh, Lambert, Gouraud, Phong  Lighting models  Lambert,
Page 60: Shading, Surfaces & Textures. Outline  Polygon shading models  Constant, interpolated, polygon mesh, Lambert, Gouraud, Phong  Lighting models  Lambert,
Page 61: Shading, Surfaces & Textures. Outline  Polygon shading models  Constant, interpolated, polygon mesh, Lambert, Gouraud, Phong  Lighting models  Lambert,

Other image-based mapping

Incandescence mapping Pixel values = ‘glow brightness’

Specularity mapping Pixel values = specularity

Reflectivity mapping Pixel values = reflectivity

Page 62: Shading, Surfaces & Textures. Outline  Polygon shading models  Constant, interpolated, polygon mesh, Lambert, Gouraud, Phong  Lighting models  Lambert,

3D texture mapping

Often, realistic objects require more than just 2D images mapped onto them E.g. Shiny surfaces (such as chrome) should

reflect the environment that surrounds them

Some of these effects can be achieved by ray tracing, but this is expensive

We can use environmental reflection mapping (sometimes called just reflection mapping)

Page 63: Shading, Surfaces & Textures. Outline  Polygon shading models  Constant, interpolated, polygon mesh, Lambert, Gouraud, Phong  Lighting models  Lambert,

Reflection mapping

Cubic (most common) Six views of the surrounding

world are generated and mapped on the object using cubic texture mapping

Six images may be rendered views

Spherical Use a single image that is

spherically texture mapped Difficult to generate the

single image correctly

Page 64: Shading, Surfaces & Textures. Outline  Polygon shading models  Constant, interpolated, polygon mesh, Lambert, Gouraud, Phong  Lighting models  Lambert,

Solid texture mapping

Useful for things such as wood grain, marble, etc.

Create a volume of texture

Object then ‘floats’ in this volume and surface points adopt colours defined in the volume

Can also be used to model transparency and other effects

Page 65: Shading, Surfaces & Textures. Outline  Polygon shading models  Constant, interpolated, polygon mesh, Lambert, Gouraud, Phong  Lighting models  Lambert,

Summary

Shading algorithms Flat, Gouraud, Phong

Lighting algorithms Lambert, Phong…

Surface properties Diffuse, specular…

Surface mapping Texture, bump, displacement…