Fix #127093: Kuwahara node produces NaNs

The Kuwahara node produces NaNs if the pixels have a very high local
standard deviation and sharpness is also high. This is because the
weighted sum of the Kuwahara sectors can have a zero total weight, which
causes zero division. To fix this, we return the original color if the
total weight is zero.

Pull Request: https://projects.blender.org/blender/blender/pulls/128378
This commit is contained in:
Omar Emara
2024-09-30 17:29:44 +02:00
committed by Omar Emara
parent b22a1499a4
commit 1b392ef016
2 changed files with 18 additions and 2 deletions

View File

@@ -266,7 +266,15 @@ void KuwaharaAnisotropicOperation::update_memory_buffer_partial(MemoryBuffer *ou
sum_of_weights += weight;
weighted_sum += color_mean * weight;
}
weighted_sum /= sum_of_weights;
/* Fallback to the original color if all sector weights are zero due to very high standard
* deviation and sharpness. */
if (sum_of_weights == 0.0f) {
weighted_sum = center_color;
}
else {
weighted_sum /= sum_of_weights;
}
copy_v4_v4(it.out, weighted_sum);
}

View File

@@ -249,7 +249,15 @@ void main()
sum_of_weights += weight;
weighted_sum += color_mean * weight;
}
weighted_sum /= sum_of_weights;
/* Fallback to the original color if all sector weights are zero due to very high standard
* deviation and sharpness. */
if (sum_of_weights == 0.0) {
weighted_sum = center_color;
}
else {
weighted_sum /= sum_of_weights;
}
imageStore(output_img, texel, weighted_sum);
}