Blender V4.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
5#include "node_shader_util.hh"
6
8
9#include "UI_interface.hh"
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 uiItemR(layout, ptr, "object", UI_ITEM_R_SPLIT_EMPTY_NAME, nullptr, ICON_NONE);
28 uiItemR(layout, ptr, "from_instancer", UI_ITEM_R_SPLIT_EMPTY_NAME, nullptr, ICON_NONE);
29}
30
32 bNode *node,
33 bNodeExecData * /*execdata*/,
34 GPUNodeStack *in,
35 GPUNodeStack *out)
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_->name;
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, SH_NODE_TEX_COORD, "Texture Coordinate", NODE_CLASS_INPUT);
110 ntype.declare = file_ns::node_declare;
111 ntype.draw_buttons = file_ns::node_shader_buts_tex_coord;
112 ntype.gpu_fn = file_ns::node_shader_gpu_tex_coord;
113 ntype.materialx_fn = file_ns::node_shader_materialx;
114
116}
#define SH_NODE_TEX_COORD
Definition BKE_node.hh:938
#define NODE_CLASS_INPUT
Definition BKE_node.hh:404
#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)
void uiItemR(uiLayout *layout, PointerRNA *ptr, const char *propname, eUI_Item_Flag flag, const char *name, int icon)
@ UI_ITEM_R_SPLIT_EMPTY_NAME
local_group_size(16, 16) .push_constant(Type b
void node_register_type(bNodeType *ntype)
Definition node.cc:1708
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)
#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, int type, const char *name, short nclass)
void node_shader_gpu_bump_tex_coord(GPUMaterial *mat, bNode *, GPUNodeLink **link)
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
void(* draw_buttons)(uiLayout *, bContext *C, PointerRNA *ptr)
Definition BKE_node.hh:238
NodeDeclareFunction declare
Definition BKE_node.hh:347
PointerRNA * ptr
Definition wm_files.cc:4126