Skip to content

Commit 9852381

Browse files
committed
Remove uniforms
1 parent 4a69556 commit 9852381

File tree

6 files changed

+32
-34
lines changed

6 files changed

+32
-34
lines changed

packages/dev/core/src/Engines/WebGPU/webgpuDrawContext.ts

Lines changed: 1 addition & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -156,27 +156,7 @@ export class WebGPUDrawContext implements IDrawContext {
156156
}
157157

158158
if (bufferNames.indexOf("indices") !== -1) {
159-
if (!useVertexPulling) {
160-
this.setBuffer("indices", null);
161-
} else {
162-
let is32bits = false;
163-
if (indexBuffer) {
164-
this.setBuffer("indices", indexBuffer as WebGPUDataBuffer);
165-
is32bits = indexBuffer.is32Bits;
166-
} else {
167-
// If no index buffer exists but the vertex shader uses the "indices" buffer, we need
168-
// to bind a dummy index buffer (of size 4 to avoid WebGPU errors). Then we'll set the
169-
// uniform to indicate that indices aren't used by the mesh.
170-
this.setBuffer("indices", this._dummyIndexBuffer);
171-
}
172-
// Set uniforms to indicate that the index buffer is used and whether it is 32-bit or 16-bit.
173-
if (webgpuPipelineContext.uniformBuffer?.has("hasIndices")) {
174-
webgpuPipelineContext.uniformBuffer.updateInt("hasIndices", indexBuffer ? 1 : 0);
175-
}
176-
if (webgpuPipelineContext.uniformBuffer?.has("indicesAre32bit")) {
177-
webgpuPipelineContext.uniformBuffer?.updateInt("indicesAre32bit", is32bits ? 1 : 0);
178-
}
179-
}
159+
this.setBuffer("indices", !useVertexPulling ? null : ((indexBuffer as WebGPUDataBuffer) ?? this._dummyIndexBuffer));
180160
}
181161
}
182162

