From e51a79d9c6fc51569c384be76659dae68ec6c7d7 Mon Sep 17 00:00:00 2001 From: zxg0622 <247274249@qq.com> Date: Thu, 28 Mar 2019 17:01:50 +0800 Subject: [PATCH] fix not bind light ubo when changing material (#4114) --- cocos/renderer/scene/model.ts | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/cocos/renderer/scene/model.ts b/cocos/renderer/scene/model.ts index cb3caf1153..5a0973f5d9 100644 --- a/cocos/renderer/scene/model.ts +++ b/cocos/renderer/scene/model.ts @@ -241,6 +241,7 @@ export class Model { if (this._subModels[idx] == null) { return; } + this.initLocalBindings(mat); if (this._subModels[idx].material === mat) { if (mat) { this.destroyPipelineState(mat!, this._matPSORecord.get(mat!)!); @@ -299,10 +300,12 @@ export class Model { } protected onSetLocalBindings (mat: Material) { - this._localBindings.set(UBOLocal.BLOCK.name, { - type: GFXBindingType.UNIFORM_BUFFER, - blockInfo: UBOLocal.BLOCK, - }); + if (!this._localBindings.has(UBOLocal.BLOCK.name)) { + this._localBindings.set(UBOLocal.BLOCK.name, { + type: GFXBindingType.UNIFORM_BUFFER, + blockInfo: UBOLocal.BLOCK, + }); + } let hasForwardLight = false; for (const p of mat.passes) { if (p.bindings.find((b) => b.name === UBOForwardLight.BLOCK.name)) { @@ -311,18 +314,18 @@ export class Model { } } if (hasForwardLight && cc.director.root.pipeline.constructor.name === 'ForwardPipeline') { - this._localBindings.set(UBOForwardLight.BLOCK.name, { - type: GFXBindingType.UNIFORM_BUFFER, - blockInfo: UBOForwardLight.BLOCK, - }); + if (!this._localBindings.has(UBOForwardLight.BLOCK.name)) { + this._localBindings.set(UBOForwardLight.BLOCK.name, { + type: GFXBindingType.UNIFORM_BUFFER, + blockInfo: UBOForwardLight.BLOCK, + }); + } } } protected initLocalBindings (mat: Material|null) { if (mat) { - if (this._localBindings.size === 0) { - this.onSetLocalBindings(mat); - } + this.onSetLocalBindings(mat); for (const localBinding of this._localBindings.values()) { if (!localBinding.buffer) { localBinding.buffer = this._device.createBuffer({