Skip to content

Commit

Permalink
feat: allow early set foveation (#25282)
Browse files Browse the repository at this point in the history
Currently foveation is set to 1.0 on setSession,
and there's no way to set it before,
because it's not saved anywere when session is not active.
So the only way to set it to a non-default value is to call setSession and
call setFoveation afterwards.
That leads to hacks in certain scenarios like pmndrs/xr#235.
This PR allows setting it beforehand, while being backwards compatible
  • Loading branch information
saitonakamura authored Jan 25, 2023
1 parent c53e1c8 commit 5275bbf
Showing 1 changed file with 11 additions and 14 deletions.
25 changes: 11 additions & 14 deletions src/renderers/webxr/WebXRManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ class WebXRManager extends EventDispatcher {

let referenceSpace = null;
let referenceSpaceType = 'local-floor';
// Set default foveation to maximum.
let foveation = 1.0;
let customReferenceSpace = null;

let pose = null;
Expand Down Expand Up @@ -338,8 +340,7 @@ class WebXRManager extends EventDispatcher {

newRenderTarget.isXRRenderTarget = true; // TODO Remove this when possible, see #23278

// Set foveation to maximum.
this.setFoveation( 1.0 );
this.setFoveation( foveation );

customReferenceSpace = null;
referenceSpace = await session.requestReferenceSpace( referenceSpaceType );
Expand Down Expand Up @@ -568,36 +569,32 @@ class WebXRManager extends EventDispatcher {

this.getFoveation = function () {

if ( glProjLayer !== null ) {

return glProjLayer.fixedFoveation;

}

if ( glBaseLayer !== null ) {
if ( glProjLayer === null && glBaseLayer === null ) {

return glBaseLayer.fixedFoveation;
return undefined;

}

return undefined;
return foveation;

};

this.setFoveation = function ( foveation ) {
this.setFoveation = function ( value ) {

// 0 = no foveation = full resolution
// 1 = maximum foveation = the edges render at lower resolution

foveation = value;

if ( glProjLayer !== null ) {

glProjLayer.fixedFoveation = foveation;
glProjLayer.fixedFoveation = value;

}

if ( glBaseLayer !== null && glBaseLayer.fixedFoveation !== undefined ) {

glBaseLayer.fixedFoveation = foveation;
glBaseLayer.fixedFoveation = value;

}

Expand Down

0 comments on commit 5275bbf

Please sign in to comment.