[Bf-blender-cvs] [3873a0f4908] master: Fix COLLADA failing to export HDR emission strength

Alex Strand noreply at git.blender.org
Tue Sep 22 16:07:55 CEST 2020


Commit: 3873a0f4908a9fe4770013bc8db0c2762e638015
Author: Alex Strand
Date:   Tue Sep 22 15:45:38 2020 +0200
Branches: master
https://developer.blender.org/rB3873a0f4908a9fe4770013bc8db0c2762e638015

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

===================================================================

M	source/blender/io/collada/Materials.cpp
M	source/blender/io/collada/collada_utils.cpp

===================================================================

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;
 }



More information about the Bf-blender-cvs mailing list