diff options
Diffstat (limited to 'source/blender/collada/Materials.cpp')
-rw-r--r-- | source/blender/collada/Materials.cpp | 47 |
1 files changed, 38 insertions, 9 deletions
diff --git a/source/blender/collada/Materials.cpp b/source/blender/collada/Materials.cpp index aa35b71b9db..e1d5b2e9d5c 100644 --- a/source/blender/collada/Materials.cpp +++ b/source/blender/collada/Materials.cpp @@ -131,18 +131,24 @@ void MaterialNode::add_link(bNode *from_node, int from_index, bNode *to_node, in void MaterialNode::set_reflectivity(COLLADAFW::FloatOrParam &val) { float reflectivity = val.getFloatValue(); - bNodeSocket *socket = nodeFindSocket(shader_node, SOCK_IN, "Metallic"); - ((bNodeSocketValueFloat *)socket->default_value)->value = reflectivity; - - material->metallic = reflectivity; + if (reflectivity >= 0) { + bNodeSocket *socket = nodeFindSocket(shader_node, SOCK_IN, "Metallic"); + ((bNodeSocketValueFloat *)socket->default_value)->value = reflectivity; + material->metallic = reflectivity; + } } +#if 0 +// needs rework to be done for 2.81 void MaterialNode::set_shininess(COLLADAFW::FloatOrParam &val) { float roughness = val.getFloatValue(); - bNodeSocket *socket = nodeFindSocket(shader_node, SOCK_IN, "Roughness"); - ((bNodeSocketValueFloat *)socket->default_value)->value = roughness; + if (roughness >= 0) { + bNodeSocket *socket = nodeFindSocket(shader_node, SOCK_IN, "Roughness"); + ((bNodeSocketValueFloat *)socket->default_value)->value = roughness; + } } +#endif void MaterialNode::set_ior(COLLADAFW::FloatOrParam &val) { @@ -162,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; @@ -176,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 } } |