[enhance] Alpha-Channel for Surfaces
discoleo opened this issue · 5 comments
Alpha-Channel for Surfaces
The Alpha-Channel has currently NO effect for surfaces:
- adding an alpha channel does NOT make the surface semi-transparent;
It would be nice to be able to make a surface semitransparent.
Could you show some code to demonstrate this? When I run
example(surface3d)
open3d()
surface3d(x, y, z, color = col, back = "lines", alpha=0.1)
I see the second surface with transparency.
My mistake: I was trying to set it via the color "#A0A0A064":
- this did not work and I did not investigate further;
- it works though when setting explicitly alpha;
The code is in:
https://github.com/discoleo/R/blob/master/Chemistry/Chem3D.R
- see function Th4.base(), which generates a regular tetrahedron with "bonds" radiating from the central atom;
I think that should have worked; I'll investigate further.
Looking back at it, that hasn't ever been supported. It probably should be, so I'll leave this open.
And now looking more closely, I still think this should be supported, but it's unlikely to happen in the near future.
The current state is this: alpha is a material property, and material properties are handled in a very convoluted way in rgl. When you call a function like triangles3d(col = "red")
, the color is changed to "red" for the duration of the call, then restored to a default afterwards. If you usecol = "#A0A0A064"
, currently the alpha channel is completely ignored in the color, but it can be specified with the alpha
argument, and that value is restored afterwards.
So the problem with using the alpha channel in a color is that it is hard for the code to know if the current default alpha value should be overridden or not. Clearly if parameter alpha
is specified in the call, it should override the value in the color. But if it is not, users might have set the default alpha to be used, so col = "red"
(with an implicit alpha = 1
) should not override the default, which might not be 1.
So perhaps the rule of precedence should be: use alpha
if specified, use alpha from the color value if it is specified there, otherwise use the default alpha. The trouble is that the convoluted code makes it hard to know if alpha
was specified by the user or by looking up the default. I think fixing this would require a lot of error-prone changes.
At some point in the distant future, this should all be rationalized, but it's not going to happen soon, so I'm going to close this, even though I haven't dealt with it.