Merge pull request #112 from YunHsiao/3d

fix uniform array
This commit is contained in:
Weiliang Wang
2019-01-23 19:20:24 +08:00
committed by GitHub
4 changed files with 28 additions and 11 deletions
+10 -6
View File
@@ -123,14 +123,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;
}
@@ -138,7 +138,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;
}
@@ -210,17 +210,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;
}
+4 -1
View File
@@ -169,6 +169,9 @@ export class ModelComponent extends RenderableComponent {
this._updateModels();
this._updateCastShadow();
this._updateReceiveShadow();
if (this._model) {
this._model.enabled = true;
}
}
public onDisable () {
@@ -279,6 +282,6 @@ export class ModelComponent extends RenderableComponent {
private _getBuiltinMaterial () {
// classic ugly pink indicating missing material
return cc.BuiltinResMgr['default-material'];
return builtinResMgr['default-material'];
}
}
+13 -2
View File
@@ -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;
}
+1 -2
View File
@@ -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 = [];