[Bf-blender-cvs] [3411a96e749] master: Fix T93382: Blender still generates subsurface render passes

Lukas Stockner noreply at git.blender.org
Thu Oct 20 02:39:40 CEST 2022


Commit: 3411a96e74938afe9b7ffe64e61a225da5f2eb6a
Author: Lukas Stockner
Date:   Wed Oct 19 04:02:39 2022 +0200
Branches: master
https://developer.blender.org/rB3411a96e74938afe9b7ffe64e61a225da5f2eb6a

Fix T93382: Blender still generates subsurface render passes

In T93382, the problem was that the Blender-side rendering code was
still generating the subsurface passes because the old render pass
flags were set, even though Cycles doesn't generate them anymore.

After a closer look, it turns out that the entire hardcoded pass
creation code can be removed. We already have an Engine API function
to query the list of render passes from the engine, so we might as
well just call that and create the returned passes.

Turns out that Eevee already did this anyways. On the Cycles side, it
allows to deduplicate a lot of `BlenderSync::sync_render_passes`.
Before, passes were defined in engine.py and in sync.cpp. Now, all
passes that engine.py returns are created automatically, so sync.cpp
only needs to handle a few special cases.

I'm not really concerned about affecting external renderer addons,
since they already needed to handle the old "builtin passes" in
their Engine API implementation anyways to make them show up in the
compositor. So, unless they missed that for like 10 releases, they
should not notice any difference.

Differential Revision: https://developer.blender.org/D16295

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

M	intern/cycles/blender/addon/engine.py
M	intern/cycles/blender/sync.cpp
M	source/blender/draw/intern/draw_manager.c
M	source/blender/render/intern/engine.cc
M	source/blender/render/intern/render_result.cc

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

diff --git a/intern/cycles/blender/addon/engine.py b/intern/cycles/blender/addon/engine.py
index 794338fe78e..e33891fa7a2 100644
--- a/intern/cycles/blender/addon/engine.py
+++ b/intern/cycles/blender/addon/engine.py
@@ -209,22 +209,25 @@ def list_render_passes(scene, srl):
         yield ("Debug Sample Count", "X", 'VALUE')
 
     # Cryptomatte passes.
-    crypto_depth = (srl.pass_cryptomatte_depth + 1) // 2
+    # NOTE: Name channels are lowercase RGBA so that compression rules check in OpenEXR DWA code
+    # uses lossless compression. Reportedly this naming is the only one which works good from the
+    # interoperability point of view. Using XYZW naming is not portable.
+    crypto_depth = (min(16, srl.pass_cryptomatte_depth) + 1) // 2
     if srl.use_pass_cryptomatte_object:
         for i in range(0, crypto_depth):
-            yield ("CryptoObject" + '{:02d}'.format(i), "RGBA", 'COLOR')
+            yield ("CryptoObject" + '{:02d}'.format(i), "rgba", 'COLOR')
     if srl.use_pass_cryptomatte_material:
         for i in range(0, crypto_depth):
-            yield ("CryptoMaterial" + '{:02d}'.format(i), "RGBA", 'COLOR')
+            yield ("CryptoMaterial" + '{:02d}'.format(i), "rgba", 'COLOR')
     if srl.use_pass_cryptomatte_asset:
         for i in range(0, crypto_depth):
-            yield ("CryptoAsset" + '{:02d}'.format(i), "RGBA", 'COLOR')
+            yield ("CryptoAsset" + '{:02d}'.format(i), "rgba", 'COLOR')
 
     # Denoising passes.
     if scene.cycles.use_denoising and crl.use_denoising:
         yield ("Noisy Image", "RGBA", 'COLOR')
         if crl.use_pass_shadow_catcher:
-            yield ("Noisy Shadow Catcher", "RGBA", 'COLOR')
+            yield ("Noisy Shadow Catcher", "RGB", 'COLOR')
     if crl.denoising_store_passes:
         yield ("Denoising Normal", "XYZ", 'VECTOR')
         yield ("Denoising Albedo", "RGB", 'COLOR')
