Transitioning 3D surface plot to Makie v0.20

I had a figure which consists of multiple 3D surface plots. The script looks something like

using CairoMakie; CairoMakie.activate!()

update_theme!(Surface = (diffuse = Vec3f(1,0), specular = Vec3f(0.2), shading = true))

fig = Figure()
g = GridLayout(fig[1,1])

update_theme!(light_direction = Vec3f(1,2,3))
ax1 = Axis3(g[1,1], elevation=pi*30/180)
surface!(ax1, x, y, z1)

update_theme!(light_direction = Vec3f(-3,2,1))   # update lighting for another surface plot
ax2 = Axis3(g[1,2], elevation=pi*40/180)
surface!(ax2, x, y, z2)


With the recent release of Makie v0.20, what’s the proper way to set the light direction? After reading the documentation, apparently I need to change shading=FastShading or something else, but I can’t quite figure out the light direction. I tried something like ax1.scene.lights = [DirectionalLight(RGBf(1,1,1), Vec3f(1,2,3))], but the 3D plot looks black regardless of the RGB and the Vec3f.

shading is automatically determined by the lights you have in a scene so you don’t need to set it here. You only need to when you want something different to the default, e.g. no shading on a surface plot or shading on a poly plot.

For the light direction it’s easy to trip over the numbers you want. If you want a light source straight above your plot, then the light is shining down so the direction is Vec3f(0, 0, -1).

Setting ax1.scene.lights = [DirectionalLight(RGBf(1,1,1), Vec3f(1,2,3))] will leave you with a directional light going diagonally up and no ambient light. So you should see the side facing -z illuminated by the directional light and the side facing +z completely black.