diff --git a/cocos/3d/assets/material.ts b/cocos/3d/assets/material.ts index 9747f6d9cf..a6f2d9797c 100644 --- a/cocos/3d/assets/material.ts +++ b/cocos/3d/assets/material.ts @@ -30,6 +30,12 @@ import { Effect } from '../../renderer/core/effect'; import { IPassOverrides, Pass } from '../../renderer/core/pass'; import { EffectAsset } from './effect-asset'; +export interface IMaterialInfo { + technique?: number; + effectName?: string; + defines?: Record; +} + @ccclass('cc.Material') export class Material extends Asset { public static getInstantiatedMaterial (mat: Material, rndCom: any) { @@ -57,6 +63,15 @@ export class Material extends Asset { protected _owner: any = null; protected _hash = 0; + constructor (opts?: IMaterialInfo) { + super(); + if (opts) { + if (opts.technique) { this._techIdx = opts.technique; } + if (opts.defines) { this._defines = opts.defines; } + if (opts.effectName) { this.effectName = opts.effectName; } + } + } + @property set effectAsset (val: EffectAsset | null) { if (!val || this.effectName !== val.name) { this.update(val, false); } diff --git a/cocos/renderer/core/pass.ts b/cocos/renderer/core/pass.ts index 553c723370..ad6a1d20c3 100644 --- a/cocos/renderer/core/pass.ts +++ b/cocos/renderer/core/pass.ts @@ -99,6 +99,9 @@ export class Pass { protected _handleMap: Record = {}; protected _blocks: IBlock[] = []; protected _bindings: IGFXBinding[] = []; + protected _bs: GFXBlendState = new GFXBlendState(); + protected _dss: GFXDepthStencilState = new GFXDepthStencilState(); + protected _rs: GFXRasterizerState = new GFXRasterizerState(); // external references protected _device: GFXDevice; protected _shader: GFXShader | null = null; @@ -275,13 +278,13 @@ export class Pass { Object.assign(bs, bsInfo); } const stateInfo = { - bs, - dss: Object.assign(new GFXDepthStencilState(), info.depthStencilState), + bs: this._bs = bs, + dss: this._dss = Object.assign(new GFXDepthStencilState(), info.depthStencilState), is: new GFXInputState(), layout: this._pipelineLayout, primitive: info.primitive || this._primitive, renderPass: this._renderPass, - rs: Object.assign(new GFXRasterizerState(), info.rasterizerState), + rs: this._rs = Object.assign(new GFXRasterizerState(), info.rasterizerState), shader: this._shader, }; if (override) { override(stateInfo); } @@ -297,7 +300,10 @@ export class Pass { get pipelineState () { return this._pipelineState as GFXPipelineState; } get bindingLayout () { return this._bindingLayout as GFXBindingLayout; } get primitive () { return this._primitive; } - get bindings () { return this.bindings; } + get bindings () { return this._bindings; } + get blendState (): GFXBlendState { return this._bs; } + get depthStencilState (): GFXDepthStencilState { return this._dss; } + get rasterizerState (): GFXRasterizerState { return this._rs; } } function serializeBlendState (bs: GFXBlendState) {