Fix COLLADA failing to export HDR emission strength

HDR is not supported by COLLADA, so clamp to export the closest approximation.

Differential Revision: https://developer.blender.org/D8955
This commit is contained in:
Alex Strand 2020-09-22 15:45:38 +02:00 committed by Brecht Van Lommel
parent b21e2cfd03
commit 3873a0f490
2 changed files with 12 additions and 6 deletions

View File

@ -317,6 +317,7 @@ void MaterialNode::set_emission(COLLADAFW::ColorOrTexture &cot)
fcol[2] = col.getBlue();
fcol[3] = col.getAlpha();
}
// texture
else if (cot.isTexture()) {
bNode *texture_node = add_texture_node(cot, -300, locy, "Emission");
if (texture_node != NULL) {

View File

@ -1340,13 +1340,18 @@ COLLADASW::ColorOrTexture bc_get_emission(Material *ma)
COLLADASW::ColorOrTexture cot = bc_get_cot_from_shader(shader, "Emission", default_color);
/* Multiply in emission strength. If using texture, emission strength is not
* supported. */
/* If using texture, emission strength is not supported. */
COLLADASW::Color col = cot.getColor();
cot.getColor().set(emission_strength * col.getRed(),
emission_strength * col.getGreen(),
emission_strength * col.getBlue(),
col.getAlpha());
double final_color[3] = {col.getRed(), col.getGreen(), col.getBlue()};
mul_v3db_db(final_color, emission_strength);
/* Collada does not support HDR colors, so clamp to 1 keeping channels proportional. */
double max_color = fmax(fmax(final_color[0], final_color[1]), final_color[2]);
if (max_color > 1.0) {
mul_v3db_db(final_color, 1.0 / max_color);
}
cot.getColor().set(final_color[0], final_color[1], final_color[2], col.getAlpha());
return cot;
}