Wednesday, 5 March 2014

A shading model is used in computer graphics to simulate the effects of light shining on a surface. The intensity that we see on a surface is dependent upon
• The type of light sources.
• The surface characteristics (eg. Shining, matte, dull, and opaque or transparent).
Types of illumination
A).Light emitting sources (eg. Light bulb, sun)
1).When the light source is far away from the object => point source (eg.Sun)
2).When the light source is large compared with the object => distributed light source (eg. Neon light)

B).Light reflecting sources (eg. Illuminated surface of an object, walls)
1).Three possible types of reflections ((1), (2), and (3)) to form the shading of a point on a surface.
2).Reflection of ambient light: Multiple reflections of light from nearby objects => ambient light (or background light). Ambient light has a uniform intensity in all directions. It causes a surface to be uniformly illuminated at any viewing position.
3).Reflection of point source light: A point source light emits directional light rays. Normally we consider light rays from a distant light source as being parallel (eg. Sun) and light rays from a close light source as being divergent (eg. Table lamp).
Two types of reflection of point source light:
Due to surface roughness => diffuse reflection
Due to shinny surface => specular reflection
When light is reflected (or refracted) from a surface, it does not reflect all light that enters the surface. Part of the energy will be absorbed by the surface. The reflection coefficient represents the amount of light reflected from an object's surface.
The unit normal vector N represents the orientation of a surface.
The unit vector L represents the direction of a light source at the surface.
The angle of incident q represents the angle between N and L.
In diffuse reflection, we consider surfaces which reflect light with equal intensity in all directions. The amount of light energy that falls on a given area and hence the intensity of the reflection is proportional to the cosine of the angle of incident (ie. cos q). This kind of surfaces are normally dull or matt.
In specular reflection, we consider surfaces which reflect light with higher intensity at a particular direction. This kind of surfaces are normally shiny.

C).Light refraction
Refraction occurs when light travels through transparent or semitransparent objects of different densities (for example, from air to glass).

Gouraud shading, computes an intensity for each vertex and then interpolates the computed intensities across the polygons. Gouraud shading performs a bi-linear interpolation of the intensities down and then across scan lines. It thus eliminates the sharp changes at polygon boundaries.
The algorithm is as follows:
1).Compute a normal N for each vertex of the polygon.
2).From N compute an intensity I for each vertex of the polygon.
3).From bi-linear interpolation compute an intensity Ii for each pixel.
4).Paint pixel to shade corresponding to Ii.
How do we compute N for a vertex? Let N = the average of the normals of the polygons which include the vertex. Note that 4 sided polygons have 4 neighbors and triangles have 6 neighbors.
We can find the neighbors for a particular vertex by searching the polygons and including any polygons which include the vertex. Now look at performing the bi-linear intensity interpolation. This is the same as the bi-linear interpolation for the z depth of a pixel (used with the z buffer visible surface algorithm).
Gouraud shading gives a much better image than faceted shading (the facets no longer visible). It is not too computationally expensive: one floating point addition (for each color) for each pixel. (the mapping to actual display registers requires a floating point multiplication)