Skip to content

Commit

Permalink
Merge pull request BabylonJS#10913 from RaananW/xrFoveated
Browse files Browse the repository at this point in the history
[XR] Foveated rendering and update framerate
  • Loading branch information
RaananW authored Aug 23, 2021
2 parents b93ccc6 + 2afcddc commit ce1c7a0
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 0 deletions.
2 changes: 2 additions & 0 deletions dist/preview release/what's new.md
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,8 @@
- Initial support for WebXR camera parenting ([#10593](https://github.com/BabylonJS/Babylon.js/issues/10593)) ([RaananW](https://github.com/RaananW))
- Fix ReflectionProbe for WebXR ([#10390](https://github.com/BabylonJS/Babylon.js/issues/10390)) ([RaananW](https://github.com/RaananW))
- Fix error on XR dispose due to undefined sepectator camera ([Alex-MSFT](https://github.com/Alex-MSFT))
- Support for WebXR Foveated rendering ([#8920](https://github.com/BabylonJS/Babylon.js/issues/8920)) ([RaananW](https://github.com/RaananW))
- Support WebXR framerate update ([#10912](https://github.com/BabylonJS/Babylon.js/issues/10912)) ([RaananW](https://github.com/RaananW))

### Gizmos

Expand Down
5 changes: 5 additions & 0 deletions src/LibDeclarations/webxr.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ declare class XRWebGLLayer {
readonly framebufferWidth: number;
readonly framebufferHeight: number;
readonly ignoreDepthValues: boolean;
fixedFoveation?: number | null;
getViewport: (view: XRView) => XRViewport;
}

Expand Down Expand Up @@ -258,6 +259,10 @@ interface XRSession {
* Provided when the optional 'dom-overlay' feature is requested.
*/
readonly domOverlayState?: XRDOMOverlayState;

readonly frameRate?: number;
readonly supportedFrameRates?: Float32Array;
updateTargetFrameRate(rate: number): Promise<void>;
}

interface XRViewerPose extends XRPose {
Expand Down
49 changes: 49 additions & 0 deletions src/XR/webXRSessionManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -376,6 +376,55 @@ export class WebXRSessionManager implements IDisposable {
return this._xrNavigator.xr.native ?? false;
}

/**
* The current frame rate as reported by the device
*/
public get currentFrameRate(): number | undefined {
return this.session?.frameRate;
}

/**
* A list of supported frame rates (only available in-session!
*/
public get supportedFrameRates(): Float32Array | undefined {
return this.session?.supportedFrameRates;
}

/**
* Set the framerate of the session.
* @param rate the new framerate. This value needs to be in the supportedFrameRates array
* @returns a promise that resolves once the framerate has been set
*/
public updateTargetFrameRate(rate: number): Promise<void> {
return this.session.updateTargetFrameRate(rate);
}

/**
* Check if fixed foveation is supported on this device
*/
public get isFixedFoveationSupported(): boolean {
return !!this._baseLayer?.fixedFoveation !== null;
}

/**
* Get the fixed foveation currently set, as specified by the webxr specs
* If this returns null, then fixed foveation is not supported
*/
public get fixedFoveation(): Nullable<number> {
return this._baseLayer?.fixedFoveation !== undefined ? this._baseLayer.fixedFoveation : null;
}

/**
* Set the fixed foveation to the specified value, as specified by the webxr specs
* This value will be normalized to be between 0 and 1, 1 being max foveation, 0 being no foveation
*/
public set fixedFoveation(value: Nullable<number>) {
const val = Math.max(0, Math.min(1, value || 0));
if (this._baseLayer?.fixedFoveation !== undefined) {
this._baseLayer.fixedFoveation = val;
}
}

private _createRenderTargetTexture(width: number, height: number, framebuffer: WebGLFramebuffer): RenderTargetTexture {
if (!this._engine) {
throw new Error("Engine is disposed");
Expand Down

0 comments on commit ce1c7a0

Please sign in to comment.