From 3873a0f4908a9fe4770013bc8db0c2762e638015 Mon Sep 17 00:00:00 2001 From: Alex Strand Date: Tue, 22 Sep 2020 15:45:38 +0200 Subject: Fix COLLADA failing to export HDR emission strength HDR is not supported by COLLADA, so clamp to export the closest approximation. Differential Revision: https://developer.blender.org/D8955 --- source/blender/io/collada/Materials.cpp | 1 + source/blender/io/collada/collada_utils.cpp | 17 +++++++++++------ 2 files changed, 12 insertions(+), 6 deletions(-) (limited to 'source/blender/io/collada') diff --git a/source/blender/io/collada/Materials.cpp b/source/blender/io/collada/Materials.cpp index 16a9691d67e..1e02e151d97 100644 --- a/source/blender/io/collada/Materials.cpp +++ b/source/blender/io/collada/Materials.cpp @@ -317,6 +317,7 @@ void MaterialNode::set_emission(COLLADAFW::ColorOrTexture &cot) fcol[2] = col.getBlue(); fcol[3] = col.getAlpha(); } + // texture else if (cot.isTexture()) { bNode *texture_node = add_texture_node(cot, -300, locy, "Emission"); if (texture_node != NULL) { diff --git a/source/blender/io/collada/collada_utils.cpp b/source/blender/io/collada/collada_utils.cpp index 2719578753b..294087ab062 100644 --- a/source/blender/io/collada/collada_utils.cpp +++ b/source/blender/io/collada/collada_utils.cpp @@ -1340,13 +1340,18 @@ COLLADASW::ColorOrTexture bc_get_emission(Material *ma) COLLADASW::ColorOrTexture cot = bc_get_cot_from_shader(shader, "Emission", default_color); - /* Multiply in emission strength. If using texture, emission strength is not - * supported. */ + /* If using texture, emission strength is not supported. */ COLLADASW::Color col = cot.getColor(); - cot.getColor().set(emission_strength * col.getRed(), - emission_strength * col.getGreen(), - emission_strength * col.getBlue(), - col.getAlpha()); + double final_color[3] = {col.getRed(), col.getGreen(), col.getBlue()}; + mul_v3db_db(final_color, emission_strength); + + /* Collada does not support HDR colors, so clamp to 1 keeping channels proportional. */ + double max_color = fmax(fmax(final_color[0], final_color[1]), final_color[2]); + if (max_color > 1.0) { + mul_v3db_db(final_color, 1.0 / max_color); + } + + cot.getColor().set(final_color[0], final_color[1], final_color[2], col.getAlpha()); return cot; } -- cgit v1.2.3