From 723fded82de0b0d78b3a7bcfae2a8ac56af8fd7a Mon Sep 17 00:00:00 2001 From: Germain AUBERT Date: Mon, 21 Nov 2022 18:11:45 +0100 Subject: [PATCH] fix bone weights default values --- .../graphics/g3d/shaders/DefaultShader.java | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/gdx/src/com/badlogic/gdx/graphics/g3d/shaders/DefaultShader.java b/gdx/src/com/badlogic/gdx/graphics/g3d/shaders/DefaultShader.java index 8aa136b9b0c..25d20c3a1ab 100644 --- a/gdx/src/com/badlogic/gdx/graphics/g3d/shaders/DefaultShader.java +++ b/gdx/src/com/badlogic/gdx/graphics/g3d/shaders/DefaultShader.java @@ -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; @@ -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); @@ -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) { @@ -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