Lighting and Surface Properties

With the default option setting Lighting->Automatic, Mathematica uses a simulated lighting model to determine how to color polygons in three-dimensional graphics.

Mathematica allows you to specify various components to the illumination of an object. One component is the "ambient lighting", which produces uniform shading all over the object. Other components are directional, and produce different shading on different parts of the object. "Point lighting" simulates light emanating in all directions from one point in space. "Spot lighting" is similar to point lighting, but emanates a cone of light in a particular direction. "Directional lighting" simulates a uniform field of light pointing in the given direction. Mathematica adds together the light from all of these sources in determining the total illumination of a particular polygon.

{"Ambient",color}uniform ambient lighting
{"Directional",color,{pos1,pos2}}directional lighting parallel to the vector from to
{"Point",color,pos}}spherical point light source at position pos
{"Spot",color,{pos,tar},}spotlight at position pos aimed at the target position tar with a half-angle opening of
Lighting->{light1,light2,...}a number of lights

Methods for specifying light sources.

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 sphere, shaded using simulated lighting using the default set of lights.
In[1]:=
Click for copyable input
Out[1]=
This shows the result of adding ambient light, and removing all point light sources. Note the Lighting option takes a list of light sources.
In[2]:=
Click for copyable input
Out[2]=
This adds a single point light source positioned at the red point. The lights are combined as appropriate.
In[3]:=
Click for copyable input
Out[3]=
Objects do not block light sources or cast shadows, so all objects in a scene will be lit evenly by light sources.
In[4]:=
Click for copyable input
Out[4]=
This adds a directional green light shining from the negative direction, effectively an infinite distance away.
In[5]:=
Click for copyable input
Out[5]=
This shows a spotlight positioned above the plot, combined with ambient lighting.
In[6]:=
Click for copyable input
Out[6]=
The Lighting option controls the lighting of all objects in a scene when used as an option to Graphics3D or Show. Lighting can also be used inline as a directive which specifies lighting for particular objects. The Lighting directive replaces the inherited lighting specifications.
The Lighting directive replaces the default value of Lighting for the two spheres after the directive.
In[7]:=
Click for copyable input
Out[7]=
This example uses list braces to restrict the effect of the Lighting directive to the middle sphere.
In[8]:=
Click for copyable input
Out[8]=

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 directives RGBColor, Specularity, and Glow to specify the way that polygons reflect or emit light.

If you do not explicitly use these coloring 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 RGBColor, Specularity, and Glow, however, you can specify more complicated models. These directives separately specify three kinds of light emission: diffuse reflection, specular reflection, and glow.

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.

Glow is light radiated from a surface at a certain color and intensity of light that is independent of incident light.

Most actual materials show a mixture of diffuse and specular reflection, and some objects glow in addition to reflecting light. For each kind of light emission, an object can have an intrinsic color. For diffuse reflection, when the incident light is white, the color of the reflected light is the material's intrinsic color. 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. Similarly, an object may have an intrinsic specular reflection color, which may be different from its diffuse reflection color, and the specularly reflected light is a component-wise product of the incident light and the intrinsic specular color. For glow, the color emitted is determined by intrinsic properties alone, with no dependence on incident light.

In Mathematica, you can specify light properties by giving any combination of diffuse reflection, specular reflection, and glow directives. To get no reflection of a particular kind, you may 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.

GrayLevel[a]matte surface with albedo a
RGBColor[r,g,b]matte surface with intrinsic color
Specularity[spec,n]surface with specularity spec and specular exponent n; spec can be a number between 0 and 1 or an RGBColor specification
Glow[col]glowing surface with color col

Specifying surface properties of lighted objects.

This shows a sphere with the default matte white surface, illuminated by several colored light sources.
In[9]:=
Click for copyable input
Out[9]=
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[10]:=
Click for copyable input
Out[10]=

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.

New to Mathematica? Find your learning path »
Have a question? Ask support »