[Bf-blender-cvs] [605c311b1bb] temp-eevee-next-cryptomatte: Eevee next: Cryptomatte Initial Commit.

Jeroen Bakker noreply at git.blender.org
Mon Aug 22 15:49:47 CEST 2022


Commit: 605c311b1bb55bb6d5ff3ac2f5d7b9ebb38fd3c0
Author: Jeroen Bakker
Date:   Sun Aug 7 16:34:17 2022 +0200
Branches: temp-eevee-next-cryptomatte
https://developer.blender.org/rB605c311b1bb55bb6d5ff3ac2f5d7b9ebb38fd3c0

Eevee next: Cryptomatte Initial Commit.

Mostly setting op data structures and data transformations.

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

M	source/blender/blenkernel/intern/cryptomatte.cc
M	source/blender/draw/CMakeLists.txt
A	source/blender/draw/engines/eevee_next/eevee_cryptomatte.cc
A	source/blender/draw/engines/eevee_next/eevee_cryptomatte.hh
M	source/blender/draw/engines/eevee_next/eevee_film.cc
M	source/blender/draw/engines/eevee_next/eevee_film.hh
M	source/blender/draw/engines/eevee_next/eevee_instance.cc
M	source/blender/draw/engines/eevee_next/eevee_pipeline.cc
M	source/blender/draw/engines/eevee_next/eevee_renderbuffers.cc
M	source/blender/draw/engines/eevee_next/eevee_renderbuffers.hh
M	source/blender/draw/engines/eevee_next/eevee_shader_shared.hh
M	source/blender/draw/engines/eevee_next/shaders/infos/eevee_film_info.hh
M	source/blender/makesdna/DNA_layer_types.h
M	source/blender/makesdna/DNA_scene_types.h

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

diff --git a/source/blender/blenkernel/intern/cryptomatte.cc b/source/blender/blenkernel/intern/cryptomatte.cc
index 102bda0f2b6..bb1e3bce92c 100644
--- a/source/blender/blenkernel/intern/cryptomatte.cc
+++ b/source/blender/blenkernel/intern/cryptomatte.cc
@@ -54,13 +54,15 @@ struct CryptomatteSession {
 CryptomatteSession::CryptomatteSession(const Main *bmain)
 {
   if (!BLI_listbase_is_empty(&bmain->objects)) {
-    blender::bke::cryptomatte::CryptomatteLayer &objects = add_layer("CryptoObject");
+    blender::bke::cryptomatte::CryptomatteLayer &objects = add_layer(
+        RE_PASSNAME_CRYPTOMATTE_OBJECT);
     LISTBASE_FOREACH (ID *, id, &bmain->objects) {
       objects.add_ID(*id);
     }
   }
   if (!BLI_listbase_is_empty(&bmain->materials)) {
-    blender::bke::cryptomatte::CryptomatteLayer &materials = add_layer("CryptoMaterial");
+    blender::bke::cryptomatte::CryptomatteLayer &materials = add_layer(
+        RE_PASSNAME_CRYPTOMATTE_MATERIAL);
     LISTBASE_FOREACH (ID *, id, &bmain->materials) {
       materials.add_ID(*id);
     }
@@ -93,13 +95,13 @@ CryptomatteSession::CryptomatteSession(const Scene *scene)
     }
 
     if (cryptoflags & VIEW_LAYER_CRYPTOMATTE_OBJECT) {
-      add_layer(blender::StringRefNull(view_layer->name) + ".CryptoObject");
+      add_layer(blender::StringRefNull(view_layer->name) + "." + RE_PASSNAME_CRYPTOMATTE_OBJECT);
     }
     if (cryptoflags & VIEW_LAYER_CRYPTOMATTE_ASSET) {
-      add_layer(blender::StringRefNull(view_layer->name) + ".CryptoAsset");
+      add_layer(blender::StringRefNull(view_layer->name) + "." + RE_PASSNAME_CRYPTOMATTE_ASSET);
     }
     if (cryptoflags & VIEW_LAYER_CRYPTOMATTE_MATERIAL) {
-      add_layer(blender::StringRefNull(view_layer->name) + ".CryptoMaterial");
+      add_layer(blender::StringRefNull(view_layer->name) + "." + RE_PASSNAME_CRYPTOMATTE_MATERIAL);
     }
   }
 }
