Skip to content

Commit

Permalink
Merge pull request #14548 from Popov72/geometrybuffer-bonetexture
Browse files Browse the repository at this point in the history
GeometryBufferRenderer: Use bone texture if supported
  • Loading branch information
sebavan committed Nov 27, 2023
2 parents 1be3929 + a2a2c13 commit a9bd265
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 7 deletions.
21 changes: 17 additions & 4 deletions packages/dev/core/src/Rendering/geometryBufferRenderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ const uniforms = [
"morphTargetInfluences",
"morphTargetTextureInfo",
"morphTargetTextureIndices",
"boneTextureWidth",
];
addClipPlaneUniforms(uniforms);

Expand Down Expand Up @@ -570,17 +571,20 @@ export class GeometryBufferRenderer {
}

// Bones
if (mesh.useBones && mesh.computeBonesUsingShaders) {
if (mesh.useBones && mesh.computeBonesUsingShaders && mesh.skeleton) {
attribs.push(VertexBuffer.MatricesIndicesKind);
attribs.push(VertexBuffer.MatricesWeightsKind);
if (mesh.numBoneInfluencers > 4) {
attribs.push(VertexBuffer.MatricesIndicesExtraKind);
attribs.push(VertexBuffer.MatricesWeightsExtraKind);
}
defines.push("#define NUM_BONE_INFLUENCERS " + mesh.numBoneInfluencers);
defines.push("#define BonesPerMesh " + (mesh.skeleton ? mesh.skeleton.bones.length + 1 : 0));
defines.push("#define BONETEXTURE " + mesh.skeleton.isUsingTextureForMatrices);
defines.push("#define BonesPerMesh " + (mesh.skeleton.bones.length + 1));
} else {
defines.push("#define NUM_BONE_INFLUENCERS 0");
defines.push("#define BONETEXTURE false");
defines.push("#define BonesPerMesh 0");
}

// Morph targets
Expand Down Expand Up @@ -629,7 +633,7 @@ export class GeometryBufferRenderer {
{
attributes: attribs,
uniformsNames: uniforms,
samplers: ["diffuseSampler", "bumpSampler", "reflectivitySampler", "albedoSampler", "morphTargets"],
samplers: ["diffuseSampler", "bumpSampler", "reflectivitySampler", "albedoSampler", "morphTargets", "boneSampler"],
defines: join,
onCompiled: null,
fallbacks: null,
Expand Down Expand Up @@ -953,7 +957,16 @@ export class GeometryBufferRenderer {

// Bones
if (renderingMesh.useBones && renderingMesh.computeBonesUsingShaders && renderingMesh.skeleton) {
effect.setMatrices("mBones", renderingMesh.skeleton.getTransformMatrices(renderingMesh));
const skeleton = renderingMesh.skeleton;

if (skeleton.isUsingTextureForMatrices && effect.getUniformIndex("boneTextureWidth") > -1) {
const boneTexture = skeleton.getTransformMatrixTexture(renderingMesh);
effect.setTexture("boneSampler", boneTexture);
effect.setFloat("boneTextureWidth", 4.0 * (skeleton.bones.length + 1));
} else {
effect.setMatrices("mBones", renderingMesh.skeleton.getTransformMatrices(renderingMesh));
}

if (this._enableVelocity) {
effect.setMatrices("mPreviousBones", this._previousBonesTransformationMatrices[renderingMesh.uniqueId]);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,10 @@
uniform float boneTextureWidth;
#else
uniform mat4 mBones[BonesPerMesh];
#ifdef BONES_VELOCITY_ENABLED
uniform mat4 mPreviousBones[BonesPerMesh];
#endif
#endif

#ifdef BONES_VELOCITY_ENABLED
uniform mat4 mPreviousBones[BonesPerMesh];
#endif

#ifdef BONETEXTURE
Expand Down

0 comments on commit a9bd265

Please sign in to comment.