RFR: 8234921: Add DirectionalLight to the selection of 3D light types

Kevin Rushforth kcr at openjdk.java.net
Thu Aug 12 23:44:26 UTC 2021


On Mon, 28 Jun 2021 12:13:44 GMT, Nir Lisker <nlisker at openjdk.org> wrote:

> Adds a directional light as a subclass of `LightBase`. I think that this is the correct hierarchy for it.
> 
> I tried to simulate a directional light by putting a point light far away, but I got artifacts when the distance was large. Instead, I added an on/off attenuation flag as the 4th component of the attenuation 4-vector. When it is 0, a simpler computation is used in the pixel/fragment shader that calculates the illumination based on the light direction only (making the position variables meaningless). When it is 1, the point/spot light computation is used. It's possible that the vertex shader can also be simplified in this case since it does not need to transform the position vectors, but I left this optimization avenue for another time.
> 
> I noticed a drop of ~1 fps in the stress test of 5000 meshes.
> 
> I added a system test that verifies the correct color result from a few directions. I also updated the lighting sample application to include 3 directional lights and tested them on all the models visually. The lights seem to behave the way I would expect.

The API and docs look good. After changing the `@since` to 18, it should be ready for the CSR.

I haven't looked at the implementation yet. I did build and try the updated manual test program on Windows and Linux and it looks fine. Long term, I still think there might be value in having a dedicated shader path for directional lights, but that can be a future enhancement.

modules/javafx.graphics/src/main/java/javafx/scene/DirectionalLight.java line 2:

> 1: /*
> 2:  * Copyright (c) 2020, Oracle and/or its affiliates. All rights reserved.

2021

modules/javafx.graphics/src/main/java/javafx/scene/DirectionalLight.java line 52:

> 50:  * source that can be simulated with this light type.
> 51:  *
> 52:  * @since 17

18

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

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


More information about the openjfx-dev mailing list