New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
8234920: Add SpotLight to the selection of 3D light types #334
8234920: Add SpotLight to the selection of 3D light types #334
Conversation
|
/csr |
@nlisker has indicated that a compatibility and specification (CSR) request is needed for this pull request. |
@nlisker |
I suggest we start with looking at the API and the subclass question. This will unblock the CSR process. |
My preference would be for |
Not that it's all that relevant, but I will note that the (very old) Java 3D API also had SpotLight as a subclass of PointLight. |
Is the old implementation worth looking at, or is is completely different? I updated the API after subclassing |
Another API point is how to implement the direction - a |
No, the Java 3D implementation was done using fixed-function pipeline (not shaders), so not really a good starting point.
Yes, we need to sort this one out for |
This is the current implementation. The only downside is that it's more difficult to use bindings with. |
I think the API looks good with a few comments about valid ranges.
modules/javafx.graphics/src/main/java/javafx/scene/SpotLight.java
Outdated
Show resolved
Hide resolved
modules/javafx.graphics/src/main/java/javafx/scene/SpotLight.java
Outdated
Show resolved
Hide resolved
modules/javafx.graphics/src/main/java/javafx/scene/SpotLight.java
Outdated
Show resolved
Hide resolved
modules/javafx.graphics/src/main/java/javafx/scene/SpotLight.java
Outdated
Show resolved
Hide resolved
@nlisker this pull request can not be integrated into git checkout 8234920_Add_SpotLight_to_the_selection_of_3D_light_types
git fetch https://git.openjdk.java.net/jfx master
git merge FETCH_HEAD
# resolve conflicts and follow the instructions given by git merge
git commit -m "Merge master"
git push |
With the change, It works fine on my mac machine too. |
Thanks for the debugging, Kevin! In the HLSL shader these are already I commented out the less performant methods. |
The glsl |
I did a full test run on 5 different system, including manual tests on 4 of them:
Windows 10 w/ Intel graphics
Linux w/ NVIDIA graphics (no manual testing)
Linux VM guest running on Windows 10 host
Mac w/ discrete graphics
Mac w/ integrated graphics
No problems detected. All looks good.
I think there could be some additional tuning done for point lights, but that could be looked at in a follow-on fix.
I reviewed the CSR and it is ready to be Finalized.
I finished reviewing the shader code, and left a couple comments on the HLSL shaders.
modules/javafx.graphics/src/main/native-prism-d3d/hlsl/psConstants.h
Outdated
Show resolved
Hide resolved
float4x3 mBones[MAX_BONES] : register(c35); | ||
|
||
float4 gReserved240[16] : register(c240); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
gReserved240
is now at the wrong location (it should be 245), so if it were ever used it would be a problem. It should be updated to avoid confusion at least.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the size should be updated to 11 as well (since we probably don't want to go past 256).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder why we need gReserved240
and gSomethingElse
(in the pixel shader) at all. If they are at the end, they don't need to be reserved I think.
Also, the vertex shader has gReserved5[5]
that reserves c5 to c9, but the pixel shader does not have anything on c2 and c3, which are also reserved for something.
Another thing I don't understand is why the vertex shader overlaps register definitions for gAmbinet
and gAmbinetData[10]
, and mWorld
and mBones[MAX_BONES]
(and why 70 of these?).
In addition to addressing the review comments, I added some comments on register assignments to help with the math and explanations. No functional changes were made there. |
Provided two suggestions. You can address if you think they are worth to address now.
Over all the PR looks good to me, I observed an existing issue while testing the attenuation.AttenLightingSample.
Both Point and Spot light are not correctly applied to Mesh when number of faces is increased to more than 60.
Following are steps to reproduce with Point light with existing source without this PR.
As this is an existing issue we can address it in a follow on.
- Apply this patch current repo, without this PR
--- a/tests/performance/3DLighting/attenuation/LightingSample.java
+++ b/tests/performance/3DLighting/attenuation/LightingSample.java
@@ -69,8 +69,8 @@ public class LightingSample extends Application {
var sphere = new Button("Sphere");
sphere.setOnAction(e -> switchTo(environment.createSphere((int) subdivisionSlider.getValue())));
- var quadSlider = new Slider(500, 10_000, 1000);
- quadSlider.setMajorTickUnit(500);
+ var quadSlider = new Slider(10, 200, 60);
+ quadSlider.setMajorTickUnit(10);
setupSlier(quadSlider);
var quadLabel = new Label();
- Compile and run attenuation.AttenLightingSample
- Turn on Magenta light and click Mesh button. Observe that light is proper
- Increase the number of quads to 70 and observe that light is not proper
modules/javafx.graphics/src/main/resources/com/sun/prism/es2/glsl/main2Lights.frag
Show resolved
Hide resolved
}; | ||
|
||
//3 lights used | ||
uniform Light lights[3]; | ||
|
||
varying vec4 lightTangentSpacePositions[3]; | ||
varying vec4 lightTangentSpaceDirections[3]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lightTangentSpacePositions
is pre existing variable. I think the name lightTangentSpacePositions
is misguiding here. We use this variable to hold a point to light vector in tangent space. I think the name should have been something like, tangentSpacePointToLightVec
or pointToLightVecInTangentSpace
. Again this is not mandatory for this PR, But it did confuse me a bit while reading.
The other variable name lightTangentSpaceDirections
sounds correct, as it holds the lights direction in tangent space, but if we change the existing variable then similarly this variable name should be also be changed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since this is preexisting, I probably wouldn't change it as part of this PR, but instead it could be done as part of the future work to support more than 3 lights.
@arapte can you file a JBS bug for this? |
Reported the issue here: JDK-8269133 |
I don't have any more comments or concerns. If you choose to reorder the variables or make other simple changes, I'll re-approve.
You need a corresponding change in the vertex shader.
float range; | ||
vec3 dir; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These need to be reordered to match the changes in the fragment shaders. As it is, it causes a shader link error.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, I can't test the fix on Linux for now. I made the change, but didn't verify that it works.
@nlisker This change now passes all automated pre-integration checks. After integration, the commit message for the final commit will be:
You can use pull request commands such as /summary, /contributor and /issue to adjust it as needed. At the time when this comment was updated there had been 19 new commits pushed to the
As there are no conflicts, your changes will automatically be rebased on top of these commits when integrating. If you prefer to avoid this automatic rebasing, please check the documentation for the /integrate command for further details.
|
/integrate |
Going to push as commit 3fd4c97.
Your commit was automatically rebased without conflicts. |
Thanks for the all the work Kevin and Ambarish. |
Added a SpotLight only to the D3D pipeline currently.
API discussion points
Added
SpotLight
as a subclass ofLightBase
. However, it could also be a subclass ofPointLight
as it's a point light with direction and extra factors. I saw thatscenario.effect.light.SpotLight
extends its respectivePointLight
, but it's not a perfect analogy. In the end, I think it's a questions of whetherPointLight
will be expanded in a way which doesn't not suitSpotLight
, and I tend to think that the answer is no.The inner and outer angles are the "diameter angles" as shown here. I, personally, find it more intuitive that these are the "radius angles", so half these angles, as used in the spotlight factor formula. Do you think I can change this or do you prefer the current definition of the angles?
The current implementation uses an ad-hoc direction property (using a
Point3D
). It crossed my mind that we could use the rotation transforms of the node to control the direction instead, just like we use the translation/layout of the node to get the position (there is an internal Affine3D transform for lights, not sure whyAmbientLight
needs it). Wouldn't that make more sense? When I rotate the light I would expect to see a change in direction.Implementation discussion points
falloff = 0
andouterAngle = 180
. These possible optimization exist inES2PhongShader.java
andD3DMeshView.cc
, and in the pixel/fragment shaders in the form of 3 different ways to compute the spotlight factor (thecomputeLightN
methods). We need to check which of these give the best results.Performance
Testing 3 point lights and comparing this branch with
master
using a 1000 division sphere, 200 meshes, and 5000 meshes.Using an AMD RX 470 4GB GPU.
In this branch, there is a possible CPU optimization for checking the light type and using precalculated values (in
D3DMeshView.cc
for d3d andES2PhongShader.java
for opengl). On the GPU, I tried 3 ways of computing the spotlight factor contributions (computeSpotlightFactor
,computeSpotlightFactor2
andcomputeSpotlightFactor3
) trying out different branching and shortcuts.Results
The CPU "optimizations" made no difference, which is understandable considering it will not be the bottleneck. We can remove these if we want to simplify, though maybe if we allow a large number of lights it could make a difference (I doubt it). I don't have a strong preference either way.
The sphere 1000 tests always gave max fps (120 on Win and 60 on Ubuntu).
Win 10
Compared with the
master
branch, this patch shows 5-10 fps drop in the mesh 200 test and ~5 in the mesh 5000 test. I repeated the tests on several occasions and got different results in terms of absolute numbers, but the relative performance difference remained more or less the same. Out of the 3computeSpotlightFactor
methods,computeSpotlightFactor3
, which has no "optimizations", gives slightly better performance.Ubuntu 18
The mesh 200 test always gave 60 fps because it is locked to this fps, so we can't measure the real GPU performance change.
The mesh 5000 test shows 2-6 fps drop from master, with
computeSpotlightFactor
>computeSpotlightFactor2
>computeSpotlightFactor3
at in terms of performance (~2 fps difference each).Conclusion: we can expect a 5 fps drop more or less with 3 point lights.
computeSpotlightFactor3
on d3d andcomputeSpotlightFactor
on opengl gave the best performances.Progress
Issue
Reviewers
Reviewing
Using
git
Checkout this PR locally:
$ git fetch https://git.openjdk.java.net/jfx pull/334/head:pull/334
$ git checkout pull/334
Update a local copy of the PR:
$ git checkout pull/334
$ git pull https://git.openjdk.java.net/jfx pull/334/head
Using Skara CLI tools
Checkout this PR locally:
$ git pr checkout 334
View PR using the GUI difftool:
$ git pr show -t 334
Using diff file
Download this PR as a diff file:
https://git.openjdk.java.net/jfx/pull/334.diff