[FIX] Convert sRGB colors to linear when writing glTF#8267
Merged
willeastcott merged 7 commits intomainfrom Dec 19, 2025
Merged
[FIX] Convert sRGB colors to linear when writing glTF#8267willeastcott merged 7 commits intomainfrom
willeastcott merged 7 commits intomainfrom
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR fixes a critical bug in the glTF exporter where material colors were not being converted from sRGB to linear color space, causing colors to become progressively brighter with each import/export cycle. It also refactors the parser to use cleaner Color API methods for consistency.
Key Changes:
- Added proper color space conversion in the glTF exporter using
Color.linear()forbaseColorFactorandemissiveFactor - Refactored the glTF parser to replace manual
Math.pow(x, 1/2.2)calls with the cleanerColor.gamma()method - Established symmetric operations:
Color.gamma()for import (linear → sRGB) andColor.linear()for export (sRGB → linear)
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
src/extras/exporters/gltf-exporter.js |
Added sRGB to linear color space conversion when writing baseColorFactor and emissiveFactor to glTF, fixing the export color space bug |
src/framework/parsers/glb-parser.js |
Refactored linear to sRGB conversions to use Color.gamma() method instead of manual Math.pow() calls for improved code clarity and consistency across all material color factors |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
mvaligursky
pushed a commit
that referenced
this pull request
Dec 19, 2025
* [FIX] Convert linear colors to sRGB when writing glTF * Drop comments * Tweak exporter * Use clone * Use array destructuring
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
This PR fixes the color space handling in the glTF exporter and refactors the importer for consistency.
Problem
The glTF exporter was writing material colors (
baseColorFactor,emissiveFactor) directly from the engine's sRGB color space without converting to linear space as required by the glTF specification. This caused colors to become brighter on each import/export cycle.Changes
Exporter (
gltf-exporter.js):Color.linear()conversion when writingbaseColorFactorandemissiveFactorto convert from engine sRGB to glTF linear spaceParser (
glb-parser.js):Math.pow(x, 1/2.2)calls to useColor.gamma()method for:baseColorFactoremissiveFactordiffuseFactor(KHR_materials_pbrSpecularGlossiness)specularFactor(KHR_materials_pbrSpecularGlossiness)specularColorFactor(KHR_materials_specular)sheenColorFactor(KHR_materials_sheen)attenuationColor(KHR_materials_volume)Result
Import and export now use symmetric operations:
Color.gamma()- linear (glTF) → sRGB (engine)Color.linear()- sRGB (engine) → linear (glTF)Material colors are now preserved correctly through import/export roundtrips.
Checklist