How to | Control the Response of a 3D Surface to Lighting

To control how a 3D surface responds to simulated light, set its reflection properties. The Wolfram Language lets you control the diffuse reflection of light on a matte surface and the specular reflection of light on a mirror-like surface. Combining them gives you extensive control over the final appearance and color of a 3D surface.

Intrinsic surface color corresponds directly to diffuse reflection, where light is scattered equally in all directions from the surface. For example, sheets of uncoated paper are matte ("dull") and thus show diffuse reflection.

By default, the intrinsic surface color of 3D objects in the Wolfram Language is white. Here, the color on the 3D cylinder comes from the Lighting setting the Wolfram Language uses by default:

In[1]:=
Click for copyable input
Out[1]=

Create a 3D cylinder where the intrinsic surface color is red. This specifies the diffuse reflection of red light by the cylinder:

In[2]:=
Click for copyable input
Out[2]=

More detailed control over the specific color of 3D surfaces can be gained with RGBColor, which lets you set explicit values ranging from 0 to 1 for red, green, and blue:

In[3]:=
Click for copyable input
Out[3]=

In fact, you can use many methods for setting the intrinsic surface color of 3D objects in the Wolfram Language. Here, CMYKColor is used:

In[4]:=
Click for copyable input
Out[4]=

This Manipulate uses RGBColor to set the intrinsic surface color of the 3D cylinder. For reference, the Inset 2D square at the top right shows the raw RGBColor setting in the absence of Lighting.

When the sliders are set all the way to the left, the surface color is black. When the sliders are set all the way to the right, the surface color is white, which causes the cylinder to appear in the default color scheme:

    

Another property of reflection that you can control is specular, or mirror-like reflection. This type of reflection occurs on "glossy" or "shiny" surfaces, such as a piece of laminated paper.

First, create a 3D sphere that uses the default settings:

In[1]:=
Click for copyable input
Out[1]=

The fraction of light that is specularly reflected can range from 0 to 1. For example, use Specularity to specularly reflect 30% of the light that falls on the sphere:

In[2]:=
Click for copyable input
Out[2]=

To see what the range of values for Specularity looks like, use this Manipulate to dynamically adjust the fraction of light that is specularly reflected:

You can also specularly reflect specific colors:

In[4]:=
Click for copyable input
Out[4]=

Many different colors in the Wolfram Language can be specularly reflected. For example, the sliders in the Manipulate here are used with RGBColor to dynamically set the color reflected by Specularity. As before, the Inset 2D square at the top right shows the raw RGBColor setting:

Specularity also lets you control exactly the width of the specular reflection of light by setting a specular exponent. The specular exponent is specified as the second argument to Specularity. If you do not explicitly set a specular exponent, Wolfram Language uses the default value of 1.5.

Create a 3D sphere where 50% of the light is specularly reflected, and the specular exponent is 1:

In[6]:=
Click for copyable input
Out[6]=

The higher the specular exponent, the more sharply defined the specular reflection is.

For example, use the slider in this Manipulate to dynamically adjust the specular exponent from 1 to 100. At a value of 100, the specularly reflected light is restricted to a small area:

    

In practice, the diffuse and specular components of reflection are often combined to control the final color and appearance of 3D surfaces.

PlotStyle is used here to color the surface of this plot Orange and specularly reflect White light with a specular exponent of 20:

In[1]:=
Click for copyable input
Out[1]=

ContourStyle is used similarly here:

In[2]:=
Click for copyable input
Out[2]=

As you might expect, Lighting has a profound effect on reflection. Use diffuse and specular reflection together with Lighting:

In[3]:=
Click for copyable input
Out[3]=