From 31ad0be86ab034288c4c598fda47be3c4007d60b Mon Sep 17 00:00:00 2001 From: Yun Hsiao Wu Date: Wed, 23 Jan 2019 19:19:31 +0800 Subject: [PATCH] fix uniform array --- cocos/3d/assets/material.ts | 16 ++++++++++------ cocos/3d/framework/model-component.ts | 5 ++++- cocos/renderer/core/pass.ts | 15 +++++++++++++-- playground/simple.html | 3 +-- 4 files changed, 28 insertions(+), 11 deletions(-) diff --git a/cocos/3d/assets/material.ts b/cocos/3d/assets/material.ts index 0517ad898f..eb53bb51ab 100644 --- a/cocos/3d/assets/material.ts +++ b/cocos/3d/assets/material.ts @@ -120,14 +120,14 @@ export class Material extends Asset { * pass.setUniform should be used instead * if you need to do per-frame property update. */ - public setProperty (name: string, val: any, passIdx?: number, arrayIdx?: number) { + public setProperty (name: string, val: any, passIdx?: number) { let success = false; if (passIdx === undefined) { // set property for all applicable passes const passes = this._passes; const len = passes.length; for (let i = 0; i < len; i++) { const pass = passes[i]; - if (this._uploadProperty(pass, name, val, arrayIdx)) { + if (this._uploadProperty(pass, name, val)) { this._props[i][name] = val; success = true; } @@ -135,7 +135,7 @@ export class Material extends Asset { } else { if (passIdx >= this._passes.length) { console.warn(`illegal pass index: ${passIdx}.`); return; } const pass = this._passes[passIdx]; - if (this._uploadProperty(pass, name, val, arrayIdx)) { + if (this._uploadProperty(pass, name, val)) { this._props[passIdx][name] = val; success = true; } @@ -207,17 +207,21 @@ export class Material extends Asset { this.onPassChange(); } - protected _uploadProperty (pass: Pass, name: string, val: any, arrayIdx?: number) { + protected _uploadProperty (pass: Pass, name: string, val: any) { const handle = pass.getHandle(name); if (handle === undefined) { return false; } const bindingType = Pass.getBindingTypeFromHandle(handle); if (bindingType === GFXBindingType.UNIFORM_BUFFER) { - pass.setUniform(handle, val, arrayIdx); + if (Array.isArray(val)) { + pass.setUniformArray(handle, val); + } else { + pass.setUniform(handle, val); + } } else if (bindingType === GFXBindingType.SAMPLER) { const textureView = val instanceof GFXTextureView ? val : val.getGFXTextureView(); if (!textureView) { console.warn('texture asset incomplete!'); return false; } const binding = Pass.getBindingFromHandle(handle); - pass.bindTextureView(binding, textureView, arrayIdx); + pass.bindTextureView(binding, textureView); } return true; } diff --git a/cocos/3d/framework/model-component.ts b/cocos/3d/framework/model-component.ts index adfb368fbe..b6fd5e939d 100644 --- a/cocos/3d/framework/model-component.ts +++ b/cocos/3d/framework/model-component.ts @@ -169,6 +169,9 @@ export class ModelComponent extends RenderableComponent { this._updateModels(); this._updateCastShadow(); this._updateReceiveShadow(); + if (this._model) { + this._model.enabled = true; + } } public onDisable () { @@ -275,6 +278,6 @@ export class ModelComponent extends RenderableComponent { private _getBuiltinMaterial () { // classic ugly pink indicating missing material - return cc.BuiltinResMgr['default-material']; + return builtinResMgr['default-material']; } } diff --git a/cocos/renderer/core/pass.ts b/cocos/renderer/core/pass.ts index e26f2fac38..b553ffecf3 100644 --- a/cocos/renderer/core/pass.ts +++ b/cocos/renderer/core/pass.ts @@ -206,12 +206,23 @@ export class Pass { return Pass.getBindingFromHandle(this.getHandle(name)); } - public setUniform (handle: number, value: any, arrayIdx?: number) { + public setUniform (handle: number, value: any) { const binding = Pass.getBindingFromHandle(handle); const type = Pass.getTypeFromHandle(handle); const idx = Pass.getIndexFromHandle(handle); const block = this._blocks[binding]; - _type2fn[type](block.views[idx], value, arrayIdx); + _type2fn[type](block.views[idx], value); + block.dirty = true; + } + + public setUniformArray (handle: number, value: any[]) { + const binding = Pass.getBindingFromHandle(handle); + const type = Pass.getTypeFromHandle(handle); + const idx = Pass.getIndexFromHandle(handle); + const block = this._blocks[binding]; + for (let i = 0; i < value.length; i++) { + _type2fn[type](block.views[idx], value[i], i); + } block.dirty = true; } diff --git a/playground/simple.html b/playground/simple.html index aaf4842886..b3788fa6d6 100644 --- a/playground/simple.html +++ b/playground/simple.html @@ -64,8 +64,7 @@ material.setDefines({ USE_COLOR: true }); // parsed effect file is embedded in cocos/3d/builtin/effects.js material.effectName = 'builtin-effect-unlit'; - material.setProperty('color', cc.Color.RED, 0, 0); - material.setProperty('color', cc.Color.BLUE, 0, 1); + material.setProperty('color', [ cc.Color.RED, cc.Color.BLUE ]); const len = 50; const models = [], passes = [];