Skip to content

Emissive and base colors are incorrectly converted #303

@richardhozak

Description

@richardhozak

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions