Intro to Shading

This lab gives you an introduction to real time shading. It uses the pfpy3d viewer.

Download file shading.py3d to your CG directory.

As before, start an editor and then run the Python 3D viewer application with commands something like

$ gedit shading.py3d &
$ pfpy3d shading.py3d

You will see a very simple scene with a ground plane quadrilateral and four geometric shapes.

This is a shaded 3D scene, not wireframe, so exit the viewer program and run it again with command line option -shade. This time you will see the objects as solid rather than wireframe and with (dull) colors.

Study the code in shading.py3d. The interesting bits are at the start, which defines the Source, Surface, Shape used for rendering; and the final "Main control" section which draws the scene. When you are asked to make changes, it will be in one of these two sections, not within the def something blocks. Most changes are not permanent and should be undone after you have seen the effect.

Ambient lighting

The file as supplied uses light source #0, which is just ambient. Move around the scene and see how all the surfaces have the same color and therefore the shape of the objects is not defined.

Change the intensity of the ambient light source to 1. What happens to the scene?

Change it back to 0.1 afterwards.

Distant lighting

In the main section, change the first parameter for addLight to 1. You will now see a properly shaded 3D scene where the surfaces of the objects are well defined.

Move around the scene and note which surfaces are very dark. In the Source list, change the on value of the ambient light to True so that it is always on. Does this improve the appearance of the scene?

The light position, which for distant lights is the "direction rays come from" is defined for light number one in the Sources array at the start of the code. Change it from being directly above to being from a side axis, or diagonally.

Increase the addLight height parameter. Why doesn't the appearance change with different heights?

Set the height to a negative value.Why does the scene continue to be illuminated even though the light source is underneath the ground plane?

Point light

Change the addLight source parameter to 2, a point light source.

Change the height of the light. What happens to the scene?

What happens if you change the addLight orbit parameter to 4?

What happens if you give the light a negative height below the ground plane?

Materials

Pick one of the Surface materials and scale down the ambient color, or set it to black. Why doesn't the scene change very much?

Change the shininess value for surface 2 to match surface 3. How does this alter the appearance of an object?

What is the important difference between the specular components of surfaces 2 and 3?

Optional

For the distant light, set the position to something other than vertical, and change the addLight orbit value parameter to 4. Why does rotation change the appearance of the scene when different heights did not?

The color of the ground plane varies very little from edge to edge as by default it is drawn as one large quadrilateral. Using a point or spot light source, change the subdivision of the ground plane, the last parameter to ground in the main section, to 4. Why does the variation increase? (To verify that it has been subdivided, run pfpy3d without the -shader option.)

Create a spotlight (see the online documentation) and try an orbiting spotlight with a stationary distant light.