Skip to content

Commit 33e4363

Browse files
committed
@
fix(rendering): use lightIdx instead of loop index l in GPU instancing forward-add light path In _addRenderQueue, the BatchingSchemes.INSTANCING branch was using the local loop index l for getInstancedBuffer() and _instancedQueues[] instead of lightIdx (the global light index from validPunctualLights). This caused mismatched indexing between the instancing path (which used local per-model light indices) and recordCommandBuffer / gatherLightPasses (which use global light indices), resulting in wrong UBO/descriptor bindings for additional lights when different models have different light culling results under GPU instancing. Also added: - Null check in recordCommandBuffer for sparse _instancedQueues entries - lightIdx multiplier on dynamicOffsets for consistency with non-instancing default branch and _instancedLightPassPool convention Fixes: #19170 @
1 parent 411f98d commit 33e4363

1 file changed

Lines changed: 5 additions & 4 deletions

File tree

cocos/rendering/render-additive-light-queue.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,7 @@ export class RenderAdditiveLightQueue {
243243
public recordCommandBuffer (device: Device, renderPass: RenderPass, cmdBuff: CommandBuffer): void {
244244
const globalDSManager: GlobalDSManager = this._pipeline.globalDSManager;
245245
for (let j = 0; j < this._instancedQueues.length; ++j) {
246+
if (!this._instancedQueues[j]) { continue; }
246247
const light = this._instancedLightPassPool.lights[j];
247248
_dynamicOffsets[0] = this._instancedLightPassPool.dynamicOffsets[j];
248249
const descriptorSet = globalDSManager.getOrCreateDescriptorSet(light);
@@ -318,11 +319,11 @@ export class RenderAdditiveLightQueue {
318319
if (((visibility & model.node.layer) === model.node.layer)) {
319320
switch (batchingScheme) {
320321
case BatchingSchemes.INSTANCING: {
321-
const buffer = pass.getInstancedBuffer(l);
322+
const buffer = pass.getInstancedBuffer(lightIdx);
322323
buffer.merge(subModel, lightPassIdx);
323-
buffer.dynamicOffsets[0] = this._lightBufferStride;
324-
if (!this._instancedQueues[l]) { this._instancedQueues[l] = new RenderInstancedQueue(); }
325-
this._instancedQueues[l].queue.add(buffer);
324+
buffer.dynamicOffsets[0] = this._lightBufferStride * lightIdx;
325+
if (!this._instancedQueues[lightIdx]) { this._instancedQueues[lightIdx] = new RenderInstancedQueue(); }
326+
this._instancedQueues[lightIdx].queue.add(buffer);
326327
} break;
327328
default:
328329
lp!.lights.push(light);

0 commit comments

Comments
 (0)