[Bf-blender-cvs] [8c618371507] master: Incompatible usage of the Collada transparency value

Gaia Clary noreply at git.blender.org
Mon Jul 22 19:03:58 CEST 2019


Commit: 8c618371507fc95d51671d2f807e864adf1f4791
Author: Gaia Clary
Date:   Mon Jul 22 18:57:44 2019 +0200
Branches: master
https://developer.blender.org/rB8c618371507fc95d51671d2f807e864adf1f4791

Incompatible usage of the Collada transparency value

Some external tools seem to have issues with the definition
of Collada <transparency> - a float value in range (0,1).
However it is possible to use the <transparent> color as a container
for the <transparency> value. This seems to be a more reliable
method to export transparency values from Blender PBSDF Shaders.

The relevant documentation is in the collada 1.14 reference manual,
page 7-5 about the usage of transparent and transparency.

This fix makes export and import of the <transparency>
and <transparent> values more convenient and more reliable.

Reviewers: brecht, jesterking

Reviewed By: brecht

Differential Revision: https://developer.blender.org/D5305

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

M	release/datafiles/locale
M	release/scripts/addons
M	release/scripts/addons_contrib
M	source/blender/collada/EffectExporter.cpp
M	source/blender/collada/Materials.cpp

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

diff --git a/release/datafiles/locale b/release/datafiles/locale
index 0f771b0f380..6625026f62f 160000
--- a/release/datafiles/locale
+++ b/release/datafiles/locale
@@ -1 +1 @@
-Subproject commit 0f771b0f380a1ae21d859416043c6119f66e40c9
+Subproject commit 6625026f62f492dd677f5f29c68b9d70c96fb34b
diff --git a/release/scripts/addons b/release/scripts/addons
index aa3366b7805..97929851191 160000
--- a/release/scripts/addons
+++ b/release/scripts/addons
@@ -1 +1 @@
-Subproject commit aa3366b7805bbe4d1afee890bda81b6d91bd47be
+Subproject commit 979298511916b25ec97bb22feb1c06cc9fbc86dd
diff --git a/release/scripts/addons_contrib b/release/scripts/addons_contrib
index 0aa23a4d617..b4fce25e94e 160000
--- a/release/scripts/addons_contrib
+++ b/release/scripts/addons_contrib
@@ -1 +1 @@
-Subproject commit 0aa23a4d6177bed4c12392c81d0b767a8b35fe61
+Subproject commit b4fce25e94ec139554e821f58bbada3384b13afa
diff --git a/source/blender/collada/EffectExporter.cpp b/source/blender/collada/EffectExporter.cpp
index a784776d342..80f84738f6e 100644
--- a/source/blender/collada/EffectExporter.cpp
+++ b/source/blender/collada/EffectExporter.cpp
@@ -102,7 +102,12 @@ void EffectsExporter::set_shader_type(COLLADASW::EffectProfile &ep, Material *ma
 void EffectsExporter::set_transparency(COLLADASW::EffectProfile &ep, Material *ma)
 {
   double alpha = bc_get_alpha(ma);
-  ep.setTransparency(alpha, false, "alpha");
+  if (alpha < 1) {
+    // workaround use <transparent> to avoid wrong handling of <transparency> by other tools
+    COLLADASW::ColorOrTexture cot = bc_get_cot(0, 0, 0, alpha);
+    ep.setTransparent(cot, false, "alpha");
+    ep.setOpaque(COLLADASW::EffectProfile::A_ONE);
+  }
 }
 
 void EffectsExporter::set_diffuse_color(COLLADASW::EffectProfile &ep, Material *ma)
@@ -134,7 +139,9 @@ void EffectsExporter::set_reflective(COLLADASW::EffectProfile &ep, Material *ma)
 void EffectsExporter::set_reflectivity(COLLADASW::EffectProfile &ep, Material *ma)
 {
   double reflectivity = bc_get_reflectivity(ma);
-  ep.setReflectivity(reflectivity, false, "specular");
+  if (reflectivity > 0.0) {
+    ep.setReflectivity(reflectivity, false, "specular");
+  }
 }
 
 void EffectsExporter::set_emission(COLLADASW::EffectProfile &ep, Material *ma)
diff --git a/source/blender/collada/Materials.cpp b/source/blender/collada/Materials.cpp
index d8a0f06c12b..e1d5b2e9d5c 100644
--- a/source/blender/collada/Materials.cpp
+++ b/source/blender/collada/Materials.cpp
@@ -168,13 +168,37 @@ void MaterialNode::set_alpha(COLLADAFW::EffectCommon::OpaqueMode mode,
                              COLLADAFW::ColorOrTexture &cot,
                              COLLADAFW::FloatOrParam &val)
 {
+  /*  Handling the alpha value according to the Collada 1.4 reference guide
+   *  see page 7-5 Determining Transparency (Opacity)
+   */
+
   if (effect == nullptr) {
     return;
   }
 
   if (cot.isColor() || !cot.isValid()) {
-    COLLADAFW::Color col = (cot.isValid()) ? cot.getColor() : COLLADAFW::Color(1, 1, 1, 1);
-    float alpha = val.getFloatValue() * col.getAlpha();  // Assuming A_ONE opaque mode
+    // transparent_cot is either a color or not defined
+
+    float transparent_alpha;
+    if (cot.isValid()) {
+      COLLADAFW::Color col = cot.getColor();
+      transparent_alpha = col.getAlpha();
+    }
+    else {
+      // no transparent color defined
+      transparent_alpha = 1;
+    }
+
+    float transparency_alpha = val.getFloatValue();
+    if (transparency_alpha < 0) {
+      // transparency is not defined
+      transparency_alpha = 1;  // set to opaque
+    }
+
+    float alpha = transparent_alpha * transparency_alpha;
+    if (mode == COLLADASW::EffectProfile::RGB_ZERO) {
+      alpha = 1 - alpha;
+    }
 
     bNodeSocket *socket = nodeFindSocket(shader_node, SOCK_IN, "Alpha");
     ((bNodeSocketValueFloat *)socket->default_value)->value = alpha;
@@ -182,7 +206,6 @@ void MaterialNode::set_alpha(COLLADAFW::EffectCommon::OpaqueMode mode,
   else if (cot.isTexture()) {
     int locy = -300 * (node_map.size() - 2);
     add_texture_node(cot, -300, locy, "Alpha");
-    // TODO: Connect node
   }
 }



More information about the Bf-blender-cvs mailing list