8
$\begingroup$

I have encountered a 3D rendering artifact that's about to drive me crazy. Here's a very minimal example:

triangle1 = {{0.8, 0, 0}, {0.997, 1, 0.5}, {0.8, 1, 0}};
triangle2 = {{1, 0, 0.5}, {1, 1, 0}, {1, 1, 0.5}};
Graphics3D[Polygon[{triangle1, triangle2}]]

This produces the following image on my computer (ThinkPad X1 Carbon, Arch Linux, Mathematica 12.2.0.0):

Two triangles

At the upper right, parts of the edges of triangle1 that should be hidden behind triangle2 are in fact visible (when viewed from certain angles). Here's a zoom:

Zoom on artifact

I've played around with various RenderingOptions, which made no difference at all. The same artifact is also visible when exporting to PDF.

It's not limited to triangles only. For example, let's add a line segment:

triangle1 = {{0.8, 0, 0}, {0.997, 1, 0.5}, {0.8, 1, 0}};
triangle2 = {{1, 0, 0.5}, {1, 1, 0}, {1, 1, 0.5}};
segment = {{1, 0.95, 0.5}, {0.95, 0.5, 0.4}};
Graphics3D[{Polygon[{triangle1, triangle2}], Line[segment]]

This segment should be completely obscured by triangle2 when viewed from the following angle, but as you can see, part of it bleeds through:

Another zoom

What's going on?!? Does this occur just on my system, or is it reproducible elsewhere? Are there any possible workarounds?

$\endgroup$
4
  • 1
    $\begingroup$ Seems to be fixed in version 13.0 $\endgroup$ Commented Jan 16, 2022 at 13:35
  • $\begingroup$ @DanielHuber: OK, I'll try upgrading. But it would still be interesting to know if someone else experiences this in version 12, or if it's something peculiar to my system. $\endgroup$ Commented Jan 16, 2022 at 14:34
  • $\begingroup$ I can reproduce in 12.3.1 but not 11.3.0 or 13.0.0. Must be a minor bug in version 12. $\endgroup$
    – bbgodfrey
    Commented Jan 16, 2022 at 15:12
  • 2
    $\begingroup$ The bug is still on for example 13.0.0 on windows 10 if we zoom in the window! $\endgroup$
    – cvgmt
    Commented Jan 16, 2022 at 16:25

2 Answers 2

9
$\begingroup$

This behavior can be turned off through the Graphics3D method option "EdgeDepthOffset" -> False. Some details are found here and here.

Here's a comparison:

Graphics3D[Polygon[{triangle1, triangle2}]]

enter image description here

Graphics3D[Polygon[{triangle1, triangle2}], Method -> {"EdgeDepthOffset" -> False}]

enter image description here

Edit

Another option is to render all of your edges with thin tubes. This will prevent hidden edges that "EdgeDepthOffset" -> False can cause.

Here's some dummy data to compare all three methods:

ball = ImageMesh[RegionImage[Ball[], RasterSize -> 25]];

Default behavior, lines we shouldn't be seeing (red arrow):

Graphics3D[
 GraphicsComplex[
  MeshCoordinates[ball],
  MeshCells[ball, 2]
 ],
 Boxed -> False
]

enter image description here

"EdgeDepthOffset" -> False yields inconsistent line thickness (red arrow):

Graphics3D[
 GraphicsComplex[
  MeshCoordinates[ball],
  MeshCells[ball, 2]
 ],
 Boxed -> False,
 Method -> {"EdgeDepthOffset" -> False}
]

enter image description here

Thin tubes look good:

Graphics3D[
 GraphicsComplex[
  MeshCoordinates[ball],
  {
   {EdgeForm[], MeshCells[ball, 2]}, 
   {Black, Tube[MeshCells[ball, 1][[All, 1]], .0175]}
  }
 ],
 Boxed -> False
]

enter image description here

$\endgroup$
3
  • $\begingroup$ That was it. Thank you very much! Unfortunately, now some lines that I want to see become hidden or blurred, but I think I can solve that by adding an offset manually, so the situation is much improved. :-) $\endgroup$ Commented Jan 16, 2022 at 17:51
  • 1
    $\begingroup$ Right, see my edit. $\endgroup$
    – Greg Hurst
    Commented Jan 17, 2022 at 2:03
  • $\begingroup$ Good suggestion! $\endgroup$ Commented Jan 17, 2022 at 6:25
4
$\begingroup$

An alternative

Graphics3D[{...}, 
 BaseStyle -> RenderingOptions -> {"3DRenderingMethod" -> "BSPTree"}]

It also works for this

blank=ConstantArray[0,{10,10}];
block=ConstantArray[1,{10,10}];

ArrayPlot3D[{block,blank,blank,block,blank,blank,block,blank,blank,block},
  MeshStyle->Directive[AbsoluteThickness[2.5],Black],ImageSize->1200,
  BaseStyle->RenderingOptions->{"3DRenderingMethod"->"BSPTree"}]

enter image description here

$\endgroup$
1
  • $\begingroup$ Thanks! This works now. $\endgroup$
    – Ycl_Phy
    Commented Apr 25, 2022 at 16:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.