Blender V5.3
node_shader_output_aov.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2005 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
8
9#include "node_shader_util.hh"
10#include "node_util.hh"
11
12#include "BLI_hash_c.hh"
13
14#include "RNA_access.hh"
15#include "RNA_prototypes.hh"
16
17#include "BKE_context.hh"
18
20#include "UI_resources.hh"
21
22namespace blender {
23
25
27{
28 b.add_input<decl::Color>("Color"_ustr).default_value({0.0f, 0.0f, 0.0f, 1.0f});
29 b.add_input<decl::Float>("Value"_ustr).default_value(0.0f).min(0.0f).max(1.0f);
30}
31
32static BIFIconID aov_icon(const ViewLayer *view_layer, PointerRNA *ptr)
33{
34 std::string aov_name = RNA_string_get(ptr, "aov_name");
35 if (aov_name.empty()) {
36 return ICON_RECORD_OFF;
37 }
38
39 const ViewLayerAOV *aov = static_cast<const ViewLayerAOV *>(
40 BLI_findstring(&view_layer->aovs, aov_name.c_str(), offsetof(ViewLayerAOV, name)));
41
42 if (aov) {
43 switch (aov->type) {
44 case AOV_TYPE_COLOR:
45 return ICON_NODE_SOCKET_RGBA;
46 case AOV_TYPE_VALUE:
47 return ICON_NODE_SOCKET_FLOAT;
48 }
49 }
50
51 return ICON_RECORD_OFF;
52}
53
55{
56 Scene *scene = CTX_data_scene(C);
57 ViewLayer *view_layer = CTX_data_view_layer(C);
58
59 if (scene && view_layer) {
60 PointerRNA view_layer_rna_ptr = RNA_pointer_create_id_subdata(
61 scene->id, RNA_ViewLayer, view_layer);
62 layout.prop_search(
63 ptr, "aov_name", &view_layer_rna_ptr, "aovs", "", aov_icon(view_layer, ptr));
64 }
65 else {
66 layout.prop(ptr, "aov_name", ui::ITEM_R_SPLIT_EMPTY_NAME, std::nullopt, ICON_NONE);
67 }
68}
69
71{
72 NodeShaderOutputAOV *aov = MEM_new<NodeShaderOutputAOV>("NodeShaderOutputAOV");
73 node->storage = aov;
74}
75
77 bNode *node,
78 bNodeExecData * /*execdata*/,
81{
82 GPUNodeLink *outlink;
83 NodeShaderOutputAOV *aov = static_cast<NodeShaderOutputAOV *>(node->storage);
85 /* WORKAROUND: We don't support int/uint constants for now. So make sure the aliasing works.
86 * We cast back to uint in GLSL. */
87 BLI_STATIC_ASSERT(sizeof(float) == sizeof(uint),
88 "GPUCodegen: AOV hash needs float and uint to be the same size.");
89 GPUNodeLink *hash_link = GPU_constant(reinterpret_cast<float *>(&hash));
90
93 node,
94 "node_output_aov",
95 in,
96 out,
97 hash_link,
100 &outlink);
102 return true;
103}
104
105} // namespace nodes::node_shader_output_aov_cc
106
107/* node type definition */
109{
110 namespace file_ns = nodes::node_shader_output_aov_cc;
111
112 static bke::bNodeType ntype;
113
114 sh_node_type_base(&ntype, "ShaderNodeOutputAOV"_ustr, SH_NODE_OUTPUT_AOV);
115 ntype.ui_name = "AOV Output";
116 ntype.ui_description =
117 "Arbitrary Output Variables.\nProvide custom render passes for arbitrary shader node "
118 "outputs";
119 ntype.enum_name_legacy = "OUTPUT_AOV";
121 ntype.declare = file_ns::node_declare;
122 ntype.draw_buttons = file_ns::node_shader_buts_output_aov;
123 ntype.initfunc = file_ns::node_shader_init_output_aov;
125 ntype, "NodeShaderOutputAOV", node_free_standard_storage, node_copy_standard_storage);
126 ntype.gpu_fn = file_ns::node_shader_gpu_output_aov;
127
128 ntype.no_muting = true;
129
131}
132
133} // namespace blender
#define NODE_CLASS_OUTPUT
Definition BKE_node.hh:479
#define SH_NODE_OUTPUT_AOV
#define C
Definition RandGen.cpp:29
#define offsetof(t, d)
void node_register_type(bNodeType &ntype)
Definition node.cc:2920
void node_type_storage(bNodeType &ntype, std::optional< StringRefNull > storagename, void(*freefunc)(bNode *node), void(*copyfunc)(bNodeTree *dest_ntree, bNode *dest_node, const bNode *src_node))
Definition node.cc:6166
static void node_shader_init_output_aov(bNodeTree *, bNode *node)
static void node_shader_buts_output_aov(ui::Layout &layout, bContext *C, PointerRNA *ptr)
static BIFIconID aov_icon(const ViewLayer *view_layer, PointerRNA *ptr)
static int node_shader_gpu_output_aov(GPUMaterial *mat, bNode *node, bNodeExecData *, GPUNodeStack *in, GPUNodeStack *out)
static void node_declare(NodeDeclarationBuilder &b)
BMesh Iterators.
bool GPU_stack_link(GPUMaterial *mat, const bNode *node, const char *name, GPUNodeStack *in, GPUNodeStack *out,...)
BLI_STATIC_ASSERT(ARRAY_SIZE(data_mode_strings)==CTX_MODE_NUM+1, "Must have a string for each context mode") const char *CTX_data_mode_string(const bContext *C)
unsigned int uint
Definition BKE_text.h:55
@ GPU_MATFLAG_OBJECT_INFO
@ GPU_MATFLAG_AOV
void * BLI_findstring(const ListBase *listbase, const char *id, int offset) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1)
Definition listbase.cc:615
void sh_node_type_base(bke::bNodeType *ntype, UString idname, const std::optional< int16_t > legacy_type)
ViewLayer * CTX_data_view_layer(const bContext *C)
GPUNodeLink * GPU_constant(const float *num)
void GPU_material_flag_set(GPUMaterial *mat, eGPUMaterialFlag flag)
int BIFIconID
Definition ED_asset.hh:30
GPUNodeLink * GPU_shading_data()
void GPU_material_add_output_link_aov(GPUMaterial *material, GPUNodeLink *link, int hash)
void register_node_type_sh_output_aov()
BLI_INLINE unsigned int BLI_hash_string(const char *str)
Definition BLI_hash_c.hh:69
PointerRNA RNA_pointer_create_id_subdata(ID &id, StructRNA *type, void *data)
GPUNodeLink * GPU_kernel_globals()
void node_copy_standard_storage(bNodeTree *, bNode *dest_node, const bNode *src_node)
Definition node_util.cc:57
Scene * CTX_data_scene(const bContext *C)
void node_free_standard_storage(bNode *node)
Definition node_util.cc:45
std::string RNA_string_get(PointerRNA *ptr, const char *name)
#define hash
Definition noise_c.cc:156
eViewLayerAOVType type
ListBaseT< ViewLayerAOV > aovs
Defines a node type.
Definition BKE_node.hh:265
void(*) draw_buttons(ui::Layout &, bContext *C, PointerRNA *ptr)
Definition BKE_node.hh:290
std::string ui_description
Definition BKE_node.hh:271
NodeGPUExecFunction gpu_fn
Definition BKE_node.hh:373
void(*) initfunc(bNodeTree *ntree, bNode *node)
Definition BKE_node.hh:320
const char * enum_name_legacy
Definition BKE_node.hh:274
NodeDeclareFunction declare
Definition BKE_node.hh:393
void prop_search(PointerRNA *ptr, PropertyRNA *prop, PointerRNA *searchptr, PropertyRNA *searchprop, PropertyRNA *item_searchpropname, std::optional< StringRefNull > name, int icon, bool results_are_suggestions)
void prop(PointerRNA *ptr, PropertyRNA *prop, int index, int value, eUI_Item_Flag flag, std::optional< StringRef > name_opt, int icon, std::optional< StringRef > placeholder=std::nullopt)