Blender V4.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
5#include "node_shader_util.hh"
6
8
10{
11 b.add_output<decl::Vector>("Position");
12 b.add_output<decl::Vector>("Normal");
13 b.add_output<decl::Vector>("Tangent");
14 b.add_output<decl::Vector>("True Normal");
15 b.add_output<decl::Vector>("Incoming");
16 b.add_output<decl::Vector>("Parametric");
17 b.add_output<decl::Float>("Backfacing");
18 b.add_output<decl::Float>("Pointiness");
19 b.add_output<decl::Float>("Random Per Island");
20}
21
23 bNode *node,
24 bNodeExecData * /*execdata*/,
25 GPUNodeStack *in,
26 GPUNodeStack *out)
27{
28 /* HACK: Don't request GPU_MATFLAG_BARYCENTRIC if not used because it will
29 * trigger the use of geometry shader (and the performance penalty it implies). */
30 if (out[5].hasoutput) {
32 }
33 /* Optimization: don't request orco if not needed. */
34 const float val[4] = {0.0f, 0.0f, 0.0f, 0.0f};
35 GPUNodeLink *orco_link = out[2].hasoutput ? GPU_attribute(mat, CD_ORCO, "") : GPU_constant(val);
36
37 const bool success = GPU_stack_link(mat, node, "node_geometry", in, out, orco_link);
38
39 int i;
40 LISTBASE_FOREACH_INDEX (bNodeSocket *, sock, &node->outputs, i) {
41 node_shader_gpu_bump_tex_coord(mat, node, &out[i].link);
42 /* Normalize some vectors after dFdx/dFdy offsets.
43 * This is the case for interpolated, non linear functions.
44 * The resulting vector can still be a bit wrong but not as much.
45 * (see #70644) */
46 if (ELEM(i, 1, 2, 4)) {
47 GPU_link(mat,
48 "vector_math_normalize",
49 out[i].link,
50 out[i].link,
51 out[i].link,
52 out[i].link,
53 &out[i].link,
54 nullptr);
55 }
56 }
57
58 return success;
59}
60
62#ifdef WITH_MATERIALX
63{
64 /* NOTE: Some outputs aren't supported by MaterialX. */
65 NodeItem res = empty();
66 std::string name = socket_out_->name;
67
68 if (name == "Position") {
69 res = create_node("position", NodeItem::Type::Vector3, {{"space", val(std::string("world"))}});
70 }
71 else if (name == "Normal") {
72 res = create_node("normal", NodeItem::Type::Vector3, {{"space", val(std::string("world"))}});
73 }
74 else if (ELEM(name, "Tangent", "True Normal")) {
75 res = create_node("tangent", NodeItem::Type::Vector3, {{"space", val(std::string("world"))}});
76 }
77 else {
78 res = get_output_default(name, NodeItem::Type::Any);
79 }
80 return res;
81}
82#endif
84
85} // namespace blender::nodes::node_shader_geometry_cc
86
87/* node type definition */
89{
91
92 static blender::bke::bNodeType ntype;
93
94 sh_node_type_base(&ntype, SH_NODE_NEW_GEOMETRY, "Geometry", NODE_CLASS_INPUT);
95 ntype.declare = file_ns::node_declare;
96 ntype.gpu_fn = file_ns::node_shader_gpu_geometry;
97 ntype.materialx_fn = file_ns::node_shader_materialx;
98
100}
#define NODE_CLASS_INPUT
Definition BKE_node.hh:404
#define LISTBASE_FOREACH_INDEX(type, var, list, index_var)
#define ELEM(...)
bool GPU_stack_link(GPUMaterial *mat, const bNode *node, const char *name, GPUNodeStack *in, GPUNodeStack *out,...)
GPUNodeLink * GPU_constant(const float *num)
@ GPU_MATFLAG_BARYCENTRIC
void GPU_material_flag_set(GPUMaterial *mat, eGPUMaterialFlag flag)
GPUNodeLink * GPU_attribute(GPUMaterial *mat, eCustomDataType type, const char *name)
bool GPU_link(GPUMaterial *mat, const char *name,...)
local_group_size(16, 16) .push_constant(Type b
void node_register_type(bNodeType *ntype)
Definition node.cc:1708
static void node_declare(NodeDeclarationBuilder &b)
static int node_shader_gpu_geometry(GPUMaterial *mat, bNode *node, bNodeExecData *, GPUNodeStack *in, GPUNodeStack *out)
#define NODE_SHADER_MATERIALX_BEGIN
#define NODE_SHADER_MATERIALX_END
void register_node_type_sh_geometry()
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
NodeDeclareFunction declare
Definition BKE_node.hh:347