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

Renderer Plugin to handle stereo rendering and head tracking for VR HMDs... #5015

Closed
wants to merge 9 commits into from

Conversation

dmarcos
Copy link
Contributor

@dmarcos dmarcos commented Jul 1, 2014

.... It uses the native Firefox API

Mr Doob, What do you think?

  • It handles stereo rendering
  • It queries the state of the hmd on each render call to keep the camera in sync with the head orientation.
  • It degrades gracefully. If used when the mozGetVRDevices is not available it behaves as a regular renderer.
  • Included example based on webgl_interactive_cubes.html

Online version here:

http://swimminglessonsformodernlife.com/three.js/examples/webgl_plugin_vr.html

The difference boils down to the following lines:

var vrPlugin = new THREE.VRPlugin();
vrPlugin.init(renderer);
var fullScreenButton = document.querySelector('.button');
fullScreenButton.onclick = function() {
  vrPlugin.enableVRMode(true);
};
vrPlugin.render( scene, camera );

The goal is making it very easy to use.

Links to VR enabled Firefox builds:

http://people.mozilla.com/~vladimir/vr/firefox-33.0a1.en-US.mac.dmg
http://people.mozilla.com/~vladimir/vr/firefox-33.0a1.en-US.win64-x86_64.zip

@mrdoob
Copy link
Owner

@mrdoob mrdoob commented Jul 1, 2014

Looking good!

Maybe we can split it to VRControls and VREffect?

var controls = new THREE.VRControls( camera );
var effect = new THREE.VREffect( renderer );
effect.setFullscreen( true );
effect.render( scene, camera );

@dmarcos
Copy link
Contributor Author

@dmarcos dmarcos commented Jul 1, 2014

Hi there. Thanks for the feedback! I have some bandwidth to polish this patch.

Do you want to just split it and still offer full functionality through a VRPlugin (or a different abstraction) interface?

or

Do you mean splitting and let the user manage the details? e.g: keeping the camera in sync with the head rotation

I like the former. I like the idea of splitting but it would still be interesting to offer something to encapsulate all the functionality for people that don't want to handle complexity. A college of mine is happy with just exporting collada files from cinema 4D and easily render them without having to worry about any details.

@mrdoob
Copy link
Owner

@mrdoob mrdoob commented Jul 1, 2014

Do you want to just split it and still offer full functionality through a VRPlugin (or a different abstraction) interface?

Yep!

Do you mean splitting and let the user manage the details? e.g: keeping the camera in sync with the head rotation

VRControls would already keep the camera in sync with the head rotation.

A college of mine is happy with just exporting collada files from cinema 4D and easily render them without having to worry about any details.

Even if it required 2 classes, it would be easy to write a example that would be ready for your colleague to play with.

@jcarpenter
Copy link

@jcarpenter jcarpenter commented Jul 1, 2014

Generally I would actually prefer splitting controls and effect, since I'm much more likely to tweak the former than the later.

Diego, some wishlist items from my notes after kicking the tires on this for a bit:

  • Button to reorient rift Y rotation to current heading. The Tuscany Demo has this, IIRC.
  • Stereo camera position should be child of parent mono camera that user creates. Current this.renderStereo function repositions cameraLeft and cameraRight, it looks like, forcing my VR camera to 0,0,0, whereas my scene camera is at 0,1.7,0 (matching user height).

@dmarcos
Copy link
Contributor Author

@dmarcos dmarcos commented Jul 2, 2014

@mrdoob I made the requested changes. How does it look now? I want to do one more pass to clean up and add some comments but it would be great to know If you think it's heading in the right direction

@tparisi
Copy link
Contributor

@tparisi tparisi commented Jul 2, 2014

Yeah +1 for splitting the controls and effect.

@tparisi
Copy link
Contributor

@tparisi tparisi commented Jul 2, 2014

+1 for parenting the stereo camera from the mono camera... then things like camera animation will get picked up automatically.

@tparisi
Copy link
Contributor

@tparisi tparisi commented Jul 2, 2014

Another thing to be mindful of is multi-pass rendering. I had to adapt the old Oculus Bridge effect code to handle multiple render passes. Think about it, if not now then for later.

orientation.w,
orientation.x,
orientation.y,
orientation.z
Copy link

@vvuk vvuk Jul 2, 2014

Choose a reason for hiding this comment

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

Why is the rotation reported as [w, x, y, z]? Then it has to get w put back in the right place to build a Quaternion. If this is interfacing with something else, then that something else should have an adapter to put w in the right place in front of it...

@tparisi
Copy link
Contributor

@tparisi tparisi commented Jul 2, 2014

+1 @vvuk

@dmarcos
Copy link
Contributor Author

@dmarcos dmarcos commented Jul 2, 2014

@tparisi @vvuk I changed the order of the reported values

vrState.hmd.rotation[2],
vrState.hmd.rotation[3]
);
camera.setRotationFromQuaternion( quat );
Copy link
Owner

@mrdoob mrdoob Jul 3, 2014

Choose a reason for hiding this comment

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

All this can be simplified to just this:

camera.quaternion.fromArray( vrState.hmd.rotation );

Then quat won't be needed.

@dmarcos
Copy link
Contributor Author

@dmarcos dmarcos commented Jul 3, 2014

@mrdoob Thanks! I replaced the way I set the camera orientation

@mrdoob
Copy link
Owner

@mrdoob mrdoob commented Jul 3, 2014

Sweet! Merged into the dev branch.
Thanks!

@mrdoob mrdoob closed this Jul 3, 2014
@dmarcos
Copy link
Contributor Author

@dmarcos dmarcos commented Jul 3, 2014

That's fantastic! What process do you follow to move things from dev to master?

@mkeblx
Copy link
Contributor

@mkeblx mkeblx commented Jul 3, 2014

Chrome build with WebVR support revealed today by @toji with minor changes: mozGetVRDevices unprefixed and returns a promise.
http://blog.tojicode.com/2014/07/bringing-vr-to-chrome.html

@dmarcos
Copy link
Contributor Author

@dmarcos dmarcos commented Jul 3, 2014

@mkeblx Thanks! Created a PR adding support to the chrome API

#5020

@mrdoob
Copy link
Owner

@mrdoob mrdoob commented Jul 3, 2014

@dmarcos When you do a PR you need to base checkout the dev branch first and make sure your PR targets the dev branch. In this case it was fine because the changes didn't conflict with any of the changes in the dev branch.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants