Skip to content

Commit

Permalink
gltfpack: Only use Kd/d from .mtl when associated maps are absent
Browse files Browse the repository at this point in the history
It's not fully clear what the expected behavior is when both Kd and
map_Kd are specified; some online documentation claims that they are
multiplied, but some .obj files in the wild have map_Kd and Kd=0, so to
stay safe we now only apply Kd/d when there's no map with the same name.
  • Loading branch information
zeux committed Aug 22, 2023
1 parent f0130a3 commit 5dccdc3
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 deletions gltf/parseobj.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,10 +71,10 @@ static void parseMaterialsObj(fastObjMesh* obj, cgltf_data* data)

gm.has_pbr_metallic_roughness = true;

gm.pbr_metallic_roughness.base_color_factor[0] = om.Kd[0];
gm.pbr_metallic_roughness.base_color_factor[1] = om.Kd[1];
gm.pbr_metallic_roughness.base_color_factor[2] = om.Kd[2];
gm.pbr_metallic_roughness.base_color_factor[3] = om.d;
gm.pbr_metallic_roughness.base_color_factor[0] = 1.0f;
gm.pbr_metallic_roughness.base_color_factor[1] = 1.0f;
gm.pbr_metallic_roughness.base_color_factor[2] = 1.0f;
gm.pbr_metallic_roughness.base_color_factor[3] = 1.0f;

gm.pbr_metallic_roughness.metallic_factor = 0.0f;
gm.pbr_metallic_roughness.roughness_factor = 1.0f;
Expand All @@ -88,6 +88,12 @@ static void parseMaterialsObj(fastObjMesh* obj, cgltf_data* data)

gm.alpha_mode = (om.illum == 4 || om.illum == 6 || om.illum == 7 || om.illum == 9) ? cgltf_alpha_mode_mask : cgltf_alpha_mode_opaque;
}
else
{
gm.pbr_metallic_roughness.base_color_factor[0] = om.Kd[0];
gm.pbr_metallic_roughness.base_color_factor[1] = om.Kd[1];
gm.pbr_metallic_roughness.base_color_factor[2] = om.Kd[2];
}

if (om.map_d.name)
{
Expand All @@ -96,9 +102,10 @@ static void parseMaterialsObj(fastObjMesh* obj, cgltf_data* data)

gm.alpha_mode = cgltf_alpha_mode_blend;
}

if (om.d < 1.0f)
else if (om.d < 1.0f)
{
gm.pbr_metallic_roughness.base_color_factor[3] = om.d;

gm.alpha_mode = cgltf_alpha_mode_blend;
}
}
Expand Down

0 comments on commit 5dccdc3

Please sign in to comment.