Skip to content

Commit 23888a0

Browse files
Multiview support for GS (#17508)
1 parent 00c4363 commit 23888a0

File tree

6 files changed

+205
-47
lines changed

6 files changed

+205
-47
lines changed

packages/dev/core/src/Materials/GaussianSplatting/gaussianSplattingMaterial.ts

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import type { Mesh } from "../../Meshes/mesh";
44
import type { Effect, IEffectCreationOptions } from "../../Materials/effect";
55
import type { Scene } from "../../scene";
66
import type { Matrix } from "../../Maths/math.vector";
7-
import type { GaussianSplattingMesh } from "../../Meshes";
7+
import type { GaussianSplattingMesh } from "../../Meshes/GaussianSplatting/gaussianSplattingMesh";
88
import { SerializationHelper } from "../../Misc/decorators.serialization";
99
import { VertexBuffer } from "../../Buffers/buffer";
1010
import { MaterialDefines } from "../../Materials/materialDefines";
@@ -150,6 +150,7 @@ export class GaussianSplattingMaterial extends PushMaterial {
150150
"kernelSize",
151151
"viewDirectionFactor",
152152
];
153+
private _sourceMesh: GaussianSplattingMesh | null = null;
153154
/**
154155
* Checks whether the material is ready to be rendered for a given mesh.
155156
* @param mesh The mesh to render
@@ -182,8 +183,12 @@ export class GaussianSplattingMaterial extends PushMaterial {
182183
return true;
183184
}
184185

186+
if (!this._sourceMesh) {
187+
return false;
188+
}
189+
185190
const engine = scene.getEngine();
186-
const gsMesh = mesh as GaussianSplattingMesh;
191+
const gsMesh = this._sourceMesh;
187192

188193
// Misc.
189194
PrepareDefinesForMisc(
@@ -270,6 +275,13 @@ export class GaussianSplattingMaterial extends PushMaterial {
270275
return true;
271276
}
272277

278+
/**
279+
* GaussianSplattingMaterial belongs to a single mesh
280+
* @param mesh mesh this material belongs to
281+
*/
282+
public setSourceMesh(mesh: GaussianSplattingMesh) {
283+
this._sourceMesh = mesh;
284+
}
273285
/**
274286
* Bind material effect for a specific Gaussian Splatting mesh
275287
* @param mesh Gaussian splatting mesh
@@ -280,11 +292,16 @@ export class GaussianSplattingMaterial extends PushMaterial {
280292
const engine = scene.getEngine();
281293
const camera = scene.activeCamera;
282294

283-
const renderWidth = engine.getRenderWidth();
284-
const renderHeight = engine.getRenderHeight();
295+
const renderWidth = engine.getRenderWidth() * camera!.viewport.width;
296+
const renderHeight = engine.getRenderHeight() * camera!.viewport.height;
297+
298+
const gsMaterial = mesh.material as GaussianSplattingMaterial;
299+
300+
if (!gsMaterial._sourceMesh) {
301+
return;
302+
}
285303

286-
const gsMesh = mesh as GaussianSplattingMesh;
287-
const gsMaterial = gsMesh.material as GaussianSplattingMaterial;
304+
const gsMesh = gsMaterial._sourceMesh;
288305

289306
// check if rigcamera, get number of rigs
290307
const numberOfRigs = camera?.rigParent?.rigCameras.length || 1;

packages/dev/core/src/Materials/uniformBuffer.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ export class UniformBuffer {
2626
private _buffer: Nullable<DataBuffer>;
2727
private _buffers: Array<[DataBuffer, Float32Array | undefined]>;
2828
private _bufferIndex: number;
29+
private _bufferUpdatedLastFrame: boolean;
2930
private _createBufferOnWrite: boolean;
3031
private _data: number[];
3132
private _bufferData: Float32Array;
@@ -258,6 +259,7 @@ export class UniformBuffer {
258259
if ((trackUBOsInFrame === undefined && this._engine._features.trackUbosInFrame) || trackUBOsInFrame === true) {
259260
this._buffers = [];
260261
this._bufferIndex = -1;
262+
this._bufferUpdatedLastFrame = false;
261263
this._createBufferOnWrite = false;
262264
this._currentFrameId = 0;
263265
this._trackUBOsInFrame = true;
@@ -691,6 +693,8 @@ export class UniformBuffer {
691693
}
692694
}
693695

696+
this._bufferUpdatedLastFrame = true;
697+
694698
this._engine.updateUniformBuffer(this._buffer, this._bufferData);
695699

696700
if (this._engine._features._collectUbosUpdatedInFrame) {
@@ -720,7 +724,11 @@ export class UniformBuffer {
720724
this._currentFrameId = this._engine.frameId;
721725
this._createBufferOnWrite = false;
722726
if (this._buffers && this._buffers.length > 0) {
723-
this._needSync = this._bufferIndex !== 0;
727+
if (this._buffers.length === 1) {
728+
this._needSync = !this._bufferUpdatedLastFrame;
729+
} else {
730+
this._needSync = this._bufferIndex !== 0;
731+
}
724732
this._bufferIndex = 0;
725733
this._buffer = this._buffers[this._bufferIndex][0];
726734
} else {

0 commit comments

Comments
 (0)