Blender V5.3
node_shader_tex_coord.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
12
14#include "UI_resources.hh"
15
16namespace blender {
17
19
21{
22 b.add_output<decl::Vector>("Generated"_ustr).translation_context(BLT_I18NCONTEXT_ID_TEXTURE);
23 b.add_output<decl::Vector>("Normal"_ustr);
24 b.add_output<decl::Vector>("UV"_ustr);
25 b.add_output<decl::Vector>("Object"_ustr);
26 b.add_output<decl::Vector>("Camera"_ustr);
27 b.add_output<decl::Vector>("Window"_ustr);
28 b.add_output<decl::Vector>("Reflection"_ustr);
29}
30
31static void node_shader_buts_tex_coord(ui::Layout &layout, bContext * /*C*/, PointerRNA *ptr)
32{
33 layout.prop(ptr, "object", ui::ITEM_R_SPLIT_EMPTY_NAME, "", ICON_NONE);
34 layout.prop(ptr, "from_instancer", ui::ITEM_R_SPLIT_EMPTY_NAME, std::nullopt, ICON_NONE);
35}
36
38 bNode *node,
39 bNodeExecData * /*execdata*/,
42{
43 Object *ob = (Object *)node->id;
44
45 /* Use special matrix to let the shader branch to using the render object's matrix. */
46 float dummy_matrix[4][4];
47 dummy_matrix[3][3] = 0.0f;
48 GPUNodeLink *inv_obmat = (ob != nullptr) ? GPU_uniform(&ob->world_to_object()[0][0]) :
49 GPU_uniform(&dummy_matrix[0][0]);
50
51 /* Optimization: don't request orco if not needed. */
52 float4 zero(0.0f);
53 GPUNodeLink *orco = out[0].hasoutput ? GPU_attribute(mat, CD_ORCO, "") : GPU_constant(zero);
55
57 node,
58 "node_tex_coord",
59 in,
60 out,
61 inv_obmat,
62 orco,
63 mtface,
66
67 for (const auto [i, sock] : node->outputs.enumerate()) {
69 /* Normalize some vectors after dFdx/dFdy offsets.
70 * This is the case for interpolated, non linear functions.
71 * The resulting vector can still be a bit wrong but not as much.
72 * (see #70644) */
73 if (ELEM(i, 1, 6)) {
74 GPU_link(mat,
75 "vector_math_normalize",
76 out[i].link,
77 out[i].link,
78 out[i].link,
79 out[i].link,
80 &out[i].link,
81 nullptr);
82 }
83 }
84
85 return 1;
86}
87
89#ifdef WITH_MATERIALX
90{
91 /* NOTE: Some outputs aren't supported by MaterialX. */
92 NodeItem res = empty();
93 std::string name = socket_out_->identifier;
94
95 if (ELEM(name, "Generated", "UV")) {
96 res = texcoord_node();
97 }
98 else if (name == "Normal") {
99 res = create_node("normal", NodeItem::Type::Vector3, {{"space", val(std::string("world"))}});
100 }
101 else if (name == "Object") {
102 res = create_node(
103 "position", NodeItem::Type::Vector3, {{"space", val(std::string("object"))}});
104 }
105 else {
106 res = get_output_default(name, NodeItem::Type::Any);
107 }
108
109 return res;
110}
111#endif
113
114} // namespace nodes::node_shader_tex_coord_cc
115
116/* node type definition */
118{
119 namespace file_ns = nodes::node_shader_tex_coord_cc;
120
121 static bke::bNodeType ntype;
122
123 sh_node_type_base(&ntype, "ShaderNodeTexCoord"_ustr, SH_NODE_TEX_COORD);
124 ntype.ui_name = "Texture Coordinate";
125 ntype.ui_description =
126 "Retrieve multiple types of texture coordinates.\nTypically used as inputs for texture "
127 "nodes";
128 ntype.enum_name_legacy = "TEX_COORD";
129 ntype.nclass = NODE_CLASS_INPUT;
130 ntype.declare = file_ns::node_declare;
131 ntype.draw_buttons = file_ns::node_shader_buts_tex_coord;
132 ntype.gpu_fn = file_ns::node_shader_gpu_tex_coord;
133 ntype.materialx_fn = file_ns::node_shader_materialx;
134
136}
137
138} // namespace blender
#define NODE_CLASS_INPUT
Definition BKE_node.hh:478
#define SH_NODE_TEX_COORD
#define BLT_I18NCONTEXT_ID_TEXTURE
#define ELEM(...)
void node_register_type(bNodeType &ntype)
Definition node.cc:2920
static int node_shader_gpu_tex_coord(GPUMaterial *mat, bNode *node, bNodeExecData *, GPUNodeStack *in, GPUNodeStack *out)
static void node_declare(NodeDeclarationBuilder &b)
static void node_shader_buts_tex_coord(ui::Layout &layout, bContext *, PointerRNA *ptr)
BMesh Iterators.
bool GPU_stack_link(GPUMaterial *mat, const bNode *node, const char *name, GPUNodeStack *in, GPUNodeStack *out,...)
void sh_node_type_base(bke::bNodeType *ntype, UString idname, const std::optional< int16_t > legacy_type)
GPUNodeLink * GPU_uniform(const float *num)
VecBase< float, 4 > float4
GPUNodeLink * GPU_constant(const float *num)
bool GPU_link(GPUMaterial *mat, const char *name,...)
void node_shader_gpu_bump_tex_coord(GPUMaterial *mat, bNode *, GPUNodeLink **link)
GPUNodeLink * GPU_shading_data()
GPUNodeLink * GPU_attribute(GPUMaterial *mat, eCustomDataType type, const char *name)
GPUNodeLink * GPU_kernel_globals()
void register_node_type_sh_tex_coord()
#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
const char * enum_name_legacy
Definition BKE_node.hh:274
NodeDeclareFunction declare
Definition BKE_node.hh:393
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)