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

switch sandbox to double (and fix a tiny GC issue with audio) #12387

Merged
merged 2 commits into from
Apr 12, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 9 additions & 7 deletions packages/dev/core/src/Audio/audioSceneComponent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -484,6 +484,8 @@ export class AudioSceneComponent implements ISceneSerializableComponent {
private _cachedCameraDirection = new Vector3();
private _cachedCameraPosition = new Vector3();
private _lastCheck = 0;
private _invertMatrixTemp = new Matrix();
private _cameraDirectionTemp = new Vector3();

private _afterRender() {
const now = PrecisionDate.Now;
Expand Down Expand Up @@ -536,14 +538,14 @@ export class AudioSceneComponent implements ISceneSerializableComponent {
if (listeningCamera.rigCameras && listeningCamera.rigCameras.length > 0) {
listeningCamera = listeningCamera.rigCameras[0];
}
const mat = Matrix.Invert(listeningCamera.getViewMatrix());
const cameraDirection = Vector3.TransformNormal(AudioSceneComponent._CameraDirection, mat);
cameraDirection.normalize();
listeningCamera.getViewMatrix().invertToRef(this._invertMatrixTemp);
Vector3.TransformNormalToRef(AudioSceneComponent._CameraDirection, this._invertMatrixTemp, this._cameraDirectionTemp);
this._cameraDirectionTemp.normalize();
// To avoid some errors on GearVR
if (!isNaN(cameraDirection.x) && !isNaN(cameraDirection.y) && !isNaN(cameraDirection.z)) {
if (!this._cachedCameraDirection.equals(cameraDirection)) {
this._cachedCameraDirection.copyFrom(cameraDirection);
audioEngine.audioContext.listener.setOrientation(cameraDirection.x, cameraDirection.y, cameraDirection.z, 0, 1, 0);
if (!isNaN(this._cameraDirectionTemp.x) && !isNaN(this._cameraDirectionTemp.y) && !isNaN(this._cameraDirectionTemp.z)) {
if (!this._cachedCameraDirection.equals(this._cameraDirectionTemp)) {
this._cachedCameraDirection.copyFrom(this._cameraDirectionTemp);
audioEngine.audioContext.listener.setOrientation(this._cameraDirectionTemp.x, this._cameraDirectionTemp.y, this._cameraDirectionTemp.z, 0, 1, 0);
}
}
}
Expand Down
8 changes: 8 additions & 0 deletions packages/dev/core/src/Engines/webgpuEngine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ import type { InternalTextureCreationOptions, TextureSize } from "../Materials/T
import { WebGPUSnapshotRendering } from "./WebGPU/webgpuSnapshotRendering";
import type { WebGPUDataBuffer } from "../Meshes/WebGPU/webgpuDataBuffer";
import type { WebGPURenderTargetWrapper } from "./WebGPU/webgpuRenderTargetWrapper";
import { PerformanceConfigurator } from "./performanceConfigurator";

declare function importScripts(...urls: string[]): void;

Expand Down Expand Up @@ -175,6 +176,11 @@ export interface WebGPUEngineOptions extends GPURequestAdapterOptions {
* Defines whether the canvas should be created in "premultiplied" mode (if false, the canvas is created in the "opaque" mode) (true by default)
*/
premultipliedAlpha?: boolean;

/**
* Make the matrix computations to be performed in 64 bits instead of 32 bits. False by default
*/
useHighPrecisionMatrix?: boolean;
}

/**
Expand Down Expand Up @@ -524,6 +530,8 @@ export class WebGPUEngine extends Engine {
options.stencil = options.stencil ?? true;
options.enableGPUDebugMarkers = options.enableGPUDebugMarkers ?? false;

PerformanceConfigurator.SetMatrixPrecision(!!options.useHighPrecisionMatrix);

Logger.Log(`Babylon.js v${Engine.Version} - ${this.description} engine`);
if (!navigator.gpu) {
Logger.Error("WebGPU is not supported by your browser.");
Expand Down
2 changes: 2 additions & 0 deletions packages/tools/sandbox/src/components/renderingZone.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -76,10 +76,12 @@ export class RenderingZone extends React.Component<IRenderingZoneProps> {
],
},
antialiasing: antialias,
useHighPrecisionMatrix: true,
});
await (this._engine as WebGPUEngine).initAsync();
} else {
this._engine = new Engine(this._canvas, antialias, {
useHighPrecisionMatrix: true,
deltakosh marked this conversation as resolved.
Show resolved Hide resolved
premultipliedAlpha: false,
preserveDrawingBuffer: true,
antialias: antialias,
Expand Down