obj2gltf icon indicating copy to clipboard operation
obj2gltf copied to clipboard

Emissive and base colors are incorrectly converted

Open richardhozak opened this issue 1 year ago • 3 comments

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

richardhozak avatar Jan 13 '24 20:01 richardhozak

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?

lilleyse avatar Jan 16 '24 17:01 lilleyse

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.

richardhozak avatar Jan 16 '24 20:01 richardhozak

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:

renders files.zip

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.

lucien-chastan avatar Jun 14 '24 11:06 lucien-chastan