Fix T103066: Cycles missing full constant foler for mix float and mix vector
This commit is contained in:
parent
18abc2feaa
commit
312e42708f
Notes:
blender-bot
2023-02-14 00:37:17 +01:00
Referenced by issue #103066, Material appears as black in cycles Referenced by issue #102967, 3.4: Potential candidates for corrective releases
|
@ -386,6 +386,46 @@ void ConstantFolder::fold_mix_color(NodeMix type, bool clamp_factor, bool clamp)
|
|||
}
|
||||
}
|
||||
|
||||
void ConstantFolder::fold_mix_float(bool clamp_factor, bool clamp) const
|
||||
{
|
||||
ShaderInput *fac_in = node->input("Factor");
|
||||
ShaderInput *float1_in = node->input("A");
|
||||
ShaderInput *float2_in = node->input("B");
|
||||
|
||||
float fac = clamp_factor ? saturatef(node->get_float(fac_in->socket_type)) :
|
||||
node->get_float(fac_in->socket_type);
|
||||
bool fac_is_zero = !fac_in->link && fac == 0.0f;
|
||||
bool fac_is_one = !fac_in->link && fac == 1.0f;
|
||||
|
||||
/* remove no-op node when factor is 0.0 */
|
||||
if (fac_is_zero) {
|
||||
if (try_bypass_or_make_constant(float1_in, clamp)) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
/* remove useless mix floats nodes */
|
||||
if (float1_in->link && float2_in->link) {
|
||||
if (float1_in->link == float2_in->link) {
|
||||
try_bypass_or_make_constant(float1_in, clamp);
|
||||
return;
|
||||
}
|
||||
}
|
||||
else if (!float1_in->link && !float2_in->link) {
|
||||
float value1 = node->get_float(float1_in->socket_type);
|
||||
float value2 = node->get_float(float2_in->socket_type);
|
||||
if (value1 == value2) {
|
||||
try_bypass_or_make_constant(float1_in, clamp);
|
||||
return;
|
||||
}
|
||||
}
|
||||
/* remove no-op mix float node when factor is 1.0 */
|
||||
if (fac_is_one) {
|
||||
try_bypass_or_make_constant(float2_in, clamp);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
void ConstantFolder::fold_math(NodeMathType type) const
|
||||
{
|
||||
ShaderInput *value1_in = node->input("Value1");
|
||||
|
|
|
@ -52,6 +52,7 @@ class ConstantFolder {
|
|||
/* Specific nodes. */
|
||||
void fold_mix(NodeMix type, bool clamp) const;
|
||||
void fold_mix_color(NodeMix type, bool clamp_factor, bool clamp) const;
|
||||
void fold_mix_float(bool clamp_factor, bool clamp) const;
|
||||
void fold_math(NodeMathType type) const;
|
||||
void fold_vector_math(NodeVectorMathType type) const;
|
||||
void fold_mapping(NodeMappingType type) const;
|
||||
|
|
|
@ -5132,6 +5132,9 @@ void MixFloatNode::constant_fold(const ConstantFolder &folder)
|
|||
}
|
||||
folder.make_constant(a * (1 - fac) + b * fac);
|
||||
}
|
||||
else {
|
||||
folder.fold_mix_float(use_clamp, false);
|
||||
}
|
||||
}
|
||||
|
||||
/* Mix Vector */
|
||||
|
@ -5185,6 +5188,9 @@ void MixVectorNode::constant_fold(const ConstantFolder &folder)
|
|||
}
|
||||
folder.make_constant(a * (one_float3() - fac) + b * fac);
|
||||
}
|
||||
else {
|
||||
folder.fold_mix_color(NODE_MIX_BLEND, use_clamp, false);
|
||||
}
|
||||
}
|
||||
|
||||
/* Mix Vector Non Uniform */
|
||||
|
|
Loading…
Reference in New Issue