packages/dev/core/src/Engines/thinEngine.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -210,8 +210,6 @@ export class ThinEngine extends AbstractEngine {
210210

211211
// Cache
212212

213-
/** @internal */
214-
public _currentMaterialContext: IMaterialContext;
215213
/** @internal */
216214
protected _currentProgram: Nullable<WebGLProgram>;
217215
private _vertexAttribArraysEnabled: boolean[] = [];

packages/dev/core/src/Materials/PBR/pbrBaseMaterial.ts

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1276,7 +1276,7 @@ export abstract class PBRBaseMaterial extends PushMaterial {
12761276

12771277
const previousEffect = subMesh.effect;
12781278
const lightDisposed = defines._areLightsDisposed;
1279-
let effect = this._prepareEffect(mesh, defines, this.onCompiled, this.onError, useInstances, null, subMesh.getRenderingMesh().hasThinInstances);
1279+
let effect = this._prepareEffect(mesh, subMesh.getRenderingMesh(), defines, this.onCompiled, this.onError, useInstances, null);
12801280

12811281
let forceWasNotReadyPreviously = false;
12821282

@@ -1332,14 +1332,14 @@ export abstract class PBRBaseMaterial extends PushMaterial {
13321332

13331333
private _prepareEffect(
13341334
mesh: AbstractMesh,
1335+
renderingMesh: AbstractMesh,
13351336
defines: PBRMaterialDefines,
13361337
onCompiled: Nullable<(effect: Effect) => void> = null,
13371338
onError: Nullable<(effect: Effect, errors: string) => void> = null,
13381339
useInstances: Nullable<boolean> = null,
1339-
useClipPlane: Nullable<boolean> = null,
1340-
useThinInstances: boolean
1340+
useClipPlane: Nullable<boolean> = null
13411341
): Nullable<Effect> {
1342-
this._prepareDefines(mesh, defines, useInstances, useClipPlane, useThinInstances);
1342+
this._prepareDefines(mesh, renderingMesh, defines, useInstances, useClipPlane);
13431343

13441344
if (!defines.isDirty) {
13451345
return null;
@@ -1647,11 +1647,13 @@ export abstract class PBRBaseMaterial extends PushMaterial {
16471647

16481648
private _prepareDefines(
16491649
mesh: AbstractMesh,
1650+
renderingMesh: AbstractMesh,
16501651
defines: PBRMaterialDefines,
16511652
useInstances: Nullable<boolean> = null,
1652-
useClipPlane: Nullable<boolean> = null,
1653-
useThinInstances: boolean = false
1653+
useClipPlane: Nullable<boolean> = null
16541654
): void {
1655+
const useThinInstances = renderingMesh.hasThinInstances;
1656+
16551657
const scene = this.getScene();
16561658
const engine = scene.getEngine();
16571659

@@ -2007,7 +2009,8 @@ export abstract class PBRBaseMaterial extends PushMaterial {
20072009
this.needAlphaTestingForMesh(mesh),
20082010
defines,
20092011
this._applyDecalMapAfterDetailMap,
2010-
this._useVertexPulling
2012+
this._useVertexPulling,
2013+
renderingMesh
20112014
);
20122015
defines.UNLIT = this._unlit || ((this.pointsCloud || this.wireframe) && !mesh.isVerticesDataPresent(VertexBuffer.NormalKind));
20132016
defines.DEBUGMODE = this._debugMode;
@@ -2051,7 +2054,7 @@ export abstract class PBRBaseMaterial extends PushMaterial {
20512054
return;
20522055
}
20532056
const defines = new PBRMaterialDefines(this._eventInfo.defineNames);
2054-
const effect = this._prepareEffect(mesh, defines, undefined, undefined, localOptions.useInstances, localOptions.clipPlane, mesh.hasThinInstances)!;
2057+
const effect = this._prepareEffect(mesh, mesh, defines, undefined, undefined, localOptions.useInstances, localOptions.clipPlane)!;
20552058
if (this._onEffectCreatedObservable) {
20562059
onCreatedEffectParameters.effect = effect;
20572060
onCreatedEffectParameters.subMesh = null;

packages/dev/core/src/Materials/materialHelper.functions.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -500,6 +500,7 @@ export function GetFogState(mesh: AbstractMesh, scene: Scene) {
500500
* @param defines defines the current list of defines
501501
* @param applyDecalAfterDetail Defines if the decal is applied after or before the detail
502502
* @param useVertexPulling Defines if vertex pulling is used
503+
* @param renderingMesh The mesh used for rendering
503504
*/
504505
export function PrepareDefinesForMisc(
505506
mesh: AbstractMesh,
@@ -510,7 +511,8 @@ export function PrepareDefinesForMisc(
510511
alphaTest: boolean,
511512
defines: any,
512513
applyDecalAfterDetail: boolean = false,
513-
useVertexPulling: boolean = false
514+
useVertexPulling: boolean = false,
515+
renderingMesh?: AbstractMesh
514516
): void {
515517
if (defines._areMiscDirty) {
516518
defines["LOGARITHMICDEPTH"] = useLogarithmicDepth;
@@ -520,6 +522,11 @@ export function PrepareDefinesForMisc(
520522
defines["ALPHATEST"] = alphaTest;
521523
defines["DECAL_AFTER_DETAIL"] = applyDecalAfterDetail;
522524
defines["USE_VERTEX_PULLING"] = useVertexPulling;
525+
526+
const indexBuffer = renderingMesh?.geometry?.getIndexBuffer();
527+
528+
defines["VERTEX_PULLING_USE_INDEX_BUFFER"] = !!indexBuffer;
529+
defines["VERTEX_PULLING_INDEX_BUFFER_32BITS"] = indexBuffer ? indexBuffer.is32Bits : false;
523530
}
524531
}
525532

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

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -880,8 +880,17 @@ export class ShaderMaterial extends PushMaterial {
880880
shaderName = this.customShaderNameResolve(this.name, uniforms, uniformBuffers, samplers, defines, attribs);
881881
}
882882

883-
if (this.useVertexPulling) {
883+
const renderingMesh = subMesh ? subMesh.getRenderingMesh() : mesh;
884+
if (renderingMesh && this.useVertexPulling) {
884885
defines.push("#define USE_VERTEX_PULLING");
886+
887+
const indexBuffer = renderingMesh.geometry?.getIndexBuffer();
888+
if (indexBuffer) {
889+
defines.push("#define VERTEX_PULLING_USE_INDEX_BUFFER");
890+
if (indexBuffer.is32Bits) {
891+
defines.push("#define VERTEX_PULLING_INDEX_BUFFER_32BITS");
892+
}
893+
}
885894
}
886895

887896
const drawWrapper = storeEffectOnSubMeshes ? subMesh._getDrawWrapper(undefined, true) : this._drawWrapper;

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1249,7 +1249,8 @@ export class StandardMaterial extends PushMaterial {
12491249
this.needAlphaTestingForMesh(mesh),
12501250
defines,
12511251
this._applyDecalMapAfterDetailMap,
1252-
this._useVertexPulling
1252+
this._useVertexPulling,
1253+
subMesh.getRenderingMesh()
12531254
);
12541255

12551256
// Values that need to be evaluated on every frame

0 commit comments

Comments
 (0)