Rendering Algorithms

Download Report

Transcript Rendering Algorithms

Shading, Surfaces & Textures

Outline

    Polygon shading models  Constant, interpolated, polygon mesh, Lambert, Gouraud, Phong Lighting models  Lambert, Phong, Blinn Surfaces properties Surface mapping  Texture    Bump Displacement …

 

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:

L N

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

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

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.

Gouraud shading

(Henri Gouraud, PhD 1971)

  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

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

I 2 I P I 1 I 3

Gouraud algorithm

   Compute S A , S B , S C  S i = shade of point i.

for triangle ABC.

For a scanline XY, compute S X , S Y interpolating   e.g. t AB = |AX| / |AB|.

S A = t AB * S A + (1-t AB )*S B X Compute S P  By interpolating A S X P by S P B between S X and S Y S Y Y C scanline

Gouraud example

Phong shading

(Bui-Tong Phong, PhD 1975)

 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

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

Problems with interpolated shading

     Polygonal silhouette Perspective distortion Orientation dependence Shared vertices Unrepresentative vertex normals

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

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

Orientation dependence

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

Shared vertices

 Problems occur when adjacent polygons do not share vertices  This can lead to discontinuities in shading

Unrepresentative vertex normals

 Vertices may not adequately represent the surface geometry  Usually can be solved by further subdividing surface

Surfaces

  Definition of visual characteristics of a surface Often defined by a ‘shader’ or ‘material’  Specifies colour, how shiny it is, etc.

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

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

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

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

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.

Lambert’s Cosine Law

  Ideal diffuse surfaces obey this cosine law

I d

 Often called

Lambertian

=

k d I incident

cos  =

k d I incident

(

N

·

L

).

surfaces.

where

k d

is the diffuse reflectance of the material.

 Wavelength dependent, so usually specified as a colour.

Maya Lambert properties

Phong

(Bui-Tong Phong, 1975)

   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.

Phong lighting model

 More recent formulations are slightly different  Replace

W

(

i

) with a constant

k s

, independent of the incident direction 

I s

=

k s I incident

=

k s I incident

V

( cos

V

·

n R

 )

n .

is the view direction.

R

is the specular reflection direction L N  R V

Variation of

n

Maya Phong properties

Maya’s ‘Phong E’

 Uses a simplified model, faster to render than pure Phong

Maya’s Blinn

(Jim Blinn, 1977)

 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

II

Maya Blinn properties

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

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)

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

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

Cylindrical projection

  Image is bent into a cylinder before projection takes place Object is then placed ‘in’ the cylinder

Spherical projection

  Image bent onto an imaginary sphere before projection Object placed ‘in’ sphere

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

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

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

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

locations on it and

V

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

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)

Maya procedural textures

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

Transparency mapping

 Use pixel value to define transparency of object  Usually uses grey values, white = opaque & black = transparent

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

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

Other image-based mapping

 Incandescence mapping  Pixel values = ‘glow brightness’  Specularity mapping  Pixel values = specularity  Reflectivity mapping  Pixel values = reflectivity

3D texture mapping

  Some of these effects can be achieved by ray tracing, but this is expensive  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 We can use

environmental reflection mapping

(sometimes called just

reflection mapping

)

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

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

Summary

 Shading algorithms  Flat, Gouraud, Phong  Lighting algorithms  Lambert, Phong…  Surface properties  Diffuse, specular…  Surface mapping  Texture, bump, displacement…