简体   繁体   English

3D透明JavaFX不会混合网格中的所有三角形

[英]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. 我目前正在绘制通过行进立方体算法生成的单个透明3D网格,目的是在问题解决后拥有更多对象。

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. 就目前而言,我可以很好地绘制3d形状,但是当我实现透明性(在我的情况下,更改网格PhongMaterial的不透明度)时,我得到了一个怪异的效果,在另一个三角形后面仅渲染了几个三角形。

see example. 参见示例。

http://i.imgur.com/1wdmYYs.png (sorry, I was unable to post the image directly, due to rep) http://i.imgur.com/1wdmYYs.png (对不起,由于代表我无法直接发布图像)

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. 消费者3D卡将任何场景分解为三角形,因此它们可以分别渲染每个场景,这是一个事实。 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. 这仍然是快速的,因为您可以拥有1000多个矢量CPU,此外,它还允许您创建复杂的程序,在将每个顶点/像素存储到内存之前对其进行修改,从而可以创建闪亮的表面等。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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