0

I am currently drawing a single transparent 3D mesh, generated via a marching cubes algorithm, with the intention of having more objects once the problem is fixed.

As it stands, I can draw 3d shapes perfectly well but when I implement transparency (in my case changing the opacity of the meshes PhongMaterial) I get a weird effect where only a few triangles are rendered when behind another triangle.

see example.

https://i.stack.imgur.com/XGv3f.png (sorry, I was unable to post the image directly, due to rep)

When the "stick" is behind the larger shape there seems to be a loss in triangles and I currently have no idea why.

The red is all the same mesh rendered in the same way.

I am currently using an ambient light if that makes a difference.

Some example code:

MeshView mesh = generate Mesh Data via marching cube;
mesh.setCullFace(CullFace.None);

PhongMaterial mat = new PhongMaterial(1, 0, 0, 0.5d);

AmbientLight light = new AmbientLight();
light.setColor(new Color(1, 0, 0, 0.5)); // I dont believe the alpha makes a difference
light.setOpacity(0.5);


mesh.setMaterial(mat);
group.getChildren().addAll(light, mesh);
  • 1
    What JDK version are you using? Notice transparency works based on the order of nodes on the scene, as you can see in this [question](http://stackoverflow.com/a/30213869/3956070) – José Pereda Aug 11 '15 at 11:14
  • I'm using JDK8u60 b15 I believe. I'll try updating to the latest build and see if anything changes. In the example I am only rendering a single mesh, so only one node. –  Aug 11 '15 at 11:46
  • That's what I meant about the order, you need to have several 3D shapes to see the transparency effect. The most on top transparent node will let you see the rest of the shapes behind it. – José Pereda Aug 11 '15 at 11:49
  • Make sure you order the triangles in the mesh by distance from the camera. Otherwise, transparency won't work as expected. – Aaron Digulla Aug 11 '15 at 11:55
  • My problem is more about how transparency is handled in a single shape(the red shape is a single model). Ie. Its own triangles are hidden behind itself. From what I have gathered the transparency works fine for multiple objects but seems to create a strage effect for each object. Here's an example of the effect. http://i.imgur.com/JtyirsA.png I hope this give shows that the problem is with regards to each 3d shape and how it handles opacity within it's own mesh. Sorry if the pictures are hard to understand, i'll try working on the better versions now. –  Aug 11 '15 at 12:03
  • @AaronDigulla that could be the problem, I did suspect. That's going to be a big job, i'll work on it now. –  Aug 11 '15 at 12:07
  • I'm not really sure about the order of triangles in the mesh affecting the result... Before going any further, make some tests first! – José Pereda Aug 11 '15 at 12:20
  • Of course, I'm hoping that isn't the reason but it would make sense, if it is the case I'm also curious as to why each mesh triangle is rendered individually. –  Aug 11 '15 at 12:50
  • That's an artefact of the 3D hardware. All 3D customer cards render 3D scenes by breaking down everything in triangles and then rendering each of them individually. That may seem a bad approach but it allows to build fast + cheap 3D cards which just have to solve a simple problem (with only a few known edge cases) which you can then run in parallel on thousands of cores. – Aaron Digulla Aug 11 '15 at 13:09

1 Answers1

0

Transparency only works correctly when the triangle faces are sorted by distance to the camera. This is an artifact of the fact that consumer 3D cards break any scene down to the triangles and so they can render each one individually. This allows to render hundreds of triangles at the same time when you have hundreds of cores. Older cards show you the number of triangles/second which they can render.

On more modern cards, part of the triangle rendering has been moved to the driver which uses the vector engines on the card to calculate the color of each point in software. This is still fast since you can have 1000+ vector CPUs plus it allows you to create complex programs that modify each vertex/pixel before it's stored in memory which allows you to create shiny surfaces, etc.

Aaron Digulla
  • 321,842
  • 108
  • 597
  • 820
  • I believe you are right. (an interesting link for those with the same problem http://www.opengl-tutorial.org/intermediate-tutorials/tutorial-10-transparency/) Do you know any techniques I could use to order the faces? If I was writting this in OpenGL I could reorder per camera movement but considering I am using javafx's scene graph would i still need to reorder per update or does javafx handle graphics differently? –  Aug 11 '15 at 13:38
  • I was wondering myself. As I see it, this is a common/standard problem and there should be a simple standard method to sort triangle strips but Google doesn't turn up anything. Maybe ask a new question? – Aaron Digulla Aug 11 '15 at 13:48
  • Think I just might need to. Cheers for the help. –  Aug 11 '15 at 13:51