Makie isosurface transparency?

In Makie is there a way to make an isosurface have some partial transparency? There used to be I think, but I cant see an alpha option or similar

Over at KleinBottle

I notice that a partially transparent colormap can be passed to mesh:

colormap = (:Spectral_11,0.95)

but if I try it with volume the transparency doesn’t work.

if I use transparency=true, i.e.

r = LinRange(-1, 1, 100)
cube = [(x.^2 + y.^2 + z.^2) for x = r, y = r, z = r]
cube_with_holes = cube .* (cube .> 1.4)
volume(cube_with_holes, algorithm = :iso, isorange = 0.05, isovalue = 1.7,transparency=true)

I get the following. But this is not really transparent in the sense that matters for me. The back surface is not visible through the front surface.

Check the absorption and contour suggestions in this amazing post.

Ok, some progress. If I do, e.g.


I get the result

Not quite what I want though. Quite dark, hard to get a clear surface

This would be really good to add to the docs, I never need volume plots but there is just one example and it’s not clear at all how to use the other modes.

I figured finding an example of roughly what I am trying to do would be more useful. I am aiming for something like the fourth example here:

I use this trick often(https://), it gives nice results.

colors = to_colormap(:balance)
n = length(colors)
alpha = [ones(n÷3);zeros(n-2*(n÷3));ones(n÷3)]
cmap_alpha = RGBAf0.(colors, alpha)

I think this shows the issue clearly.

I would expect to see two intersecting ellipsoids, with axis sitting behind (less visible due to being behind more than one layer). Here I plotted the smaller (closer) surface first. The impression is that both sit behind the axis, and the closer one appears behind the further because transparency is only with respect to axes. I have tried applying an alpha to colormap (suggested above), but I haven’t had much luck improving this

	using GLMakie
	X = -40:5:40
	ellipse1 = [X^2/2 + Y^2 + 2Z^2 for X in X, Y in X, Z in X];
	ellipse2 = [X^2/2 + (Y-20)^2 + 2Z^2 for X in X, Y in X, Z in X];
	v1=volume(ellipse2, algorithm = :iso,isovalue =350,isorange = 50,transparency=true)
	volume!(ellipse1, algorithm = :iso, isovalue =700,isorange = 50,transparency=true)

did you tried like this:

using GLMakie, ColorSchemes
cbarPal= :plasma
cmap = get(colorschemes[cbarPal], LinRange(0,1,100))
cmap2 = [(cmap[i],0.65) for i in 1:100]

X = -40:5:40
ellipse1 = [X^2/2 + Y^2 + 2Z^2 for X in X, Y in X, Z in X];
ellipse2 = [X^2/2 + (Y-20)^2 + 2Z^2 for X in X, Y in X, Z in X];
volume(ellipse2, algorithm = :iso,isovalue =350,isorange = 50, colormap=cmap2)
volume!(ellipse1, algorithm = :iso, isovalue =700,isorange = 50, colormap=cmap2)


Ok that looks great, thanks!

Ok, getting closer. Still puzzling: I make a torus geometry. Why isn’t the full torus visible even though there is an alpha? It seems that the alpha is applied to another surface (dual ellipsoid case above), but not to different parts of the same surface. We should be able to see the core of the torus, and the back surface:

using GLMakie
using ColorSchemes
cmap3 = get(colorschemes[:plasma], LinRange(0,1,100))
	cmap4 = [(cmap3[i],0.65) for i in 1:100]
	ξ = -40:1:40
	c = 20
	a = 15
	torus = [((hypot(X,Y)-c)^2+Z^2-a^2) for X in ξ, Y in ξ, Z in ξ]
	volume(torus, algorithm = :iso,isovalue =100,isorange =50, colormap=cmap4)

I would expect something more like this:

Screen Shot 2021-08-20 at 2.02.55 PM