Skip to content

Commit

Permalink
Merge pull request libgdx#7032 from mgsx-dev/fix/bone-weights-regression
Browse files Browse the repository at this point in the history
fix bone weights default values
  • Loading branch information
Tom-Ski authored Nov 22, 2022
2 parents bc65f3f + 723fded commit 8b0f2b4
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions gdx/src/com/badlogic/gdx/graphics/g3d/shaders/DefaultShader.java
Original file line number Diff line number Diff line change
Expand Up @@ -504,6 +504,7 @@ public static String getDefaultFragmentShader () {
protected final long attributesMask;
private final long vertexMask;
private final int textureCoordinates;
private int[] boneWeightsLocations;
protected final Config config;
/** Attributes which are not required but always supported. */
private final static long optionalAttributes = IntAttribute.CullFace | DepthTestAttribute.Type;
Expand Down Expand Up @@ -561,6 +562,9 @@ public DefaultShader (final Renderable renderable, final Config config, final Sh
if (boneWeights > config.numBoneWeights) {
throw new GdxRuntimeException("too many bone weights: " + boneWeights + ", max configured: " + config.numBoneWeights);
}
if (renderable.bones != null) {
boneWeightsLocations = new int[config.numBoneWeights];
}

// Global uniforms
u_projTrans = register(Inputs.projTrans, Setters.projTrans);
Expand Down Expand Up @@ -634,6 +638,12 @@ public void init () {
spotLightsExponentOffset = loc(u_spotLights0exponent) - spotLightsLoc;
spotLightsSize = loc(u_spotLights1color) - spotLightsLoc;
if (spotLightsSize < 0) spotLightsSize = 0;

if (boneWeightsLocations != null) {
for (int i = 0; i < boneWeightsLocations.length; i++) {
boneWeightsLocations[i] = program.getAttributeLocation(ShaderProgram.BONEWEIGHT_ATTRIBUTE + i);
}
}
}

private static final boolean and (final long mask, final long flag) {
Expand Down Expand Up @@ -783,6 +793,15 @@ public void begin (final Camera camera, final RenderContext context) {
lightsSet = false;

if (has(u_time)) set(u_time, time += Gdx.graphics.getDeltaTime());

// set generic vertex attribute value for all bone weights in case a mesh has missing attributes.
if (boneWeightsLocations != null) {
for (int location : boneWeightsLocations) {
if (location >= 0) {
Gdx.gl.glVertexAttrib2f(location, 0, 0);
}
}
}
}

@Override
Expand Down

0 comments on commit 8b0f2b4

Please sign in to comment.