Collada import: use black for Base Color when missing <diffuse>

Treat a missing <diffuse> the same as a black diffuse color.

The easiest way to see this bug is with a Collada shader like

```
          <constant>
            <emission>
              <color sid="emission">1 0 0 1</color>
            </emission>
          </constant>
```

The Collada spec says this should be just

```
color = <emission>
```

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
This commit is contained in:
Gaia Clary 2021-05-17 21:05:20 +02:00
parent 542b8da831
commit 43046d82b7
1 changed files with 20 additions and 10 deletions

View File

@ -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()