Light Control Fixes and GLTF Punctual Light and Unlit Material Extensions

That works. I’ve never been good with quaternions.
Perhaps when @tlf30 gets back from his trip and confirms, we can coordinate his punctual lights PR along with a second PR adding this code to the standard LightControl. Beyond that, I have also noticed that lightToSpatial is also incomplete in the spot-light field, so the LightControl PR would be a good opportunity to finish that (it doesn’t look too hard anyway).

I submitted it earlier today. I’m just waiting for @sgold to check out the latest commit to that.

1 Like

You are not alone… but I often encourage folks to think of them as “rotational black boxes”. Stick a vector in (mult()) get a rotated vector out.

So the getRotationColumn() stuff always seems like unnecessary magic thrown into that explanation.

“I want to know what the Z-axis is in this quaternion’s space” = quat.mult(Vector3f.UNIT_Z)

…which seems straight forward for a rotational black box.

3 Likes

This looks great. I have not had time to dive into the exact details, but it makes way more sense then what I was seeing. I will be home is a week (I am ready to be home for a while…), and can do a more thorough review then, but I think you are correct that perhaps a PR just needs to be done to the LightControl and we remove the GltfLightControl.

It is a wonderful -41 F outside right now (yes that is a negative sign), and the sun came entirely over the horizon for the first time this year a couple days ago. I am currently hiding in my office :stuck_out_tongue:

2 Likes

I’ll get that PR going now (that’s two PRs in one week!)

Ah, the Tundra…

Yeah, but what’s the wind chill? :slight_smile:

Sending warm thoughts your way…

The PR with the LightControl fixes has been submitted, and the checks are in progress.

I am a little concerned that, during my tests of lightToSpatial, the differences in the quaternion’s direction and the light’s direction did differ as much as by 4 units (squared length), but I didn’t see anything too wonky with the tests, and the vectors did look fairly close upon inspection of the output. I’m attributing this to rounding error with the quaternion math, but someone with more experience with quaternions may want to double-check that method.

2 Likes

Unsure what you mean by the “direction” of a Quaternion. Please elaborate.

-65F with wind chill right now, but now that the sun is at its peek for the day the ambient is at a balmy -31F. :cold_face:

When I set a spatial to use the transformation data of a light, I need to adapt the light’s direction into a rotation quaternion. However, I can’t just use spatial.setLocalRotation(new Quaternion().lookAt(light.getDirection(), Vector3f.UNIT_Y));, as that doesn’t account for the fact that light directions are independant of the scene graph and work in global coordinates. I need to do a whole bunch of other stuff to account for that, since there is no setWorldRotation method.

In my tests, though, I essentially reverse that process to get what I hope is the original direction (much easier, spatial.getWorldRotation().mult(Vector3f.UNIT_Z); or spatial.getWorldRotation().getRotationColumn(2);). I then compare it to the original direction of the light to see if they match. However, my tests show that the vectors are off by a rather disturbing angle as far as numbers go. However, despite the warnings, the visuals don’t seem to be affected. This is a little confusing to me.

1 Like

When you say the directions “differ as much as by 4 units” what do you mean?

I’m not clear whether you’re talking about roundoff errors (4 units in the last place) or something more worrisome.

I mean spatial units. When I normalize both vectors and subtract one from another, the difference vector has a length of 2 spatial units (4 if using squared length, which I do for efficiency since square roots aren’t cheap). If my calculations are correct, this means that the difference in angles is over 63°.

1 Like

Actually: I think I found it:

Rotation not equal: is (0.0, 0.0, 1.0) ((0.0, 0.0, 1.0)), needs to be (0.0, 0.0, -1.0)

It would seem that my reverse engineering results in one vector pointing in the opposite direction as the other. If I negate one of them, the errors stop.
I’ll add the change to the PR.

EDIT:
Changes pushed, checks are green.

1 Like

Is that cold enough for your spit to freeze before it hits the ground? I can’t remember if it’s 60 below or 80 below.

1 Like

I just went outside and tested. Not quite solid when it hit the ground, it broke into two lumps. Definitely did not stay liquid though.

2 Likes

The internet is amazing.

1 Like

In my life, the temperature today is 25 degrees Celsius, and only one week is winter. Keep warm. :wink:

Let us know when you can freeze coffee.

1 Like

OK, I’m finally back home!

I will go though everything in the next couple days.

2 Likes

@Markil3 I will be home for another week still (I am finally getting caught up on everything from being gone)

What needs tested at this point? I know the PR for the light control fix Light control fix by Markil3 · Pull Request #1466 · jMonkeyEngine/jmonkeyengine (github.com) needs merged. Does it need further testing at this point, or is it just code cleanup? After it is merged, I will rebase my PR for lights punctual Added KHR_lights_punctual gltf extension by tlf30 · Pull Request #1443 · jMonkeyEngine/jmonkeyengine (github.com) and make sure it works. Is there anything I should look at on your unlit pr? Gltf unlit by Markil3 · Pull Request #1463 · jMonkeyEngine/jmonkeyengine (github.com)

Thanks,
Trevor