From 43046d82b7d18398027afb6b92ea0be7588f08a8 Mon Sep 17 00:00:00 2001 From: Gaia Clary Date: Mon, 17 May 2021 21:05:20 +0200 Subject: Collada import: use black for Base Color when missing Treat a missing the same as a black diffuse color. The easiest way to see this bug is with a Collada shader like ``` 1 0 0 1 ``` The Collada spec says this should be just ``` color = ``` ie. red everywhere. The importer slots the red into the Principled Emission socket, but since it leaves the Base Color as the default off-white, this is added to red, and the material looks white-pink in the light and red only in the shadows. Putting black in the Base Color makes it look red everywhere. D10939 will also eliminate the much-less-noticeable specular term for this case. Reviewed By: gaiaclary Differential Revision: https://developer.blender.org/D10941 --- source/blender/io/collada/Materials.cpp | 30 ++++++++++++++++++++---------- 1 file changed, 20 insertions(+), 10 deletions(-) (limited to 'source/blender/io/collada') diff --git a/source/blender/io/collada/Materials.cpp b/source/blender/io/collada/Materials.cpp index 4b90e459e61..ac4c65464c8 100644 --- a/source/blender/io/collada/Materials.cpp +++ b/source/blender/io/collada/Materials.cpp @@ -231,22 +231,32 @@ void MaterialNode::set_alpha(COLLADAFW::EffectCommon::OpaqueMode mode, void MaterialNode::set_diffuse(COLLADAFW::ColorOrTexture &cot) { int locy = -300 * (node_map.size() - 2); - if (cot.isColor()) { - COLLADAFW::Color col = cot.getColor(); - bNodeSocket *socket = nodeFindSocket(shader_node, SOCK_IN, "Base Color"); - float *fcol = (float *)socket->default_value; - fcol[0] = material->r = col.getRed(); - fcol[1] = material->g = col.getGreen(); - fcol[2] = material->b = col.getBlue(); - fcol[3] = material->a = col.getAlpha(); - } - else if (cot.isTexture()) { + if (cot.isTexture()) { bNode *texture_node = add_texture_node(cot, -300, locy, "Base Color"); if (texture_node != nullptr) { add_link(texture_node, 0, shader_node, 0); } } + else { + bNodeSocket *socket = nodeFindSocket(shader_node, SOCK_IN, "Base Color"); + float *fcol = (float *)socket->default_value; + + if (cot.isColor()) { + COLLADAFW::Color col = cot.getColor(); + fcol[0] = material->r = col.getRed(); + fcol[1] = material->g = col.getGreen(); + fcol[2] = material->b = col.getBlue(); + fcol[3] = material->a = col.getAlpha(); + } + else { + /* no diffuse term = same as black */ + fcol[0] = material->r = 0.0f; + fcol[1] = material->g = 0.0f; + fcol[2] = material->b = 0.0f; + fcol[3] = material->a = 1.0f; + } + } } Image *MaterialNode::get_diffuse_image() -- cgit v1.2.3