diff options
author | Gaia Clary <gaia.clary@machinimatrix.org> | 2019-07-22 19:57:44 +0300 |
---|---|---|
committer | Gaia Clary <gaia.clary@machinimatrix.org> | 2019-07-22 20:03:56 +0300 |
commit | 8c618371507fc95d51671d2f807e864adf1f4791 (patch) | |
tree | d3f1e4817eef35f3a508b052f14d5c171dd8adb1 /source | |
parent | 2de95e8149a3483341a29c36de9e1200e398c26a (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
Diffstat (limited to 'source')
-rw-r--r-- | source/blender/collada/EffectExporter.cpp | 11 | ||||
-rw-r--r-- | source/blender/collada/Materials.cpp | 29 |
2 files changed, 35 insertions, 5 deletions
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 } } |