Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGaia Clary <gaia.clary@machinimatrix.org>2019-07-22 19:57:44 +0300
committerBrecht Van Lommel <brechtvanlommel@gmail.com>2019-07-24 17:17:53 +0300
commit73379fd974c17fd14f4b64b983623e6e5e2363e4 (patch)
tree0561156a60150acf04c015be8688234e14ca705d
parent33acb752b350681ee928abcebca3d91e37ea0ab3 (diff)
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/scripts/addons_contrib0
-rw-r--r--source/blender/collada/EffectExporter.cpp11
-rw-r--r--source/blender/collada/Materials.cpp29
3 files changed, 35 insertions, 5 deletions
diff --git a/release/scripts/addons_contrib b/release/scripts/addons_contrib
-Subproject 0aa23a4d6177bed4c12392c81d0b767a8b35fe6
+Subproject b4fce25e94ec139554e821f58bbada3384b13af
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
}
}