Blender V5.0
node_shader_vertex_color.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
5#include "node_shader_util.hh"
6#include "node_util.hh"
7
8#include "BKE_context.hh"
9
11
12#include "RNA_access.hh"
13
15#include "UI_resources.hh"
16
18
20{
21 b.add_output<decl::Color>("Color");
22 b.add_output<decl::Float>("Alpha");
23}
24
26{
27 PointerRNA obptr = CTX_data_pointer_get(C, "active_object");
28 Object *object = static_cast<Object *>(obptr.data);
29
30 if (object && object->type == OB_MESH) {
32
33 if (depsgraph) {
34 Object *object_eval = DEG_get_evaluated(depsgraph, object);
35 PointerRNA dataptr = RNA_id_pointer_create(static_cast<ID *>(object_eval->data));
36 layout->prop_search(ptr, "layer_name", &dataptr, "color_attributes", "", ICON_GROUP_VCOL);
37 return;
38 }
39 }
40
41 layout->prop(ptr, "layer_name", UI_ITEM_R_SPLIT_EMPTY_NAME, std::nullopt, ICON_GROUP_VCOL);
42 layout->label(RPT_("No mesh in active object"), ICON_ERROR);
43}
44
45static void node_shader_init_vertex_color(bNodeTree * /*ntree*/, bNode *node)
46{
47 NodeShaderVertexColor *vertexColor = MEM_callocN<NodeShaderVertexColor>("NodeShaderVertexColor");
48 node->storage = vertexColor;
49}
50
52 bNode *node,
53 bNodeExecData * /*execdata*/,
56{
58 /* NOTE: Using #CD_AUTO_FROM_NAME is necessary because there are multiple color attribute types,
59 * and the type may change during evaluation anyway. This will also make EEVEE and Cycles
60 * consistent. See #93179. */
61
62 GPUNodeLink *vertexColorLink;
63
64 if (vertexColor->layer_name[0]) {
65 vertexColorLink = GPU_attribute(mat, CD_AUTO_FROM_NAME, vertexColor->layer_name);
66 }
67 else { /* Fall back on active render color attribute. */
68 vertexColorLink = GPU_attribute_default_color(mat);
69 }
70
71 return GPU_stack_link(mat, node, "node_vertex_color", in, out, vertexColorLink);
72}
73
75#ifdef WITH_MATERIALX
76{
77 /* TODO: some output expected be implemented within the next iteration
78 * (see node-definition `<geomcolor>`). */
79 return get_output_default(socket_out_->identifier, NodeItem::Type::Any);
80}
81#endif
83
84} // namespace blender::nodes::node_shader_vertex_color_cc
85
87{
89
90 static blender::bke::bNodeType ntype;
91
92 sh_node_type_base(&ntype, "ShaderNodeVertexColor", SH_NODE_VERTEX_COLOR);
93 ntype.ui_name = "Color Attribute";
94 ntype.ui_description =
95 "Retrieve a color attribute, or the default fallback if none is specified";
96 ntype.enum_name_legacy = "VERTEX_COLOR";
98 ntype.declare = file_ns::node_declare;
99 ntype.draw_buttons = file_ns::node_shader_buts_vertex_color;
100 ntype.initfunc = file_ns::node_shader_init_vertex_color;
102 ntype, "NodeShaderVertexColor", node_free_standard_storage, node_copy_standard_storage);
103 ntype.gpu_fn = file_ns::node_shader_gpu_vertex_color;
104 ntype.materialx_fn = file_ns::node_shader_materialx;
105
107}
PointerRNA CTX_data_pointer_get(const bContext *C, const char *member)
Depsgraph * CTX_data_depsgraph_pointer(const bContext *C)
#define NODE_CLASS_INPUT
Definition BKE_node.hh:447
#define SH_NODE_VERTEX_COLOR
#define RPT_(msgid)
T * DEG_get_evaluated(const Depsgraph *depsgraph, T *id)
@ CD_AUTO_FROM_NAME
@ OB_MESH
bool GPU_stack_link(GPUMaterial *mat, const bNode *node, const char *name, GPUNodeStack *in, GPUNodeStack *out,...)
GPUNodeLink * GPU_attribute_default_color(GPUMaterial *mat)
GPUNodeLink * GPU_attribute(GPUMaterial *mat, eCustomDataType type, const char *name)
#define C
Definition RandGen.cpp:29
@ UI_ITEM_R_SPLIT_EMPTY_NAME
BPy_StructRNA * depsgraph
#define in
#define out
void * MEM_callocN(size_t len, const char *str)
Definition mallocn.cc:118
void node_register_type(bNodeType &ntype)
Definition node.cc:2416
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:5414
static void node_shader_init_vertex_color(bNodeTree *, bNode *node)
static void node_shader_buts_vertex_color(uiLayout *layout, bContext *C, PointerRNA *ptr)
static void node_declare(NodeDeclarationBuilder &b)
static int node_shader_gpu_vertex_color(GPUMaterial *mat, bNode *node, bNodeExecData *, GPUNodeStack *in, GPUNodeStack *out)
#define NODE_SHADER_MATERIALX_BEGIN
#define NODE_SHADER_MATERIALX_END
void sh_node_type_base(blender::bke::bNodeType *ntype, std::string idname, const std::optional< int16_t > legacy_type)
void register_node_type_sh_vertex_color()
void node_free_standard_storage(bNode *node)
Definition node_util.cc:42
void node_copy_standard_storage(bNodeTree *, bNode *dest_node, const bNode *src_node)
Definition node_util.cc:54
PointerRNA RNA_id_pointer_create(ID *id)
Definition DNA_ID.h:414
void * data
Definition RNA_types.hh:53
void * storage
Defines a node type.
Definition BKE_node.hh:238
NodeMaterialXFunction materialx_fn
Definition BKE_node.hh:344
std::string ui_description
Definition BKE_node.hh:244
void(* initfunc)(bNodeTree *ntree, bNode *node)
Definition BKE_node.hh:289
NodeGPUExecFunction gpu_fn
Definition BKE_node.hh:342
const char * enum_name_legacy
Definition BKE_node.hh:247
void(* draw_buttons)(uiLayout *, bContext *C, PointerRNA *ptr)
Definition BKE_node.hh:259
NodeDeclareFunction declare
Definition BKE_node.hh:362
void label(blender::StringRef name, int icon)
void prop_search(PointerRNA *ptr, PropertyRNA *prop, PointerRNA *searchptr, PropertyRNA *searchprop, PropertyRNA *item_searchpropname, std::optional< blender::StringRefNull > name, int icon, bool results_are_suggestions)
void prop(PointerRNA *ptr, PropertyRNA *prop, int index, int value, eUI_Item_Flag flag, std::optional< blender::StringRef > name_opt, int icon, std::optional< blender::StringRef > placeholder=std::nullopt)
PointerRNA * ptr
Definition wm_files.cc:4238