Skip to main content

graphics - Opacity renders lines incorrect in certain viewing angles


Trying to learn how Opacity works, I found a possible issue. Generating points in a square spiral with:


sqrSpiral[rev_, inc_] := Module[{x, y, z, dx, dy, list = {}},

x = y = z = 0;
dx = {0, 1, 0, -1}; dy = {1, 0, -1, 0};
Do[
Do[
list = Append[list, {x += dx[[i]], y += dy[[i]], z += inc}], {i, 4}
], {rev}]; list
]

and applying it in Graphics like so:


pts = sqrSpiral[50, 0.005];

line = Line[pts];
Graphics3D[{Thickness[0.01], Opacity[0.5], Red, line}, Boxed -> False]

gives the following strange appearence: enter image description here


As you can see, of all the overlapping lines from the current viewpoint, only the far left corners, seem to be rendered correctly. While turning the spiral as to view it from below, seem to render the lines in a more expected way.


enter image description here


Why is this the case?


(If you have an answer, please feel free to refine my procedural code:)



Answer



This appears to be a problem with the hardware rendering engine. A workaround is to use the "BSPTree" renderer:



Style[
Graphics3D[{Thickness[0.01], Opacity[0.5], Red, line}, Boxed -> False],
"RenderingOptions" -> {"Graphics3DRenderingEngine" -> "BSPTree"}]

enter image description here


Comments