I want to apply some lighting effects using JavaFX onto a canvas GraphicsContext
. At first I used the Lighting.bumpInput
to pass a static bump-map for lighting. However this only lights a certain area of my canvas correct.
So now I do the lighting manually by first drawing all bump-maps onto the canvas then applying my lighting effect and finally blending all the original images with BlendMode.MULTIPLY
together with the lit bump-maps.
This does not look as nice as the first approach but it does its job.
Now there is still the problem that the lighting effect (Pointlight) is applied across the whole canvas no matter how big the area is.
public void start(Stage primaryStage) {
Image texture = new Image("...");
Image bumpMap = new Image("...");
Light.Point pointLight = new Light.Point(256, 256, 25, Color.WHITE);
Lighting lighting = new Lighting(pointLight);
Canvas canvas = new Canvas(1280, 800);
canvas.getGraphicsContext().setGlobalBlendMode(BlendMode.MULTIPLY);
canvas.getGraphicsContext().drawImage(bumpMap, 0, 0);
canvas.getGraphicsContext().applyEffect(lighting);
canvas.getGraphicsContext().drawImage(texture, 0, 0);
Scene scene = new Scene(new AnchorPane(canvas), 1280, 800);
primaryStage.setScene(scene);
primaryStage.show();
}
Now my question is, what is the proper way in JavaFX to apply the lighting only to a specific area on my canvas? Like to define the radius of my point light?