# 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. *Mathematica* 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 *Mathematica* is white. Here, the color on the 3D cylinder comes from the Lighting setting *Mathematica* uses by default:

In[19]:= |

Out[19]= |

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

In[16]:= |

Out[16]= |

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[10]:= |

Out[10]= |

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

In[20]:= |

Out[20]= |

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:

In[43]:= |

Out[43]= | Play Animation ▪ |

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[52]:= |

Out[52]= |

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[51]:= |

Out[51]= |

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:

In[50]:= |

Out[50]= | Play Animation ▪ |

You can also specularly reflect specific colors:

In[49]:= |

Out[49]= |

Many different colors in *Mathematica* 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:

In[47]:= |

Out[47]= | Play Animation ▪ |

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, *Mathematica* 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[48]:= |

Out[48]= |

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[53]:= |

Out[53]= | Play Animation ▪ |

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[49]:= |

Out[49]= |

ContourStyle is used similarly here:

In[74]:= |

Out[74]= |

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

In[2]:= |

Out[2]= |