Fix Cycles denoising NaNs with a 1 sample renders.
authorBrecht Van Lommel <brechtvanlommel@gmail.com>
Fri, 21 Jul 2017 19:43:49 +0000 (21:43 +0200)
committerBrecht Van Lommel <brechtvanlommel@gmail.com>
Sat, 22 Jul 2017 21:58:51 +0000 (23:58 +0200)
This was causing different render results with different compilers. We
can't do much useful with 1 sample, but better for debugging.

intern/cycles/kernel/filter/filter_prefilter.h

index d5ae1b7392754269f643ee440e72b9b4887b5afd..a0b89c1111fcb3b473db80ae67b8f5060bae12f7 100644 (file)
@@ -61,8 +61,8 @@ ccl_device void kernel_filter_divide_shadow(int sample,
                varA = max(0.0f, varA - unfilteredA[idx]*unfilteredA[idx]*odd_sample);
                varB = max(0.0f, varB - unfilteredB[idx]*unfilteredB[idx]*even_sample);
        }
-       varA /= (odd_sample - 1);
-       varB /= (even_sample - 1);
+       varA /= max(odd_sample - 1, 1);
+       varB /= max(even_sample - 1, 1);
 
        sampleVariance[idx]  = 0.5f*(varA + varB) / sample;
        sampleVarianceV[idx] = 0.5f * (varA - varB) * (varA - varB) / (sample*sample);
@@ -96,11 +96,17 @@ ccl_device void kernel_filter_get_feature(int sample,
        int idx = (y-rect.y)*buffer_w + (x - rect.x);
 
        mean[idx] = center_buffer[m_offset] / sample;
-       if(use_split_variance) {
-               variance[idx] = max(0.0f, (center_buffer[v_offset] - mean[idx]*mean[idx]*sample) / (sample * (sample-1)));
+       if (sample > 1) {
+               if(use_split_variance) {
+                       variance[idx] = max(0.0f, (center_buffer[v_offset] - mean[idx]*mean[idx]*sample) / (sample * (sample-1)));
+               }
+               else {
+                       variance[idx] = center_buffer[v_offset] / (sample * (sample-1));
+               }
        }
        else {
-               variance[idx] = center_buffer[v_offset] / (sample * (sample-1));
+               /* Can't compute variance with single sample, just set it very high. */
+               variance[idx] = 1e10f;
        }
 }