From aa9b3e1ac59b5a16864d4667f60ece2e40de0024 Mon Sep 17 00:00:00 2001 From: Yun Hsiao Wu Date: Wed, 3 Jul 2019 15:22:58 +0800 Subject: [PATCH] fix model update (#4801) * no shadow for disabled model * fix model update --- cocos/renderer/core/pass.ts | 13 ++++++++----- cocos/renderer/scene/model.ts | 3 ++- cocos/renderer/scene/planar-shadows.ts | 4 ++-- 3 files changed, 12 insertions(+), 8 deletions(-) diff --git a/cocos/renderer/core/pass.ts b/cocos/renderer/core/pass.ts index de55edaaa5..1e9f4a5459 100644 --- a/cocos/renderer/core/pass.ts +++ b/cocos/renderer/core/pass.ts @@ -90,7 +90,7 @@ const btMask = 0xf0000000; // 4 bits, 16 slots const typeMask = 0x0fc00000; // 6 bits, 64 slots const bindingMask = 0x003ff800; // 11 bits, 2048 slots const indexMask = 0x000007ff; // 11 bits, 2048 slots -const genHandle = (bt: GFXBindingType, type: GFXType, binding: number, index: number = 0) => +const genHandle = (bt: GFXBindingType, binding: number, type: GFXType, index: number = 0) => ((bt << 28) & btMask) | ((type << 22) & typeMask) | ((binding << 11) & bindingMask) | (index & indexMask); const getBindingTypeFromHandle = (handle: number) => (handle & btMask) >>> 28; const getTypeFromHandle = (handle: number) => (handle & typeMask) >>> 22; @@ -196,7 +196,8 @@ export class Pass { size: u.size, usage: GFXBufferUsageBit.UNIFORM | GFXBufferUsageBit.TRANSFER_DST, }); - // buffer data processing system + // non-builtin UBO data pools, note that the effect compiler + // guarantees these bindings to be consecutive, starting from 0 const block: IBlock = this._blocks[u.binding] = { buffer: new ArrayBuffer(u.size), dirty: false, @@ -207,13 +208,13 @@ export class Pass { const view = new Float32Array(block.buffer, acc, cur.size / Float32Array.BYTES_PER_ELEMENT); block.views.push(view); // store handle map - this._handleMap[cur.name] = genHandle(GFXBindingType.UNIFORM_BUFFER, cur.type, u.binding, idx); + this._handleMap[cur.name] = genHandle(GFXBindingType.UNIFORM_BUFFER, u.binding, cur.type, idx); // proceed the counter return acc + cur.size; }, 0); // === u.size } for (const u of this._shaderInfo.samplers) { - this._handleMap[u.name] = genHandle(GFXBindingType.SAMPLER, u.type, u.binding); + this._handleMap[u.name] = genHandle(GFXBindingType.SAMPLER, u.binding, u.type); } this.resetUBOs(); @@ -408,7 +409,9 @@ export class Pass { if (texture) { this._textureViews[u.binding] = texture.getGFXTextureView()!; const samplerInfo = texture.getGFXSamplerInfo(); - if (!this._samplers[u.binding] || samplerInfo.length) { this._samplers[u.binding] = samplerLib.getSampler(device, samplerInfo); } + if (!this._samplers[u.binding] || samplerInfo.length) { + this._samplers[u.binding] = samplerLib.getSampler(device, samplerInfo); + } } else { console.warn('illegal texture default value ' + texName); } } } diff --git a/cocos/renderer/scene/model.ts b/cocos/renderer/scene/model.ts index c1bae1baf6..ff0adec54e 100644 --- a/cocos/renderer/scene/model.ts +++ b/cocos/renderer/scene/model.ts @@ -205,7 +205,8 @@ export class Model { public updateTransform () { const node = this._transform; - if (!node.hasChanged) { return; } + // @ts-ignore + if (!node.hasChanged && !node._dirty) { return; } node.updateWorldTransformFull(); if (!this._modelBounds || !this._worldBounds) { return; } // @ts-ignore diff --git a/cocos/renderer/scene/planar-shadows.ts b/cocos/renderer/scene/planar-shadows.ts index 3a7d09f555..5856c93072 100644 --- a/cocos/renderer/scene/planar-shadows.ts +++ b/cocos/renderer/scene/planar-shadows.ts @@ -148,10 +148,10 @@ export class PlanarShadows { public updateCommandBuffers () { this._cmdBuffs.clear(); for (const model of this._scene.models) { - if (!model.node || !model.castShadow) { continue; } + if (!model.enabled || !model.node || !model.castShadow) { continue; } let pso = this._psoRecord.get(model); if (!pso) { pso = this._createPSO(model); this._psoRecord.set(model, pso); } - if (!model.UBOUpdated) { model.updateUBOs(); } + if (!model.UBOUpdated) { model.updateUBOs(); } // for those outside the frustum for (let i = 0; i < model.subModelNum; i++) { const ia = model.getSubModel(i).inputAssembler; if (!ia) { continue; }