Skip to content

Commit 5275bbf

Browse files
feat: allow early set foveation (#25282)
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
1 parent c53e1c8 commit 5275bbf

File tree

1 file changed

+11
-14
lines changed

1 file changed

+11
-14
lines changed

src/renderers/webxr/WebXRManager.js

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ class WebXRManager extends EventDispatcher {
2929

3030
let referenceSpace = null;
3131
let referenceSpaceType = 'local-floor';
32+
// Set default foveation to maximum.
33+
let foveation = 1.0;
3234
let customReferenceSpace = null;
3335

3436
let pose = null;
@@ -338,8 +340,7 @@ class WebXRManager extends EventDispatcher {
338340

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

341-
// Set foveation to maximum.
342-
this.setFoveation( 1.0 );
343+
this.setFoveation( foveation );
343344

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

569570
this.getFoveation = function () {
570571

571-
if ( glProjLayer !== null ) {
572-
573-
return glProjLayer.fixedFoveation;
574-
575-
}
576-
577-
if ( glBaseLayer !== null ) {
572+
if ( glProjLayer === null && glBaseLayer === null ) {
578573

579-
return glBaseLayer.fixedFoveation;
574+
return undefined;
580575

581576
}
582577

583-
return undefined;
578+
return foveation;
584579

585580
};
586581

587-
this.setFoveation = function ( foveation ) {
582+
this.setFoveation = function ( value ) {
588583

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

587+
foveation = value;
588+
592589
if ( glProjLayer !== null ) {
593590

594-
glProjLayer.fixedFoveation = foveation;
591+
glProjLayer.fixedFoveation = value;
595592

596593
}
597594

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

600-
glBaseLayer.fixedFoveation = foveation;
597+
glBaseLayer.fixedFoveation = value;
601598

602599
}
603600

0 commit comments

Comments
 (0)