-->

In my post First steps in Papervision3D : Part 4 - lighting and shading, I mentioned that the materials provided by Papervision3D do not allow us to include ambient, diffuse and specular lighting all together at the same time. The two principal shaded materials provided by Papervision3D are

  • GouraudMaterial: includes ambient and diffuse lighting
  • PhongMaterial: includes ambient and specular lighting

The Phong reflection model however is a combination of all three and allows us to model surfaces that have both a rough (diffusive) characteristic and a shiny (specular) one. This is particularly good, for example, in modeling plastic-type materials.

Even though there is not a specific material for which we can specify ambient, diffuse and specular lighting all together, using the viewport layers interface of Papervision3D we can create different lighting effects on an object and combine them together on the screen.

In theory, diffusive lighting is added to a scene in a multiplicative fashion. The resulting colour seen on the screen is the product of the colour of the material and the quantity of the diffused light. For example we can have a material that is blue (0×0000FF) with a diffusive light pattern that varies from bright white (0xFFFFFF) to grey (ambient) (0×222222). The resulting colours seen on the screen therefore vary from bright blue (0×0000FF) to dark blue (0×000022).

Specular light is added to the scene in an additive way: light is reflected off an object towards an observer thereby brightening the object. Therefore even parts of a black material can be seen with specular light.

Phong reflection is the combination of these two lighting techniques: a material darkened with a diffusive and abient light and enhanced by a specular one.

The demo shown here tries to implement these characteristics. Using ViewportLayers a surface is rendered three times: once with a simple material colour, once with a diffuse light pattern (using a GouraudMaterial to create both diffusive and ambient effects) and finally with a specular one (using a modified PhongMaterial for which the ambient light is turned off, hence producing only specular light).

Each layer is added to the scene with a different BlendMode: MULTIPLY for the diffusive light pattern and ADD for the specular one. The order of each layers is important hence the coloured material is rendered first, followed by the diffusive light and finally the specular light added to the end.

You can take a look at the demo by clicking on the image below. To rotate the scene click and move the mouse. Clicking on the surface separates it into the different components for five seconds so you can see what each individual layer looks like.

Surface showing phong reflection

You can take a look at the source at http://www.tartiflop.com/pv3d/PhongReflection/srcview/.