Cycles Denoising: Add more failsafes for invalid pixels

Now, when there is no usable neighboring pixel for denoising, the noisy value
is preserved instead of producing a NaN.
Also, negative results are clamped to zero.

Note that there are just workarounds that don't fix the underlying problems,
but these issues are very rare and I'm not sure if it's even possible to fix
the underlying problems without introducing a significant slowdown or quality
decrease in other situations.
Because of that and since 2.79 is happening very soon, I just went for these
workarounds for now.
This commit is contained in:
Lukas Stockner 2017-06-11 01:44:06 +02:00
parent 0dd6e5bfee
commit 558bea2252

@ -81,6 +81,12 @@ ccl_device_inline void kernel_filter_finalize(int x, int y, int w, int h,
(void) storage_stride;
#endif
if(XtWX[0] < 1e-3f) {
/* There is not enough information to determine a denoised result.
* As a fallback, keep the original value of the pixel. */
return;
}
/* The weighted average of pixel colors (essentially, the NLM-filtered image).
* In case the solution of the linear model fails due to numerical issues,
* fall back to this value. */
@ -93,6 +99,9 @@ ccl_device_inline void kernel_filter_finalize(int x, int y, int w, int h,
final_color = mean_color;
}
/* Clamp pixel value to positive values. */
final_color = max(final_color, make_float3(0.0f, 0.0f, 0.0f));
ccl_global float *combined_buffer = buffer + (y*buffer_params.y + x + buffer_params.x)*buffer_params.z;
final_color *= sample;
if(buffer_params.w) {