Skip to content
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

feat(WebXR): Support rendering to Looking Glass holographic displays #2669

Merged
merged 7 commits into from
Feb 28, 2023

Conversation

tbirdso
Copy link
Contributor

@tbirdso tbirdso commented Jan 12, 2023

Adds support for rendering to Looking Glass holographic display via Looking Glass WebXR polyfill.

View transforms provided by the Looking Glass WebXR polyfill are retrieved each frame and used to render into a quilt to be copied onto the Looking Glass external display.

Includes minor breaking changes to the OpenGL RenderWindow API where the "isAR" boolean is replaced with an enum for the XR session type to request.

Context

See Looking Glass support under (4) in the vtk.js WebXR roadmap: #2571

xref https://lookingglassfactory.com/webxr , https://docs.lookingglassfactory.com/keyconcepts/quilts

Results

Scene views are appropriately generated and composited to render a hologram on a Looking Glass Portrait display.

Inline browser view (swizzled):

cone-swizzled

Inline browser view (quilt):

cone-quilt

Changes

  • Defines XrSessionTypes enum in RenderWindow/Constants.js and updates RenderWindow.startXR throughout the project and examples to use the new enum definitions
  • Adds support for Looking Glass XR sessions
  • Adds basic cone example and documentation for Looking Glass XR support

PR and Code Checklist

  • semantic-release commit messages
  • Run npm run reformat

Tested On

Windows 10
Chrome 110.0.0.0
vtk.js v26.6.1
Looking Glass WebXR Polyfill v0.3.0 release

Notes

Originally tested with [email protected] pre-release, verified compatibility with 0.3.0 release.

Includes a fix where the WebGL scissor box is reset in RenderWindow.xrRender. Rendering otherwise does not reset the scissor box at the end of an animation frame but also the Looking Glass polyfill does not reset the scissor box when settings its viewport. Will follow up with investigation into whether a more sustainable fix is available in the Looking Glass polyfill or in vtk.js.

@tbirdso tbirdso requested a review from floryst January 12, 2023 16:09
@tbirdso
Copy link
Contributor Author

tbirdso commented Jan 12, 2023

Hi @floryst , would you please take a look and let me know what I'm doing wrong in this branch? Attempting to use vtkResourceLoader to fetch the LookingGlassWebXRPolyfill script, but the LookingGlassWebXRPolyfill class is apparently not made available to the vtk.js example script after load.

Once I can get the polyfill loaded for testing I can move forward with adjusting OpenGL WebXR rendering to create the LookingGlass quilt for display.

@floryst
Copy link
Collaborator

floryst commented Jan 17, 2023

It looks like that exports a module and does not register a global LookingGlassWebXRPolyfill variable. Try using a dynamic import: import(URL).then(obj => ....) for now (in a bid to avoid having to add that as a dependency).

@tbirdso
Copy link
Contributor Author

tbirdso commented Jan 18, 2023

@floryst Thanks for the feedback. When I try to use a dynamic import

import('https://unpkg.com/@lookingglass/[email protected]/dist/@lookingglass/bundle/webxr.js').then((obj) => {
  console.log('lookingglasspolyfillloaded!');
  console.log(obj);
  new obj.LookingGlassWebXRPolyfill();
});

then compile

npm run example -- LookingGlass

I get an error

ERROR in external "https://unpkg.com/@lookingglass/[email protected]/dist/@lookingglass/bundle/webxr.js"
The target environment doesn't support dynamic import() syntax so it's not possible to use external type 'module' within a script
Error: The target environment doesn't support dynamic import() syntax so it's not possible to use external type 'module' within a script
    at ExternalModule._getSourceData (C:\repos\vtk-js\node_modules\webpack\lib\ExternalModule.js:580:13)
    at ExternalModule.codeGeneration (C:\repos\vtk-js\node_modules\webpack\lib\ExternalModule.js:650:29)
    at C:\repos\vtk-js\node_modules\webpack\lib\Compilation.js:3326:22
    at C:\repos\vtk-js\node_modules\webpack\lib\Cache.js:91:34
    at Array.<anonymous> (C:\repos\vtk-js\node_modules\webpack\lib\cache\MemoryCachePlugin.js:45:13)
    at C:\repos\vtk-js\node_modules\webpack\lib\Cache.js:91:19
    at Hook.eval [as callAsync] (eval at create (C:\repos\vtk-js\node_modules\webpack\node_modules\tapable\lib\HookCodeFactory.js:33:10), <anonymous>:19:1)
    at Cache.get (C:\repos\vtk-js\node_modules\webpack\lib\Cache.js:75:18)
    at ItemCacheFacade.get (C:\repos\vtk-js\node_modules\webpack\lib\CacheFacade.js:111:15)
    at Compilation._codeGenerationModule (C:\repos\vtk-js\node_modules\webpack\lib\Compilation.js:3319:9)
 @ ./Geometry/LookingGlass/index.js 21:0-88

