Importing 3D models + skeleton with tangents

I’m having some problems getting the tangents to work after importing Blender models to Defold. I display them by setting

var_tangent = normalize((mtx_worldview * vec4(tangent, 0.0)).xyz);

in the vertex program and

gl_FragColor = vec4(var_tangent, 1.0);

in the fragment program. This is working just fine – the tangents are displayed correctly. However, the moment I add a skeleton to the Defold model the render shows the normals instead. I have been using this guide https://forum.defold.com/t/blender-to-defold-3d-animation-guide/73771 for the export/import.

I have also been trying multiple export settings in Blender (e.g. not including any mesh data in the skeleton if that would override the model data or something). I have also tried excluding the armature in the main model, and that does display the tangents but disables the animation.

Is there anyone here that’s got 3D animations with tangents working?

1 Like

@jhonny.goransson any input here?

We produce tangent data for skinned meshes so without looking at the project I don’t really know :thinking:

1 Like

If you have any examples of when that happens we’d gladly take a look!

1 Like

test-tangent.zip (6.9 KB)

Here’s a small test project with three icospheres. The left one uses a shader to show the normals while the middle and right ones use a tangent shader instead. The issue can be seen in the right sphere where the tangents do not seem to be displayed properly. Instead the normals are showing. The only difference between the middle and the right one is the presence of a skeleton. All of the spheres use a Blender model exported with an armature.

3 Likes

I investigated this problem a bit more by stepping through the function GenerateNormalData in rig.cpp. This line https://github.com/defold/defold/blob/dev/engine/rig/src/rig.cpp#L863 seemed a bit fishy. After changing from

tangent = normal_matrix * normal_out;

to

tangent = normal_matrix * tangent_out;

my test project with the three spheres works just as intended. Do you think there’s a typo here?

3 Likes

Oh, yes that looks like a typo to me :slight_smile: pinging @JCash here as well since he wrote it initially (no shaming)

2 Likes

I agree, that looks like a typo. We’ll add a fix to the beta today!

3 Likes

PR coming up:

4 Likes

The fix has been pushed to beta, and should be available within an hour.

3 Likes

Thanks for the quick fix. Works fine on the beta!

2 Likes