diff options
author | Alex Strand <astrand130> | 2020-09-22 16:45:38 +0300 |
---|---|---|
committer | Brecht Van Lommel <brecht@blender.org> | 2020-09-22 17:07:37 +0300 |
commit | 3873a0f4908a9fe4770013bc8db0c2762e638015 (patch) | |
tree | 8e7a75eb1720202ddf5ac05d80a5dc5898e02605 /source/blender/io | |
parent | b21e2cfd03f079a04a1527fc3c9ec34084278bd8 (diff) |
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
Diffstat (limited to 'source/blender/io')
-rw-r--r-- | source/blender/io/collada/Materials.cpp | 1 | ||||
-rw-r--r-- | source/blender/io/collada/collada_utils.cpp | 17 |
2 files changed, 12 insertions, 6 deletions
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; } |