question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

WebXRCamera's projection matrix is incorrect

See original GitHub issue

WebXRCamera has a set of “rig cameras” that represent the views/eyes of the XR device. The world and projection matrices of those views are copied over to the rig cameras, but no projection matrix is assigned to the WebXRCamera itself. Since the WebXRCamera is the active scene camera, and many APIs use the active scene camera by default, some of those APIs (that depend on the projection matrix) don’t work correctly. For example, all the picking related APIs (scene.pick, scene.createPickingRay, etc.) produce unexpected results. If you explicitly pass in a rig camera to those APIs, they work as expected since the correct projection matrix is then used, but I think the behavior should be correct with the default camera when the active camera is the WebXRCamera.

I created a Playground example where tapping on the screen (for a mobile device) uses scene.createPickingRay at screen coordinate 0,0 and places a box along the ray. It should show up in the upper left corner of the display. This works correctly when the rig camera is explicitly passed in to createPickingRay, but does not if the default (WebXRCamera) is used. With WebXRCamera: https://playground.babylonjs.com/#AC8XPN#25 With WebXRCamera.rigCameras[0]: https://playground.babylonjs.com/#AC8XPN#28

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:6 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
RaananWcommented, Sep 14, 2020

The projection matrix we are using is the one provided by the XR hosts itself.

As the main camera (the parent of both rig cameras) has no projection matrix defined, we are calculating it on our own. I would assume that due to parameters incorrectly set (fov?) our calculation of the projection matrix is wrong.

The simplest solution (that should work out of the box) is set the main camera’s projection matrix to be the first eye’s projection matrix. This won’t work on a split-screen emulation, but should work in the immersive session. I will submit a PR, waiting for your feedback

0reactions
RaananWcommented, Oct 5, 2020

Closing this issue. Using the first camera’s projection matrix is the best solution. Apart from changing the way we calculate the projection matrix (which we won’t), I don’t see a different way of getting the information from the data we do have.

Read more comments on GitHub >

github_iconTop Results From Across the Web

A perspective retrospective for WebXR developers - Web APIs
If your virtual camera's perspective projection matrix doesn't result in virtual objects having the same apparent perspective as the real world, ...
Read more >
Remove ProjectionMatrix in favor of FOV values? #461 - GitHub
I think this assumes that the top/bottom edges are horizontal and the left/right edges are vertical? This would support HMDs with tilted screens ......
Read more >
[Solved] WebXR + Reflection => strange camera matrix
Hi all. I am working on WebXR teleportation. Everything worked fine until I add water to the scene. (“three/examples/jsm/objects/Water.js”).
Read more >
WebXR Device API - W3C
If the operation IsDetachedBuffer on internal projection matrix is false , return view 's internal projection matrix.
Read more >
camera-access-barebones.html - Google Git
This sample demonstrates extremely simple use of WebXR's camera access by ... Calculates the camera intrinsics matrix from a projection matrix and viewport....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found