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

WebXR: Allows near and far clipping to be set #18320

Merged
merged 4 commits into from
Jan 21, 2020

Conversation

DougReeder
Copy link
Contributor

@DougReeder DougReeder commented Jan 7, 2020

Fixes #14829

@DougReeder
Copy link
Contributor Author

DougReeder commented Jan 7, 2020

Half of a fix for aframevr/aframe#4387
The other half is changing A-Frame to call setCameraClipping()

@Mugen87
Copy link
Collaborator

Mugen87 commented Jan 7, 2020

It seems this is a duplicate of #14854.

Also notice #14854 (comment). It seems your current implementation does not fulfill the mentioned requirements.

@DougReeder
Copy link
Contributor Author

#14854 appears to be out of date and either incomplete, or for an older version of the WebVR spec - depthNear and depthFar must be set on the render state, not the session.

WebGLRenderer.render() is passed a single camera object (which might be an ArrayCamera) which it then always passes to WebXRManager.getCamera(camera):
https://github.com/mrdoob/three.js/blob/dev/src/renderers/WebGLRenderer.js#L1109
I don't see that that comment raises any actual issues.

I will update this PR to set depthNear and depthFar from the camera passed to getCamera().

@@ -301,6 +301,13 @@ function WebXRManager( renderer, gl ) {

this.getCamera = function ( camera ) {

cameraVR.near = cameraR.near = cameraL.near = camera.near;
cameraVR.far = cameraR.far = cameraL.far = camera.far;
session.updateRenderState( {
Copy link
Collaborator

@Mugen87 Mugen87 Jan 8, 2020

Choose a reason for hiding this comment

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

Instead of always doing the API call, you could cache depthNear and depthFar and only call the method if these values are different to cameraVR.near and cameraVR.far.

This kind of state caching is also used in the renderer. I would call the cache variables: _currentDepthNear and _currentDepthFar and then do this:

if ( _currentDepthNear !== cameraVR.near || _currentDepthFar !== cameraVR.far ) {

    session.updateRenderState( {
        depthNear: cameraVR.near,
        depthFar: cameraVR.far
    } );

    _currentDepthNear = cameraVR.near;
    _currentDepthFar = cameraVR.far;

}

@DougReeder
Copy link
Contributor Author

DougReeder commented Jan 8, 2020 via email

@Mugen87
Copy link
Collaborator

Mugen87 commented Jan 8, 2020

There’s no evidence that this API call is expensive.

@toji Is this true? In this case, caching depthNear and depthFar on engine level would not be necessary.

@toji
Copy link
Contributor

toji commented Jan 8, 2020

It'll depend on the browser implementation, but in Chrome at least this call wouldn't be too expensive.

I'd double-check the timing, though. Any values passed into session.updateRenderState() will wait until the start of the next session.requestAnimationFrame() callback to take effect (so that everything is synchronized and the native systems have time to take it into account.) As such if you call this in a session.requestAnimationFrame() it won't actually take effect until the next frame, and if you change the value per-frame it would always be a frame behind. (Which is silly for depth near/far, I'm just trying to illustrate the point.)

Given how Three.js is structured, though, it may be that's impossible to fully avoid, since you won't know what camera is in use till it's passed to the render() function and that's pretty much guaranteed to be in a frame callback. 🤷‍♀

@Mugen87
Copy link
Collaborator

Mugen87 commented Jan 9, 2020

It'll depend on the browser implementation, but in Chrome at least this call wouldn't be too expensive.

I think it can't hurt to implement the suggested caching. Checking to variables is not expensive and in this way, we are on the safe side.

@mrdoob What do you think?

@DougReeder
Copy link
Contributor Author

So, how do we proceed from here? Who does the merge into dev? I don't see an r113 branch.

@Mugen87
Copy link
Collaborator

Mugen87 commented Jan 15, 2020

@DougReeder The PR will be reviewed by @mrdoob and then be merged (if everything is fine).

@mrdoob mrdoob added this to the r113 milestone Jan 21, 2020
@mrdoob mrdoob merged commit cfc62cd into mrdoob:dev Jan 21, 2020
@mrdoob
Copy link
Owner

mrdoob commented Jan 21, 2020

Thanks!

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.

WebXR: XRSession.depthNear/depthFar are not set
4 participants