Blender V5.0
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
5#include "node_shader_util.hh"
6
8
10#include "UI_resources.hh"
11
13
15{
16 b.add_output<decl::Vector>("Generated").translation_context(BLT_I18NCONTEXT_ID_TEXTURE);
17 b.add_output<decl::Vector>("Normal");
18 b.add_output<decl::Vector>("UV");
19 b.add_output<decl::Vector>("Object");
20 b.add_output<decl::Vector>("Camera");
21 b.add_output<decl::Vector>("Window");
22 b.add_output<decl::Vector>("Reflection");
23}
24
26{
27 layout->prop(ptr, "object", UI_ITEM_R_SPLIT_EMPTY_NAME, "", ICON_NONE);
28 layout->prop(ptr, "from_instancer", UI_ITEM_R_SPLIT_EMPTY_NAME, std::nullopt, ICON_NONE);
29}
30
32 bNode *node,
33 bNodeExecData * /*execdata*/,
36{
37 Object *ob = (Object *)node->id;
38
39 /* Use special matrix to let the shader branch to using the render object's matrix. */
40 float dummy_matrix[4][4];
41 dummy_matrix[3][3] = 0.0f;
42 GPUNodeLink *inv_obmat = (ob != nullptr) ? GPU_uniform(&ob->world_to_object()[0][0]) :
43 GPU_uniform(&dummy_matrix[0][0]);
44
45 /* Optimization: don't request orco if not needed. */
46 float4 zero(0.0f);
47 GPUNodeLink *orco = out[0].hasoutput ? GPU_attribute(mat, CD_ORCO, "") : GPU_constant(zero);
49
50 GPU_stack_link(mat, node, "node_tex_coord", in, out, inv_obmat, orco, mtface);
51
52 int i;
53 LISTBASE_FOREACH_INDEX (bNodeSocket *, sock, &node->outputs, i) {
54 node_shader_gpu_bump_tex_coord(mat, node, &out[i].link);
55 /* Normalize some vectors after dFdx/dFdy offsets.
56 * This is the case for interpolated, non linear functions.
57 * The resulting vector can still be a bit wrong but not as much.
58 * (see #70644) */
59 if (ELEM(i, 1, 6)) {
60 GPU_link(mat,
61 "vector_math_normalize",
62 out[i].link,
63 out[i].link,
64 out[i].link,
65 out[i].link,
66 &out[i].link,
67 nullptr);
68 }
69 }
70
71 return 1;
72}
73
75#ifdef WITH_MATERIALX
76{
77 /* NOTE: Some outputs aren't supported by MaterialX. */
78 NodeItem res = empty();
79 std::string name = socket_out_->identifier;
80
81 if (ELEM(name, "Generated", "UV")) {
82 res = texcoord_node();
83 }
84 else if (name == "Normal") {
85 res = create_node("normal", NodeItem::Type::Vector3, {{"space", val(std::string("world"))}});
86 }
87 else if (name == "Object") {
88 res = create_node(
89 "position", NodeItem::Type::Vector3, {{"space", val(std::string("object"))}});
90 }
91 else {
92 res = get_output_default(name, NodeItem::Type::Any);
93 }
94
95 return res;
96}
97#endif
99
100} // namespace blender::nodes::node_shader_tex_coord_cc
101
102/* node type definition */
104{
106
107 static blender::bke::bNodeType ntype;
108
109 sh_node_type_base(&ntype, "ShaderNodeTexCoord", SH_NODE_TEX_COORD);
110 ntype.ui_name = "Texture Coordinate";
111 ntype.ui_description =
112 "Retrieve multiple types of texture coordinates.\nTypically used as inputs for texture "
113 "nodes";
114 ntype.enum_name_legacy = "TEX_COORD";
115 ntype.nclass = NODE_CLASS_INPUT;
116 ntype.declare = file_ns::node_declare;
117 ntype.draw_buttons = file_ns::node_shader_buts_tex_coord;
118 ntype.gpu_fn = file_ns::node_shader_gpu_tex_coord;
119 ntype.materialx_fn = file_ns::node_shader_materialx;
120
122}
#define NODE_CLASS_INPUT
Definition BKE_node.hh:447
#define SH_NODE_TEX_COORD
#define LISTBASE_FOREACH_INDEX(type, var, list, index_var)
#define ELEM(...)
#define BLT_I18NCONTEXT_ID_TEXTURE
@ CD_AUTO_FROM_NAME
bool GPU_stack_link(GPUMaterial *mat, const bNode *node, const char *name, GPUNodeStack *in, GPUNodeStack *out,...)
GPUNodeLink * GPU_constant(const float *num)
GPUNodeLink * GPU_attribute(GPUMaterial *mat, eCustomDataType type, const char *name)
bool GPU_link(GPUMaterial *mat, const char *name,...)
GPUNodeLink * GPU_uniform(const float *num)
@ UI_ITEM_R_SPLIT_EMPTY_NAME
#define in
#define out
void node_register_type(bNodeType &ntype)
Definition node.cc:2416
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(uiLayout *layout, bContext *, PointerRNA *ptr)
VecBase< float, 4 > float4
#define NODE_SHADER_MATERIALX_BEGIN
#define NODE_SHADER_MATERIALX_END
void register_node_type_sh_tex_coord()
void sh_node_type_base(blender::bke::bNodeType *ntype, std::string idname, const std::optional< int16_t > legacy_type)
void node_shader_gpu_bump_tex_coord(GPUMaterial *mat, bNode *, GPUNodeLink **link)
const char * name
struct ID * id
ListBase outputs
Defines a node type.
Definition BKE_node.hh:238
NodeMaterialXFunction materialx_fn
Definition BKE_node.hh:344
std::string ui_description
Definition BKE_node.hh:244
NodeGPUExecFunction gpu_fn
Definition BKE_node.hh:342
const char * enum_name_legacy
Definition BKE_node.hh:247
void(* draw_buttons)(uiLayout *, bContext *C, PointerRNA *ptr)
Definition BKE_node.hh:259
NodeDeclareFunction declare
Definition BKE_node.hh:362
void prop(PointerRNA *ptr, PropertyRNA *prop, int index, int value, eUI_Item_Flag flag, std::optional< blender::StringRef > name_opt, int icon, std::optional< blender::StringRef > placeholder=std::nullopt)
i
Definition text_draw.cc:230
PointerRNA * ptr
Definition wm_files.cc:4238