Fragment shading involves converting vertex illumination values (the illumination value at that point based on colour etc) into appropriate colours for every pixel on a polygon face.

Shades the entire face the colour of the vertex.

 Pros/Good for Cons/Bad for Flat surfaces Curved surfaces Distant light sources Close light sources Diffuse shading Specular shading When speed is crucial

The first of the smooth shaders, Gouraud Shading takes colours and interpolates them. Isn’t lerping magical? This produces much smoother colors than flat shading. (see image)

This is an example of Gouraud shading - this is where it fails.

Phong Shading should not be confused with Phong Reflection.

• Phong reflection is the specular illumination formula $(r \cdot v)^f$ (r and v being normalised)
• Phong Shading is bilinear interpolation of Normals which give us the correct input values for Phong reflection.

This differs to Gouraud shading which does bilinear interpolation of colors and hence produces incorrect values when dealing with specular lighting. Because the normals are interpolated in Phong Shading the light has the right angles for computing illumination.

# Normal Maps

When surfaces are designed to be rough rather than smooth (e.g. pockmarked, bullet holes, gravel road) it can look odd just doing this with textures without lighting (the light doesn’t bounce off as expected).

Rather than add lots of extra polygons in (computationally infeasible), we can store a map of normals. Each fragment is given a vector, and upon loading the normal map the ‘default’ vector for a fragment (interpolated based on the vector normals) is added to the normal map vector for that fragment.

The interpolated normals on the left, and the result of the addition on the right.

Pros:

• Provides the illusion of surface texture

Cons:

• Doesn’t affect silhouette or calculation of hidden surfaces (e.g. depth of the object)
page revision: 3, last edited: 25 Sep 2014 03:52