Blender V5.3
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
8
9#include "node_shader_util.hh"
10#include "node_util.hh"
11
12#include "BKE_context.hh"
13
15
16#include "ED_node.hh"
17
18#include "RNA_access.hh"
19
21#include "UI_resources.hh"
22
23namespace blender {
24
26
28{
29 b.add_output<decl::Color>("Color"_ustr);
30 b.add_output<decl::Float>("Alpha"_ustr);
31}
32
34{
36
37 if (object && object->type == OB_MESH) {
38 Depsgraph *depsgraph = CTX_data_depsgraph_pointer(C);
39
40 if (depsgraph) {
41 Object *object_eval = DEG_get_evaluated(depsgraph, object);
42 PointerRNA dataptr = RNA_id_pointer_create(object_eval->data);
43 layout.prop_search(ptr, "layer_name", &dataptr, "color_attributes", "", ICON_GROUP_VCOL);
44 return;
45 }
46 }
47
48 layout.prop(ptr, "layer_name", ui::ITEM_R_SPLIT_EMPTY_NAME, "", ICON_GROUP_VCOL);
49 layout.label_multiline(RPT_("No mesh in active object"), ICON_STATUS_ERROR);
50}
51
53{
54 NodeShaderVertexColor *vertexColor = MEM_new<NodeShaderVertexColor>("NodeShaderVertexColor");
55 node->storage = vertexColor;
56}
57
59 bNode *node,
60 bNodeExecData * /*execdata*/,
63{
64 NodeShaderVertexColor *vertexColor = static_cast<NodeShaderVertexColor *>(node->storage);
65 /* NOTE: Using #CD_AUTO_FROM_NAME is necessary because there are multiple color attribute types,
66 * and the type may change during evaluation anyway. This will also make EEVEE and Cycles
67 * consistent. See #93179. */
68
69 GPUNodeLink *vertexColorLink;
70
71 if (vertexColor->layer_name[0]) {
72 vertexColorLink = GPU_attribute(mat, CD_AUTO_FROM_NAME, vertexColor->layer_name);
73 }
74 else { /* Fall back on active render color attribute. */
75 vertexColorLink = GPU_attribute_default_color(mat);
76 }
77
78 GPU_stack_link(mat, node, "node_vertex_color", in, out, vertexColorLink);
79
80 for (const auto [i, sock] : node->outputs.enumerate()) {
82 }
83
84 return 1;
85}
86
88#ifdef WITH_MATERIALX
89{
90 /* TODO: some output expected be implemented within the next iteration
91 * (see node-definition `<geomcolor>`). */
92 return get_output_default(socket_out_->identifier, NodeItem::Type::Any);
93}
94#endif
96
97} // namespace nodes::node_shader_vertex_color_cc
98
100{
101 namespace file_ns = nodes::node_shader_vertex_color_cc;
102
103 static bke::bNodeType ntype;
104
105 sh_node_type_base(&ntype, "ShaderNodeVertexColor"_ustr, SH_NODE_VERTEX_COLOR);
106 ntype.ui_name = "Color Attribute";
107 ntype.ui_description =
108 "Retrieve a color attribute, or the default fallback if none is specified";
109 ntype.enum_name_legacy = "VERTEX_COLOR";
110 ntype.nclass = NODE_CLASS_INPUT;
111 ntype.declare = file_ns::node_declare;
112 ntype.draw_buttons = file_ns::node_shader_buts_vertex_color;
113 ntype.initfunc = file_ns::node_shader_init_vertex_color;
115 ntype, "NodeShaderVertexColor", node_free_standard_storage, node_copy_standard_storage);
116 ntype.gpu_fn = file_ns::node_shader_gpu_vertex_color;
117 ntype.materialx_fn = file_ns::node_shader_materialx;
118
120}
121
122} // namespace blender
#define NODE_CLASS_INPUT
Definition BKE_node.hh:478
#define SH_NODE_VERTEX_COLOR
#define RPT_(msgid)
#define C
Definition RandGen.cpp:29
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
Object * get_space_editor_object(const bContext *C)
static void node_shader_init_vertex_color(bNodeTree *, bNode *node)
static void node_declare(NodeDeclarationBuilder &b)
static int node_shader_gpu_vertex_color(GPUMaterial *mat, bNode *node, bNodeExecData *, GPUNodeStack *in, GPUNodeStack *out)
static void node_shader_buts_vertex_color(ui::Layout &layout, bContext *C, PointerRNA *ptr)
BMesh Iterators.
bool GPU_stack_link(GPUMaterial *mat, const bNode *node, const char *name, GPUNodeStack *in, GPUNodeStack *out,...)
PointerRNA RNA_id_pointer_create(ID *id)
Depsgraph * CTX_data_depsgraph_pointer(const bContext *C)
void sh_node_type_base(bke::bNodeType *ntype, UString idname, const std::optional< int16_t > legacy_type)
T * DEG_get_evaluated(const Depsgraph *depsgraph, T *id)
GPUNodeLink * GPU_attribute_default_color(GPUMaterial *mat)
void register_node_type_sh_vertex_color()
void node_shader_gpu_bump_tex_coord(GPUMaterial *mat, bNode *, GPUNodeLink **link)
GPUNodeLink * GPU_attribute(GPUMaterial *mat, eCustomDataType type, const char *name)
void node_copy_standard_storage(bNodeTree *, bNode *dest_node, const bNode *src_node)
Definition node_util.cc:57
void node_free_standard_storage(bNode *node)
Definition node_util.cc:45
#define NODE_SHADER_MATERIALX_BEGIN
#define NODE_SHADER_MATERIALX_END
Defines a node type.
Definition BKE_node.hh:265
NodeMaterialXFunction materialx_fn
Definition BKE_node.hh:375
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 label_multiline(StringRefNull label, int icon, FontStyleAlign align=UI_STYLE_TEXT_LEFT, int max_lines=0)
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)