[Bf-blender-cvs] [94b7b354d97] temp-eevee-next-cryptomatte: Eevee-next: Cryptomatte merging samples.
Jeroen Bakker
noreply at git.blender.org
Mon Aug 22 15:49:47 CEST 2022
Commit: 94b7b354d9771cd3aec8becabf62776a951f73ad
Author: Jeroen Bakker
Date: Thu Aug 11 16:18:26 2022 +0200
Branches: temp-eevee-next-cryptomatte
https://developer.blender.org/rB94b7b354d9771cd3aec8becabf62776a951f73ad
Eevee-next: Cryptomatte merging samples.
===================================================================
M source/blender/draw/engines/eevee_next/eevee_cryptomatte.cc
M source/blender/draw/engines/eevee_next/shaders/eevee_cryptomatte_lib.glsl
M source/blender/draw/engines/eevee_next/shaders/infos/eevee_cryptomatte_info.hh
M source/blender/makesrna/intern/rna_space.c
===================================================================
diff --git a/source/blender/draw/engines/eevee_next/eevee_cryptomatte.cc b/source/blender/draw/engines/eevee_next/eevee_cryptomatte.cc
index 5207d588d44..25f8a608a18 100644
--- a/source/blender/draw/engines/eevee_next/eevee_cryptomatte.cc
+++ b/source/blender/draw/engines/eevee_next/eevee_cryptomatte.cc
@@ -29,8 +29,8 @@ void Cryptomatte::sync()
cryptomatte_ps_ = DRW_pass_create("Cryptomatte", DRW_STATE_WRITE_COLOR | DRW_STATE_DEPTH_EQUAL);
GPUShader *sh_mesh = inst_.shaders.static_shader_get(CRYPTOMATTE_MESH);
mesh_grp_ = DRW_shgroup_create(sh_mesh, cryptomatte_ps_);
- GPUShader *sh_curves = inst_.shaders.static_shader_get(CRYPTOMATTE_CURVES);
- hair_grp_ = DRW_shgroup_create(sh_curves, cryptomatte_ps_);
+ //GPUShader *sh_curves = inst_.shaders.static_shader_get(CRYPTOMATTE_CURVES);
+ //hair_grp_ = DRW_shgroup_create(sh_curves, cryptomatte_ps_);
}
static float hash_id(const ID *id)
diff --git a/source/blender/draw/engines/eevee_next/shaders/eevee_cryptomatte_lib.glsl b/source/blender/draw/engines/eevee_next/shaders/eevee_cryptomatte_lib.glsl
index 5699be9da23..57f4c880132 100644
--- a/source/blender/draw/engines/eevee_next/shaders/eevee_cryptomatte_lib.glsl
+++ b/source/blender/draw/engines/eevee_next/shaders/eevee_cryptomatte_lib.glsl
@@ -1,25 +1,38 @@
/** Storing/merging and sorting cryptomatte samples. */
-void film_store_cryptomatte_sample(FilmSample dst, int cryptomatte_layer_id, float hash){
- float weight = dst.weight;
- /*
- first need to detect the operation.
- - when hash exists it should be updated and can optionally be reinserted into a new position.
- - when hash doesn't exist we should find an insertion point. only samples to a null sample (hash 0, weight 0) should be moved. When no null sample exist it will remove the lowest weight.
+bool can_merge_cryptomatte_sample(vec2 cryptomatte_sample, float hash) {
+ if (cryptomatte_sample == vec2(0.0, 0.0)) {
+ return true;
+ }
+ if (cryptomatte_sample.x == hash) {
+ return true;
+ }
+}
- Second option would be to find the place to fit the sample. Doing the sorting in a separate shader
- pro is that the performance when adding samples. Sorting only happens once during
- final rendering. When using the viewport compositor this shader could be called
- as a post process for active layers.
+vec2 merge_cryptomatte_sample(vec2 cryptomatte_sample, float hash, float weight) {
+ return vec2(hash, cryptomatte_sample.y + weight);
+}
- perhaps in the viewport the first option would fit better. The second option
- is better for final rendering, but at that time performance is secondary.
- Technically the order of the samples don't matter that much, But it depends on how many
- cryptomatte nodes are used to make sorting more efficient.
- Would need some feedback from Beau/Andy on this subject.
-
- */
- int operation = 0;
+void film_store_cryptomatte_sample(FilmSample dst, int cryptomatte_layer_id, float hash){
+ float weight = dst.weight;
-
+ for (int i = 0; i < film_buf.cryptomatte_samples_len/2; i ++) {
+ ivec3 img_co = ivec3(dst.texel, i);
+ vec4 sample_pair = imageLoad(cryptomatte_img, img_co);
+ if (can_merge_cryptomatte_sample(sample_pair.xy, hash)) {
+ sample_pair.xy = merge_cryptomatte_sample(sample_pair.xy, hash, weight);
+ }
+ else if (can_merge_cryptomatte_sample(sample_pair.zw, hash)) {
+ sample_pair.zw = merge_cryptomatte_sample(sample_pair.zw, hash, weight);
+ }
+ else if (i == film_buf.cryptomatte_samples_len / 2 -1) {
+ // TODO: new hash, no space, we should compare/overwrite lowest sample.
+ continue;
+ }
+ else {
+ continue;
+ }
+ imageStore(cryptomatte_img, img_co, sample_pair);
+ break;
+ }
}
diff --git a/source/blender/draw/engines/eevee_next/shaders/infos/eevee_cryptomatte_info.hh b/source/blender/draw/engines/eevee_next/shaders/infos/eevee_cryptomatte_info.hh
index 31351ada847..26de5ac73b7 100644
--- a/source/blender/draw/engines/eevee_next/shaders/infos/eevee_cryptomatte_info.hh
+++ b/source/blender/draw/engines/eevee_next/shaders/infos/eevee_cryptomatte_info.hh
@@ -3,7 +3,8 @@
GPU_SHADER_CREATE_INFO(eevee_cryptomatte)
.fragment_source("eevee_cryptomatte_frag.glsl")
.push_constant(Type::VEC4, "cryptomatte_hash")
- .fragment_out(0, Type::VEC4, "fragColor");
+ .fragment_out(0, Type::VEC4, "fragColor")
+ .additional_info("eevee_surf_forward");
GPU_SHADER_CREATE_INFO(eevee_cryptomatte_curves)
.do_static_compilation(true)
diff --git a/source/blender/makesrna/intern/rna_space.c b/source/blender/makesrna/intern/rna_space.c
index 502b0404764..bd35e56df55 100644
--- a/source/blender/makesrna/intern/rna_space.c
+++ b/source/blender/makesrna/intern/rna_space.c
@@ -455,6 +455,9 @@ static const EnumPropertyItem rna_enum_view3dshading_render_pass_type_items[] =
RNA_ENUM_ITEM_HEADING("Data", NULL),
{EEVEE_RENDER_PASS_NORMAL, "NORMAL", 0, "Normal", ""},
{EEVEE_RENDER_PASS_MIST, "MIST", 0, "Mist", ""},
+ {EEVEE_RENDER_PASS_CRYPTOMATTE_OBJECT, "CryptoObject", 0, "CryptoObject", ""},
+ {EEVEE_RENDER_PASS_CRYPTOMATTE_ASSET, "CryptoAsset", 0, "CryptoAsset", ""},
+ {EEVEE_RENDER_PASS_CRYPTOMATTE_MATERIAL, "CryptoMaterial", 0, "CryptoMaterial", ""},
RNA_ENUM_ITEM_HEADING("Shader AOV", NULL),
{EEVEE_RENDER_PASS_AOV, "AOV", 0, "AOV", ""},
More information about the Bf-blender-cvs
mailing list