mirror of
https://github.com/cocos/cocos4.git
synced 2026-12-04 18:42:40 +08:00
material defines
This commit is contained in:
@@ -26,14 +26,14 @@ import { Asset } from '../../assets/asset';
|
||||
import { ccclass, property } from '../../core/data/class-decorator';
|
||||
import { murmurhash2_32_gc } from '../../core/utils/murmurhash2_gc';
|
||||
import { GFXBindingType } from '../../gfx/define';
|
||||
import { Effect } from '../../renderer/core/effect';
|
||||
import { Effect, IDefineMap } from '../../renderer/core/effect';
|
||||
import { Pass, PassOverrides } from '../../renderer/core/pass';
|
||||
import { RenderableComponent } from '../framework/renderable-component';
|
||||
import { EffectAsset } from './effect-asset';
|
||||
|
||||
export interface IMaterialInfo {
|
||||
technique?: number;
|
||||
defines?: Record<string, number | boolean>;
|
||||
defines?: IDefineMap[];
|
||||
effectName?: string;
|
||||
}
|
||||
|
||||
@@ -56,7 +56,7 @@ export class Material extends Asset {
|
||||
@property
|
||||
protected _techIdx = 0;
|
||||
@property
|
||||
protected _defines: Record<string, number | boolean> = {};
|
||||
protected _defines: IDefineMap[] = [];
|
||||
@property
|
||||
protected _props: Array<Record<string, any>> = [];
|
||||
|
||||
@@ -68,7 +68,7 @@ export class Material extends Asset {
|
||||
super();
|
||||
if (info) {
|
||||
if (info.technique) { this._techIdx = info.technique; }
|
||||
if (info.defines) { this._defines = info.defines; }
|
||||
if (info.defines) { this.setDefines(info.defines); }
|
||||
if (info.effectName) { this.effectName = info.effectName; }
|
||||
}
|
||||
}
|
||||
@@ -109,8 +109,8 @@ export class Material extends Asset {
|
||||
return this._hash;
|
||||
}
|
||||
|
||||
public setDefines (defines: Record<string, number | boolean>) {
|
||||
this._defines = defines;
|
||||
public setDefines (defines: IDefineMap | IDefineMap[]) {
|
||||
this._defines = Array.isArray(defines) ? defines : [defines];
|
||||
this.update();
|
||||
}
|
||||
|
||||
|
||||
@@ -182,20 +182,23 @@ export class ModelComponent extends RenderableComponent {
|
||||
}
|
||||
|
||||
_updateModels() {
|
||||
if (!this.node._scene) {
|
||||
if (!this.enabled || !this.node._scene) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (this._model) {
|
||||
this._getRenderScene().destroyModel(this._model);
|
||||
}
|
||||
|
||||
let model = this._createModel();
|
||||
model.createBoundingShape(this._mesh.minPosition, this._mesh.maxPosition);
|
||||
this._model = model;
|
||||
this._model.node = this.node;
|
||||
|
||||
this._updateModelParams();
|
||||
}
|
||||
|
||||
_createModel() {
|
||||
return this._getRenderScene().createModel(Model);
|
||||
return this._getRenderScene().createModel(Model, this.node);
|
||||
}
|
||||
|
||||
_updateModelParams() {
|
||||
|
||||
@@ -140,7 +140,7 @@ export default class ParticleSystemRenderer extends RenderableComponent {
|
||||
return;
|
||||
}
|
||||
if (this._model == null) {
|
||||
this._model = this._getRenderScene().createModel(ParticleBatchModel) as ParticleBatchModel;
|
||||
this._model = this._getRenderScene().createModel(ParticleBatchModel, this.node) as ParticleBatchModel;
|
||||
this._model.setCapacity(this.particleSystem.capacity);
|
||||
this._model.setVertexAttributes(this._vertAttrs);
|
||||
this._model.node = this.node;
|
||||
|
||||
Vendored
+1
-1
@@ -28,7 +28,7 @@ import { CCObject } from '../core/data/object';
|
||||
import { getClassName, value } from '../core/utils/js';
|
||||
import IDGenerator from '../core/utils/id-generator';
|
||||
import { ccclass, property } from '../core/data/class-decorator';
|
||||
import { Node } from '../scene-graph/node';
|
||||
import { Node } from '../scene-graph';
|
||||
import { RenderScene } from '../renderer/scene/render-scene';
|
||||
|
||||
export class Component extends CCObject {
|
||||
|
||||
@@ -7,7 +7,7 @@ import { IPassInfoFull, Pass } from './pass';
|
||||
export interface IDefineMap { [name: string]: number | boolean; }
|
||||
export interface IEffectInfo {
|
||||
techIdx?: number;
|
||||
defines?: IDefineMap;
|
||||
defines?: IDefineMap[];
|
||||
}
|
||||
|
||||
export class Effect {
|
||||
@@ -24,7 +24,7 @@ export class Effect {
|
||||
for (let k = 0; k < passNum; ++k) {
|
||||
const passInfo = tech.passes[k] as IPassInfoFull;
|
||||
const prog = cc.game._programLib.getTemplate(passInfo.program);
|
||||
passInfo.shader = cc.game._programLib.getGFXShader(passInfo.program, defines || {});
|
||||
passInfo.shader = cc.game._programLib.getGFXShader(passInfo.program, defines && defines[k] || {});
|
||||
passInfo.renderPass = cc.director.root.pipeline.getRenderPass(passInfo.stage || RenderPassStage.DEFAULT);
|
||||
passInfo.globals = cc.director.root.pipeline.globalUBO;
|
||||
passInfo.blocks = prog!.blocks;
|
||||
|
||||
@@ -6,7 +6,7 @@ import { GFX_DRAW_INFO_SIZE, GFXBuffer, IGFXIndirectBuffer } from '../../gfx/buf
|
||||
import { GFXAttributeName, GFXBufferUsageBit, GFXFormat, GFXFormatInfos,
|
||||
GFXMemoryUsageBit, GFXPrimitiveMode } from '../../gfx/define';
|
||||
import { IGFXInputAttribute } from '../../gfx/input-assembler';
|
||||
import { Node } from '../../scene-graph/node';
|
||||
import { Node } from '../../scene-graph';
|
||||
import { Model } from '../scene/model';
|
||||
import { RenderScene } from '../scene/render-scene';
|
||||
import { IRenderingSubmesh } from '../../3d/assets/mesh';
|
||||
|
||||
@@ -79,7 +79,7 @@ export class SubModel {
|
||||
}
|
||||
for (let i = 0; i < this._material!.passes.length; i++) {
|
||||
if (this._material!.passes[i].primitive !== this._subMeshObject!.primitiveMode) {
|
||||
cc.error('the model(%d)\'s primitive type doesn\'t match its pass\'s', i);
|
||||
cc.error(`the model(%d)'s primitive type doesn't match its pass's`, i);
|
||||
}
|
||||
this.recordCommandBuffer(i);
|
||||
}
|
||||
|
||||
@@ -52,12 +52,13 @@
|
||||
cameraNode.parent = scene;
|
||||
cameraNode.setPosition(20, 20, 20);
|
||||
cameraNode.lookAt(cc.v3());
|
||||
cameraNode.addComponent(FirstPersonCamera);
|
||||
// cameraNode.addComponent(FirstPersonCamera);
|
||||
const camComp = cameraNode.addComponent(cc.CameraComponent);
|
||||
|
||||
const material = new cc.Material();
|
||||
material.setDefines({ USE_COLOR: true });
|
||||
material.effectName = 'builtin-effect-unlit';
|
||||
const material = new cc.Material({
|
||||
effectName: 'builtin-effect-unlit',
|
||||
defines: { USE_COLOR: true },
|
||||
});
|
||||
|
||||
|
||||
const createArrow = (color, rotation) => {
|
||||
|
||||
Reference in New Issue
Block a user