Open richardhozak opened 5 months ago
OBJ files have their colors defined in sRGB space.
Is this always true? If I export a glTF from blender it keeps the base color in linear space. I could see there being discrepancies across software though. Maybe it should be an option?
Reading this https://projects.blender.org/blender/blender/issues/43025 hints that it could be sRGB or linear, so yes, probably should be an option.
Hi there,
I think I have the same problem, but on OBJ exports from sketchup (unlike blender I have few export options on sketchup)
Converting .obj + .mtl files to .gltf gives pale colors. While if I import directly .obj / .mlt files in threejs I have the original colors
Here's a simple example, the different files and the renderings I get:
I'm not as expert as @richardhozak, but I have a feeling it's a color conversion problem, or at least, a special case of color conversion.
Thanks for the tool and the work. Right now I'm trying to find a way to correct the colors after importing the .gltf file.
GLTF specifies that all colors in gltf json should be represented in linear space.
OBJ files have their colors defined in sRGB space.
obj2gltf
now takes colors directly from OBJ and puts them in GLTF, but there should be conversion from sRGB to linear rgb colorspace.Note that colors in textures are sRGB both in obj and gltf, only base color (diffuse) and emissive colors should be converted.
See this linked issue in Blender: https://projects.blender.org/blender/blender-addons/issues/102905#issuecomment-11438
and the corresponding discussion in gltf spec repository: https://github.com/KhronosGroup/glTF/issues/1609#issuecomment-491097601
The corresponding locations in code where the change should be made:
https://github.com/CesiumGS/obj2gltf/blob/ce0c36e28193205f6465a22c03f554fe22597f46/lib/loadMtl.js#L139-L144
https://github.com/CesiumGS/obj2gltf/blob/ce0c36e28193205f6465a22c03f554fe22597f46/lib/loadMtl.js#L131-L136
EDIT:
Let me also link Bevy engine PR that also fixed this: https://github.com/bevyengine/bevy/pull/6828