Function Repository Resource:

 ShadowGraphics3D

Source Notebook

Add shadows of a 3D graphic projected onto the walls of its bounding box

Contributed by: Jon McLoone

ResourceFunction["ShadowGraphics3D"][gr]

adds the projections of the 3D graphic gr onto the walls of its bounding box that are behind it from its ViewPoint.

ResourceFunction["ShadowGraphics3D"][gr,wall]

adds the projection of gr onto a single wall, such as Back or Bottom or group of walls such as All.

ResourceFunction["ShadowGraphics3D"][gr,{w1,w2,…}]

adds the projections of gr onto the walls wi of its bounding box.

ResourceFunction["ShadowGraphics3D"][gr,walls,"Dynamic"]

adds the projections of gr onto walls, showing each only while its wall is behind the graphic, so the shadows follow interactive rotation.

Details and Options

Walls are numbered 1 to 6 for the minimum x, maximum x, minimum y, maximum y, minimum z and maximum z walls. All is equivalent to {1,2,3,4,5,6}.
The projections are computed with ResourceFunction["ProjectGraphics3D"], using the PlotRange of gr.
Walls wi can be numbers or the following names, which are relative to the ViewPoint and ViewVertical of gr:
Topwall above the plot on screen
Bottomwall below the plot on screen
Backwall behind the plot
Frontwall in front of the plot
Leftwall to the left on screen
Rightwall to the right on screen
"Sides"{Left,Right,Front,Back}
"BackSides"Back and whichever of Left and Right is farther from the viewer
"FrontSides"Front and whichever of Left and Right is nearer the viewer
Top is the wall in the direction that ViewVertical points on screen, Back is the far wall on the remaining axis closest to the line of sight, and Left and Right are as seen on screen.
With Automatic or named walls, the walls are chosen once from the ViewPoint and ViewVertical of gr, and do not change when the graphic is rotated.
The following options can be given:
"ShadowStyle"Automaticstyle for the projected polygons
"LineShadowStyle"Automaticstyle for the projected lines
With "\"Dynamic\"" as the third argument, each projection is rendered only while its wall is behind the graphic. Therefore the shadows follow interactive rotation without the graphic being rebuilt. In this case the result is a DynamicModule rather than a Graphics3D, unless the projections contain no lines or points. The default, "Static", always shows every projection.
With "LineShadowStyle"→style, the projected lines are drawn with style in place of their own colors. With "LineShadowStyle"→None, lines are removed from the projections, though points are retained.
With "ShadowStyle"→style, the colors, lighting and other styling of the projected polygons are replaced by style, lit with neutral lighting unless style specifies Lighting. With "ShadowStyle"→None, only the projected lines and points are shown. The styling of gr itself is unchanged.

Examples

Basic Examples (1) 

Add shadows on the walls of the bounding box that are behind a surface:

In[1]:=
ResourceFunction["ShadowGraphics3D"][
 Plot3D[1/(1 + x^2 + (y + 1)^2) + 1/(1 + x^2 + (y - 1)^2), {x, -4, 4}, {y, -4, 4}]]
Out[1]=
Image

Scope (10) 

Choose the walls explicitly, numbered 1 to 6 for the minimum and maximum x, y and z walls:

In[2]:=
ResourceFunction["ShadowGraphics3D"][
 Plot3D[1/(1 + x^2 + (y + 1)^2) + 1/(1 + x^2 + (y - 1)^2), {x, -4, 4}, {y, -4, 4}], {1, 3, 5}]
Out[2]=
Image

Project onto all six walls:

In[3]:=
ResourceFunction["ShadowGraphics3D"][
 Plot3D[Sin[x y], {x, y} \[Element] Disk[]], All]
Out[3]=
Image

Name walls relative to the viewer:

In[4]:=
ResourceFunction["ShadowGraphics3D"][
 ExampleData[{"Geometry3D", "Horse"}], {Left, Bottom}]
Out[4]=
Image

Named walls follow the ViewPoint of the graphic:

In[5]:=
ResourceFunction["ShadowGraphics3D"][
 Show[ExampleData[{"Geometry3D", "Horse"}], ViewPoint -> {-1, 2, 0}], {Left, Bottom}]
Out[5]=
Image

Project onto the back wall and the far side wall:

In[6]:=
ResourceFunction["ShadowGraphics3D"][
 ExampleData[{"Geometry3D", "Horse"}], "BackSides"]
Out[6]=
Image

Mix named walls with wall numbers:

In[7]:=
ResourceFunction["ShadowGraphics3D"][
 ExampleData[{"Geometry3D", "Triceratops"}], {Left, 4}]
Out[7]=
Image

Shadows of a parametric surface:

In[8]:=
ResourceFunction["ShadowGraphics3D"][
 ParametricPlot3D[{(2 + Cos[v]) Cos[u], (2 + Cos[v]) Sin[u], Sin[v]}, {u, 0, 2 Pi}, {v, 0, 2 Pi}, PlotStyle -> Orange], Automatic]
