Blender V5.3
node_shader_geometry.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
11namespace blender {
12
14
16{
17 b.add_output<decl::Vector>("Position"_ustr);
18 b.add_output<decl::Vector>("Normal"_ustr);
19 b.add_output<decl::Vector>("Tangent"_ustr);
20 b.add_output<decl::Vector>("True Normal"_ustr);
21 b.add_output<decl::Vector>("Incoming"_ustr);
22 b.add_output<decl::Vector>("Parametric"_ustr);
23 b.add_output<decl::Float>("Backfacing"_ustr);
24 b.add_output<decl::Float>("Pointiness"_ustr);
25 b.add_output<decl::Float>("Random Per Island"_ustr);
26}
27
29 bNode *node,
30 bNodeExecData * /*execdata*/,
33{
34 /* HACK: Don't request GPU_MATFLAG_BARYCENTRIC if not used because it will
35 * trigger the use of geometry shader (and the performance penalty it implies). */
36 if (out[5].hasoutput) {
38 }
39 /* Optimization: don't request orco if not needed. */
40 const float val[4] = {0.0f, 0.0f, 0.0f, 0.0f};
41 GPUNodeLink *orco_link = out[2].hasoutput ? GPU_attribute(mat, CD_ORCO, "") : GPU_constant(val);
42
43 const bool success = GPU_stack_link(
44 mat, node, "node_geometry", in, out, orco_link, GPU_kernel_globals(), GPU_shading_data());
45
46 for (const auto [i, sock] : node->outputs.enumerate()) {
48 /* Normalize some vectors after dFdx/dFdy offsets.
49 * This is the case for interpolated, non linear functions.
50 * The resulting vector can still be a bit wrong but not as much.
51 * (see #70644) */
52 if (ELEM(i, 1, 2, 4)) {
53 GPU_link(mat,
54 "vector_math_normalize",
55 out[i].link,
56 out[i].link,
57 out[i].link,
58 out[i].link,
59 &out[i].link,
60 nullptr);
61 }
62 }
63
64 return success;
65}
66
68#ifdef WITH_MATERIALX
69{
70 /* NOTE: Some outputs aren't supported by MaterialX. */
71 NodeItem res = empty();
72 std::string name = socket_out_->identifier;
73
74 if (name == "Position") {
75 res = create_node("position", NodeItem::Type::Vector3, {{"space", val(std::string("world"))}});
76 }
77 else if (name == "Normal") {
78 res = create_node("normal", NodeItem::Type::Vector3, {{"space", val(std::string("world"))}});
79 }
80 else if (ELEM(name, "Tangent", "True Normal")) {
81 res = create_node("tangent", NodeItem::Type::Vector3, {{"space", val(std::string("world"))}});
82 }
83 else {
84 res = get_output_default(name, NodeItem::Type::Any);
85 }
86 return res;
87}
88#endif
90
91} // namespace nodes::node_shader_geometry_cc
92
93/* node type definition */
95{
96 namespace file_ns = nodes::node_shader_geometry_cc;
97
98 static bke::bNodeType ntype;
99
100 sh_node_type_base(&ntype, "ShaderNodeNewGeometry"_ustr, SH_NODE_NEW_GEOMETRY);
101 ntype.ui_name = "Geometry";
102 ntype.ui_description = "Retrieve geometric information about the current shading point";
103 ntype.enum_name_legacy = "NEW_GEOMETRY";
104 ntype.nclass = NODE_CLASS_INPUT;
105 ntype.declare = file_ns::node_declare;
106 ntype.gpu_fn = file_ns::node_shader_gpu_geometry;
107 ntype.materialx_fn = file_ns::node_shader_materialx;
108
110}
111
112} // namespace blender
#define NODE_CLASS_INPUT
Definition BKE_node.hh:478
#define SH_NODE_NEW_GEOMETRY
#define ELEM(...)
void node_register_type(bNodeType &ntype)
Definition node.cc:2920
static void node_declare(NodeDeclarationBuilder &b)
static int node_shader_gpu_geometry(GPUMaterial *mat, bNode *node, bNodeExecData *, GPUNodeStack *in, GPUNodeStack *out)
BMesh Iterators.
bool GPU_stack_link(GPUMaterial *mat, const bNode *node, const char *name, GPUNodeStack *in, GPUNodeStack *out,...)
@ GPU_MATFLAG_BARYCENTRIC
void sh_node_type_base(bke::bNodeType *ntype, UString idname, const std::optional< int16_t > legacy_type)
GPUNodeLink * GPU_constant(const float *num)
bool GPU_link(GPUMaterial *mat, const char *name,...)
void register_node_type_sh_geometry()
void GPU_material_flag_set(GPUMaterial *mat, eGPUMaterialFlag flag)
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()
#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