[Bf-blender-cvs] [e05552f7c4a] master: Revert "Fix T74572: adaptive sampling not scaling render passes correctly"

Brecht Van Lommel noreply at git.blender.org
Mon Apr 6 23:23:55 CEST 2020


Commit: e05552f7c4ac27faa510048e8c010e4323acb569
Author: Brecht Van Lommel
Date:   Mon Apr 6 23:19:01 2020 +0200
Branches: master
https://developer.blender.org/rBe05552f7c4ac27faa510048e8c010e4323acb569

Revert "Fix T74572: adaptive sampling not scaling render passes correctly"

This reverts commit 82a8da0ec38a70efde4a91957824c67d0e60b8ad. It was completely
wrong. Fixes T75388.

===================================================================

M	intern/cycles/render/buffers.cpp
M	intern/cycles/render/film.cpp
M	intern/cycles/render/film.h

===================================================================

diff --git a/intern/cycles/render/buffers.cpp b/intern/cycles/render/buffers.cpp
index 22db8e875dc..2d89fb9ffba 100644
--- a/intern/cycles/render/buffers.cpp
+++ b/intern/cycles/render/buffers.cpp
@@ -165,35 +165,6 @@ bool RenderBuffers::copy_from_device()
   return true;
 }
 
-static const float *get_sample_count_pass(const vector<Pass> &passes, device_vector<float> &buffer)
-{
-  int sample_offset = 0;
-
-  for (const Pass &pass : passes) {
-    if (pass.type != PASS_SAMPLE_COUNT) {
-      sample_offset += pass.components;
-    }
-    else {
-      return buffer.data() + sample_offset;
-    }
-  }
-
-  return NULL;
-}
-
-static float get_pixel_pass_scale(const float rcp_sample,
-                                  const float *sample_count,
-                                  const int i,
-                                  const int pass_stride)
-{
-  if (sample_count) {
-    return 1.0f / fabsf(sample_count[i * pass_stride]);
-  }
-  else {
-    return rcp_sample;
-  }
-}
-
 bool RenderBuffers::get_denoising_pass_rect(
     int type, float exposure, int sample, int components, float *pixels)
 {
@@ -289,7 +260,22 @@ bool RenderBuffers::get_pass_rect(
     return false;
   }
 
-  const float *sample_count = get_sample_count_pass(params.passes, buffer);
+  float *sample_count = NULL;
+  if (name == "Combined") {
+    int sample_offset = 0;
+    for (size_t j = 0; j < params.passes.size(); j++) {
+      Pass &pass = params.passes[j];
+      if (pass.type != PASS_SAMPLE_COUNT) {
+        sample_offset += pass.components;
+        continue;
+      }
+      else {
+        sample_count = buffer.data() + sample_offset;
+        break;
+      }
+    }
+  }
+
   int pass_offset = 0;
 
   for (size_t j = 0; j < params.passes.size(); j++) {
@@ -307,8 +293,8 @@ bool RenderBuffers::get_pass_rect(
     float *in = buffer.data() + pass_offset;
     int pass_stride = params.get_passes_size();
 
-    const float rcp_sample = 1.0f / (float)sample;
-    const float pass_exposure = (pass.exposure) ? exposure : 1.0f;
+    float scale = (pass.filter) ? 1.0f / (float)sample : 1.0f;
+    float scale_exposure = (pass.exposure) ? scale * exposure : scale;
 
     int size = params.width * params.height;
 
@@ -326,36 +312,28 @@ bool RenderBuffers::get_pass_rect(
       if (type == PASS_DEPTH) {
         for (int i = 0; i < size; i++, in += pass_stride, pixels++) {
           float f = *in;
-          pixels[0] = (f == 0.0f) ? 1e10f : f;
-        }
-      }
-      else if (type == PASS_OBJECT_ID || type == PASS_MATERIAL_ID) {
-        for (int i = 0; i < size; i++, in += pass_stride, pixels++) {
-          pixels[0] = *in;
+          pixels[0] = (f == 0.0f) ? 1e10f : f * scale_exposure;
         }
       }
       else if (type == PASS_MIST) {
         for (int i = 0; i < size; i++, in += pass_stride, pixels++) {
-          const float scale = get_pixel_pass_scale(rcp_sample, sample_count, i, pass_stride);
-          const float f = *in;
-          pixels[0] = saturate(f * scale);
+          float f = *in;
+          pixels[0] = saturate(f * scale_exposure);
         }
       }
 #ifdef WITH_CYCLES_DEBUG
       else if (type == PASS_BVH_TRAVERSED_NODES || type == PASS_BVH_TRAVERSED_INSTANCES ||
                type == PASS_BVH_INTERSECTIONS || type == PASS_RAY_BOUNCES) {
         for (int i = 0; i < size; i++, in += pass_stride, pixels++) {
-          const float scale = get_pixel_pass_scale(rcp_sample, sample_count, i, pass_stride);
-          const float f = *in;
+          float f = *in;
           pixels[0] = f * scale;
         }
       }
 #endif
       else {
         for (int i = 0; i < size; i++, in += pass_stride, pixels++) {
-          const float scale = get_pixel_pass_scale(rcp_sample, sample_count, i, pass_stride);
-          const float f = *in;
-          pixels[0] = f * scale * pass_exposure;
+          float f = *in;
+          pixels[0] = f * scale_exposure;
         }
       }
     }
@@ -389,7 +367,7 @@ bool RenderBuffers::get_pass_rect(
           float3 f = make_float3(in[0], in[1], in[2]);
           float3 f_divide = make_float3(in_divide[0], in_divide[1], in_divide[2]);
 
-          f = safe_divide_even_color(f * pass_exposure, f_divide);
+          f = safe_divide_even_color(f * exposure, f_divide);
 
           pixels[0] = f.x;
           pixels[1] = f.y;
@@ -399,9 +377,7 @@ bool RenderBuffers::get_pass_rect(
       else {
         /* RGB/vector */
         for (int i = 0; i < size; i++, in += pass_stride, pixels += 3) {
-          const float scale = get_pixel_pass_scale(rcp_sample, sample_count, i, pass_stride);
-          const float scale_exposure = scale * pass_exposure;
-          const float3 f = make_float3(in[0], in[1], in[2]);
+          float3 f = make_float3(in[0], in[1], in[2]);
 
           pixels[0] = f.x * scale_exposure;
           pixels[1] = f.y * scale_exposure;
@@ -449,9 +425,7 @@ bool RenderBuffers::get_pass_rect(
       }
       else if (type == PASS_CRYPTOMATTE) {
         for (int i = 0; i < size; i++, in += pass_stride, pixels += 4) {
-          const float scale = get_pixel_pass_scale(rcp_sample, sample_count, i, pass_stride);
-          const float4 f = make_float4(in[0], in[1], in[2], in[3]);
-
+          float4 f = make_float4(in[0], in[1], in[2], in[3]);
           /* x and z contain integer IDs, don't rescale them.
              y and w contain matte weights, they get scaled. */
           pixels[0] = f.x;
@@ -462,9 +436,12 @@ bool RenderBuffers::get_pass_rect(
       }
       else {
         for (int i = 0; i < size; i++, in += pass_stride, pixels += 4) {
-          const float scale = get_pixel_pass_scale(rcp_sample, sample_count, i, pass_stride);
-          const float scale_exposure = scale * pass_exposure;
-          const float4 f = make_float4(in[0], in[1], in[2], in[3]);
+          if (sample_count && sample_count[i * pass_stride] < 0.0f) {
+            scale = (pass.filter) ? -1.0f / (sample_count[i * pass_stride]) : 1.0f;
+            scale_exposure = (pass.exposure) ? scale * exposure : scale;
+          }
+
+          float4 f = make_float4(in[0], in[1], in[2], in[3]);
 
           pixels[0] = f.x * scale_exposure;
           pixels[1] = f.y * scale_exposure;
diff --git a/intern/cycles/render/film.cpp b/intern/cycles/render/film.cpp
index c29810d1494..baf02901123 100644
--- a/intern/cycles/render/film.cpp
+++ b/intern/cycles/render/film.cpp
@@ -76,6 +76,7 @@ void Pass::add(PassType type, vector<Pass> &passes, const char *name)
   Pass pass;
 
   pass.type = type;
+  pass.filter = true;
   pass.exposure = false;
   pass.divide_type = PASS_NONE;
   if (name) {
@@ -92,6 +93,7 @@ void Pass::add(PassType type, vector<Pass> &passes, const char *name)
       break;
     case PASS_DEPTH:
       pass.components = 1;
+      pass.filter = false;
       break;
     case PASS_MIST:
       pass.components = 1;
@@ -112,6 +114,7 @@ void Pass::add(PassType type, vector<Pass> &passes, const char *name)
     case PASS_OBJECT_ID:
     case PASS_MATERIAL_ID:
       pass.components = 1;
+      pass.filter = false;
       break;
 
     case PASS_EMISSION:
diff --git a/intern/cycles/render/film.h b/intern/cycles/render/film.h
index 0fe4fe89d5e..aae8fb404b0 100644
--- a/intern/cycles/render/film.h
+++ b/intern/cycles/render/film.h
@@ -42,6 +42,7 @@ class Pass {
  public:
   PassType type;
   int components;
+  bool filter;
   bool exposure;
   PassType divide_type;
   string name;



More information about the Bf-blender-cvs mailing list