-
Notifications
You must be signed in to change notification settings - Fork 3.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Incorrect lights direction when exported to glb 0, 1 or 2 times #7377
Comments
Linking As my test process touches on the light gizmo not aligning with the light's actual orientation |
Few initial takeaways: I'd assume that we're just improperly inverting the light z scale when exporting the scene. This seems similar to our double root issues via #6349 where we're converting our already converted light transform, but I'll have to actually dig in and debug to confirm this. @noalak for the linked light dummy issue, you linked to the original PG: Thanks |
The light dummies are the light meshes parenting the actual light. They are used as Transform nodes when importing a glTF light. |
Do you have all the informations you need to fix those bugs ? |
In investigating the light export issue, I am noticing some strange behavior of the lights when we use a right handed coordinate system: I am using #KX53VK#32 to reproduce this (using my #7603 fix). When I use a right handed coordinate system: I have a directional light in scene configured so that it should illuminate my triangle mesh, however it renders as black: This does not reproduce in a left handed system. Some investigation with @bghgary indicates that this change: is related to some of the issues that I am observing in addressing the original export issue, but I'm not totally sure if this is the sole cause of the triangles being shaded black in our test scene. @sebavan, @CedricGuillemet , would you be able to help advise? |
The triangle is black because the face winding doesn't correspond to the normal.
The 1st swap will make the normal flipped (because of the positions), then you flip again the normal with the ComputeNormals call. |
Thanks @CedricGuillemet, If we use the vertex normal gizmo, it shows the normals as pointing backwards from the plane? This doesn't seem right either, the generated plane in scene seems generated with proper normal orientation and winding order, but is also lit backwards: I'm starting to suspect that we're lighting our scene wrong in right handed mode... |
After talking with @CedricGuillemet , he pointed me to this thread which prompted the original change to the vLightSpecular direction: This looks very similar to the change I just addressed via #7603, looks like we conflated a lighting error with the gizmo error. I believe that it's for the best to fix this, as we can reproduce this regression by modifying this testing scene: Which causes our poor cat to be eerily lit. Undoing commit https://github.com/BabylonJS/Babylon.js/pull/6712/files/8dcdbf7386243e7acdededa6d8b8ecde436d1b4c#r313200449 appears to fix this regression in combination with the previously mentioned gizmo fix: |
Now this causes our original test scene: https://www.babylonjs-playground.com/#KX53VK#30 I will update this testing scene to work correctly as a part of the light direction reverting PR; the lights should face our triangles regardless of scene handedness. The unit tests will be updated to reference: |
It would be good to verify that the double root issue is also fixed once ready. |
Regarding the light orientation issue, there are multiple issues happening here: For one, our lights aren't being properly exported from a right handed scene, they are 180degY off, as the exported node should be oriented such that the light shines towards -Z: This appears to be caused by using the same calculation for the light's yaw angle given the direction, a right handed system should invert the input direction Z axis to align with the coordinate system:
In addition, the light direction is toggled, due to a duplication of light dummy nodes. On import, we create a dummy node oriented such that the light has a direction of (0,0,-1) regardless of scene handedness. On export, we preserve that node, and export that dummy node with the light parented to that node as a new node containing the KHR_lights_punctual extension. This node then duplicated on the next import, causing the light to flip direction. In order to fix this issue, I had to make some alterations to the _applyExtension contract (and affected methods and interfaces that use this contract) Originally, there was no capability to use or return a null value from an export extension handler method, my changes intended to expand the contract to allow for an extension to "void" an exported node via returning null. In this case we don't want to duplicate the existing exported node, after modifying its parent. From there, all that's needed is to reorient the exported grandparent node of the light to encapsulate the light. |
Primary playground is #KX53VK#30 testing right handed export to glb.
All bugs could be related, so I grouped them here.
Black triangles
Bug repro: https://www.babylonjs-playground.com/#9DXCHP#1
Expected result: Triangles should be colored
Current result: When scene is exported and imported once (not twice), the triangles are black (unlighted).
Comments:
The light direction is back to front (0,0,-1).
When imported into the sandbox, the triangles are visible due to a default ambient light. The directional light is still back to front and the gizmo toggle has no effect on light direction. Those behaviors in the sandbox are as expected.
Light direction
Bug repro: https://www.babylonjs-playground.com/#KX53VK#30
Expected result: The light should be oriented as initially front to back (0,0,1).
Current result: When scene is exported and imported twice (unmodified playground), the light direction is reversed: oriented back to front (0,0,-1).
Comments:
The gizmo toggle has no effect on light direction (unlike other 2 bugs above).
Triangles are lighted correctly, despite light direction being reversed.
Linked light dummies
Bug repro: https://www.babylonjs-playground.com/#KX53VK#30
Expected result: Each Light dummy should be independant from each other
Current result: the 2 Light dummies, parent of the actual directional light, are someway linked together. Transform edition of one dummy through Inspector impacts the other. Comparing world matrix using the console.
I'm off the office until Monday 6th.
Adding @Jaskar for any question meanwhile.
The text was updated successfully, but these errors were encountered: