# BarChart3D lighting for negative values

I'm using BarChart3D to plot matrices. The code I wrote used to work fine until Mathematica 11.

For some reason, negative values of the matrix appear very dark on the plot, whereas it didn't before. It looks like, rendering speaking, the face normals switch direction when the bars are negative, and the lighting is thus reversed.

Example code:

BarChart3D[Table[1 Exp[-(((x - 4)^2 + (y - 4)^2)/8)] (x - 4), {x, 1, 8}, {y, 1,8}], ChartLayout -> "Grid", ChartElementFunction -> "Cube", Method ->{"Canvas" -> None}, ColorFunctionScaling -> False,ColorFunction -> (Blend[{{-1, Red}, {0, White}, {1, Red}}, #] &),BarSpacing -> {0, 0}, ViewPoint -> {-6, -9, 4.2},ViewVertical -> {0, 0, 1}, ImageSize -> 850]

Comparison between 11.01 and 10.4:

I found some ways around it by fiddling with Lighting->{...}, but it never looks as good as it used to.

Any idea ?

Thanks !

• Welcome. Wait a few minutes that one of our users will leave some tips. – LCarvalho Nov 22 '16 at 19:30
• Quite strange that all the other chart functions from ChartElementData["BarChart3D"], such as FadingCube, work fine. – Stitch Nov 22 '16 at 21:37

You are correct about the face normals switching direction, it seems that in version 11 we must be careful that pt1 is lower than pt2 in Cuboid[pt1, pt2]. Cuboids may appear inside-out if this is not the case. Example:

Graphics3D[{FaceForm[Red, Green],
Cuboid[{0, 0, 0}, {1, 1, 1}],
Cuboid[{0, 0, 0}, {1, 1, -1}]}]

The bar chart can therefore be fixed by post-processing the CuboidBox boxes to meet the new requirement.

fix = CuboidBox[data__] :> RuleCondition[CuboidBox @@ Transpose[Sort /@ Transpose[{data}]]]

BarChart3D[
Table[1 Exp[-(((x - 4)^2 + (y - 4)^2)/8)] (x - 4), {x, 1, 8}, {y, 1, 8}],
ChartLayout -> "Grid", ChartElementFunction -> "Cube",
Method -> {"Canvas" -> None}, ColorFunctionScaling -> False,
ColorFunction -> (Blend[{{-1, Red}, {0, White}, {1, Red}}, #] &),
BarSpacing -> {0, 0}, ViewPoint -> {-6, -9, 4.2},
ViewVertical -> {0, 0, 1}, ImageSize -> 850] /. fix

• Awesome, thanks a lot ! – Valérian Thiel Nov 23 '16 at 16:49