Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJeroen Bakker <jbakker>2022-09-13 12:07:30 +0300
committerJeroen Bakker <jeroen@blender.org>2022-09-13 12:07:38 +0300
commit8068b89a681c467f3d449b9ddc2ebec5b817c2fc (patch)
tree2bed18be11a6b13ccd9092ea133993a19509a726 /source/blender/gpu/intern/gpu_codegen.cc
parentbb3a021427f2132f1db62a76eeca2ca4be1601da (diff)
EEVEE-Next: Cryptomatte render passes.
This change adds cryptomatte render passes to EEVEE-Next. Due to the upcoming viewport compositor we also improved cryptomatte so it will be real-time. This also allows viewing the cryptomatte passes in the viewport directly. {F13482749} A surface shader would store any active cryptomatte layer to a texture. Object hash is stored as R, Asset hash as G and Material hash as B. Hashes are only calculated when the cryptomatte layer is active to reduce any unneeded work. During film accumulation the hashes are separated and stored in a texture array that matches the cryptomatte standard. For the real-time use case sorting is skipped. For final rendering the samples are sorted and normalized. NOTE: Eventually we should also do sample normalization in the viewport in order to extract the correct mask when using the viewport compositor. Reviewed By: fclem Maniphest Tasks: T99390 Differential Revision: https://developer.blender.org/D15753
Diffstat (limited to 'source/blender/gpu/intern/gpu_codegen.cc')
-rw-r--r--source/blender/gpu/intern/gpu_codegen.cc31
1 files changed, 30 insertions, 1 deletions
diff --git a/source/blender/gpu/intern/gpu_codegen.cc b/source/blender/gpu/intern/gpu_codegen.cc
index 0102b8db5b2..75e148e0a8f 100644
--- a/source/blender/gpu/intern/gpu_codegen.cc
+++ b/source/blender/gpu/intern/gpu_codegen.cc
@@ -11,6 +11,7 @@
#include "DNA_customdata_types.h"
#include "DNA_image_types.h"
+#include "DNA_material_types.h"
#include "BLI_ghash.h"
#include "BLI_hash_mm2a.h"
@@ -20,6 +21,7 @@
#include "PIL_time.h"
+#include "BKE_cryptomatte.hh"
#include "BKE_material.h"
#include "GPU_capabilities.h"
@@ -238,6 +240,7 @@ class GPUCodegen {
uint32_t hash_ = 0;
BLI_HashMurmur2A hm2a_;
ListBase ubo_inputs_ = {nullptr, nullptr};
+ GPUInput *cryptomatte_input_ = nullptr;
public:
GPUCodegen(GPUMaterial *mat_, GPUNodeGraph *graph_) : mat(*mat_), graph(*graph_)
@@ -262,11 +265,13 @@ class GPUCodegen {
MEM_SAFE_FREE(output.displacement);
MEM_SAFE_FREE(output.composite);
MEM_SAFE_FREE(output.material_functions);
+ MEM_SAFE_FREE(cryptomatte_input_);
delete create_info;
BLI_freelistN(&ubo_inputs_);
};
void generate_graphs();
+ void generate_cryptomatte();
void generate_uniform_buffer();
void generate_attribs();
void generate_resources();
@@ -399,7 +404,12 @@ void GPUCodegen::generate_resources()
ss << "struct NodeTree {\n";
LISTBASE_FOREACH (LinkData *, link, &ubo_inputs_) {
GPUInput *input = (GPUInput *)(link->data);
- ss << input->type << " u" << input->id << ";\n";
+ if (input->source == GPU_SOURCE_CRYPTOMATTE) {
+ ss << input->type << " crypto_hash;\n";
+ }
+ else {
+ ss << input->type << " u" << input->id << ";\n";
+ }
}
ss << "};\n\n";
@@ -535,6 +545,24 @@ char *GPUCodegen::graph_serialize(eGPUNodeTag tree_tag)
return eval_c_str;
}
+void GPUCodegen::generate_cryptomatte()
+{
+ cryptomatte_input_ = static_cast<GPUInput *>(MEM_callocN(sizeof(GPUInput), __func__));
+ cryptomatte_input_->type = GPU_FLOAT;
+ cryptomatte_input_->source = GPU_SOURCE_CRYPTOMATTE;
+
+ float material_hash = 0.0f;
+ Material *material = GPU_material_get_material(&mat);
+ if (material) {
+ blender::bke::cryptomatte::CryptomatteHash hash(material->id.name,
+ BLI_strnlen(material->id.name, MAX_NAME - 2));
+ material_hash = hash.float_encoded();
+ }
+ cryptomatte_input_->vec[0] = material_hash;
+
+ BLI_addtail(&ubo_inputs_, BLI_genericNodeN(cryptomatte_input_));
+}
+
void GPUCodegen::generate_uniform_buffer()
{
/* Extract uniform inputs. */
@@ -615,6 +643,7 @@ GPUPass *GPU_generate_pass(GPUMaterial *material,
GPUCodegen codegen(material, graph);
codegen.generate_graphs();
+ codegen.generate_cryptomatte();
codegen.generate_uniform_buffer();
/* Cache lookup: Reuse shaders already compiled. */