11

Consider this code

$data = With[{step = .1, r = 2}, 
   Table[Exp[-Norm[{x, y, z}]^2], {x, -r, r, step}, {y, -r, r, 
     step}, {z, -r, r, step}]];

Graphics3D[{Raster3D[$data, {{0, 0, 0}, {1, 1, 1}}, 
   ColorFunction -> (Opacity[#, Red] &)], 
  Raster3D[$data, {{1, 1, 1}, {2, 2, 2}}, 
   ColorFunction -> (Opacity[#, Red] &)]}]

The generated figure looks like

Obviously the transparency works within one Raster3D object but not between them.

  1. Is this an expected behaviour?
  2. How could I go around this, assuming I cannot generate everything in one Raster3D object? I want to be able to patch various Raster3D objects according to my liking.
Mr.Wizard
  • 271,378
  • 34
  • 587
  • 1,371
jhrmnn
  • 265
  • 1
  • 8

1 Answers1

10

Changing the rendering engine to BSPTree seems to help for me:

SetOptions[$FrontEnd, RenderingOptions -> {"Graphics3DRenderingEngine" -> "BSPTree"}]

enter image description here

Not sure if this is the best solution, but do try it out.

Arnoud Buzing
  • 9,801
  • 2
  • 49
  • 58
  • works perfectly, thanks – jhrmnn Jul 17 '15 at 21:59
  • I think this is because with the "^2" the values on the edge of the bounding box are still not zero, especially in the cube face centers. Try it with e.g. Exp[-Norm[{x, y, z}]^3.0] (which makes the spheres not touch the boundary). – Arnoud Buzing Jul 17 '15 at 22:03
  • I've realized that before and deleted my comment, probably while you were writing the reply, sorry about that – jhrmnn Jul 17 '15 at 22:09
  • @ArnoudBuzing Could you comment about this option? When should/could be tried? – Dr. belisarius Jul 17 '15 at 23:26
  • 1
    Note that Style[graphics, RenderingOptions -> {"Graphics3DRenderingEngine" -> "BSPTree"}] also works without making a persistent change to the $FrontEnd. (I assume SetOptions[$FrontEndSession, RenderingOptions -> {"Graphics3DRenderingEngine" -> "BSPTree"}] would work, too.) – Michael E2 Jul 18 '15 at 02:41
  • @belisarius I understand this switches from default hardware rendering to software rendering, whose behaviour is more predictable I guess. But it is considerably slower. There is also the "Software" option, which seems even slower. – jhrmnn Jul 18 '15 at 10:53