Changeset View
Changeset View
Standalone View
Standalone View
source/blender/io/wavefront_obj/importer/obj_import_mtl.cc
| Context not available. | |||||
| bool do_glass = false; | bool do_glass = false; | ||||
| /* See https://wikipedia.org/wiki/Wavefront_.obj_file for possible values of illum. */ | /* See https://wikipedia.org/wiki/Wavefront_.obj_file for possible values of illum. */ | ||||
| switch (illum) { | switch (illum) { | ||||
| case 1: { | case -1: | ||||
deadpin: For consistency, should the code that parses the "illum" value line default to 1 as well if the… | |||||
aras_pAuthorUnsubmitted Done Inline ActionsGood catch! I noticed that the python importer was parsing "illum" as a float (apparently some .mtl files have that), so I did that too. aras_p: Good catch! I noticed that the python importer was parsing "illum" as a float (apparently some . | |||||
| case 1: | |||||
| /* Base color on, ambient on. */ | /* Base color on, ambient on. */ | ||||
| break; | break; | ||||
| } | |||||
| case 2: { | case 2: { | ||||
| /* Highlight on. */ | /* Highlight on. */ | ||||
| do_highlight = true; | do_highlight = true; | ||||
| Context not available. | |||||
| * Principled BSDF: */ | * Principled BSDF: */ | ||||
| /* Specular: average of Ks components. */ | /* Specular: average of Ks components. */ | ||||
| float specular = (mtl_mat_.Ks[0] + mtl_mat_.Ks[1] + mtl_mat_.Ks[2]) / 3; | float specular = (mtl_mat_.Ks[0] + mtl_mat_.Ks[1] + mtl_mat_.Ks[2]) / 3; | ||||
| /* Roughness: map 0..1000 range to 1..0 and apply non-linearity. */ | |||||
| float clamped_ns = std::max(0.0f, std::min(1000.0f, mtl_mat_.Ns)); | |||||
| float roughness = 1.0f - sqrt(clamped_ns / 1000.0f); | |||||
| /* Metallic: average of Ka components. */ | |||||
| float metallic = (mtl_mat_.Ka[0] + mtl_mat_.Ka[1] + mtl_mat_.Ka[2]) / 3; | |||||
| float ior = mtl_mat_.Ni; | |||||
| float alpha = mtl_mat_.d; | |||||
| if (specular < 0.0f) { | if (specular < 0.0f) { | ||||
| specular = static_cast<float>(do_highlight); | specular = do_highlight ? 1.0f : 0.0f; | ||||
| } | } | ||||
| /* Roughness: map 0..1000 range to 1..0 and apply non-linearity. */ | |||||
| float roughness; | |||||
| if (mtl_mat_.Ns < 0.0f) { | if (mtl_mat_.Ns < 0.0f) { | ||||
| roughness = static_cast<float>(!do_highlight); | roughness = do_highlight ? 0.0f : 1.0f; | ||||
| } | } | ||||
| if (metallic < 0.0f) { | else { | ||||
| if (do_reflection) { | float clamped_ns = std::max(0.0f, std::min(1000.0f, mtl_mat_.Ns)); | ||||
| roughness = 1.0f - sqrt(clamped_ns / 1000.0f); | |||||
| } | |||||
| /* Metallic: average of Ka components. */ | |||||
| float metallic = (mtl_mat_.Ka[0] + mtl_mat_.Ka[1] + mtl_mat_.Ka[2]) / 3; | |||||
| if (do_reflection) { | |||||
| if (metallic < 0.0f) { | |||||
| metallic = 1.0f; | metallic = 1.0f; | ||||
| } | } | ||||
| } | } | ||||
| else { | else { | ||||
| metallic = 0.0f; | metallic = 0.0f; | ||||
| } | } | ||||
| float ior = mtl_mat_.Ni; | |||||
| if (ior < 0) { | if (ior < 0) { | ||||
| if (do_tranparency) { | if (do_tranparency) { | ||||
| ior = 1.0f; | ior = 1.0f; | ||||
| Context not available. | |||||
| ior = 1.5f; | ior = 1.5f; | ||||
| } | } | ||||
| } | } | ||||
| if (alpha < 0) { | float alpha = mtl_mat_.d; | ||||
| if (do_tranparency) { | if (do_tranparency && alpha < 0) { | ||||
| alpha = 1.0f; | alpha = 1.0f; | ||||
| } | |||||
| } | } | ||||
| float3 base_color = {std::max(0.0f, mtl_mat_.Kd[0]), | |||||
| std::max(0.0f, mtl_mat_.Kd[1]), | |||||
| std::max(0.0f, mtl_mat_.Kd[2])}; | |||||
| float3 emission_color = {std::max(0.0f, mtl_mat_.Ke[0]), | |||||
| std::max(0.0f, mtl_mat_.Ke[1]), | |||||
| std::max(0.0f, mtl_mat_.Ke[2])}; | |||||
| set_property_of_socket(SOCK_RGBA, "Base Color", {base_color, 3}, bsdf_); | float3 base_color = {mtl_mat_.Kd[0], mtl_mat_.Kd[1], mtl_mat_.Kd[2]}; | ||||
| set_property_of_socket(SOCK_RGBA, "Emission", {emission_color, 3}, bsdf_); | if (base_color.x >= 0 && base_color.y >= 0 && base_color.z >= 0) { | ||||
| set_property_of_socket(SOCK_RGBA, "Base Color", {base_color, 3}, bsdf_); | |||||
| /* Viewport shading uses legacy r,g,b base color. */ | |||||
| mat->r = base_color.x; | |||||
| mat->g = base_color.y; | |||||
| mat->b = base_color.z; | |||||
| } | |||||
| float3 emission_color = {mtl_mat_.Ke[0], mtl_mat_.Ke[1], mtl_mat_.Ke[2]}; | |||||
| if (emission_color.x >= 0 && emission_color.y >= 0 && emission_color.z >= 0) { | |||||
| set_property_of_socket(SOCK_RGBA, "Emission", {emission_color, 3}, bsdf_); | |||||
| } | |||||
| if (mtl_mat_.texture_maps.contains_as(eMTLSyntaxElement::map_Ke)) { | if (mtl_mat_.texture_maps.contains_as(eMTLSyntaxElement::map_Ke)) { | ||||
| set_property_of_socket(SOCK_FLOAT, "Emission Strength", {1.0f}, bsdf_); | set_property_of_socket(SOCK_FLOAT, "Emission Strength", {1.0f}, bsdf_); | ||||
| } | } | ||||
| set_property_of_socket(SOCK_FLOAT, "Specular", {specular}, bsdf_); | set_property_of_socket(SOCK_FLOAT, "Specular", {specular}, bsdf_); | ||||
| set_property_of_socket(SOCK_FLOAT, "Roughness", {roughness}, bsdf_); | set_property_of_socket(SOCK_FLOAT, "Roughness", {roughness}, bsdf_); | ||||
| mat->roughness = roughness; | |||||
| set_property_of_socket(SOCK_FLOAT, "Metallic", {metallic}, bsdf_); | set_property_of_socket(SOCK_FLOAT, "Metallic", {metallic}, bsdf_); | ||||
| set_property_of_socket(SOCK_FLOAT, "IOR", {ior}, bsdf_); | mat->metallic = metallic; | ||||
| set_property_of_socket(SOCK_FLOAT, "Alpha", {alpha}, bsdf_); | if (ior != -1) { | ||||
| set_property_of_socket(SOCK_FLOAT, "IOR", {ior}, bsdf_); | |||||
| } | |||||
| if (alpha != -1) { | |||||
| set_property_of_socket(SOCK_FLOAT, "Alpha", {alpha}, bsdf_); | |||||
| } | |||||
| if (do_tranparency) { | if (do_tranparency) { | ||||
| mat->blend_method = MA_BM_BLEND; | mat->blend_method = MA_BM_BLEND; | ||||
| } | } | ||||
| Context not available. | |||||
For consistency, should the code that parses the "illum" value line default to 1 as well if the value is not present? Currently it defaults to 2: parse_int(line, 2, material->illum);