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:
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user