Changing the background color of a 3D Scene in Makie

How can I make the background color of a (3D) scene contained within an LScene ? Including backgroundcolor=:black in the scenekw arg doesn’t seem to do it, nor does setting the attribute directly on lscene.scene . However, setting the attribute on scene seems to change lscene.scene.attributes[:background].

With a bit of fumbling around I found that if I set lscene.scene.clear=true then I get the effect that I’m looking for in particular which is a black background. However if I use a different color, e.g. lscene.scene.attributes[:background] = :purple then this kills performance; also it seems that once that attribute has been set it can’t be changed.

@airpmb, was this issue solved?

Not as yet. Though I do wonder if it’s related to some of the other performance issues on MacOS and wonder if anyone can duplicate it on another platform.

I’m not sure what are you looking for but the following works just fine:

using GLMakie, ColorSchemes, Colors
# archimedean spiral
a, m, z₀ = 1, 2.1, 0
φ = LinRange(0,20π,500)
r = a*φ
x, y, z = r .* cos.(φ), r .* sin.(φ), m .* r .+ z₀;

set_theme!(backgroundcolor = :black)

fig = Figure(resolution = (500, 500))
ax = LScene(fig)
lines!(x, y, z, color = z, colormap = :viridis)
axis = ax.scene[OldAxis] # you can change more colors here!
axis[:ticks][:textcolor] = :white
fig[1, 1] = ax
#save("./results/FigBlack.png", fig, px_per_unit = 1)
fig

FigBlack
For more details you can take a look at this notebook.
Jupyter Notebook Viewer

Best,
Lazaro

1 Like

@lazarusA, do you know why the following is not enough to set the background color (at least in Win10, Julia Version 1.6.0-beta1.0):

lines(x, y, z, color = z, backgroundcolor = :black)

To be honest, nope :smiley: (this also doesn’t work for me), but probably @jules knows ?

1 Like

That works for me as well but I think the issue I’m seeing has to do with wanting to have a different background color in a 3D LScene within a larger layout which has another background color. I probably should have made that part clearer in my post.

With regards to what I was observing about performance when I used :purple I just noticed something that I hadn’t before: it seems that the background in this case actually isn’t a constant purple but actually there is a very subtle color gradient towards black at the edges:

The really weird thing is that not every color causes this. I just picked purple at random; when I change that one word :purple in the code to :green instead, I see no gradient and no sluggishness:

Fortunately, as I mentioned in the original post, :black works in that it doesn’t kill performance, and I do get what I’m looking for which is something like this:

(in this last I also used the set_theme! as suggested to get the grey background outside of the 3D view).

Anyhow to be clear, for now I have the output I’m looking for but I really can’t say I understand why it works, and in particularly why lscene.scene.clear=true is important, and why I sometimes see the gradient and performance behavior based just on what color I specify in the scenekw args in the LScene call.

Is someone aware of a similar example combining controls on a different-color background, with a 3D view (subscene? LScene?), all using the newer layout API?

I’ll try to get to making a MWE and post it so others can explore this if they want, but unless maybe something about the gradient makes one of you Makie experts say ‘aha’, I won’t be too sad about going forward with what I have.

1 Like

The gradient is an SSAO artifact I think, and that’s also what drags down performance. At least @ffreyer said something to that effect if I’m not mistaken, and he’s the one who implemented it and currently has a PR active to fix this (and disable SSAO by default)

2 Likes

Oh, I messed up a bit there.

SSAO uses a normal buffer which gets cleared to (1,1,1) at the start of the drawing process. I use that clear value to discard pixels that have no geometry. What I overlooked is that the background color again clears that buffer, so if you set it to something other than white the ssao pipeline thinks there is geometry there. I pushed a fix in the pr that allows you to skip the whole SSAO pipeline.

2 Likes