Closed Bug 1650714 Opened 5 years ago Closed 5 years ago

Correct Matrix Decompose and SetRotationFromQuaternion

Categories

(Core :: WebVR, defect)

defect

Tracking

()

RESOLVED FIXED
mozilla80
Tracking Status
firefox79 --- fixed
firefox80 --- fixed

People

(Reporter: daoshengmu, Assigned: daoshengmu)

References

Details

(Whiteboard: [fxr:p1])

Attachments

(4 files, 1 obsolete file)

Per Bug 1635363, our current result from Decompose() and SetRotationFromQuaternion() doesn't match.

 gfx::Matrix4x4Double transformMatrix;
 transformMatrix.RotateX(0.785f);   // 45 degree.
 transformMatrix.Decompose(trans, orient, scale);   // orient: (x: -0.38, y:0, z:0, w: 0.92)

 gfx::Matrix4x4Double transformMatrix1;
 transformMatrix1.SetRotationFromQuaternion(orient);
 transformMatrix1.Decompose(trans, orient, scale);   // orient: (x: 0.38, y:0, z:0, w: 0.92)

The correct result orient should be (x: 0.38, y:0, z:0, w: 0.92).

I have rewritten it according to Blender's source code [1][2] (Chromium's as ours, so they did a workaround as I mentioned at Bug 1635363).

After that

gfx::Matrix4x4Double transformMatrix;
transformMatrix.RotateX(0.785f);   // 45 degree.
transformMatrix.Decompose(trans, orient, scale);   // orient: (x: 0.38, y:0, z:0, w: 0.92)

gfx::Matrix4x4Double transformMatrix1;
transformMatrix1.SetRotationFromQuaternion(orient);
transformMatrix1.Decompose(trans, orient, scale);   // orient: (x: 0.38, y:0, z:0, w: 0.92)

The orient here be matched now, and we can remove all our invert() workaround code not only in viewerpose but also in XRInputSource. I also checked Babylon.js [3] work properly after this change.

However, we still need to refine our viewpose matrix. It seems like we did wrong when applying translate transform. In addition, I haven't verify it with WebVR sites, we need to remove other invert() in Gamepad code [4] at least.

[1] https://github.com/blender/blender/blob/b0da78084bd73fd1bec25570da12515f127f1fd1/source/blender/blenlib/intern/math_rotation.c#L232
[2] https://github.com/blender/blender/blob/b0da78084bd73fd1bec25570da12515f127f1fd1/source/blender/blenlib/intern/math_rotation.c#L322
[3] https://github.com/MozillaReality/FirefoxReality/issues/3578
[4] https://searchfox.org/mozilla-central/rev/c86c19bd64f8f19590a4190c282781d3a9631422/gfx/vr/VRDisplayClient.cpp#171

See Also: → 1635363
Assignee: nobody → imanol
Status: NEW → ASSIGNED
Assignee: imanol → dmu

Try looks good, https://treeherder.mozilla.org/#/jobs?repo=try&revision=cdab330a52b610f8ff5bf735e40cf3d158d880da. Let me see if we are able to add tests to avoid regressions.

Checked PlayCanvas also works properly.

Whiteboard: [fxr:p1]
Attachment #9161628 - Attachment description: Bug 1650714 - Correct Matrix Decompose and SetRotationFromQuaternion. → Bug 1650714 - Part 1: Correct Matrix Decompose and SetRotationFromQuaternion.

Try looks good after adding a matrix unit test. https://treeherder.mozilla.org/#/jobs?repo=try&revision=c75214676ec245bb1f33543471ead2d608fe1af8

We also can run this test via ./mach gtest Matrix.RotateTransform

Per Comment 6, I am trying to verify if it has no regression on OpenVRSession, but the current FF Windows build from m-c is only able to show a blank page and chrome UI. I will check it again once m-c resolve this issue.

Attachment #9161711 - Attachment description: Bug 1650714 - Correct XRRigidTransform inverse math → Bug 1650714 - Part 2: Correct XRRigidTransform inverse math
Attachment #9162647 - Attachment description: Bug 1650714 - Part 2: Add Matrix rotate transform unit tests. → Bug 1650714 - Part 3: Add Matrix rotate transform unit tests.
Attachment #9162658 - Attachment is obsolete: true

OculusVR and OpenVR are checked.

Pushed by dmu@mozilla.com: https://hg.mozilla.org/integration/autoland/rev/3c68259c8d81 Part 1: Correct Matrix Decompose and SetRotationFromQuaternion. r=kip,imanol,lsalzman https://hg.mozilla.org/integration/autoland/rev/16d11232b22a Part 2: Correct XRRigidTransform inverse math r=daoshengmu,kip,lsalzman https://hg.mozilla.org/integration/autoland/rev/687fd0ab5bbc Part 3: Add Matrix rotate transform unit tests. r=kip,lsalzman https://hg.mozilla.org/integration/autoland/rev/f6618ced82a8 Part 4: Adjust OpenVR and OculusVR rotate transform. r=kip

Comment on attachment 9161628 [details]
Bug 1650714 - Part 1: Correct Matrix Decompose and SetRotationFromQuaternion.

Beta/Release Uplift Approval Request

  • User impact if declined: We implemented wrong math in matrix rotate, we need to fix it as soon as we can in order to avoid affect our WebVR/XR content users. It will cause us lose our users if we deliver wrong matrix transform results. (Please uplift patches all of part 1 to part 4)
  • Is this code covered by automated tests?: Yes
  • Has the fix been verified in Nightly?: Yes
  • Needs manual test from QE?: No
  • If yes, steps to reproduce:
  • List of other uplifts needed: None
  • Risk to taking this patch: Low
  • Why is the change risky/not risky? (and alternatives if risky): It is not risky. We only use matrix decompose() and SetRotationFromQuaternion() in WebVR/XR modules, and we have verified all possible content work properly in our team internally. In addition, we also added an unit test for matrix rotate transform that is run by g-test (in part 3). Therefore, I think we should be able to uplift it to beta.
  • String changes made/needed:
Attachment #9161628 - Flags: approval-mozilla-beta?
Attachment #9161711 - Flags: approval-mozilla-beta?
Attachment #9162647 - Flags: approval-mozilla-beta?
Attachment #9162906 - Flags: approval-mozilla-beta?

Comment on attachment 9161628 [details]
Bug 1650714 - Part 1: Correct Matrix Decompose and SetRotationFromQuaternion.

Approved for 79.0b8/GV79. Thanks for including tests.

Attachment #9161628 - Flags: approval-mozilla-beta? → approval-mozilla-beta+
Attachment #9161711 - Flags: approval-mozilla-beta? → approval-mozilla-beta+
Attachment #9162647 - Flags: approval-mozilla-beta? → approval-mozilla-beta+
Attachment #9162906 - Flags: approval-mozilla-beta? → approval-mozilla-beta+
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: