force use uniform for skinning (#4305)

This commit is contained in:
Leslie Leigh
2019-04-25 18:27:30 +08:00
committed by Weiliang Wang
parent acf505a32b
commit 04c47d047b
3 changed files with 30 additions and 17 deletions
+13 -10
View File
File diff suppressed because one or more lines are too long
@@ -27,7 +27,7 @@ import { ccclass, executeInEditMode, executionOrder, menu, property } from '../.
import { Mat4 } from '../../core/value-types';
import { mat4 } from '../../core/vmath';
import { GFXDevice } from '../../gfx/device';
import { JointStorageKind, selectStorageKind, SkinningModel } from '../../renderer/models/skinning-model';
import { __DEFER_BINDPOSE_COMPUTATION__, JointStorageKind, selectStorageKind, SkinningModel } from '../../renderer/models/skinning-model';
import { Node } from '../../scene-graph/node';
import { Mesh } from '../assets';
import { Material } from '../assets/material';
@@ -160,7 +160,7 @@ export class SkinningModelComponent extends ModelComponent {
if (!targetNode) {
continue;
}
if (isTextureStorage) {
if (isTextureStorage && __DEFER_BINDPOSE_COMPUTATION__) {
skinningModel.updateJointMatrix(iJoint, targetNode.worldMatrix);
} else {
const bindpose = skeleton.bindposes[iJoint];
@@ -212,6 +212,7 @@ export class SkinningModelComponent extends ModelComponent {
const mat = this.getMaterial(index, CC_EDITOR);
if (mat) {
mat.recompileShaders({
CC_BINDPOSE_COMPUTATION_DEFERED: __DEFER_BINDPOSE_COMPUTATION__,
CC_USE_SKINNING: true,
CC_USE_JOINTS_TEXTURE: kind === JointStorageKind.textureRGBA32F || kind === JointStorageKind.textureRGBA8,
CC_USE_JOINTS_TEXTURE_RGBA8888: kind === JointStorageKind.textureRGBA8,
+14 -5
View File
@@ -38,7 +38,8 @@ function isTextureStorage (storage: JointStorage): storage is ITextureStorage {
return storage.kind === JointStorageKind.textureRGBA8 || storage.kind === JointStorageKind.textureRGBA32F;
}
export const __FORCE_USE_UNIFORM_STORAGE__ = false;
export const __FORCE_USE_UNIFORM_STORAGE__ = true;
export const __DEFER_BINDPOSE_COMPUTATION__ = true;
export class SkinningModel extends Model {
private _binded: null | {
@@ -63,10 +64,14 @@ export class SkinningModel extends Model {
if (storageKind === JointStorageKind.textureRGBA32F ||
storageKind === JointStorageKind.textureRGBA8) {
const mat4TextureKind = storageKind === JointStorageKind.textureRGBA32F ? Mat4TextureKind.rgba32f : Mat4TextureKind.rgba8888;
const mat4Texture = new MatrixTexture(skeleton.joints.length * 2, mat4TextureKind);
const mat4Texture = new MatrixTexture(
__DEFER_BINDPOSE_COMPUTATION__ ? skeleton.joints.length * 2 : skeleton.joints.length,
mat4TextureKind);
for (let iJoint = 0; iJoint < skeleton.bindposes.length; ++iJoint) {
mat4Texture.set(iJoint * 2 + 0, skeleton.bindposes[iJoint]);
if (__DEFER_BINDPOSE_COMPUTATION__) {
for (let iJoint = 0; iJoint < skeleton.bindposes.length; ++iJoint) {
mat4Texture.set(iJoint * 2 + 0, skeleton.bindposes[iJoint]);
}
}
this._binded = {
@@ -115,7 +120,11 @@ export class SkinningModel extends Model {
}
const { jointStorage, skinningUBO } = this._binded;
if (isTextureStorage(jointStorage)) {
jointStorage.texture.set(iMatrix * 2 + 1, matrix);
if (__DEFER_BINDPOSE_COMPUTATION__) {
jointStorage.texture.set(iMatrix * 2 + 1, matrix);
} else {
jointStorage.texture.set(iMatrix, matrix);
}
} else {
setMat4InUniform(jointStorage.nativeData, iMatrix, matrix);
}