RFR: 8217472: Add attenuation for PointLight [v5]

Kevin Rushforth kcr at openjdk.java.net
Sat Sep 19 15:36:08 UTC 2020


On Fri, 4 Sep 2020 23:20:43 GMT, Nir Lisker <nlisker at openjdk.org> wrote:

>> Thanks, the test runs now, but I've run into an issue with `snapshot`.
>> 
>> `Node#snapshot` uses its scene parameters (like lights) to render the image, but if the node is in a subscene then the
>> image will be wrong since it takes the wrong data. Bounds transforms like `sceneToLocal` and `localToScene` do take
>> care of this case. I think that this is a mistake in `snapshot`, and maybe it should use the subscene, or a `boolean
>> subScene` parameter should be offered, or `SnapshotParameters` should allow to specify it.
>
> Looks like there's more to it. I've created the test code:
> 
> import javafx.application.Application;
> import javafx.scene.Group;
> import javafx.scene.PerspectiveCamera;
> import javafx.scene.PointLight;
> import javafx.scene.Scene;
> import javafx.scene.control.Button;
> import javafx.scene.control.Slider;
> import javafx.scene.image.ImageView;
> import javafx.scene.layout.BorderPane;
> import javafx.scene.paint.Color;
> import javafx.scene.shape.Box;
> import javafx.stage.Stage;
> 
> public class PointLightAttenuationTest extends Application {
> 
>     public static void main(String[] args) throws Exception {
>         launch(args);
>     }
> 
>     @Override
>     public void start(Stage stage) {
>         var light = new PointLight(Color.BLUE);
>         light.setTranslateZ(-10);
>         Box box = new Box(100, 100, 1);
>         var group = new Group(light, box);
> 
>         var scene = new Scene(group, 500, 500, true);
>         var camera = new PerspectiveCamera(true);
>         camera.setTranslateZ(-300);
>         camera.setFarClip(1000);
>         scene.setCamera(camera);
>         stage.setScene(scene);
>         stage.show();
> 
>         var imageView = new ImageView();
>         var snapshotButton = new Button("Node Snaphot");
>         snapshotButton.setOnAction(e -> imageView.setImage(scene.snapshot(null)));
> 
>         var slider = new Slider(0, 0.2, 0);
>         slider.setShowTickMarks(true);
>         slider.setShowTickLabels(true);
>         light.linearAttenuationProperty().bindBidirectional(slider.valueProperty());
> 
>         var snapshotStage = new Stage();
>         snapshotStage.setScene(new Scene(new BorderPane(imageView, snapshotButton, null, slider, null)));
>         snapshotStage.setWidth(600);
>         snapshotStage.setHeight(600);
>         snapshotStage.show();
>     }
> }
> If the line `snapshotButton.setOnAction(e -> imageView.setImage(scene.snapshot(null)));`  is replaced to use
> `box.snapshot(null, null)` then the snapshot is wrong.

@nlisker Since there is a possible bug in snapshot, you might consider using Robot screen capture instead?

Also, I don't know if you noticed, but there are now whitespace errors after the fix for
[JDK-8240499](https://bugs.openjdk.java.net/browse/JDK-8240499).

-------------

PR: https://git.openjdk.java.net/jfx/pull/43


More information about the openjfx-dev mailing list