Skip to content

Commit

Permalink
Rearrange material parsing code a bit
Browse files Browse the repository at this point in the history
This is necessary to correctly process scenes processed by
glTF-Transform as it inserts a dummy pbrMetallicRoughness node.
  • Loading branch information
zeux committed Dec 21, 2024
1 parent 6dcf754 commit b82ce9e
Showing 1 changed file with 13 additions and 8 deletions.
21 changes: 13 additions & 8 deletions src/scene.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -472,14 +472,7 @@ bool loadScene(Geometry& geometry, std::vector<Material>& materials, std::vector

mat.diffuseFactor = vec4(1);

if (material->has_pbr_metallic_roughness)
{
if (material->pbr_metallic_roughness.base_color_texture.texture)
mat.albedoTexture = 1 + int(cgltf_texture_index(data, material->pbr_metallic_roughness.base_color_texture.texture));

mat.diffuseFactor = vec4(material->pbr_metallic_roughness.base_color_factor[0], material->pbr_metallic_roughness.base_color_factor[1], material->pbr_metallic_roughness.base_color_factor[2], material->pbr_metallic_roughness.base_color_factor[3]);
}
else if (material->has_pbr_specular_glossiness)
if (material->has_pbr_specular_glossiness)
{
if (material->pbr_specular_glossiness.diffuse_texture.texture)
mat.albedoTexture = 1 + int(cgltf_texture_index(data, material->pbr_specular_glossiness.diffuse_texture.texture));
Expand All @@ -491,6 +484,18 @@ bool loadScene(Geometry& geometry, std::vector<Material>& materials, std::vector

mat.specularFactor = vec4(material->pbr_specular_glossiness.specular_factor[0], material->pbr_specular_glossiness.specular_factor[1], material->pbr_specular_glossiness.specular_factor[2], material->pbr_specular_glossiness.glossiness_factor);
}
else if (material->has_pbr_metallic_roughness)
{
if (material->pbr_metallic_roughness.base_color_texture.texture)
mat.albedoTexture = 1 + int(cgltf_texture_index(data, material->pbr_metallic_roughness.base_color_texture.texture));

mat.diffuseFactor = vec4(material->pbr_metallic_roughness.base_color_factor[0], material->pbr_metallic_roughness.base_color_factor[1], material->pbr_metallic_roughness.base_color_factor[2], material->pbr_metallic_roughness.base_color_factor[3]);

if (material->pbr_metallic_roughness.metallic_roughness_texture.texture)
mat.specularTexture = 1 + int(cgltf_texture_index(data, material->pbr_metallic_roughness.metallic_roughness_texture.texture));

mat.specularFactor = vec4(1, 1, 1, 1 - material->pbr_metallic_roughness.roughness_factor);
}

if (material->normal_texture.texture)
mat.normalTexture = 1 + int(cgltf_texture_index(data, material->normal_texture.texture));
Expand Down

0 comments on commit b82ce9e

Please sign in to comment.