From e1bcd08f61314909598ecb032104dc520fc22d91 Mon Sep 17 00:00:00 2001 From: Nikita Lisitsa Date: Tue, 25 Feb 2025 14:13:12 +0200 Subject: [PATCH] Fix #135073: OBJ import of emissive colors The emissions strength was only set when using an emissive texture. Additionally, for colors brighter than 1.0, normalize the color into 0..1 range and set the strength accordingly. Pull-Request: https://projects.blender.org/blender/blender/pulls/135094 --- .../wavefront_obj/importer/obj_import_mtl.cc | 21 +++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/source/blender/io/wavefront_obj/importer/obj_import_mtl.cc b/source/blender/io/wavefront_obj/importer/obj_import_mtl.cc index d24d7eb56c9..1fe8a194f8a 100644 --- a/source/blender/io/wavefront_obj/importer/obj_import_mtl.cc +++ b/source/blender/io/wavefront_obj/importer/obj_import_mtl.cc @@ -302,13 +302,26 @@ static void set_bsdf_socket_values(bNode *bsdf, Material *mat, const MTLMaterial mat->b = base_color.z; } - float3 emission_color = mtl_mat.emission_color; - if (emission_color.x >= 0 && emission_color.y >= 0 && emission_color.z >= 0) { - set_property_of_socket(SOCK_RGBA, "Emission Color", {emission_color, 3}, bsdf); - } if (mtl_mat.tex_map_of_type(MTLTexMapType::Emission).is_valid()) { set_property_of_socket(SOCK_FLOAT, "Emission Strength", {1.0f}, bsdf); } + + float3 emission_color = mtl_mat.emission_color; + if (emission_color.x >= 0 && emission_color.y >= 0 && emission_color.z >= 0) { + float emission_strength = fmax(emission_color.x, fmax(emission_color.y, emission_color.z)); + if (emission_strength > 1.0f) { + /* For colors brighter than 1.0, change color to be in 0..1 range, and set emission + * strength accordingly. */ + set_property_of_socket( + SOCK_RGBA, "Emission Color", {emission_color / emission_strength, 3}, bsdf); + set_property_of_socket(SOCK_FLOAT, "Emission Strength", {emission_strength}, bsdf); + } + else { + set_property_of_socket(SOCK_RGBA, "Emission Color", {emission_color, 3}, bsdf); + set_property_of_socket(SOCK_FLOAT, "Emission Strength", {1.0f}, bsdf); + } + } + set_property_of_socket(SOCK_FLOAT, "Specular IOR Level", {specular}, bsdf); set_property_of_socket(SOCK_FLOAT, "Roughness", {roughness}, bsdf); mat->roughness = roughness;