GLTF: Fix wrong color space for GLTFLight on export #103853
Open
+26
−25
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Oh my goodness, I wrote this 2 months ago and forgot to submit it as a PR... 🤦♂️
glTF uses linear color space for lights, while Godot's Light3D node uses sRGB color space (the docs don't specify, but I tested how it visually looks, and well, it's either sRGB or close to it).
In the past I had only tested lights with trivial colors, such as pure white or pure red. Or maybe I've only tested importing lights, and not exporting them. Godot performs a color space conversion during import, but does not perform the reverse on export. This means that the color of lights does not survive a round-trip. Additionally, the conversion was performed at the wrong step, leading to the GLTFLight data not matching the data in the glTF light. This PR fixes both of these problems. Now the color space is correctly converted when generating new nodes and when converting existing nodes.
To test this, I made a Light3D node and set its color to (0.75, 0.5, 0.25). In the current master, it incorrectly exports the Light3D color value as-is without performing a conversion, resulting in this file that doesn't visually match Godot:
With this PR, exporting the same scene gives almost the same file but with a color of
[0.522521495819092, 0.214041143655777, 0.0508760772645473]
, which is the correct linear version of the sRGB(0.75, 0.5, 0.25)
, and then after import Godot reads the color as(0.75, 0.5, 0.25)
again. With this PR, the exported glTF looks the same in Godot as it does in online glTF viewers such as glTF Viewer and glTF Sample Viewer.Additionally, this PR adds the above color space information to the Light3D and GLTFLight documentation.