I’ve ran into an issue in which lines with an opacity setting don’t get rendered properly on top of Mesh objects (in this case spheres) also containing a transparency setting. But only sometimes…
As you zoom in you’ll notice that some spheres have solid line segments on top of them while others don’t. Also by rotating/panning around this may change and a sphere that was fine suddenly shows the glitch and vice-versa.
The component which has the ThreeJS code is here:
The relevant code which generates the Three objects is:
mySphere = new THREE.Mesh(
new THREE.SphereGeometry(myRadius, 8, 8),
new THREE.MeshLambertMaterial({ color: myColor, transparent: true, opacity: 0.75 })
);
myLine = new THREE.Line(
new THREE.Geometry(),
new THREE.LineBasicMaterial({ color: 0xf0f0f0, transparent: true, opacity: 0.2 })
);
The renderer is used with all the default options: new THREE.WebGLRenderer()
I’m at a complete loss as to what is causing this glitch, any help/pointers as to what may be the cause will be much appreciated!
And sorry, I should’ve added a screenshot to clarify the issue. The glitch I’m referring to is in neither cases 1 or 2. Here’s what it looks like:
I’m referring to those dark line segments on the large sphere, which doesn’t occur in the other spheres and even appears/disappears as the objects are rotated.
What’s puzzling is the way it renders a line on top of the object is not consistent. In fact, if you look at the two smaller spheres in the my previous screenshot, those lines are actually “in front” of the object, yet they are rendered the way I’d expect it, by mixing the two opacities.
It just seems that for some camera angles that opacity mixing is misbehaving, causing some line segments to be completely solid.
I’ve tried the blending settings you suggested, both on the lines and/or sphere objects. No combination of blending makes any difference except when selecting NoBlending (effectively cancelling the object’s transparency) or SubtractiveBlending which makes matters worse by always drawing dark lines on top of the spheres:
By setting the lines to render after all the spheres, the issue is gone. I’m not quite certain why rendering the lines mixed in with the spheres (I suppose that’s what was happening) would cause that visual anomaly in the mixed opacity.
Depending on the view, the renderer was using the background only to define the line color (with opacity). Setting the order, tells the renderer to layer the objects with the proper hierarchy and thus have all the colors to blend.