Skip to content

Commit

Permalink
fix: resize max uniform vector count (galacean#660)
Browse files Browse the repository at this point in the history
* fix: resize max uniform vector count

Co-authored-by: shensi.zxd <shensi.zxd@alibaba-inc.com>
  • Loading branch information
zhuxudong and shensi.zxd authored Mar 2, 2022
1 parent 5401e8a commit 3728413
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions packages/core/src/mesh/SkinnedMeshRenderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,23 +123,24 @@ export class SkinnedMeshRenderer extends MeshRenderer {
const rhi = this.entity.engine._hardwareRenderer;
if (!rhi) return;
const maxAttribUniformVec4 = rhi.renderStates.getParameter(rhi.gl.MAX_VERTEX_UNIFORM_VECTORS);
const maxJoints = Math.floor((maxAttribUniformVec4 - 20) / 4);
const maxJoints = Math.floor((maxAttribUniformVec4 - 30) / 4);
const shaderData = this.shaderData;
const jointCount = this.jointNodes?.length;
const jointCount = jointNodes.length;

if (jointCount) {
shaderData.enableMacro("O3_HAS_SKIN");
shaderData.setInt(SkinnedMeshRenderer._jointCountProperty, jointCount);
if (joints.length > maxJoints) {
if (jointCount > maxJoints) {
if (rhi.canIUseMoreJoints) {
this._useJointTexture = true;
} else {
Logger.error(
`component's joints count(${joints}) greater than device's MAX_VERTEX_UNIFORM_VECTORS number ${maxAttribUniformVec4}, and don't support jointTexture in this device. suggest joint count less than ${maxJoints}.`,
`component's joints count(${jointCount}) greater than device's MAX_VERTEX_UNIFORM_VECTORS number ${maxAttribUniformVec4}, and don't support jointTexture in this device. suggest joint count less than ${maxJoints}.`,
this
);
}
} else {
const maxJoints = Math.max(SkinnedMeshRenderer._maxJoints, joints.length);
const maxJoints = Math.max(SkinnedMeshRenderer._maxJoints, jointCount);
SkinnedMeshRenderer._maxJoints = maxJoints;
shaderData.disableMacro("O3_USE_JOINT_TEXTURE");
shaderData.enableMacro("O3_JOINTS_NUM", maxJoints.toString());
Expand Down

0 comments on commit 3728413

Please sign in to comment.