This is documentation for Mathematica 3, which was
based on an earlier version of the Wolfram Language.
View current documentation (Version 11.2)
 Documentation / Mathematica / The Mathematica Book / Principles of Mathematica / The Structure of Graphics and Sound  /

2.9.12 Lighting and Surface Properties

With the default option setting Lighting->True, Mathematica uses a simulated lighting model to determine how to color polygons in three-dimensional graphics.
Mathematica allows you to specify two components to the illumination of an object. The first is "ambient lighting", which produces uniform shading all over the object. The second is light from a collection of point sources, each with a particular position and color. Mathematica adds together the light from all of these sources in determining the total illumination of a particular polygon.

Options for simulated illumination.

The default lighting used by Mathematica involves three point light sources, and no ambient component. The light sources are colored respectively red, green and blue, and are placed at

angles on the right-hand side of the object.

  • Here is a surface, shaded using simulated lighting using the default set of lights.
  • In[1]:= Plot3D[Sin[x + Sin[y]], {x, -3, 3}, {y, -3, 3},
    Lighting -> True]

  • This shows the result of adding ambient light, and removing all point light sources.
  • In[2]:= Show[%, AmbientLight -> GrayLevel[0.5],
    LightSources -> {}]

  • This adds a single point light source at the left-hand side of the image.
  • In[3]:= Show[%,
    LightSources -> {{{-1, 0, 0.5}, GrayLevel[0.5]}}]

    The positions of light sources in Mathematica are specified in the display coordinate system. The and coordinates are in the plane of the final display, and the

    coordinate goes into the plane. Using this coordinate system ensures that the light sources remain fixed with respect to the viewer, even when the relative positions of the viewer and object change.
    The end of the Graphics Gallery later in this book shows some examples of results obtained with various different arrangements of light sources.

  • Even though the view point is changed, the light source is kept fixed on the left-hand side of the image.
  • In[4]:= Show[%, ViewPoint -> {2, 2, 6}]

    The perceived color of a polygon depends not only on the light which falls on the polygon, but also on how the polygon reflects that light. You can use the graphics directive SurfaceColor to specify the way that polygons reflect light.
    If you do not explicitly use SurfaceColor directives, Mathematica effectively assumes that all polygons have matte white surfaces. Thus the polygons reflect light of any color incident on them, and do so equally in all directions. This is an appropriate model for materials such as uncoated white paper.
    Using SurfaceColor, however, you can specify more complicated models. The basic idea is to distinguish two kinds of reflection: diffuse and specular.
    In diffuse reflection, light incident on a surface is scattered equally in all directions. When this kind of reflection occurs, a surface has a "dull" or "matte" appearance. Diffuse reflectors obey Lambert's Law of light reflection, which states that the intensity of reflected light is times the intensity of the incident light, where is the angle between the incident light direction and the surface normal vector. Note that when , there is no reflected light.
    In specular reflection, a surface reflects light in a mirror-like way. As a result, the surface has a "shiny" or "gloss" appearance. With a perfect mirror, light incident at a particular angle is reflected at exactly the same angle. Most materials, however, scatter light to some extent, and so lead to reflected light that is distributed over a range of angles. Mathematica allows you to specify how broad the distribution is by giving a specular exponent, defined according to the Phong lighting model. With specular exponent , the intensity of light at an angle away from the mirror reflection direction is assumed to vary like . As , therefore, the surface behaves like a perfect mirror. As decreases, however, the surface becomes less "shiny", and for , the surface is a completely diffuse reflector. Typical values of for actual materials range from about 1 to several hundred.
    Most actual materials show a mixture of diffuse and specular reflection. In addition, they typically behave as if they have a certain intrinsic color. When the incident light is white, the reflected light has the color of the material. When the incident light is not white, each color component in the reflected light is a product of the corresponding component in the incident light and in the intrinsic color of the material.
    In Mathematica, you can specify reflection properties by giving an intrinsic color associated with diffuse reflection, and another one associated with specular reflection. To get no reflection of a particular kind, you must give the corresponding intrinsic color as black, or GrayLevel[0]. For materials that are effectively "white", you can specify intrinsic colors of the form GrayLevel[

    a], where a is the reflectance or albedo of the surface.
    The end of the Graphics Gallery shows examples of results obtained with various choices of reflection parameters.

    Specifying surface properties of lighted polygons.

  • This loads a package containing various graphics objects.
  • In[5]:= <<Graphics`Shapes`

  • Sphere creates a graphics object which represents a sphere.
  • In[6]:= s = Sphere[ ] ;

  • This shows the sphere with the default matte white surface.
  • In[7]:= Show[Graphics3D[s]]

  • This makes the sphere have low diffuse reflectance, but high specular reflectance. As a result, the sphere has a "specular highlight" near the light sources, and is quite dark elsewhere.
  • In[8]:= Show[Graphics3D[{
    GrayLevel[0.8], 5], s}]]

    When you set up light sources and surface colors, it is important to make sure that the total intensity of light reflected from a particular polygon is never larger than 1. You will get strange effects if the intensity is larger than 1.