diff --git a/source/blender/draw/CMakeLists.txt b/source/blender/draw/CMakeLists.txt
index c34a6daa126..7d10563147e 100644
--- a/source/blender/draw/CMakeLists.txt
+++ b/source/blender/draw/CMakeLists.txt
@@ -134,6 +134,7 @@ set(SRC
   engines/eevee/eevee_temporal_sampling.c
   engines/eevee/eevee_volumes.c
   engines/eevee_next/eevee_camera.cc
+  engines/eevee_next/eevee_cryptomatte.cc
   engines/eevee_next/eevee_depth_of_field.cc
   engines/eevee_next/eevee_engine.cc
   engines/eevee_next/eevee_film.cc
diff --git a/source/blender/draw/engines/eevee_next/eevee_cryptomatte.cc b/source/blender/draw/engines/eevee_next/eevee_cryptomatte.cc
new file mode 100644
index 00000000000..e69de29bb2d
diff --git a/source/blender/draw/engines/eevee_next/eevee_cryptomatte.hh b/source/blender/draw/engines/eevee_next/eevee_cryptomatte.hh
new file mode 100644
index 00000000000..8566c76a0e9
--- /dev/null
+++ b/source/blender/draw/engines/eevee_next/eevee_cryptomatte.hh
@@ -0,0 +1,41 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later
+ * Copyright 2021 Blender Foundation.
+ */
+
+/** \file
+ * \ingroup eevee
+ *
+ * Cryptomatte.
+ *
+ * Cryptomatte stores the output during rendering in a single texture.
+ * Inside the film the output is extracted per enabled cryptomatte layer.
+ * Each cryptomatte layer can hold N samples. These are stored in multiple
+ * sequentially bound textures. The samples are sorted and merged.
+ */
+
+#pragma once
+
+#include "eevee_shader_shared.hh"
+
+namespace blender::eevee {
+
+class Instance;
+
+/* -------------------------------------------------------------------- */
+/** \name Cryptomatte
+ * \{ */
+
+class Cryptomatte {
+ private:
+  class Instance &inst_;
+
+ public:
+  DepthOfField(Instance &inst) : inst_(inst){};
+  ~DepthOfField(){};
+
+  void init();
+};
+
+/** \} */
+
+}  // namespace blender::eevee
diff --git a/source/blender/draw/engines/eevee_next/eevee_film.cc b/source/blender/draw/engines/eevee_next/eevee_film.cc
index b3fbe088471..6fd0c638a12 100644
--- a/source/blender/draw/engines/eevee_next/eevee_film.cc
+++ b/source/blender/draw/engines/eevee_next/eevee_film.cc
@@ -210,6 +210,7 @@ void Film::init(const int2 &extent, const rcti *output_rect)
 
 #undef ENABLE_FROM_LEGACY
     }
+    // TODO(jbakker): unsure if cryptomatte passes are passed along.
 
     /* Filter obsolete passes. */
     render_passes &= ~(EEVEE_RENDER_PASS_UNUSED_8 | EEVEE_RENDER_PASS_BLOOM);
@@ -241,6 +242,7 @@ void Film::init(const int2 &extent, const rcti *output_rect)
     /* TODO(fclem): parameter hidden in experimental.
      * We need to figure out LOD bias first in order to preserve texture crispiness. */
     data.scaling_factor = 1;
+    data.cryptomatte_samples_len = inst_.view_layer->cryptomatte_levels;
 
     data.background_opacity = (scene.r.alphamode == R_ALPHAPREMUL) ? 0.0f : 1.0f;
     if (inst_.is_viewport() && false /* TODO(fclem): StudioLight */) {
@@ -316,6 +318,20 @@ void Film::init(const int2 &extent, const rcti *output_rect)
 
     data_.color_len += data_.aov_color_len;
     data_.value_len += data_.aov_value_len;
+
+    data_.cryptomatte_object_id = data_.cryptomatte_asset_id = data_.cryptomatte_material_id = -1;
+    int cryptomatte_id = 0;
+    if (enabled_passes_ & EEVEE_RENDER_PASS_CRYPTOMATTE_OBJECT) {
+      data_.cryptomatte_object_id = cryptomatte_id;
+      cryptomatte_id += data_.cryptomatte_samples_len / 2;
+    }
+    if (enabled_passes_ & EEVEE_RENDER_PASS_CRYPTOMATTE_ASSET) {
+      data_.cryptomatte_asset_id = cryptomatte_id;
+      cryptomatte_id += data_.cryptomatte_samples_len / 2;
+    }
+    if (enabled_passes_ & EEVEE_RENDER_PASS_CRYPTOMATTE_MATERIAL) {
+      data_.cryptomatte_material_id = cryptomatte_id;
+    }
   }
   {
     /* TODO(@fclem): Over-scans. */
@@ -327,6 +343,7 @@ void Film::init(const int2 &extent, const rcti *output_rect)
     eGPUTextureFormat float_format = GPU_R16F;
     eGPUTextureFormat weight_format = GPU_R32F;
     eGPUTextureFormat depth_format = GPU_R32F;
+    eGPUTextureFormat cryptomatte_format = GPU_RGBA32F;
 
     int reset = 0;
     reset += depth_tx_.ensure_2d(depth_format, data_.extent);
@@ -341,6 +358,12 @@ void Film::init(const int2 &extent, const rcti *output_rect)
     reset += value_accum_tx_.ensure_2d_array(float_format,
                                              (data_.value_len > 0) ? data_.extent : int2(1),
                                              (data_.value_len > 0) ? data_.value_len : 1);
+    /* Divided by two as two cryptomatte samples fit in pixel (RG, BA). */
+    int cryptomatte_array_len = cryptomatte_layer_len_get() * data_.cryptomatte_samples_len / 2;
+    reset += cryptomatte_tx_.ensure_2d_array(cryptomatte_format,
+                                             (cryptomatte_array_len > 0) ? data_.extent : int2(1),
+                                             (cryptomatte_array_len > 0) ? cryptomatte_array_len :
+                                                                           1);
 
     if (reset > 0) {
       sampling.reset();
@@ -353,6 +376,7 @@ void Film::init(const int2 &extent, const rcti *output_rect)
       combined_tx_.current().clear(float4(0.0f));
       weight_tx_.current().clear(float4(0.0f));
       depth_tx_.clear(float4(0.0f));
+      cryptomatte_tx_.clear(float4(0.0f));
     }
   }
 
