Visible light source in JavaFX 3D

I am currently exploring the possibilities of JavaFX 3D, and I would like to simulate a solar system. I quite successfully create a type light source PointLightand set its coordinates, tied to solar coordinates. Now I would like to see the sun shine with its radiance as a source of light. How can I do it?

@Component
public class RootPane extends StackPane {

    @Inject
    protected Scene scene;

    @Inject
    protected PerspectiveCamera camera;

    @Inject
    protected LightBase lightBase;

    @PostConstruct
    public void init() {
        setBackground(new Background(new BackgroundFill(
                Color.TRANSPARENT, CornerRadii.EMPTY, Insets.EMPTY)));
        setAlignment(Pos.CENTER);
        setPadding(new Insets(20));

        Sphere sunSphere = new Sphere(80);
        sunSphere.setEffect(new Glow(5));

        Sphere mercurySphere = new Sphere(40);
        mercurySphere.translateZProperty().bind(sunSphere.translateZProperty()
                .add(200));

        Sphere venusSphere = new Sphere(40);
        venusSphere.translateXProperty().bind(sunSphere.translateXProperty()
                .subtract(300));
        venusSphere.translateZProperty().bind(sunSphere.translateZProperty()
                .subtract(300));

        Sphere earthSphere = new Sphere(40);
        earthSphere.translateXProperty().bind(sunSphere.translateXProperty()
                .add(300));
        earthSphere.translateZProperty().bind(sunSphere.translateZProperty()
                .subtract(400));

        Rotate rotateX = new Rotate(0, Rotate.X_AXIS);
        Rotate rotateY = new Rotate(0, Rotate.Y_AXIS);
        Rotate rotateZ = new Rotate(0, Rotate.Z_AXIS);

        Translate translate = new Translate(0, 0, -3000);

        camera.getTransforms().addAll(rotateX, rotateY, rotateZ, translate);

        scene.addEventHandler(
                KeyEvent.KEY_PRESSED,
                event -> {
                    if (Objects.equals(event.getCode(), KeyCode.D)) {
                        rotateY.setAngle(rotateY.getAngle() - 
                                (event.isShiftDown() ? 5 : 0.1));
                    } else if (Objects.equals(event.getCode(), KeyCode.A)) {
                        rotateY.setAngle(rotateY.getAngle() + 
                                (event.isShiftDown() ? 5 : 0.1));
                    }
                });
        scene.addEventHandler(
                KeyEvent.KEY_PRESSED,
                event -> {
                    if (Objects.equals(event.getCode(), KeyCode.W)) {
                        rotateX.setAngle(rotateX.getAngle() - 
                                (event.isShiftDown() ? 5 : 0.1));
                    } else if (Objects.equals(event.getCode(), KeyCode.S)) {
                        rotateX.setAngle(rotateX.getAngle() + 
                                (event.isShiftDown() ? 5 : 0.1));
                    }
                });

        lightBase.translateXProperty().bind(sunSphere.translateXProperty());
        lightBase.translateYProperty().bind(sunSphere.translateYProperty());
        lightBase.translateZProperty().bind(sunSphere.translateZProperty());

        getChildren().addAll(sunSphere, mercurySphere, venusSphere,
                earthSphere, camera, lightBase);
    }

}
+4
source share
2 answers

Without an example of the effect that you want to achieve, it is difficult to give an answer, but here are two options:

Create a particle effect emitted by the sun with the addition of blending

Create material with a mirror map.

+1
source

PhongMaterial JavaDoc

:

for each ambient light source i {
    ambient += lightColor[i]
}
for each point light source i {
    diffuse += (L[i] . N) * lightColor[i]
    specular += ((R[i] . V) ^ (specularPower * intensity(specularMap))) * lightColor[i]
}
color = (ambient + diffuse) * diffuseColor * diffuseMap
         + specular * specularColor * specularMap
         + selfIlluminationMap

:

lightColor [i] - i,

L [i] - i,

N - ( BumpMap, ),

R [i] - L [i] ,

V - .

PointLight Sun Sphere, L [i]. N < 0, . , .

, selfIlluminationMap, , . .

google , : . , , .

+1

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


All Articles