Out[8]=
Image

A space curve, with a plot range that leaves room between it and the walls:

In[9]:=
curve = ParametricPlot3D[{Cos[t], Sin[t], t/5}, {t, 0, 10}, PlotRange -> {{-2, 2}, {-2, 2}, {-1, 3}}]
Out[9]=
Image

Add its shadows:

In[10]:=
ResourceFunction["ShadowGraphics3D"][curve, "LineShadowStyle" -> LightGray]
Out[10]=
Image

Project onto every wall, but show each projection only while its wall is behind the graphic, so the shadows switch as it is rotated interactively:

In[11]:=
ResourceFunction["ShadowGraphics3D"][
 ExampleData[{"Geometry3D", "Cow"}], All, "Dynamic"]
Out[11]=
Image

Options (6) 

ShadowStyle (4) 

Draw the projections as gray shadows:

In[12]:=
ResourceFunction["ShadowGraphics3D"][
 Plot3D[1/(1 + x^2 + (y + 1)^2) + 1/(1 + x^2 + (y - 1)^2), {x, -4, 4}, {y, -4, 4}], "ShadowStyle" -> Gray]
Out[12]=
Image

Any graphics directives can be used:

In[13]:=
ResourceFunction["ShadowGraphics3D"][
 Plot3D[Sin[x y], {x, 0, 2}, {y, 0, 2}], Automatic, "ShadowStyle" -> Directive[Blue, Opacity[0.4]]]
Out[13]=
Image

The style replaces colors from a ColorFunction:

In[14]:=
ResourceFunction["ShadowGraphics3D"][
 Plot3D[Sin[x y], {x, -2, 2}, {y, -2, 2}, ColorFunction -> "Rainbow"], Automatic, "ShadowStyle" -> Gray]
Out[14]=
Image

Show only the projected lines:

In[15]:=
ResourceFunction["ShadowGraphics3D"][
 Plot3D[1/(1 + x^2 + (y + 1)^2) + 1/(1 + x^2 + (y - 1)^2), {x, -4, 4}, {y, -4, 4}], "ShadowStyle" -> None]
Out[15]=
Image

LineShadowStyle (2) 

Draw the projected lines in a single color:

In[16]:=
ResourceFunction["ShadowGraphics3D"][
 Plot3D[1/(1 + x^2 + (y + 1)^2) + 1/(1 + x^2 + (y - 1)^2), {x, -4, 4}, {y, -4, 4}], "LineShadowStyle" -> White]
Out[16]=
Image

Remove the lines from the projections:

In[17]:=
ResourceFunction["ShadowGraphics3D"][
 Plot3D[1/(1 + x^2 + (y + 1)^2) + 1/(1 + x^2 + (y - 1)^2), {x, -4, 4}, {y, -4, 4}], Automatic, "LineShadowStyle" -> None]
Out[17]=
Image

Possible Issues (4) 

With "Dynamic", the result is a DynamicModule when the projections contain lines, so it cannot be combined with Show:

In[18]:=
Head[ResourceFunction["ShadowGraphics3D"][
  Plot3D[Sin[x y], {x, -2, 2}, {y, -2, 2}], All, "Dynamic"]]
Out[18]=
Image

Without lines, the result is a Graphics3D:

In[19]:=
Head[ResourceFunction["ShadowGraphics3D"][
  Plot3D[Sin[x y], {x, -2, 2}, {y, -2, 2}], All, "Dynamic", "LineShadowStyle" -> None]]
Out[19]=
Image

Give options such as ViewPoint to the input graphic instead:

In[20]:=
ResourceFunction["ShadowGraphics3D"][
 Plot3D[Sin[x y], {x, -2, 2}, {y, -2, 2}, ViewPoint -> {-2, 1.5, -1.2}], All, "Dynamic", "ShadowStyle" -> Gray]
Out[20]=
Image

The projections are computed using the ResourceFunction["ProjectGraphics3D"]. This is currently limited to Polygon, Line and Point. Other Graphics3D primitives will not cast shadows:

In[21]:=
ResourceFunction["ShadowGraphics3D"][Graphics3D[Sphere[]]]
Out[21]=
Image

Neat Examples (1) 

Show the skyline of Mount Everest together with its elevation plot:

In[22]:=
ResourceFunction["ShadowGraphics3D"][
 ListPlot3D[
  Reverse[GeoElevationData[Entity["Mountain", "MountEverest"], GeoRange -> Quantity[4, "Kilometers"], GeoProjection -> Automatic]],
   MeshFunctions -> {#3 &}, Mesh -> 15,
  PlotRange -> {{-25, 250}, {0, 275}, Automatic}], "BackSides"]
Out[22]=
Image

Publisher

Jon McLoone

Version History

  • 1.0.0 – 02 November 2026

Related Resources

License Information