forked from WonderlandEngine/components
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfixed-foveation.js
32 lines (27 loc) · 971 Bytes
/
fixed-foveation.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
import {Component, Type} from '@wonderlandengine/api';
/**
* Applies [fixed foveation](https://www.w3.org/TR/webxrlayers-1/#dom-xrcompositionlayer-fixedfoveation)
* once a WebXR session is started
*
* Fixed foveation reduces shading cost at the periphery by rendering at lower resolutions at the
* edges of the users vision.
*/
export class FixedFoveation extends Component {
static TypeName = 'fixed-foveation';
static Properties = {
/** Amount to apply from 0 (none) to 1 (full) */
fixedFoveation: {type: Type.Float, default: 0.5},
};
start() {
this.onSessionStartCallback = this.setFixedFoveation.bind(this);
}
onActivate() {
this.engine.onXRSessionStart.add(this.onSessionStartCallback);
}
onDeactivate() {
this.engine.onXRSessionStart.remove(this.onSessionStartCallback);
}
setFixedFoveation() {
this.engine.xr.baseLayer.fixedFoveation = this.fixedFoveation;
}
}