JavaFX 3D Transparency

I am looking for a way to render a transparent object in JavaFX 3D. Nothing yet. I found the problem https://bugs.openjdk.java.net/browse/JDK-8090548 . Is there a workaround or is this something that I cannot use? Will I need something other than JavaFX (like Java3D) if I need a transparent object?

+6
source share
3 answers

Since the transparency of the JDK8u60 b14 is included in three-dimensional forms.

This is a quick test done with it:

Transparency

A cylinder with diffuse color Color.web("#ffff0080") added on top of the box and two spheres.

 group.getChildren().addAll(sphere1, sphere2, box, cylinder); 

There is no algorithm for sorting by depth, although this means that the order of adding three-dimensional shapes to the scene. We need to reorder to ensure transparency in the field:

 group.getChildren().addAll(sphere1, sphere2, cylinder, box); 

Transparency

+11
source

Update

This answer is deprecated, like Java 8u60b14, since transparency was added to JavaFX in this assembly.


As a problem with your comments, transparency is not supported in JavaFX 3D for Java 8. It can be implemented for Java 9.

The workaround that the user mentions in the comments to the problem tracker, which includes hacking native code for the JavaFX OpenGL pipeline. If you are desperate for this feature, you can try this hack. If this does not suit you, you will need to choose a different technology.

+4
source

Here is a partial solution. To add transparency to a sphere with an image of the earth texture mapped to it, set diffuseMap and diffuseColor:

 private void makeEarth() { PhongMaterial earthMaterial = new PhongMaterial(); Image earthImage = new Image("file:imgs/earth.jpg"); earthMaterial.setDiffuseMap(earthImage); earthMaterial.setDiffuseColor(new Color(1,1,1,0.6)); // Note alpha of 0.6 earthMaterial.diffuseMapProperty(); earth=createSphere(0,0,0,300,earthMaterial); earthMaterial.setSpecularColor(Color.INDIANRED); earth.setRotationAxis(Rotate.Y_AXIS); world.getChildren().add(earth); } 

This only works so that you can view the background image of the scene (set by scene.setFill(starFieldImagePattern); ). It does not work yet to show other forms.

Apparently, the reason is because the diffuse color is multiplied by the diffuseMap color when calculating the color of the pixels. See https://docs.oracle.com/javase/8/javafx/api/javafx/scene/paint/PhongMaterial.html .

+2
source

Source: https://habr.com/ru/post/984335/


All Articles