@@ -400,6 +424,7 @@ void Film::sync()
   DRW_shgroup_uniform_texture_ref(grp, "ambient_occlusion_tx", &rbuffers.ambient_occlusion_tx);
   DRW_shgroup_uniform_texture_ref(grp, "aov_color_tx", &rbuffers.aov_color_tx);
   DRW_shgroup_uniform_texture_ref(grp, "aov_value_tx", &rbuffers.aov_value_tx);
+  DRW_shgroup_uniform_texture_ref(grp, "cryptomatte_tx", &rbuffers.cryptomatte_tx);
   /* NOTE(@fclem): 16 is the max number of sampled texture in many implementations.
    * If we need more, we need to pack more of the similar passes in the same textures as arrays or
    * use image binding instead. */
@@ -410,6 +435,7 @@ void Film::sync()
   DRW_shgroup_uniform_image_ref(grp, "depth_img", &depth_tx_);
   DRW_shgroup_uniform_image_ref(grp, "color_accum_img", &color_accum_tx_);
   DRW_shgroup_uniform_image_ref(grp, "value_accum_img", &value_accum_tx_);
+  DRW_shgroup_uniform_image_ref(grp, "cryptomatte_img", &cryptomatte_tx_);
   /* Sync with rendering passes. */
   DRW_shgroup_barrier(grp, GPU_BARRIER_TEXTURE_FETCH);
   /* Sync with rendering passes. */
@@ -468,6 +494,15 @@ eViewLayerEEVEEPassType Film::enabled_passes_get() const
   return enabled_passes_;
 }
 
+int Film::cryptomatte_layer_len_get() const
+{
+  int result = 0;
+  result += data_.cryptomatte_object_id == -1 ? 0 : 1;
+  result += data_.cryptomatte_asset_id == -1 ? 0 : 1;
+  result += data_.cryptomatte_material_id == -1 ? 0 : 1;
+  return result;
+}
+
 void Film::update_sample_table()
 {
   data_.subpixel_offset = pixel_jitter_get();
@@ -608,7 +643,7 @@ float *Film::read_pass(eViewLayerEEVEEPassType pass_type)
   bool is_value = pass_is_value(pass_type);
   Texture &accum_tx = (pass_type == EEVEE_RENDER_PASS_COMBINED) ?
                           combined_tx_.current() :
-                      (pass_type == EEVEE_RENDER_PASS_Z) ?
+                          (pass_type == EEVEE_RENDER_PASS_Z) ?
                           depth_tx_ :
                           (is_value ? value_accum_tx_ : color_accum_tx_);
 
diff --git a/source/blender/draw/engines/eevee_next/eevee_film.hh b/source/blender/draw/engines/eevee_next/eevee_film.hh
index 3e368782d31..17d297ac218 100644
--- a/source/blender/draw/engines/eevee_next/eevee_film.hh
+++ b/source/blender/draw/engines/eevee_next/eevee_film.hh
@@ -43,11 +43,16 @@ class Film {
   /** Incoming combined buffer with post FX applied (motion blur + depth of field). */
   GPUTexture *combined_final_tx_ = nullptr;
 
-  /** Main accumulation textures containing every render-pass except depth and combined. */
+  /**
+   * Main accumulation textures containing every render-pass except depth, cryptomatte and
+   * combined.
+   */
   Texture color_accum_tx_;
   Texture value_accum_tx_;
   /** Depth accumulation texture. Separated because using a different format. */
   Texture depth_tx_;
+  /** Cryptomatte texture. Separated because it requires full floats. */
+  Texture cryptomatte_tx_;
   /** Combined "Color" buffer. Double buffered to allow re-projection. */
   SwapChain<Texture, 2> combined_tx_;
   /** Weight b

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list