From a998f0a48209bd226f1ee0d53cc7cbde4364b077 Mon Sep 17 00:00:00 2001 From: bqqbarbhg Date: Fri, 12 Apr 2024 03:52:46 +0300 Subject: [PATCH 1/4] Convert FBX material colors from linear to sRGB --- modules/fbx/fbx_document.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/modules/fbx/fbx_document.cpp b/modules/fbx/fbx_document.cpp index 1dbe4c535ad6..e857640bd0b8 100644 --- a/modules/fbx/fbx_document.cpp +++ b/modules/fbx/fbx_document.cpp @@ -1080,7 +1080,7 @@ Error FBXDocument::_parse_materials(Ref p_state) { if (fbx_material->pbr.base_color.has_value) { Color albedo = _material_color(fbx_material->pbr.base_color, fbx_material->pbr.base_factor); - material->set_albedo(albedo); + material->set_albedo(albedo.linear_to_srgb()); } if (fbx_material->features.double_sided.enabled) { @@ -1232,7 +1232,7 @@ Error FBXDocument::_parse_materials(Ref p_state) { if (fbx_material->pbr.emission_color.has_value) { material->set_feature(BaseMaterial3D::FEATURE_EMISSION, true); - material->set_emission(_material_color(fbx_material->pbr.emission_color)); + material->set_emission(_material_color(fbx_material->pbr.emission_color).linear_to_srgb()); material->set_emission_energy_multiplier(float(fbx_material->pbr.emission_factor.value_real)); } From d238b0ef572599df5295e49d502b31ccaa9d0773 Mon Sep 17 00:00:00 2001 From: bqqbarbhg Date: Fri, 12 Apr 2024 03:52:57 +0300 Subject: [PATCH 2/4] Fix FBX emission_texture copy-paste issue --- modules/fbx/fbx_document.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/fbx/fbx_document.cpp b/modules/fbx/fbx_document.cpp index e857640bd0b8..682cd02efc26 100644 --- a/modules/fbx/fbx_document.cpp +++ b/modules/fbx/fbx_document.cpp @@ -1236,7 +1236,7 @@ Error FBXDocument::_parse_materials(Ref p_state) { material->set_emission_energy_multiplier(float(fbx_material->pbr.emission_factor.value_real)); } - const ufbx_texture *emission_texture = _get_file_texture(fbx_material->pbr.ambient_occlusion.texture); + const ufbx_texture *emission_texture = _get_file_texture(fbx_material->pbr.emission_color.texture); if (emission_texture) { material->set_texture(BaseMaterial3D::TEXTURE_EMISSION, _get_texture(p_state, GLTFTextureIndex(emission_texture->file_index), TEXTURE_TYPE_GENERIC)); material->set_feature(BaseMaterial3D::FEATURE_EMISSION, true); From 5e52db5c939416379548d0f101cb58863811bcf7 Mon Sep 17 00:00:00 2001 From: bqqbarbhg Date: Fri, 12 Apr 2024 04:02:50 +0300 Subject: [PATCH 3/4] Fix FBX orthographic camera size --- modules/fbx/fbx_document.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/fbx/fbx_document.cpp b/modules/fbx/fbx_document.cpp index 682cd02efc26..846dcc753eee 100644 --- a/modules/fbx/fbx_document.cpp +++ b/modules/fbx/fbx_document.cpp @@ -1266,7 +1266,7 @@ Error FBXDocument::_parse_cameras(Ref p_state) { camera->set_fov(Math::deg_to_rad(real_t(fbx_camera->field_of_view_deg.y))); } else { camera->set_perspective(false); - camera->set_size_mag(real_t(fbx_camera->orthographic_size.y)); + camera->set_size_mag(real_t(fbx_camera->orthographic_size.y * 0.5f)); } if (fbx_camera->near_plane != 0.0f) { camera->set_depth_near(fbx_camera->near_plane); From 659597b29064c683aa5fd790fd2064a0a1296909 Mon Sep 17 00:00:00 2001 From: bqqbarbhg Date: Sat, 13 Apr 2024 03:12:03 +0300 Subject: [PATCH 4/4] Enable FBX albedo factor when textures are bound --- modules/fbx/fbx_document.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/modules/fbx/fbx_document.cpp b/modules/fbx/fbx_document.cpp index 846dcc753eee..63766247ee0c 100644 --- a/modules/fbx/fbx_document.cpp +++ b/modules/fbx/fbx_document.cpp @@ -1178,7 +1178,11 @@ Error FBXDocument::_parse_materials(Ref p_state) { } // Combined textures and factors are very unreliable in FBX - material->set_albedo(Color(1, 1, 1)); + Color albedo_factor = Color(1, 1, 1); + if (fbx_material->pbr.base_factor.has_value) { + albedo_factor *= (float)fbx_material->pbr.base_factor.value_real; + } + material->set_albedo(albedo_factor.linear_to_srgb()); // TODO: Does not support rotation, could be inverted? material->set_uv1_offset(_as_vec3(base_texture->uv_transform.translation));