@@ -232,6 +235,8 @@ def list_render_passes(scene, srl):
 
     # Custom AOV passes.
     for aov in srl.aovs:
+        if not aov.is_valid:
+            continue
         if aov.type == 'VALUE':
             yield (aov.name, "X", 'VALUE')
         else:
diff --git a/intern/cycles/blender/sync.cpp b/intern/cycles/blender/sync.cpp
index a69a94614d3..5251f0fee9c 100644
--- a/intern/cycles/blender/sync.cpp
+++ b/intern/cycles/blender/sync.cpp
@@ -575,68 +575,72 @@ void BlenderSync::sync_images()
 
 /* Passes */
 
-static PassType get_blender_pass_type(BL::RenderPass &b_pass)
+static bool get_known_pass_type(BL::RenderPass &b_pass, PassType &type, PassMode &mode)
 {
   string name = b_pass.name();
-#define MAP_PASS(passname, passtype) \
+#define MAP_PASS(passname, passtype, noisy) \
   if (name == passname) { \
-    return passtype; \
+    type = passtype; \
+    mode = (noisy) ? PassMode::NOISY : PassMode::DENOISED; \
+    return true; \
   } \
   ((void)0)
 
-  /* NOTE: Keep in sync with defined names from DNA_scene_types.h */
+  /* NOTE: Keep in sync with defined names from engine.py */
 
-  MAP_PASS("Combined", PASS_COMBINED);
-  MAP_PASS("Noisy Image", PASS_COMBINED);
+  MAP_PASS("Combined", PASS_COMBINED, false);
+  MAP_PASS("Noisy Image", PASS_COMBINED, true);
 
-  MAP_PASS("Depth", PASS_DEPTH);
-  MAP_PASS("Mist", PASS_MIST);
-  MAP_PASS("Position", PASS_POSITION);
-  MAP_PASS("Normal", PASS_NORMAL);
-  MAP_PASS("IndexOB", PASS_OBJECT_ID);
-  MAP_PASS("UV", PASS_UV);
-  MAP_PASS("Vector", PASS_MOTION);
-  MAP_PASS("IndexMA", PASS_MATERIAL_ID);
+  MAP_PASS("Depth", PASS_DEPTH, false);
+  MAP_PASS("Mist", PASS_MIST, false);
+  MAP_PASS("Position", PASS_POSITION, false);
+  MAP_PASS("Normal", PASS_NORMAL, false);
+  MAP_PASS("IndexOB", PASS_OBJECT_ID, false);
+  MAP_PASS("UV", PASS_UV, false);
+  MAP_PASS("Vector", PASS_MOTION, false);
+  MAP_PASS("IndexMA", PASS_MATERIAL_ID, false);
 
-  MAP_PASS("DiffDir", PASS_DIFFUSE_DIRECT);
-  MAP_PASS("GlossDir", PASS_GLOSSY_DIRECT);
-  MAP_PASS("TransDir", PASS_TRANSMISSION_DIRECT);
-  MAP_PASS("VolumeDir", PASS_VOLUME_DIRECT);
+  MAP_PASS("DiffDir", PASS_DIFFUSE_DIRECT, false);
+  MAP_PASS("GlossDir", PASS_GLOSSY_DIRECT, false);
+  MAP_PASS("TransDir", PASS_TRANSMISSION_DIRECT, false);
+  MAP_PASS("VolumeDir", PASS_VOLUME_DIRECT, false);
 
-  MAP_PASS("DiffInd", PASS_DIFFUSE_INDIRECT);
-  MAP_PASS("GlossInd", PASS_GLOSSY_INDIRECT);
-  MAP_PASS("TransInd", PASS_TRANSMISSION_INDIRECT);
-  MAP_PASS("VolumeInd", PASS_VOLUME_INDIRECT);
+  MAP_PASS("DiffInd", PASS_DIFFUSE_INDIRECT, false);
+  MAP_PASS("GlossInd", PASS_GLOSSY_INDIRECT, false);
+  MAP_PASS("TransInd", PASS_TRANSMISSION_INDIRECT, false);
+  MAP_PASS("VolumeInd", PASS_VOLUME_INDIRECT, false);
 
-  MAP_PASS("DiffCol", PASS_DIFFUSE_COLOR);
-  MAP_PASS("GlossCol", PASS_GLOSSY_COLOR);
-  MAP_PASS("TransCol", PASS_TRANSMISSION_COLOR);
+  MAP_PASS("DiffCol", PASS_DIFFUSE_COLOR, false);
+  MAP_PASS("GlossCol", PASS_GLOSSY_COLOR, false);
+  MAP_PASS("TransCol", PASS_TRANSMISSION_COLOR, false);
 
-  MAP_PASS("Emit", PASS_EMISSION);
-  MAP_PASS("Env", PASS_BACKGROUND);
-  MAP_PASS("AO", PASS_AO);
-  MAP_PASS("Shadow", PASS_SHADOW);
+  MAP_PASS("Emit", PASS_EMISSION, false);
+  MAP_PASS("Env", PASS_BACKGROUND, false);
+  MAP_PASS("AO", PASS_AO, false);
+  MAP_PASS("Shadow", PASS_SHADOW, false);
 
-  MAP_PASS("BakePrimitive", PASS_BAKE_PRIMITIVE);
-  MAP_PASS("BakeDifferential", PASS_BAKE_DIFFERENTIAL);
+  MAP_PASS("BakePrimitive", PASS_BAKE_PRIMITIVE, false);
+  MAP_PASS("BakeDifferential", PASS_BAKE_DIFFERENTIAL, false);
 
-  MAP_PASS("Denoising Normal", PASS_DENOISING_NORMAL);
-  MAP_PASS("Denoising Albedo", PASS_DENOISING_ALBEDO);
-  MAP_PASS("Denoising Depth", PASS_DENOISING_DEPTH);
+  MAP_PASS("Denoising Normal", PASS_DENOISING_NORMAL, true);
+  MAP_PASS("Denoising Albedo", PASS_DENOISING_ALBEDO, true);
+  MAP_PASS("Denoising Depth", PASS_DENOISING_DEPTH, true);
 
-  MAP_PASS("Shadow Catcher", PASS_SHADOW_CATCHER);
-  MAP_PASS("Noisy Shadow Catcher", PASS_SHADOW_CATCHER);
+  MAP_PASS("Shadow Catcher", PASS_SHADOW_CATCHER, false);
+  MAP_PASS("Noisy Shadow Catcher", PASS_SHADOW_CATCHER, true);
 
-  MAP_PASS("AdaptiveAuxBuffer", PASS_ADAPTIVE_AUX_BUFFER);
-  MAP_PASS("Debug Sample Count", PASS_SAMPLE_COUNT);
+  MAP_PASS("AdaptiveAuxBuffer", PASS_ADAPTIVE_AUX_BUFFER, false);
+  MAP_PASS("Debug Sample Count", PASS_SAMPLE_COUNT, false);
 
   if (string_startswith(name, cryptomatte_prefix)) {
-    return PASS_CRYPTOMATTE;
+    type = PASS_CRYPTOMATTE;
+    mode = PassMode::DENOISED;
+    return true;
   }
 
 #undef MAP_PASS
 
-  return PASS_NONE;
+  return false;
 }
 
 static Pass *pass_add(Scene *scene,
@@ -655,8 +659,6 @@ static Pass *pass_add(Scene *scene,
 
 void BlenderSync::sync_render_passes(BL::RenderLayer &b_rlay, BL::ViewLayer &b_view_layer)
 {
-  PointerRNA cscene = RNA_pointer_get(&b_scene.ptr, "cycles");
-
   /* Delete all existing passes. */
   set<Pass *> clear_passes(scene->passes.begin(), scene->passes.end());
   scene->delete_nodes(clear_passes);
@@ -664,103 +666,23 @@ void BlenderSync::sync_render_passes(BL::RenderLayer &b_rlay, BL::ViewLayer &b_v
   /* Always add combined pass. */
   pass_add(scene, PASS_COMBINED, "Combined");
 
-  /* Blender built-in data and light passes. */
-  for (BL::RenderPass &b_pass : b_rlay.passes) {
-    const PassType pass_type = get_blender_pass_type(b_pass);
-
-    if (pass_type == PASS_NONE) {
-      LOG(ERROR) << "Unknown pass " << b_pass.name();
-      continue;
-    }
-
-    if (pass_type == PASS_MOTION &&
-        (b_view_layer.use_motion_blur() && b_scene.render().use_motion_blur())) {
-      continue;
-    }
-
-    pass_add(scene, pass_type, b_pass.name().c_str());
-  }
-
-  PointerRNA crl = RNA_pointer_get(&b_view_layer.ptr, "cycles");
-
-  /* Debug passes. */
-  if (get_boolean(crl, "pass_debug_sample_count")) {
-    b_engine.add_pass("Debug Sample Count", 1, "X", b_view_layer.name().c_str());
-    pass_add(scene, PASS_SAMPLE_COUNT, "Debug Sample Count");
-  }
-
-  /* Cycles specific passes. */
-  if (get_boolean(crl, "use_pass_volume_direct")) {
-    b_engine.add_pass("VolumeDir", 3, "RGB", b_view_layer.name().c_str());
-    pass_add(scene, PASS_VOLUME_DIRECT, "VolumeDir");
-  }
-  if (get_boolean(crl, "use_pass_volume_indirect")) {
-    b_engine.add_pass("VolumeInd", 3, "RGB", b_view_layer.name().c_str());
-    pass_add(scene, PASS_VOLUME_INDIRECT, "VolumeInd");
-  }
-  if (get_boolean(crl, "use_pass_shadow_catcher")) {
-    b_engine.add_pass("Shadow Catcher", 3, "RGB", b_view_layer.name().c_str());
-    pass_add(scene, PASS_SHADOW_CATCHER, "Shadow Catcher");
-  }
-
   /* Cryptomatte stores two ID/weight pairs per RGBA layer.
-   * User facing parameter is the number of pairs.
-   *
-   * NOTE: Name channels lowercase RGBA so that compression rules check in OpenEXR DWA code uses
-   * lossless compression. Reportedly this naming is the only one which works good from the
-   * interoperability point of view. Using XYZW naming is not portable. */
+   * User facing parameter is the number of pairs. */
   int crypto_depth = divide_up(min(16, b_view_layer.pass_cryptomatte_depth()), 2);
   scene->film->set_cryptomatte_depth(crypto_depth);
   CryptomatteType cryptomatte_passes = CRYPT_NONE;
   if (b_view_layer.use_pass_cryptomatte_object()) {
-    for (int i = 0; i < crypto_depth; i++) {
-      string passname = cryptomatte_prefix + string_printf("Object%02d", i);
-      b_engine.add_pass(passname.c_str(), 4, "rgba", b_view_layer.name().c_str());
-      pass_add(scene, PASS_CRYPTOMATTE, passname.c_str());
-    }
     cryptomatte_passes = (CryptomatteType)(cryptomatte_passes | CRYPT_OBJECT);
   }
   if (b_view_layer.use_pass_cryptomatte_material()) {
-    for (int i = 0; i < crypto_depth; i++) {
-      string passname = cryptomatte_prefix + string_printf("Material%02d", i);
-      b_engine.add_pass(passname.c_str(), 4, "rgba", b_view_layer.name().c_str());
-      pass_add(scene, PASS_CRYPTOMATTE, passname.c_str());
-    }
     cryptomatte_passes = (CryptomatteType)(cryptomatte_passes | CRYPT_MATERIAL);
   }
   if (b_view_layer.use_pass_cryptomatte_asset()) {
-    for (int i = 0; i < crypto_depth; i++) {
-      string passname = cryptomatte_prefix + string_printf("Asset%02d", i);
-      b_engine.add_pass(passname.c_str(), 4, "rgba", b_view_layer.name().c_str(

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list