glTF 2.0 exporter uses wrong color space #102905
Labels
No Label
Interest
Animation & Rigging
Interest
Blender Cloud
Interest
Collada
Interest
Core
Interest
Documentation
Interest
Eevee & Viewport
Interest
Geometry Nodes
Interest
Grease Pencil
Interest
Import and Export
Interest
Modeling
Interest
Modifiers
Interest
Nodes & Physics
Interest
Pipeline, Assets & IO
Interest
Platforms, Builds, Tests & Devices
Interest
Python API
Interest
Rendering & Cycles
Interest
Sculpt, Paint & Texture
Interest
Translations
Interest
User Interface
Interest
UV Editing
Interest
VFX & Video
Meta
Good First Issue
Meta
Papercut
Module
Add-ons (BF-Blender)
Module
Add-ons (Community)
Platform
Linux
Platform
macOS
Platform
Windows
Priority
High
Priority
Low
Priority
Normal
Priority
Unbreak Now!
Status
Archived
Status
Confirmed
Status
Duplicate
Status
Needs Info from Developers
Status
Needs Information from User
Status
Needs Triage
Status
Resolved
Type
Bug
Type
Design
Type
Known Issue
Type
Patch
Type
Report
Type
To Do
No Milestone
No project
No Assignees
3 Participants
Notifications
Due Date
No due date set.
Dependencies
No dependencies set.
Reference: blender/blender-addons#102905
Loading…
Reference in New Issue
Block a user
No description provided.
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
System Information
system-info.txt
Blender Version
As per the 'About Blender' screen:
3.3.1
Date: 2022-10-04 18:35
Hash: b292cfe5a936
Branch: master
Short description of error
The glTF 2.0 spec mandates that colors be represented in the sRGB color space, but Blender currently erroneously exports colors in the scene linear color space, resulting in glTF 2.0 exports having an incorrect appearance when imported into other software.
This requirement is described in various parts of the spec, such as section 3.9 :
And section 5.22 :
etc.
Here are a few example screenshots produced with the attached minimal Bevy application and .blend file, showing the differences in color between Blender renders and glTF 2.0 exports:
These examples use an unlit material for simplicity, and to remove lighting as a factor that may affect the perceived color, but this issue also exists with most other ways that colors can be described in a glTF 2.0 export.
Exact steps for others to reproduce the error
Observe the color of the cube as rendered in the application, and compare it to the color of the cube in the Blender render
repro.blend
repro-bevy.tar.gz
Added subscriber: @Pixelstorm
Added subscriber: @scurest
Actually in glTF, the space for color values in the JSON (plus vertex colors and most calculations) is linear space. Only the pixels in color textures (base color, emission) are in sRGB.
Expanding your quotes with more context, you can see both are actually talking about color textures
See also this comment on the spec repo: https://github.com/KhronosGroup/glTF/issues/1609#issuecomment-491097601
Additionally when you compare colors between Blender and a viewer, you also need to change Blender's default Colorspace View Transform from "Filmic" to "Standard". Filmic applies a transform that essentially darkens all colors; standard passes the color through unchanged.
If I do that, then export and compare the unlit cube between Blender and https://gltf-viewer.donmccurdy.com/ I get the same color.
Added subscriber: @JulienDuroure
Changed status from 'Needs Triage' to: 'Resolved'
After looking into it some more, I've realized that yes, you're correct. I got it the wrong way round - the bug is actually in Bevy, which is interpreting colors in glTF files as sRGB instead of linear as it should be, and Blender is working perfectly fine.
I got correct, matching results after patching Bevy and following your advice about the view transform. (Although, why exactly does blender have a default setting that subtly changes all the colors to be different?)
I had to reread the glTF spec a few times to parse where it was specified that colors should be processed in linear - it's the phrase 'RGB values MUST be decoded to real linear values' from one of the aforementioned quotes. I think I (and the Bevy developers, evidently) got confused by the spec in this regard, because it always refers to color spaces as 'transfer functions' - a term that isn't defined in the spec's glossary, and that until now I had never heard before - so I didn't understand what the spec meant by 'linear transfer function', or what these 'real linear values' were meant to be.