Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Emissive and base colors are incorrectly converted #303

Open
richardhozak opened this issue Jan 13, 2024 · 3 comments
Open

Emissive and base colors are incorrectly converted #303

richardhozak opened this issue Jan 13, 2024 · 3 comments

Comments

@richardhozak
Copy link

richardhozak commented Jan 13, 2024

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: KhronosGroup/glTF#1609 (comment)

The corresponding locations in code where the change should be made:

obj2gltf/lib/loadMtl.js

Lines 139 to 144 in ce0c36e

material.diffuseColor = [
parseFloat(values[0]),
parseFloat(values[1]),
parseFloat(values[2]),
1.0,
];

obj2gltf/lib/loadMtl.js

Lines 131 to 136 in ce0c36e

material.emissiveColor = [
parseFloat(values[0]),
parseFloat(values[1]),
parseFloat(values[2]),
1.0,
];

EDIT:

Let me also link Bevy engine PR that also fixed this: bevyengine/bevy#6828

@lilleyse
Copy link
Contributor

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?

@richardhozak
Copy link
Author

richardhozak commented Jan 16, 2024

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.

@lucien-chastan
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants