11#include <fmt/format.h>
57 const bNode &node,
const bool build_meta_data)
95 const bNode &node,
const bool build_meta_data)
98 if (node.type != CMP_NODE_CRYPTOMATTE) {
102 switch (node.custom1) {
117 if (entry->encoded_hash == encoded_hash) {
154 BLI_assert(
ELEM(node->type, CMP_NODE_CRYPTOMATTE, CMP_NODE_CRYPTOMATTE_LEGACY));
164 BLI_assert(
ELEM(node->type, CMP_NODE_CRYPTOMATTE, CMP_NODE_CRYPTOMATTE_LEGACY));
173 BLI_assert(node->type == CMP_NODE_CRYPTOMATTE);
185 layer_name.copy(layer->name);
193 BLI_assert(node->type == CMP_NODE_CRYPTOMATTE);
197 std::string first_layer_name;
203 if (first_layer_name.empty()) {
204 first_layer_name = layer_name;
207 if (layer_name == node_cryptomatte->
layer_name) {
214 const char *cstr = first_layer_name.c_str();
222 return session_ptr.release();
251 if (layers.is_empty()) {
289 if (matte.should_compute()) {
290 matte.allocate_invalid();
294 if (image.should_compute()) {
295 image.allocate_invalid();
310 GPUTexture *first_layer = layers[0];
359 for (GPUTexture *layer : layers) {
386 matte.bind_as_texture(shader,
"matte_tx");
397 matte.unbind_as_texture();
408 identifiers.
append(cryptomatte_entry->encoded_hash);
430 .default_value({0.0f, 0.0f, 0.0f, 1.0f})
431 .compositor_domain_priority(0);
440 node->storage = user;
447 BLI_assert(node->type == CMP_NODE_CRYPTOMATTE);
448 node->id = &scene->id;
454 BLI_assert(
ELEM(node->type, CMP_NODE_CRYPTOMATTE, CMP_NODE_CRYPTOMATTE_LEGACY));
467 const bNode *src_node)
480 const char **r_disabled_hint)
486 for (scene =
static_cast<Scene *
>(
G.main->scenes.first);
scene;
487 scene =
static_cast<Scene *
>(scene->id.next))
489 if (scene->nodetree == ntree) {
494 if (scene ==
nullptr) {
495 *r_disabled_hint =
RPT_(
496 "The node tree must be the compositing node tree of any scene in the file");
498 return scene !=
nullptr;
500 *r_disabled_hint =
RPT_(
"Not a compositor node tree");
515 using BaseCryptoMatteOperation::BaseCryptoMatteOperation;
548 int view_layer_index = 0;
551 if (!
StringRef(type_name).startswith(view_layer->name)) {
556 const char *cryptomatte_type =
nullptr;
557 const std::string layer_prefix = std::string(view_layer->name) +
".";
568 if (!cryptomatte_type) {
573 const int cryptomatte_layers_count =
int(
math::ceil(view_layer->cryptomatte_levels / 2.0f));
574 for (
int i = 0; i < cryptomatte_layers_count; i++) {
575 const std::string pass_name = fmt::format(
"{}{:02}", cryptomatte_type, i);
577 scene, view_layer_index, pass_name.c_str());
584 layers.append(pass_texture);
610 if (!image_buffer || !image->rr) {
620 const bool is_unnamed_layer = render_layer->name[0] ==
'\0';
621 if (!is_unnamed_layer && !
StringRefNull(type_name).startswith(render_layer->name)) {
625 image_user_for_layer.
layer = layer_index;
630 if (combined_name == type_name || !
StringRef(combined_name).startswith(type_name)) {
635 context(), image, &image_user_for_layer, render_pass->name);
636 layers.append(*pass_result);
640 if (!layers.is_empty()) {
652 if (render_layer->
name[0] ==
'\0') {
653 return std::string(render_pass->
name);
655 return std::string(render_layer->
name) +
"." + std::string(render_pass->
name);
666 return std::string(type_name);
674 return int2(compositing_region.
xmin, compositing_region.
ymin);
707 return NodeOperation::compute_domain();
712 return NodeOperation::compute_domain();
716 if (!render_result) {
718 return NodeOperation::compute_domain();
723 return Domain(render_size);
734 return NodeOperation::compute_domain();
740 return NodeOperation::compute_domain();
743 const int2 image_size =
int2(image_buffer->
x, image_buffer->
y);
745 return Domain(image_size);
751 return &node_storage(
bnode()).iuser;
786 ntype.
declare = file_ns::cmp_node_cryptomatte_declare;
788 ntype.
initfunc = file_ns::node_init_cryptomatte;
789 ntype.
initfunc_api = file_ns::node_init_api_cryptomatte;
790 ntype.
poll = file_ns::node_poll_cryptomatte;
791 ntype.
updatefunc = file_ns::node_update_cryptomatte;
793 &ntype,
"NodeCryptomatte", file_ns::node_free_cryptomatte, file_ns::node_copy_cryptomatte);
807 BLI_assert(node->type == CMP_NODE_CRYPTOMATTE_LEGACY);
819 BLI_assert(node->type == CMP_NODE_CRYPTOMATTE_LEGACY);
835 file_ns::node_init_cryptomatte(ntree, node);
850 using BaseCryptoMatteOperation::BaseCryptoMatteOperation;
883 &ntype, CMP_NODE_CRYPTOMATTE_LEGACY,
"Cryptomatte (Legacy)",
NODE_CLASS_MATTE);
885 ntype.
initfunc = legacy_file_ns::node_init_cryptomatte_legacy;
887 &ntype,
"NodeCryptomatte", file_ns::node_free_cryptomatte, file_ns::node_copy_cryptomatte);
Scene * CTX_data_scene(const bContext *C)
bool BKE_cryptomatte_find_name(const struct CryptomatteSession *session, float encoded_hash, char *r_name, int name_maxncpy)
struct CryptomatteSession * BKE_cryptomatte_init_from_render_result(const struct RenderResult *render_result)
struct CryptomatteSession * BKE_cryptomatte_init_from_scene(const struct Scene *scene, bool build_meta_data)
ImBuf * BKE_image_acquire_ibuf(Image *ima, ImageUser *iuser, void **r_lock)
void BKE_image_release_ibuf(Image *ima, ImBuf *ibuf, void *lock)
#define NODE_STORAGE_FUNCS(StorageT)
#define BLI_assert_unreachable()
A dynamically sized string ADT.
#define LISTBASE_FOREACH(type, var, list)
void void void void void void BLI_duplicatelist(struct ListBase *dst, const struct ListBase *src) ATTR_NONNULL(1
BLI_INLINE void BLI_listbase_clear(struct ListBase *lb)
#define LISTBASE_FOREACH_INDEX(type, var, list, index_var)
void void BLI_freelistN(struct ListBase *listbase) ATTR_NONNULL(1)
void BLI_addtail(struct ListBase *listbase, void *vlink) ATTR_NONNULL(1)
void BLI_remlink(struct ListBase *listbase, void *vlink) ATTR_NONNULL(1)
MINLINE void zero_v3(float r[3])
#define SNPRINTF(dst, format,...)
char * BLI_strncpy(char *__restrict dst, const char *__restrict src, size_t dst_maxncpy) ATTR_NONNULL(1
@ CMP_NODE_CRYPTOMATTE_SOURCE_IMAGE
@ CMP_NODE_CRYPTOMATTE_SOURCE_RENDER
#define RE_PASSNAME_CRYPTOMATTE_MATERIAL
#define RE_PASSNAME_CRYPTOMATTE_ASSET
#define RE_PASSNAME_CRYPTOMATTE_OBJECT
int GPU_shader_get_sampler_binding(GPUShader *shader, const char *name)
void GPU_shader_uniform_1i(GPUShader *sh, const char *name, int value)
void GPU_shader_uniform_1f_array(GPUShader *sh, const char *name, int len, const float *val)
void GPU_shader_uniform_2iv(GPUShader *sh, const char *name, const int data[2])
void GPU_shader_bind(GPUShader *shader)
void GPU_texture_bind(GPUTexture *texture, int unit)
void GPU_texture_clear(GPUTexture *texture, eGPUDataFormat data_format, const void *data)
void GPU_texture_unbind(GPUTexture *texture)
Contains defines and structs used throughout the imbuf module.
Read Guarded memory(de)allocation.
struct GPUShader GPUShader
void append(const T &value)
Vector< float > get_identifiers()
virtual int2 get_layers_lower_bound()
void compute_image(Result &matte)
virtual Result & get_input_image()=0
void compute_pick(Vector< GPUTexture * > &layers)
virtual Vector< GPUTexture * > get_layers()=0
Result compute_matte(Vector< GPUTexture * > &layers)
std::string get_combined_layer_pass_name(RenderLayer *render_layer, RenderPass *render_pass)
Result & get_input_image() override
Domain compute_render_domain()
Vector< GPUTexture * > get_layers_from_render()
int2 get_layers_lower_bound() override
std::string get_type_name()
Domain compute_domain() override
Vector< GPUTexture * > get_layers() override
const ImageUser * get_image_user()
CMPNodeCryptomatteSource get_source()
Domain compute_image_domain()
Vector< GPUTexture * > get_layers_from_image()
Vector< GPUTexture * > get_layers() override
Result & get_input_image() override
Result * get(Context &context, Image *image, const ImageUser *image_user, const char *pass_name)
virtual rcti get_compositing_region() const =0
StaticCacheManager & cache_manager()
GPUShader * get_shader(const char *info_name, ResultPrecision precision)
Result create_result(ResultType type, ResultPrecision precision)
virtual GPUTexture * get_input_texture(const Scene *scene, int view_layer, const char *pass_name)=0
NodeOperation(Context &context, DNode node)
const bNode & bnode() const
Result & get_input(StringRef identifier) const
Result & get_result(StringRef identifier)
Context & context() const
virtual Domain compute_domain()
void bind_as_image(GPUShader *shader, const char *image_name, bool read=false) const
void unbind_as_texture() const
void set_precision(ResultPrecision precision)
void unbind_as_image() const
void allocate_texture(Domain domain, bool from_pool=true)
void steal_data(Result &source)
void bind_as_texture(GPUShader *shader, const char *texture_name) const
CachedImageContainer cached_images
local_group_size(16, 16) .push_constant(Type b
draw_view push_constant(Type::INT, "radiance_src") .push_constant(Type capture_info_buf storage_buf(1, Qualifier::READ, "ObjectBounds", "bounds_buf[]") .push_constant(Type draw_view int
void MEM_freeN(void *vmemh)
void *(* MEM_dupallocN)(const void *vmemh)
std::unique_ptr< CryptomatteSession, CryptomatteSessionDeleter > CryptomatteSessionPtr
const blender::Vector< std::string > & BKE_cryptomatte_layer_names_get(const CryptomatteSession &session)
bNodeSocket * node_add_static_socket(bNodeTree *ntree, bNode *node, eNodeSocketInOut in_out, int type, int subtype, const char *identifier, const char *name)
void node_type_socket_templates(bNodeType *ntype, bNodeSocketTemplate *inputs, bNodeSocketTemplate *outputs)
void node_remove_socket(bNodeTree *ntree, bNode *node, bNodeSocket *sock)
void node_type_size(bNodeType *ntype, int width, int minwidth, int maxwidth)
void node_type_storage(bNodeType *ntype, const char *storagename, void(*freefunc)(bNode *node), void(*copyfunc)(bNodeTree *dest_ntree, bNode *dest_node, const bNode *src_node))
void node_register_type(bNodeType *ntype)
static void node_update_cryptomatte(bNodeTree *ntree, bNode *node)
static void node_copy_cryptomatte(bNodeTree *, bNode *dest_node, const bNode *src_node)
static void node_init_api_cryptomatte(const bContext *C, PointerRNA *ptr)
static NodeOperation * get_compositor_operation(Context &context, DNode node)
static void node_free_cryptomatte(bNode *node)
static void cmp_node_cryptomatte_declare(NodeDeclarationBuilder &b)
static bool node_poll_cryptomatte(const blender::bke::bNodeType *, const bNodeTree *ntree, const char **r_disabled_hint)
static void node_init_cryptomatte(bNodeTree *, bNode *node)
static bke::bNodeSocketTemplate cmp_node_cryptomatte_out[]
static void node_init_cryptomatte_legacy(bNodeTree *ntree, bNode *node)
static NodeOperation * get_compositor_operation(Context &context, DNode node)
void compute_dispatch_threads_at_least(GPUShader *shader, int2 threads_range, int2 local_size=int2(16))
VecBase< float, 4 > float4
VecBase< int32_t, 2 > int2
void ntreeCompositCryptomatteLayerPrefix(const bNode *node, char *r_prefix, size_t prefix_maxncpy)
void register_node_type_cmp_cryptomatte_legacy()
static blender::bke::cryptomatte::CryptomatteSessionPtr cryptomatte_init_from_node_render(const bNode &node, const bool build_meta_data)
static CryptomatteEntry * cryptomatte_find(const NodeCryptomatte &n, float encoded_hash)
int ntreeCompositCryptomatteRemoveSocket(bNodeTree *ntree, bNode *node)
void ntreeCompositCryptomatteSyncFromRemove(bNode *node)
CryptomatteSession * ntreeCompositCryptomatteSession(bNode *node)
bNodeSocket * ntreeCompositCryptomatteAddSocket(bNodeTree *ntree, bNode *node)
void ntreeCompositCryptomatteUpdateLayerNames(bNode *node)
static void cryptomatte_remove(NodeCryptomatte &n, float encoded_hash)
static blender::bke::cryptomatte::CryptomatteSessionPtr cryptomatte_init_from_node(const bNode &node, const bool build_meta_data)
static void cryptomatte_add(bNode &node, NodeCryptomatte &node_cryptomatte, float encoded_hash)
void register_node_type_cmp_cryptomatte()
void ntreeCompositCryptomatteSyncFromAdd(bNode *node)
static blender::bke::cryptomatte::CryptomatteSessionPtr cryptomatte_init_from_node_image(const bNode &node)
void cmp_node_type_base(blender::bke::bNodeType *ntype, int type, const char *name, short nclass)
void cmp_node_update_default(bNodeTree *, bNode *node)
RenderResult * RE_AcquireResultRead(Render *re)
void RE_ReleaseResult(Render *re)
Render * RE_GetSceneRender(const Scene *scene)
NodeCryptomatte_Runtime runtime
NodeGetCompositorOperationFunction get_compositor_operation
void(* initfunc)(bNodeTree *ntree, bNode *node)
bool(* poll)(const bNodeType *ntype, const bNodeTree *nodetree, const char **r_disabled_hint)
NodeGatherSocketLinkOperationsFunction gather_link_search_ops
NodeDeclareFunction declare
void(* updatefunc)(bNodeTree *ntree, bNode *node)
void(* initfunc_api)(const bContext *C, PointerRNA *ptr)