pass shader recompile interface (#4181)

This commit is contained in:
Yun Hsiao Wu
2019-04-09 18:30:32 +08:00
committed by Weiliang Wang
parent fa2493c972
commit 1fb5a90d82
5 changed files with 21 additions and 26 deletions
+3 -4
View File
@@ -255,9 +255,9 @@ export class AnimationSampler {
propertyAnimation.values[index * 3 + 1],
propertyAnimation.values[index * 3 + 2]);
const getRotationAt = (index: number, out: Quat) => quat.set(out,
propertyAnimation.values[index * 4 + 0],
propertyAnimation.values[index * 4 + 1],
propertyAnimation.values[index * 4 + 2],
propertyAnimation.values[index * 4 + 0],
propertyAnimation.values[index * 4 + 1],
propertyAnimation.values[index * 4 + 2],
propertyAnimation.values[index * 4 + 3]);
const getScaleAt = getPositionAt;
const keys = clip.keysList[propertyAnimation.indexOfKeys];
@@ -296,7 +296,6 @@ export class AnimationSampler {
}
}
});
});
}
}
@@ -320,12 +320,7 @@ export default class ParticleSystemRenderer extends RenderableComponent {
} else {
console.warn(`particle system renderMode ${this._renderMode} not support.`);
}
const ea = mat!.effectAsset;
mat!.destroy();
mat!.initialize({
defines: this._defines,
effectAsset: ea,
});
for (const pass of mat!.passes) { pass.tryCompile(this._defines); }
if (this.particleSystem.textureAnimationModule.enable) {
mat!.setProperty('frameTile_velLenScale', vec2.set(this.frameTile_velLenScale, this.particleSystem.textureAnimationModule.numTilesX, this.particleSystem.textureAnimationModule.numTilesY));
+10 -10
View File
@@ -25,15 +25,17 @@
// @ts-check
import { ccclass, executeInEditMode, executionOrder, menu, property } from '../../core/data/class-decorator';
import { Mat4 } from '../../core/value-types';
import { mat4 } from '../../core/vmath';
import { GFXDevice, GFXFeature } from '../../gfx/device';
import { __FORCE_USE_UNIFORM_STORAGE__, SkinningModel, useJointsTexture } from '../../renderer/models/skinning-model';
import { GFXDevice } from '../../gfx/device';
import { SkinningModel, useJointsTexture } from '../../renderer/models/skinning-model';
import { Node } from '../../scene-graph/node';
import { Material } from '../assets/material';
import Skeleton from '../assets/skeleton';
import { ModelComponent } from './model-component';
const _m4_tmp = mat4.create();
const _m4_tmp = new Mat4();
const _m4_tmp2 = new Mat4();
type SkinningTarget = Map<string, Node>;
@@ -110,7 +112,7 @@ export class SkinningModelComponent extends ModelComponent {
const skeleton = this._skeleton;
const skinningTarget = this._skinningTarget;
const cancelThisNodeTransform = this.node.getWorldMatrix();
const cancelThisNodeTransform = this.node.getWorldMatrix(_m4_tmp2);
mat4.invert(cancelThisNodeTransform, cancelThisNodeTransform);
this._skeleton.joints.forEach((joint, index) => {
// If target joint doesn't exists in scene graph, skip it.
@@ -123,7 +125,7 @@ export class SkinningModelComponent extends ModelComponent {
// 3. because it has been in world space, just cancel this mesh's original local-world transform
const bindpose = skeleton.bindposes[index];
const jointMatrix = _m4_tmp;
mat4.multiply(jointMatrix, cancelThisNodeTransform, targetNode.getWorldMatrix());
mat4.multiply(jointMatrix, cancelThisNodeTransform, targetNode.getWorldMatrix(_m4_tmp));
mat4.multiply(jointMatrix, jointMatrix, bindpose);
skinningModel.updateJointMatrix(index, jointMatrix);
});
@@ -142,14 +144,12 @@ export class SkinningModelComponent extends ModelComponent {
}
protected _onMaterialModified (index: number, material: Material) {
super._onMaterialModified(index, material);
const device = _getGlobalDevice();
const useJointTexture = device !== null && useJointsTexture(device);
const mat = this.getMaterial(index, CC_EDITOR)!;
const effectAsset = mat.effectAsset;
mat.destroy();
mat.initialize({ effectAsset, defines: { CC_USE_SKINNING: true, CC_USE_JOINTS_TEXTURE: useJointTexture } });
const defines = { CC_USE_SKINNING: true, CC_USE_JOINTS_TEXTURE: useJointTexture };
for (const pass of mat.passes) { pass.tryCompile(defines); }
super._onMaterialModified(index, mat);
}
private _bindSkeleton () {
+5 -4
View File
@@ -17,10 +17,10 @@ import { GFXSampler } from '../../gfx/sampler';
import { GFXShader } from '../../gfx/shader';
import { GFXTextureView } from '../../gfx/texture-view';
import { RenderPassStage, RenderPriority } from '../../pipeline/define';
import { getPhaseID } from '../../pipeline/pass-phase';
import { RenderPipeline } from '../../pipeline/render-pipeline';
import { programLib } from './program-lib';
import { samplerLib } from './sampler-lib';
import { getPhaseID } from '../../pipeline/pass-phase';
export interface IDefineMap { [name: string]: number | boolean | string; }
export interface IPassInfoFull extends IPassInfo {
@@ -276,7 +276,8 @@ export class Pass {
}
}
public tryCompile () {
public tryCompile (defines?: IDefineMap) {
if (defines) { Object.assign(this._defines, defines); }
const pipeline = cc.director.root.pipeline as RenderPipeline | null;
if (!pipeline) { return false; }
this._renderPass = pipeline.getRenderPass(this._stage);
@@ -363,8 +364,8 @@ export class Pass {
if (info.priority !== undefined) { this._priority = info.priority; }
if (info.primitive !== undefined) { this._primitive = info.primitive; }
if (info.stage !== undefined) { this._stage = info.stage; }
if (info.dynamics !== undefined) { this._dynamicStates = info.dynamics; }
if (info.customizations) { this._customizations = info.customizations; }
if (info.dynamics !== undefined) { this._dynamicStates = info.dynamics as GFXDynamicState[]; }
if (info.customizations) { this._customizations = info.customizations as string[]; }
if (this._phase === 0) {
const phaseName = info.phase || 'default';
this._phase = getPhaseID(phaseName);
+2 -2
View File
@@ -35,7 +35,7 @@ function isUniformStorage (storage: JointStorage): storage is IJointUniformsStor
return !('texture' in storage);
}
export const __FORCE_USE_UNIFORM_STORAGE__ = true;
export const __FORCE_USE_UNIFORM_STORAGE__ = false;
export class SkinningModel extends Model {
private _jointStorage: JointStorage | null = null;
@@ -168,7 +168,7 @@ function _createJointsTexture (skinning: { joints: any[]; }) {
}
}
if (textureExtent < 0) {
throw new Error('To many joints.');
throw new Error('Too many joints.');
}
const texture = new Texture2D();