From what I can find online the @babel/preset-env plugin should support dynamic imports, but I can't find any other examples in vtk.js where they are used.

https://babeljs.io/blog/2019/07/03/7.5.0

Any thoughts on how to proceed?

@floryst
Copy link
Collaborator

floryst commented Jan 18, 2023

Try the following: import(/* webpackIgnore: true */ 'https://unpkg.com/@lookingglass/[email protected]/dist/webxr.js')

@tbirdso
Copy link
Contributor Author

tbirdso commented Jan 18, 2023

It looks like that worked, excellent. I am able to load and instantiate the polyfill from the module. Thank you @floryst !

@tbirdso tbirdso force-pushed the looking-glass-webxr branch 4 times, most recently from c9b1b78 to 0f60eab Compare February 27, 2023 13:14
@tbirdso tbirdso marked this pull request as ready for review February 27, 2023 13:31
@tbirdso tbirdso changed the title WIP: Looking glass webxr feat(WebXR): Support rendering to Looking Glass holographic displays Feb 27, 2023
@tbirdso tbirdso force-pushed the looking-glass-webxr branch from 0f60eab to 91ad837 Compare February 27, 2023 13:39
@tbirdso tbirdso requested a review from aylward February 27, 2023 13:39
Copy link

@aylward aylward left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me.!

@BryanChrisBrown
Copy link

Will follow up with investigation into whether a more sustainable fix is available in the Looking Glass polyfill or in vtk.js.

I'm definitely interested in seeing what we can do to improve this on the Looking Glass side, in general our goal is to make it as easy and straightforward as possible to integrate our WebXR Library with any WebGL framework. The connection between the rendered canvas dimensions and the framebufferwidth has definitely hit us before and there are a few approaches we've been looking at as possible alternatives, like offScreenCanvas. The most interesting one to me currently is using Virtual WebGL Contexts to improve the rendering between the two different webGL contexts we're using with the library.

On the babel side of things, we have an open issue to investigate a non-module based build option. This was primarily for adding support for global namespaces as frameworks like PlayCanvas and Babylon.JS still commonly use it.

I am glad to see you were able to find a solution for this in your build tool but would love to make it more streamlined for you. Would providing a version of the library with global namespaces improve the integration on your end?

@tbirdso
Copy link
Contributor Author

tbirdso commented Feb 27, 2023

@BryanChrisBrown Yes definitely, thanks for your work on the WebXR polyfill so far.

I've opened an issue at Looking-Glass/looking-glass-webxr#35 to track the scissor test issue we've addressed here, that would be a small change with major impact on integration.

The connection between the rendered canvas dimensions and the framebufferwidth has definitely hit us before and there are a few approaches we've been looking at as possible alternatives, like offScreenCanvas. The most interesting one to me currently is using Virtual WebGL Contexts to improve the rendering between the two different webGL contexts we're using with the library.

The variable framebuffer size may have contributed to debugging difficulties in 0.3.0 but does not seem to have been the root cause of issues. In general it is nice to control the number of views for performance, but the fixed quilt size in 0.4.0-alpha.3 is also valuable for debugging. Is it possible to support both options?

I am glad to see you were able to find a solution for this in your build tool but would love to make it more streamlined for you. Would providing a version of the library with global namespaces improve the integration on your end?

A version with global namespaces would be an integration improvement, but not strictly necessary. The solution @floryst described is sufficient for using the module-based option in our case.

@tbirdso tbirdso force-pushed the looking-glass-webxr branch from 91ad837 to 37af25f Compare February 27, 2023 22:47
@BryanChrisBrown
Copy link

The variable framebuffer size may have contributed to debugging difficulties in 0.3.0 but does not seem to have been the root cause of issues. In general it is nice to control the number of views for performance, but the fixed quilt size in 0.4.0-alpha.3 is also valuable for debugging. Is it possible to support both options?

I think we could figure something out with the API to support both options, it sounds like the main thing you want to do is reduce the view count correct? I think we can use the quilt presets to set the default view count per device, but then provide an override using the numViews input, to allow the user to specify a lower number of views. I do understand why this is useful, but I will note that going below 45 views will degrade the holographic quality you see on Looking Glass displays.

A version with global namespaces would be an integration improvement, but not strictly necessary. The solution @floryst described is sufficient for using the module-based option in our case.

Glad to hear the current solution is sufficient, It's likely the global namespace work won't occur until v0.5 which will start work after v0.4 is released.

Replaces RenderWindow boolean "isAR" parameter with enumerated list of
XR session types. Updates internal logic and examples to use enumerated
session types in place of simple "isAR" checks.

These changes are introduced as a prerequisite for adding Looking Glass
support as a third type of XR session.

