Blender  V3.3
node_shader_vertex_color.cc
Go to the documentation of this file.
1 /* SPDX-License-Identifier: GPL-2.0-or-later
2  * Copyright 2005 Blender Foundation. All rights reserved. */
3 
4 #include "node_shader_util.hh"
5 
6 #include "BKE_context.h"
7 
8 #include "UI_interface.h"
9 #include "UI_resources.h"
10 
12 
14 {
15  b.add_output<decl::Color>(N_("Color"));
16  b.add_output<decl::Float>(N_("Alpha"));
17 }
18 
20 {
21  PointerRNA obptr = CTX_data_pointer_get(C, "active_object");
22  if (obptr.data && RNA_enum_get(&obptr, "type") == OB_MESH) {
23  PointerRNA dataptr = RNA_pointer_get(&obptr, "data");
24 
25  uiItemPointerR(layout, ptr, "layer_name", &dataptr, "color_attributes", "", ICON_GROUP_VCOL);
26  }
27  else {
28  uiItemL(layout, TIP_("No mesh in active object"), ICON_ERROR);
29  }
30 }
31 
33 {
34  NodeShaderVertexColor *vertexColor = MEM_cnew<NodeShaderVertexColor>("NodeShaderVertexColor");
35  node->storage = vertexColor;
36 }
37 
39  bNode *node,
40  bNodeExecData *UNUSED(execdata),
41  GPUNodeStack *in,
43 {
44  NodeShaderVertexColor *vertexColor = (NodeShaderVertexColor *)node->storage;
45  /* NOTE: Using #CD_AUTO_FROM_NAME is necessary because there are multiple color attribute types,
46  * and the type may change during evaluation anyway. This will also make EEVEE and Cycles
47  * consistent. See T93179. */
48 
49  GPUNodeLink *vertexColorLink;
50 
51  if (vertexColor->layer_name[0]) {
52  vertexColorLink = GPU_attribute(mat, CD_AUTO_FROM_NAME, vertexColor->layer_name);
53  }
54  else { /* Fall back on active render color attribute. */
55  vertexColorLink = GPU_attribute_default_color(mat);
56  }
57 
58  return GPU_stack_link(mat, node, "node_vertex_color", in, out, vertexColorLink);
59 }
60 
61 } // namespace blender::nodes::node_shader_vertex_color_cc
62 
64 {
66 
67  static bNodeType ntype;
68 
69  sh_node_type_base(&ntype, SH_NODE_VERTEX_COLOR, "Color Attribute", NODE_CLASS_INPUT);
74  &ntype, "NodeShaderVertexColor", node_free_standard_storage, node_copy_standard_storage);
76 
77  nodeRegisterType(&ntype);
78 }
PointerRNA CTX_data_pointer_get(const bContext *C, const char *member)
Definition: context.c:462
void node_type_gpu(struct bNodeType *ntype, NodeGPUExecFunction gpu_fn)
Definition: node.cc:4465
void node_type_init(struct bNodeType *ntype, void(*initfunc)(struct bNodeTree *ntree, struct bNode *node))
Definition: node.cc:4390
void node_type_storage(struct bNodeType *ntype, const char *storagename, void(*freefunc)(struct bNode *node), void(*copyfunc)(struct bNodeTree *dest_ntree, struct bNode *dest_node, const struct bNode *src_node))
Definition: node.cc:4426
#define NODE_CLASS_INPUT
Definition: BKE_node.h:345
void nodeRegisterType(struct bNodeType *ntype)
Definition: node.cc:1357
#define UNUSED(x)
#define TIP_(msgid)
@ CD_AUTO_FROM_NAME
@ OB_MESH
GPUNodeLink * GPU_attribute(GPUMaterial *mat, eCustomDataType type, const char *name)
GPUNodeLink * GPU_attribute_default_color(GPUMaterial *mat)
bool GPU_stack_link(GPUMaterial *mat, struct bNode *node, const char *name, GPUNodeStack *in, GPUNodeStack *out,...)
in reality light always falls off quadratically Particle Retrieve the data of the particle that spawned the object for example to give variation to multiple instances of an object Point Retrieve information about points in a point cloud Retrieve the edges of an object as it appears to Cycles topology will always appear triangulated Convert a blackbody temperature to an RGB value Normal Generate a perturbed normal from an RGB normal map image Typically used for faking highly detailed surfaces Generate an OSL shader from a file or text data block Image Sample an image file as a texture Sky Generate a procedural sky texture Noise Generate fractal Perlin noise Wave Generate procedural bands or rings with noise Voronoi Generate Worley noise based on the distance to random points Typically used to generate textures such as or biological cells Brick Generate a procedural texture producing bricks Texture Retrieve multiple types of texture coordinates nTypically used as inputs for texture nodes Vector Convert a or normal between and object coordinate space Combine Create a color from its and value channels SH_NODE_VERTEX_COLOR
#define C
Definition: RandGen.cpp:25
void uiItemL(uiLayout *layout, const char *name, int icon)
void uiItemPointerR(uiLayout *layout, struct PointerRNA *ptr, const char *propname, struct PointerRNA *searchptr, const char *searchpropname, const char *name, int icon)
OperationNode * node
bNodeTree * ntree
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 *UNUSED(execdata), GPUNodeStack *in, GPUNodeStack *out)
static void node_shader_init_vertex_color(bNodeTree *UNUSED(ntree), bNode *node)
static const pxr::TfToken out("out", pxr::TfToken::Immortal)
static const pxr::TfToken b("b", pxr::TfToken::Immortal)
void sh_node_type_base(struct bNodeType *ntype, int type, const char *name, short nclass)
void register_node_type_sh_vertex_color()
void node_copy_standard_storage(bNodeTree *UNUSED(dest_ntree), bNode *dest_node, const bNode *src_node)
Definition: node_util.c:55
void node_free_standard_storage(bNode *node)
Definition: node_util.c:43
PointerRNA RNA_pointer_get(PointerRNA *ptr, const char *name)
Definition: rna_access.c:5167
int RNA_enum_get(PointerRNA *ptr, const char *name)
Definition: rna_access.c:5004
void * data
Definition: RNA_types.h:38
Defines a node type.
Definition: BKE_node.h:226
void(* draw_buttons)(struct uiLayout *, struct bContext *C, struct PointerRNA *ptr)
Definition: BKE_node.h:244
NodeDeclareFunction declare
Definition: BKE_node.h:324
#define N_(msgid)
PointerRNA * ptr
Definition: wm_files.c:3480