Blender V5.3
node_shader_object_info.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
11#include "DNA_material_types.h"
12
13namespace blender {
14
16
18{
19 b.add_output<decl::Vector>("Location"_ustr);
20 b.add_output<decl::Color>("Color"_ustr);
21 b.add_output<decl::Float>("Alpha"_ustr);
22 b.add_output<decl::Float>("Object Index"_ustr);
23 b.add_output<decl::Float>("Material Index"_ustr);
24 b.add_output<decl::Float>("Random"_ustr);
25}
26
28 bNode *node,
29 bNodeExecData * /*execdata*/,
32{
34 float index = ma ? ma->index : 0.0f;
36 return GPU_stack_link(mat,
37 node,
38 "node_object_info",
39 in,
40 out,
44}
45
47#ifdef WITH_MATERIALX
48{
49 /* NOTE: Some outputs isn't supported by MaterialX. */
50 NodeItem res = empty();
51 std::string name = socket_out_->identifier;
52
53 if (name == "Location") {
54 res = create_node("position", NodeItem::Type::Vector3, {{"space", val(std::string("world"))}});
55 }
56 else if (name == "Random") {
57 res = create_node("randomfloat", NodeItem::Type::Float);
58 }
59 else {
60 res = get_output_default(name, NodeItem::Type::Any);
61 }
62 return res;
63}
64#endif
66
67} // namespace nodes::node_shader_object_info_cc
68
70{
71 namespace file_ns = nodes::node_shader_object_info_cc;
72
73 static bke::bNodeType ntype;
74
75 sh_node_type_base(&ntype, "ShaderNodeObjectInfo"_ustr, SH_NODE_OBJECT_INFO);
76 ntype.ui_name = "Object Info";
77 ntype.ui_description = "Retrieve information about the object instance";
78 ntype.enum_name_legacy = "OBJECT_INFO";
80 ntype.declare = file_ns::node_declare;
81 ntype.gpu_fn = file_ns::node_shader_gpu_object_info;
82 ntype.materialx_fn = file_ns::node_shader_materialx;
83
85}
86
87} // namespace blender
#define NODE_CLASS_INPUT
Definition BKE_node.hh:478
#define SH_NODE_OBJECT_INFO
void node_register_type(bNodeType &ntype)
Definition node.cc:2920
static int node_shader_gpu_object_info(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,...)
@ GPU_MATFLAG_OBJECT_INFO
void register_node_type_sh_object_info()
void sh_node_type_base(bke::bNodeType *ntype, UString idname, const std::optional< int16_t > legacy_type)
GPUNodeLink * GPU_constant(const float *num)
void GPU_material_flag_set(GPUMaterial *mat, eGPUMaterialFlag flag)
GPUNodeLink * GPU_shading_data()
Material * GPU_material_get_material(GPUMaterial *material)
GPUNodeLink * GPU_kernel_globals()
#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
std::string ui_description
Definition BKE_node.hh:271
NodeGPUExecFunction gpu_fn
Definition BKE_node.hh:373
const char * enum_name_legacy
Definition BKE_node.hh:274
NodeDeclareFunction declare
Definition BKE_node.hh:393