3

If I use the following material, I get some transparency which is fine:

PhongMaterial material = new PhongMaterial(new Color(0.5, 0, 0, 0.5));

But I can never get fully transparent mesh. For example, I expect the material below to be fully invisible but it's still visible:

PhongMaterial material = new PhongMaterial(new Color(0.5, 0, 0, 0));

Is this a bug?

enter image description here

Code:

import javafx.application.Application;
import javafx.scene.Group;
import javafx.scene.PerspectiveCamera;
import javafx.scene.Scene;
import javafx.scene.paint.Color;
import javafx.scene.paint.PhongMaterial;
import javafx.scene.shape.Box;
import javafx.stage.Stage;

public class Hello extends Application {
    public void start(Stage stage) throws Exception {
        PhongMaterial material = new PhongMaterial(new Color(0.5, 0, 0, 0));
        Box box = new Box(1, 1, 1);
        box.setMaterial(material);
        box.setTranslateZ(10);

        Scene scene = new Scene(new Group(box), 100, 100);
        scene.setFill(Color.BLACK);
        scene.setCamera(new PerspectiveCamera(true));

        stage.setScene(scene);
        stage.show();
    }
}
Saeid Nourian
  • 1,606
  • 15
  • 32
  • In asking a debugging question, you must provide a [mcve] to get an answer. – jewelsea Mar 03 '23 at 02:25
  • Added minimal code. – Saeid Nourian Mar 03 '23 at 02:32
  • Originally JavaFX did’t support transparency in 3D at all. It does (kind of) today, but not really fully in the way you may expect IMO. In particular for application of transparency, the order in which nodes are added to the scene graph matters. Whether that is related to or the cause of your issue, I do not know. For more info see this question on [JavaFX 3D Transparency](https://stackoverflow.com/questions/29308397/javafx-3d-transparency/30213869#30213869). – jewelsea Mar 03 '23 at 02:32
  • 1
    Please add complete code that reproduces the issue via copy and paste with no addition. It may seem unnecessary, but increases the chances of you receiving a useful answer and of your answer being of use to others. – jewelsea Mar 03 '23 at 02:34
  • 1
    Added. Is it better now? – Saeid Nourian Mar 03 '23 at 02:47
  • 1
    I am unable to reproduce the effect described using the example shown—the scene remains uniformly black unless the `opacity` exceeds zero. Please consider adding the `import` statements, software version numbers and platform you used. – trashgod Mar 03 '23 at 12:54
  • Interesting. Then maybe problem is with my version of Javafx. I use Javafx 18. Which version do you use? – Saeid Nourian Mar 03 '23 at 14:17
  • 2
    As of JFX 19 Transparency doesn't go to zero for a PhongMaterial(Color) generated material because of the way the color is calculated under the hood. (more details via the link @jewelsea provided). You CAN get 3D shapes to be fully/partially transparent by using a PhongMaterial with a DiffuseMap defined by an image that has transparent pixels. I think the look you're going for is very translucent (gossamer) . You could possibly get it by loading a diffuse map with a NEARLY transparent image and then set diffuse color to nearly transparent. There may be pixel artifacts left over though. – Birdasaur Mar 03 '23 at 16:39
  • I get the same result as @trashgod. Not reproducible, JavaFX 19, openjdk-19.0.2, OS X (Intel) 13.2.1. – jewelsea Mar 03 '23 at 20:11
  • I updated to Javafx 19 and jdk 19 and it still didn't fix my problem. I see the red box even with zero opacity. But I'm running this on windows so I wonder if it's directx issue. Anybody here tested this on a windows machine? – Saeid Nourian Mar 03 '23 at 21:29
  • @Birdasaur can you refer me to link with info about transparency not going to zero? I didn't find any mention of it on jewelsea link. – Saeid Nourian Mar 03 '23 at 21:34
  • @SaeidNourian: A related issue is examined [here](https://stackoverflow.com/a/73298705/230513); Java/FX 17; macOS x86. – trashgod Mar 03 '23 at 22:27
  • @trashgod that seem to be a different issue related to sorting. – Saeid Nourian Mar 04 '23 at 02:06
  • I found a bug report that seem to confirm what @Birdasaur said about transparency working with transparent textures but not transparent diffuse color: https://bugs.openjdk.org/browse/JDK-8144684 – Saeid Nourian Mar 04 '23 at 02:09
  • @SaeidNourian: You are correct; I see the example I cited and your bug report as two facets of the same problem—compromises in abstracting 3D translucency across supported platforms. As you are on Windows, your result may also depend on the [_Graphics System_](https://docs.oracle.com/javase/8/javafx/get-started-tutorial/jfx-architecture.htm#A1106308). – trashgod Mar 04 '23 at 13:31

0 Answers0