Understanding Lighting in Makie


I’m having some problems understanding how the lighting works in Makie. I’m trying to draw a surface displaying a cone with a blunt leading edge, and then draw some flow fields extending from the surface of the cone in the X-Z plane, one extending in the +Z direction and one in the -Z direction. The plane in the -Z direction is “shadowed” by the cone, despite the light being in the X-Y plane.

Here is a pared down bit of code I used:

    # Generate the cone surface
    # Use wall-based coordinates to start
    sw = LinRange(0, 17.78e-3 * 83π / 180 + 1.2, 1000)
    ϕ = LinRange(π, -π, 100)

    # wall_to_xyz() takes a wall-based coordinate (streamwise, wallnormal, azimuth) and converts
    # to cartesian
    pts = [wall_to_xyz([s, 0.0, θ], 17.78e-3, deg2rad(7)) for s = sw, θ = ϕ]

    # Build the figure, axis, surface for the full cone geometry
    fig, ax, s = surface(getindex.(pts, 1), getindex.(pts, 2), getindex.(pts, 3), colormap = cgrad([:gray, :gray], alpha = 1.0), 
                         axis = (scenekw = (lightposition = Vec3f(1.0, -0.75, 0.0), ambient = RGBf(0.5, 0.5, 0.5), backlight = 2.0f0), show_axis = false),
                         diffuse = Vec3f(0.5, 0.5, 0.2), specular = Vec3f(1.0, 1.0, 1.0), shininess = 128f0, figure = (resolution = (1500, 1000),))

    # Add the surfaces for the flow quantities- cell_entropy and cell_Mach are results from a simulation
    s_e = surface!(ax, getindex.(flowpts, 1), getindex.(flowpts, 3), getindex.(flowpts, 2), color = cell_entropy, colormap = cgrad(:autumn1, rev = true))
    s_m = surface!(ax, getindex.(flowpts, 1), getindex.(flowpts, 3), -getindex.(flowpts, 2), color = cell_Mach, colormap = cgrad(:autumn1, rev = true))

    cam = cameracontrols(ax.scene)
    cam.lookat[] = [0.7, 0.0, 0.0]
    cam.eyeposition[] = [0.7, -1.2, 0.0]
    update_cam!(ax.scene, cam)
    save("Cone_Demo.png", fig)

As you can see, the bottom surface appears to be in the “shadow” of the geometry, despite the scene light position and camera position being in the X-Y plane. Can anyone give an explanation of this behaviour and how to stop the bottom field being shadowed?

1 Like

I think the normals point upward, so the bottom side doesn’t get lighting. I’m not actually sure why backsides of planes cannot receive light, maybe that could be changed. Cc @ffreyer

Ah, that does explain the issue. Setting the backlight to 1.0 fixed the problem.