Rotating imported glTF meshes doesn't update lighting

Hey!

https://playground.babylonjs.com/#A01WSP#3

You can try rotating the _root node or the child armature but the lighting doesn’t update.

Could this be something to do with the camera & light inside the _root node? (I’ve tried disabling them but still have the issue)

Hey, there is no light under the _root node. The light is at the root so you need to update it as well

Ah sorry, my GitHub mesh changes were not updated so that last comment is out of date.

My problem is that I have a global light used for all meshes in the scene, but when I rotate this glTF mesh, the shading cast by this global light source does not update. It’s like the model used to transform the rays is not updated.

Unfortunately without a repro it is not easy to help you

Sorry I mean the current link is correct, what I was saying before is wrong.

If you try rotating the _root mesh using the UI, you can see the lighting/shading doesn’t change.

If you rotate the _root mesh in this example however, it works (the lighting/shading updates): https://playground.babylonjs.com/#8WZ93H#1

Ok this is because your normals are broken
here is a rendering of the vertex normals:

The dot below your character are the normals :slight_smile: they should be on his surface

I just tried to recalculate normals in Blender but I still get the same result: Babylon.js Playground

This is the normals:

I guess this leaves us with two options:

  • The glTF exporter is breaking the normals
  • The babylonJS glTF importer is not the using the normals correctly

adding @bghgary

So I just tried to import the glTF object into Blender and I found that the lighting works when I move around the light source, however, when I take a look at the edges and the normals, I see nothing except this at the very bottom of the mesh:

Zoomed out:

adding @PirateJC who knows Blender :slight_smile:

I’m not sure what is going on with the Blender scene, but it looks like from the glTF that the skin is scaling the vertices so that the model is bigger. The normals are working as far as I can tell.

I’m not sure exactly what the problem is. I rotate the light or rotate the root node and everything updates correctly. What exactly is the issue?

I updated to use an arc rotate camera so that it’s easier to move around.
https://playground.babylonjs.com/#A01WSP#4

Also note that the PG has a directional light that is pointing up at an angle which will make the lighting look a bit weird.

I’ve uploaded a video recorded from the babylonJS scene showing the issue here:

In the video, you can see the light is coming from the camera, pointing at the mesh.

When I rotate the mesh around without moving the light source, the diffuse shading looks like it’s baked on the mesh. The way I reproduce this is by going to Inspector > root > Transformations > Rotation > Y .

I just noticed the specular shading seems to update on rotations too I think.

Also, changing the light direction in the inspector does seem to work.

Wait, I’m wrong about the light, sorry about that. It’s pointing down, not up…

The main problem is that when you rotate the mesh light is staying static. Like the normals are not brought into world space

Hence my conclusion about normals being wrong (The capture I did with the tools tend to showcase that they are wrong)

1 Like

The normals appear wrong:


The normals here are straight up.


The normals here are straight down.

If the normals are wrong, why does changing the light direction correctly shade the mesh, but rotating the _root doesn’t?

That is still unclear but it seems that your normals are not getting computed in world space. so changing the light will still work

1 Like

Is this something I can fix or test on my side or is it a bug during importing?

You can try to export your character scene with a directional light trained on the mesh, and animate the character spinning around the Y (Z in blender) axis to see how it imports in different engines via the glTF viewer VSCode plugin