Changes are technically API breaking, though consuming projects using VR
== 0, AR == 1 implicit enumerated values are unlikely to see changes in
project behavior.
@tbirdso tbirdso force-pushed the looking-glass-webxr branch from fc6fd89 to 3f64bda Compare February 28, 2023 15:21
@tbirdso
Copy link
Contributor Author

tbirdso commented Feb 28, 2023

Updated WebXR volume rendering examples with Looking Glass support and rebased on master.

@tbirdso
Copy link
Contributor Author

tbirdso commented Feb 28, 2023

@BryanChrisBrown

I think we could figure something out with the API to support both options, it sounds like the main thing you want to do is reduce the view count correct? I think we can use the quilt presets to set the default view count per device, but then provide an override using the numViews input, to allow the user to specify a lower number of views. I do understand why this is useful, but I will note that going below 45 views will degrade the holographic quality you see on Looking Glass displays.

Yes, having a default number of views that can be overridden would address the issue. This PR will adapt several of our existing examples for vtk.js WebXR support to run on Looking Glass, including several that are severely processing intensive. As you've said, diminishing the number of views improves scene responsiveness at the cost of the holographic quality.

Once this PR is merged you could try out cinematic volume rendering on the Looking Glass here: https://kitware.github.io/vtk-js/examples/WebXRHeadFullVolumeCVR.html

Glad to hear the current solution is sufficient, It's likely the global namespace work won't occur until v0.5 which will start work after v0.4 is released.

Sure, that sounds good.

@tbirdso tbirdso force-pushed the looking-glass-webxr branch from 3f64bda to 7af3b5e Compare February 28, 2023 16:28
@tbirdso
Copy link
Contributor Author

tbirdso commented Feb 28, 2023

@floryst @aylward I've included updates to add Looking Glass support to existing WebXR examples, ready for re-review and merge.

@aylward
Copy link

aylward commented Feb 28, 2023 via email

@tbirdso tbirdso force-pushed the looking-glass-webxr branch from 7af3b5e to 3d4b35c Compare February 28, 2023 18:18
@tbirdso
Copy link
Contributor Author

tbirdso commented Feb 28, 2023

Added a WebXRVolume link to load ultrasound fetus volume data from VolView sample data set, in .vti format

https://data.kitware.com/#collection/586fef9f8d777f05f44a5c86/folder/634713cf11dab81428208e1e

@tbirdso
Copy link
Contributor Author

tbirdso commented Feb 28, 2023

Added @aylward 's Head_And_Chest volume with "CT-AAA" presets, please take a look.

ct-aaa

@tbirdso tbirdso force-pushed the looking-glass-webxr branch from 9136aa7 to a8167da Compare February 28, 2023 20:02
tbirdso and others added 6 commits February 28, 2023 15:28
Adds support for rendering to Looking Glass holographic display
via Looking Glass WebXR polyfill.

View transforms provided by the Looking Glass WebXR polyfill are
retrieved each frame and used to render into a quilt to be copied onto
the Looking Glass external display.

xref https://lookingglassfactory.com/webxr

xref https://docs.lookingglassfactory.com/keyconcepts/quilts
Adds new example for rendering to Looking Glass holographic display with
the Looking Glass WebXR polyfill. The example is a port of the existing
VR cone example that explicitly fetches and loads the Looking Glass
polyfill.

xref https://docs.lookingglassfactory.com/developer-tools/webxr

co-authored-by: Forrest Li <[email protected]>
Changes:
- Adds `xrSessionType` URL parameter to allow user requested session
- Fetch and use Looking Glass polyfill on request
- Adds holographic section to documentation
- Adds reference to 3DUS-Fetus.vti ultrasound data sample
Adds Looking Glass WebXR support to two WebXR cinematic rendering
examples.

Note that the number of views is intentionally constrained in
`WebXRHeadFullVolumeCVR` to address observed performance issues.
`WebXRChestCTBlendedCVR` is excluded from changes due to image size and
subsequent rendering performance.
Adds "xrSessionType" URL parameter with Looking Glass option.
Adds Looking Glass section to gallery of existing WebXR examples.
@tbirdso tbirdso force-pushed the looking-glass-webxr branch from 59c6b4c to c8fca3c Compare February 28, 2023 20:29
@tbirdso
Copy link
Contributor Author

tbirdso commented Feb 28, 2023

@floryst I've addressed comments and squashed WebXRVolume commits. Ready for me to merge?

@floryst
Copy link
Collaborator

floryst commented Feb 28, 2023

LGTM!

@tbirdso tbirdso merged commit 241c4a4 into Kitware:master Feb 28, 2023
@github-actions
Copy link

🎉 This PR is included in version 26.8.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

@github-actions github-actions bot added the released Automated label label Feb 28, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
released Automated label
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants