Blender V4.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
5#include "node_shader_util.hh"
6
8
10
12{
13 b.add_output<decl::Vector>("Location");
14 b.add_output<decl::Color>("Color");
15 b.add_output<decl::Float>("Alpha");
16 b.add_output<decl::Float>("Object Index");
17 b.add_output<decl::Float>("Material Index");
18 b.add_output<decl::Float>("Random");
19}
20
22 bNode *node,
23 bNodeExecData * /*execdata*/,
24 GPUNodeStack *in,
25 GPUNodeStack *out)
26{
28 float index = ma ? ma->index : 0.0f;
30 return GPU_stack_link(mat, node, "node_object_info", in, out, GPU_constant(&index));
31}
32
34#ifdef WITH_MATERIALX
35{
36 /* NOTE: Some outputs isn't supported by MaterialX. */
37 NodeItem res = empty();
38 std::string name = socket_out_->name;
39
40 if (name == "Location") {
41 res = create_node("position", NodeItem::Type::Vector3, {{"space", val(std::string("world"))}});
42 }
43 else if (name == "Random") {
44 res = create_node("randomfloat", NodeItem::Type::Float);
45 }
46 else {
47 res = get_output_default(name, NodeItem::Type::Any);
48 }
49 return res;
50}
51#endif
53
54} // namespace blender::nodes::node_shader_object_info_cc
55
57{
59
60 static blender::bke::bNodeType ntype;
61
63 ntype.declare = file_ns::node_declare;
64 ntype.gpu_fn = file_ns::node_shader_gpu_object_info;
65 ntype.materialx_fn = file_ns::node_shader_materialx;
66
68}
#define SH_NODE_OBJECT_INFO
Definition BKE_node.hh:950
#define NODE_CLASS_INPUT
Definition BKE_node.hh:404
bool GPU_stack_link(GPUMaterial *mat, const bNode *node, const char *name, GPUNodeStack *in, GPUNodeStack *out,...)
GPUNodeLink * GPU_constant(const float *num)
@ GPU_MATFLAG_OBJECT_INFO
void GPU_material_flag_set(GPUMaterial *mat, eGPUMaterialFlag flag)
Material * GPU_material_get_material(GPUMaterial *material)
local_group_size(16, 16) .push_constant(Type b
void node_register_type(bNodeType *ntype)
Definition node.cc:1708
static int node_shader_gpu_object_info(GPUMaterial *mat, bNode *node, bNodeExecData *, GPUNodeStack *in, GPUNodeStack *out)
static void node_declare(NodeDeclarationBuilder &b)
#define NODE_SHADER_MATERIALX_BEGIN
#define NODE_SHADER_MATERIALX_END
void register_node_type_sh_object_info()
void sh_node_type_base(blender::bke::bNodeType *ntype, int type, const char *name, short nclass)
Defines a node type.
Definition BKE_node.hh:218
NodeMaterialXFunction materialx_fn
Definition BKE_node.hh:320
NodeGPUExecFunction gpu_fn
Definition BKE_node.hh:318
NodeDeclareFunction declare
Definition BKE_node.hh:347