Lighting and Surface Properties

With the default option setting (RefLink[Lighting, paclet:ref/Lighting])->(RefLink[Automatic, paclet:ref/Automatic]), the Wolfram Language uses a simulated lighting model to determine how to color polygons in three-dimensional graphics.

The Wolfram Language 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. The Wolfram Language adds together the light from all of these sources in determining the total illumination of a particular polygon.

Methods for specifying light sources.

The default lighting used by the Wolfram Language involves three point light sources, and no ambient component. The light sources are colored respectively red, green and blue, and are placed at (45^◦) angles on the right-hand side of the object.

Here is a sphere, shaded using simulated lighting using the default set of lights:

spheres=Graphics3D[{Sphere[{-1,-1,0}],Sphere[{-1,1,0}],Sphere[{1,1,0}],Sphere[{1,-1,0}]},Axes->True,AxesLabel->{"x","y","z"}]

This shows the result of adding ambient light, and removing all point light sources. Note the (RefLink[Lighting, paclet:ref/Lighting]) option takes a list of light sources:

Show[spheres,Lighting->{{"Ambient",Blue}}]

This adds a single point light source positioned at the red point. The lights are combined as appropriate:

Show[{spheres,Graphics3D[{Red,PointSize[Large],Point[{0,0,2}]}]},Lighting->{{"Ambient",Blue},{"Point",Red,{0,0,2}}}]

Objects do not block light sources or cast shadows, so all objects in a scene will be lit evenly by light sources:

Show[{spheres,Graphics3D[{Red,PointSize[Large],Point[{3,0,0}]}]},Lighting->{{"Ambient",Blue},{"Point",Red,{3,0,0}}}]

This adds a directional green light shining from the negative y direction, effectively an infinite distance away:

Show[%,Lighting->{{"Ambient",Blue},{"Point",Red,{3,0,0}},{"Directional",Green,{{0,0,0},{0,1,0}}}}]

This shows a spotlight positioned above the plot, combined with ambient lighting:

Plot3D[Sin[x+Sin[y]],{x,-3,3},{y,-3,3},Lighting->{{"Ambient",RGBColor[0,0,.6]},{"Spot",Red,{{0,0,5},{0,0,0}},15 Degree}}]

The (RefLink[Lighting, paclet:ref/Lighting]) directive replaces the default value of (RefLink[Lighting, paclet:ref/Lighting]) for the two spheres after the directive:

Graphics3D[{Sphere[{0,0,0}],Lighting->{{"Point", Green,{0,0,5}}}, Sphere[{1,1,1}],Sphere[{2,2,2}]}]

This example uses list braces to restrict the effect of the (RefLink[Lighting, paclet:ref/Lighting]) directive to the middle sphere:

Graphics3D[{Sphere[{0,0,0}],{Lighting->{{"Point", Green,{0,0,5}}}, Sphere[{1,1,1}]},Sphere[{2,2,2}]}]

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 (RefLink[RGBColor, paclet:ref/RGBColor]), (RefLink[Specularity, paclet:ref/Specularity]), and (RefLink[Glow, paclet:ref/Glow]) to specify the way that polygons reflect or emit light.

If you do not explicitly use these coloring directives, the Wolfram Language 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 (RefLink[RGBColor, paclet:ref/RGBColor]), (RefLink[Specularity, paclet:ref/Specularity]), and (RefLink[Glow, paclet:ref/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 cos(α) times the intensity of the incident light, where α is the angle between the incident light direction and the surface normal vector. Note that when α>(90^◦), 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. The Wolfram Language allows you to specify how broad the distribution is by giving a specular exponent, defined according to the Phong lighting model. With specular exponent n, the intensity of light at an angle θ away from the mirror reflection direction is assumed to vary like cos(((θ))^n). As n->∞, therefore, the surface behaves like a perfect mirror. As n decreases, however, the surface becomes less "shiny", and for n==0, the surface is a completely diffuse reflector. Typical values of n 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 the Wolfram Language, 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 (RefLink[Black, paclet:ref/Black]), or (RefLink[GrayLevel, paclet:ref/GrayLevel])[0]. For materials that are effectively "white", you can specify intrinsic colors of the form (RefLink[GrayLevel, paclet:ref/GrayLevel])[a], where a is the reflectance or albedo of the surface.

Specifying surface properties of lighted objects.

This shows a sphere with the default matte white surface, illuminated by several colored light sources:

Graphics3D[Sphere[]]

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:

Graphics3D[{GrayLevel[0.2],Specularity[0.8,5],Sphere[]}]

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.