[Bf-blender-cvs] [5367d106dbf] temp-eevee-next-cryptomatte: Cryptomatte: FBs, Passes and Shaders.
Jeroen Bakker
noreply at git.blender.org
Mon Aug 8 14:18:13 CEST 2022
Commit: 5367d106dbffca0e6e8861e7c8aa1294bdc6fbaa
Author: Jeroen Bakker
Date: Mon Aug 8 14:18:05 2022 +0200
Branches: temp-eevee-next-cryptomatte
https://developer.blender.org/rB5367d106dbffca0e6e8861e7c8aa1294bdc6fbaa
Cryptomatte: FBs, Passes and Shaders.
===================================================================
M source/blender/draw/CMakeLists.txt
M source/blender/draw/engines/eevee_next/eevee_cryptomatte.cc
M source/blender/draw/engines/eevee_next/eevee_cryptomatte.hh
M source/blender/draw/engines/eevee_next/eevee_instance.cc
M source/blender/draw/engines/eevee_next/eevee_instance.hh
M source/blender/draw/engines/eevee_next/eevee_shader.cc
M source/blender/draw/engines/eevee_next/eevee_shader.hh
M source/blender/draw/engines/eevee_next/eevee_view.cc
A source/blender/draw/engines/eevee_next/shaders/eevee_cryptomatte_frag.glsl
A source/blender/draw/engines/eevee_next/shaders/infos/eevee_cryptomatte_info.hh
M source/blender/gpu/CMakeLists.txt
===================================================================
diff --git a/source/blender/draw/CMakeLists.txt b/source/blender/draw/CMakeLists.txt
index 7d10563147e..81dfb5b8f91 100644
--- a/source/blender/draw/CMakeLists.txt
+++ b/source/blender/draw/CMakeLists.txt
@@ -365,6 +365,7 @@ set(GLSL_SRC
engines/eevee_next/shaders/eevee_attributes_lib.glsl
engines/eevee_next/shaders/eevee_camera_lib.glsl
engines/eevee_next/shaders/eevee_colorspace_lib.glsl
+ engines/eevee_next/shaders/eevee_cryptomatte_frag.glsl
engines/eevee_next/shaders/eevee_depth_of_field_accumulator_lib.glsl
engines/eevee_next/shaders/eevee_depth_of_field_bokeh_lut_comp.glsl
engines/eevee_next/shaders/eevee_depth_of_field_downsample_comp.glsl
diff --git a/source/blender/draw/engines/eevee_next/eevee_cryptomatte.cc b/source/blender/draw/engines/eevee_next/eevee_cryptomatte.cc
index e69de29bb2d..a611a9f57e5 100644
--- a/source/blender/draw/engines/eevee_next/eevee_cryptomatte.cc
+++ b/source/blender/draw/engines/eevee_next/eevee_cryptomatte.cc
@@ -0,0 +1,44 @@
+#include "eevee_cryptomatte.hh"
+#include "eevee_instance.hh"
+#include "eevee_renderbuffers.hh"
+
+namespace blender::eevee {
+
+void Cryptomatte::init()
+{
+ eViewLayerEEVEEPassType enabled_passes = inst_.film.enabled_passes_get();
+ layer_len_ = 0;
+ object_offset_ = (enabled_passes & EEVEE_RENDER_PASS_CRYPTOMATTE_OBJECT) ? layer_len_++ : -1;
+ asset_offset_ = (enabled_passes & EEVEE_RENDER_PASS_CRYPTOMATTE_ASSET) ? layer_len_++ : -1;
+ material_offset_ = (enabled_passes & EEVEE_RENDER_PASS_CRYPTOMATTE_MATERIAL) ? layer_len_++ : -1;
+
+ BLI_assert_msg(layer_len_ == inst_.film.cryptomatte_layer_len_get(),
+ "Cryptomatte and film mismatch");
+}
+
+void Cryptomatte::sync()
+{
+ if (layer_len_ == 0) {
+ return;
+ }
+
+ 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_);
+}
+
+void Cryptomatte::render()
+{
+ if (layer_len_ == 0) {
+ return;
+ }
+ const RenderBuffers &rbufs = inst_.render_buffers;
+ cryptomatte_fb_.ensure(GPU_ATTACHMENT_TEXTURE(rbufs.depth_tx),
+ GPU_ATTACHMENT_TEXTURE(rbufs.combined_tx));
+ GPU_framebuffer_bind(cryptomatte_fb_);
+ DRW_draw_pass(cryptomatte_ps_);
+}
+
+} // namespace blender::eevee
\ No newline at end of file
diff --git a/source/blender/draw/engines/eevee_next/eevee_cryptomatte.hh b/source/blender/draw/engines/eevee_next/eevee_cryptomatte.hh
index 8566c76a0e9..578eea77fe8 100644
--- a/source/blender/draw/engines/eevee_next/eevee_cryptomatte.hh
+++ b/source/blender/draw/engines/eevee_next/eevee_cryptomatte.hh
@@ -29,11 +29,31 @@ class Cryptomatte {
private:
class Instance &inst_;
+ /**
+ * Offsets of cryptomatte layers inside the components of a color. (-1 means the layer isn't
+ * enabled.)
+ */
+ int object_offset_;
+ int asset_offset_;
+ int material_offset_;
+
+ /** Number of enabled cryptomatte layers. */
+ int layer_len_;
+
+ DRWPass *cryptomatte_ps_ = nullptr;
+ Framebuffer cryptomatte_fb_ = {"cryptomatte"};
+ DRWShadingGroup *mesh_grp_;
+ DRWShadingGroup *hair_grp_;
+
public:
- DepthOfField(Instance &inst) : inst_(inst){};
- ~DepthOfField(){};
+ Cryptomatte(Instance &inst) : inst_(inst){};
+ ~Cryptomatte(){};
void init();
+
+ void sync();
+ void object_sync(Object *ob);
+ void render();
};
/** \} */
diff --git a/source/blender/draw/engines/eevee_next/eevee_instance.cc b/source/blender/draw/engines/eevee_next/eevee_instance.cc
index 96ce4046e23..338fe5d82d1 100644
--- a/source/blender/draw/engines/eevee_next/eevee_instance.cc
+++ b/source/blender/draw/engines/eevee_next/eevee_instance.cc
@@ -63,6 +63,7 @@ void Instance::init(const int2 &output_res,
velocity.init();
depth_of_field.init();
motion_blur.init();
+ cryptomatte.init();
main_view.init();
}
@@ -101,6 +102,7 @@ void Instance::begin_sync()
depth_of_field.sync();
motion_blur.sync();
+ cryptomatte.sync();
pipelines.sync();
main_view.sync();
world.sync();
diff --git a/source/blender/draw/engines/eevee_next/eevee_instance.hh b/source/blender/draw/engines/eevee_next/eevee_instance.hh
index 60dffd7c5ec..1fc0eba89d2 100644
--- a/source/blender/draw/engines/eevee_next/eevee_instance.hh
+++ b/source/blender/draw/engines/eevee_next/eevee_instance.hh
@@ -16,6 +16,7 @@
#include "DRW_render.h"
#include "eevee_camera.hh"
+#include "eevee_cryptomatte.hh"
#include "eevee_depth_of_field.hh"
#include "eevee_film.hh"
#include "eevee_material.hh"
@@ -46,6 +47,7 @@ class Instance {
VelocityModule velocity;
MotionBlurModule motion_blur;
DepthOfField depth_of_field;
+ Cryptomatte cryptomatte;
Sampling sampling;
Camera camera;
Film film;
@@ -83,6 +85,7 @@ class Instance {
velocity(*this),
motion_blur(*this),
depth_of_field(*this),
+ cryptomatte(*this),
sampling(*this),
camera(*this),
film(*this),
diff --git a/source/blender/draw/engines/eevee_next/eevee_shader.cc b/source/blender/draw/engines/eevee_next/eevee_shader.cc
index 357f2796a7e..9c25036a7dd 100644
--- a/source/blender/draw/engines/eevee_next/eevee_shader.cc
+++ b/source/blender/draw/engines/eevee_next/eevee_shader.cc
@@ -82,6 +82,10 @@ const char *ShaderModule::static_shader_create_info_name_get(eShaderType shader_
return "eevee_film_frag";
case FILM_COMP:
return "eevee_film_comp";
+ case CRYPTOMATTE_CURVES:
+ return "eevee_cryptomatte_curves";
+ case CRYPTOMATTE_MESH:
+ return "eevee_cryptomatte_mesh";
case MOTION_BLUR_GATHER:
return "eevee_motion_blur_gather";
case MOTION_BLUR_TILE_DILATE:
diff --git a/source/blender/draw/engines/eevee_next/eevee_shader.hh b/source/blender/draw/engines/eevee_next/eevee_shader.hh
index dd6b9c9d4ab..6c578e18ad8 100644
--- a/source/blender/draw/engines/eevee_next/eevee_shader.hh
+++ b/source/blender/draw/engines/eevee_next/eevee_shader.hh
@@ -29,6 +29,9 @@ enum eShaderType {
FILM_FRAG = 0,
FILM_COMP,
+ CRYPTOMATTE_CURVES,
+ CRYPTOMATTE_MESH,
+
DOF_BOKEH_LUT,
DOF_DOWNSAMPLE,
DOF_FILTER,
diff --git a/source/blender/draw/engines/eevee_next/eevee_view.cc b/source/blender/draw/engines/eevee_next/eevee_view.cc
index c195f68380c..2344a859550 100644
--- a/source/blender/draw/engines/eevee_next/eevee_view.cc
+++ b/source/blender/draw/engines/eevee_next/eevee_view.cc
@@ -131,6 +131,8 @@ void ShadingView::render()
// inst_.lights.debug_draw(view_fb_);
// inst_.shadows.debug_draw(view_fb_);
+ inst_.cryptomatte.render();
+
GPUTexture *combined_final_tx = render_postfx(rbufs.combined_tx);
inst_.film.accumulate(sub_view_, combined_final_tx);
diff --git a/source/blender/draw/engines/eevee_next/shaders/eevee_cryptomatte_frag.glsl b/source/blender/draw/engines/eevee_next/shaders/eevee_cryptomatte_frag.glsl
new file mode 100644
index 00000000000..eaf30c08321
--- /dev/null
+++ b/source/blender/draw/engines/eevee_next/shaders/eevee_cryptomatte_frag.glsl
@@ -0,0 +1,3 @@
+void main() {
+ fragColor = cryptomatte_hash;
+}
\ No newline at end of file
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
new file mode 100644
index 00000000000..31351ada847
--- /dev/null
+++ b/source/blender/draw/engines/eevee_next/shaders/infos/eevee_cryptomatte_info.hh
@@ -0,0 +1,13 @@
+#include "gpu_shader_create_info.hh"
+
+GPU_SHADER_CREATE_INFO(eevee_cryptomatte)
+ .fragment_source("eevee_cryptomatte_frag.glsl")
+ .push_constant(Type::VEC4, "cryptomatte_hash")
+ .fragment_out(0, Type::VEC4, "fragColor");
+
+GPU_SHADER_CREATE_INFO(eevee_cryptomatte_curves)
+ .do_static_compilation(true)
+ .additional_info("eevee_geom_curves", "eevee_cryptomatte");
+GPU_SHADER_CREATE_INFO(eevee_cryptomatte_mesh)
+ .do_static_compilation(true)
+ .additional_info("eevee_geom_mesh", "eevee_cryptomatte");
diff --git a/source/blender/gpu/CMakeLists.txt b/source/blender/gpu/CMakeLists.txt
index 4157caf45d7..23f7ec5b447 100644
--- a/source/blender/gpu/CMakeLists.txt
+++ b/source/blender/gpu/CMakeLists.txt
@@ -454,6 +454,7 @@ list(APPEND INC ${CMAKE_CURRENT_BINARY_DIR})
set(SRC_SHADER_CREATE_INFOS
../draw/engines/basic/shaders/infos/basic_depth_info.hh
+ ../draw/engines/eevee_next/shaders/infos/eevee_cryptomatte_info.hh
../draw/engines/eevee_next/shaders/infos/eevee_depth_of_field_info.hh
../draw/engines/eevee_next/shaders/infos/eevee_film_info.hh
../draw/engines/eevee_next/shaders/infos/eevee_material_info.hh
More information about the Bf-blender-cvs
mailing list