13

Bug introduced in 11.2 or earlier and persisting through 13.0


There are something wrong when I try to evaluate the example from Lighting Docs, here is the code:

lights = {{"Spot", Red, {{3, 3, 5}, {3, 3, 0}}, Pi/8}, {"Spot", Green, {{7, 3, 5}, {7, 3, 0}}, Pi/8}, {"Spot", Blue, {{5, 6, 5}, {5, 6, 0}}, Pi/8}};

plane = ParametricPlot3D[{u, v, -2}, {u, 0, 10}, {v, 0, 9}, PlotPoints -> 100, MaxRecursion -> 0, Mesh -> None, Axes -> False];

Show[plane, Lighting -> lights]

Unfortunately, it does not work as expected in Mathematica version 11.3:

output

But if we directly use the form

ParametricPlot3D[{u, v, -2}, {u, 0, 10}, {v, 0, 9}, PlotPoints -> 100, MaxRecursion -> 0, Mesh -> None, Axes -> False,Lighting -> lights]  

it works:

output

So I want to know the reason for creating the different outcomes, maybe researching the InputForm of output seems a feasible point, but I failed. Thanks for any info on this matter.

kglr
  • 394,356
  • 18
  • 477
  • 896
Ren Witcher
  • 707
  • 3
  • 12

1 Answers1

12

Update: This is yet another case of automatic PlotTheme settings injecting directives that override the user-specified ones. So, a much easier fix is to add the option PlotTheme -> None to ParametricPlot3D.

plane = ParametricPlot3D[{u, v, -2}, {u, 0, 10}, {v, 0, 9}, 
   PlotPoints -> 100, MaxRecursion -> 0, Mesh -> None, Axes -> False, 
   PlotTheme -> None];

Show[plane, Lighting -> lights]

enter image description here

Note: You can find a number of other issues fixed by explicitly removing PlotTheme on this page.

Original answer:

I think this is a bug.

A fix is to remove Lighting from plane before using it in Show:

plane = ParametricPlot3D[{u, v, -2}, {u, 0, 10}, {v, 0, 9}, 
   PlotPoints -> 100, MaxRecursion -> 0, Mesh -> None, Axes -> False, ImageSize -> 300];
planeb = DeleteCases[plane, Lighting -> _, All];
Grid[Labeled[ToExpression@#, #, Top] & /@ # & /@ 
 {{"plane", "Show[plane,Lighting->lights]"},
  {"planeb", "Show[planeb,Lighting->lights]"}}]

enter image description here

What I think is happening:

The lighting settings from the default PlotTheme -> Automatic are embedded as directives before graphics primitives in ParametricPlot3D. This can be verified using

Cases[plane, {a : ___, l : (Lighting -> _), ___} :> {a, l}, All]

enter image description here

or using

Cases["DefaultPlotStyle" /. (Method /. 
  Charting`ResolvePlotTheme[Automatic, ParametricPlot3D]), HoldPattern[Lighting -> _], All]

enter image description here

As noted by xzczd in comments, this issue does not arise in version 9:

Labeled[Row[Labeled[ToExpression@#, #, Top] & /@ {"plane", 
    "Show[plane,Lighting -> lights]"}], "Version: " <> $Version]

enter image description here

kglr
  • 394,356
  • 18
  • 477
  • 896