LightSources

The lighting model in Mathematica allows you to simulate lighting from one or more light sources when the setting (Lighting:->True) is used. Each light source has a certain positioon and color. Cartesian coordinates relative to the display are used to specify the position of light sources.  The axes are oriented with the positive x - axis right of the display, the positive y - axis above the display, and the positive z - axis in front of the display.  Some examples are given below to demonstrate.

First we have an example where
{{0,1,0},RGBColor[1,0,0]} is a red light source from above, and
{{1,0,0},RGBColor[0,1,0]} is a green light source from the right.

RowBox[{RowBox[{Show, [, RowBox[{Graphics3D, [, RowBox[{{Cuboid[{1, 1, 1}]}, ,, BoxedF ... 62754; {{{0, 1, 0}, RGBColor[1, 0, 0]}, {{1, 0, 0}, RGBColor[0, 1, 0]}}}], , ]}], ]}], ;}]

In the next cell we have an example where
{{0,-1,0},RGBColor[1,0,0]}is a red light source from below,and
{{-1,0,0},RGBColor[0,1,0]}is a green light source from the left.

RowBox[{RowBox[{Show, [, RowBox[{Graphics3D, [, RowBox[{{Cuboid[{1, 1, 1}]}, ,, BoxedF ... 754; {{{0, -1, 0}, RGBColor[1, 0, 0]}, {{-1, 0, 0}, RGBColor[0, 1, 0]}}}], , ]}], ]}], ;}]

In the next cell we have an example where
{{0,0,1},RGBColor[1,0,0]}is a red light source from directly infront of the display and
{{1,0,0},RGBColor[0,1,0]}is a green light source from the right.

RowBox[{RowBox[{Show, [, RowBox[{Graphics3D, [, RowBox[{{Cuboid[{1, 1, 1}]}, ,, BoxedF ... 62754; {{{0, 0, 1}, RGBColor[1, 0, 0]}, {{1, 0, 0}, RGBColor[0, 1, 0]}}}], , ]}], ]}], ;}]

In the examples above the cubes were oriented so that two surfaces were nearly normal to the incident light rays. Hence reflected light was nearly identical to the incident light. In the next example the default ViewPoint is used, and each of three sides are iluminated by more than one light source.

RowBox[{RowBox[{Show, [, RowBox[{Graphics3D, [, RowBox[{{Cuboid[{1, 1, 1}]}, ,, BoxedF ... p;  , 1., ,, 0.2}], }}], ,, RGBColor[0, 0, 1]}], }}]}], }}]}]}], , ]}], ]}], ;}]

The Mathematica lighting model doesn't account for shadows. This is normally preffered for scientific illustrations, but not for life like 3D graphics. The fact that Mathematica doesn't account for shadows is demonstrated with the code in the next cell in which the top of all cubes are red, and the right side of all cubes are green.

RowBox[{RowBox[{Show, [, RowBox[{Graphics3D, [, RowBox[{RowBox[{{, RowBox[{RowBox[{Cuboid, [,  ... 62754; {{{0, 1, 0}, RGBColor[1, 0, 0]}, {{1, 0, 0}, RGBColor[0, 1, 0]}}}], , ]}], ]}], ;}]

For the next example we need to load a graphics package.

<<Graphics`Shapes`

Keep in mind the coordinate system used for LightSources has nothing to do with the axes of the Graphics3D object. For evidence of this consider the next cell which make an annimation of a rotating sphere with only one light source from the right and a little ambient light.  If you click on one of the graphic cells you can see the box spining around, but the sphere always looks the same.

gr1 = Sphere[1, 50, 25] ;  RowBox[{RowBox[{Table, [, , RowBox[{RowBox[{Show, [ ...  , Sin[θ]}], ,, 2.}], }}]}]}], ]}], ,, , {θ, 0, 2π, π/10}}], ]}], ;}]

The next cell makes an annimation showing a torus lit with a moving light source. The only thing that changes in the annimation is the direction of the light source.  The virtural location of the light moves in a counter clockwise circle around the viewing surface.

gr1 = Torus[3, 1, 30, 30] ; Table[Show[Graphics3D[{EdgeForm[], gr1}], LightSources {{{Cos[a], Sin[a], 1}, GrayLevel[1]}}], {a, 0, 2π, π/8}] ;


Created by Mathematica  (May 16, 2004)

Back to Ted’s Tricks index page