简体   繁体   中英

3D Transparency JavaFX not blending all triangles in a mesh

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.

http://i.imgur.com/1wdmYYs.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);

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM