Blender  V3.3
node_shader_geometry.cc
Go to the documentation of this file.
1 /* SPDX-License-Identifier: GPL-2.0-or-later
2  * Copyright 2005 Blender Foundation. All rights reserved. */
3 
4 #include "node_shader_util.hh"
5 
7 
9 {
10  b.add_output<decl::Vector>(N_("Position"));
11  b.add_output<decl::Vector>(N_("Normal"));
12  b.add_output<decl::Vector>(N_("Tangent"));
13  b.add_output<decl::Vector>(N_("True Normal"));
14  b.add_output<decl::Vector>(N_("Incoming"));
15  b.add_output<decl::Vector>(N_("Parametric"));
16  b.add_output<decl::Float>(N_("Backfacing"));
17  b.add_output<decl::Float>(N_("Pointiness"));
18  b.add_output<decl::Float>(N_("Random Per Island"));
19 }
20 
22  bNode *node,
23  bNodeExecData *UNUSED(execdata),
24  GPUNodeStack *in,
26 {
27  /* HACK: Don't request GPU_MATFLAG_BARYCENTRIC if not used because it will
28  * trigger the use of geometry shader (and the performance penalty it implies). */
29  if (out[5].hasoutput) {
31  }
32  /* Opti: don't request orco if not needed. */
33  const float val[4] = {0.0f, 0.0f, 0.0f, 0.0f};
34  GPUNodeLink *orco_link = (!out[2].hasoutput) ? GPU_constant(val) :
35  GPU_attribute(mat, CD_ORCO, "");
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 T70644) */
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 
61 } // namespace blender::nodes::node_shader_geometry_cc
62 
63 /* node type definition */
65 {
66  namespace file_ns = blender::nodes::node_shader_geometry_cc;
67 
68  static bNodeType ntype;
69 
73 
74  nodeRegisterType(&ntype);
75 }
void node_type_gpu(struct bNodeType *ntype, NodeGPUExecFunction gpu_fn)
Definition: node.cc:4465
#define NODE_CLASS_INPUT
Definition: BKE_node.h:345
#define SH_NODE_NEW_GEOMETRY
Definition: BKE_node.h:1116
void nodeRegisterType(struct bNodeType *ntype)
Definition: node.cc:1357
#define LISTBASE_FOREACH_INDEX(type, var, list, index_var)
Definition: BLI_listbase.h:344
#define UNUSED(x)
#define ELEM(...)
GPUNodeLink * GPU_attribute(GPUMaterial *mat, eCustomDataType type, const char *name)
GPUNodeLink * GPU_constant(const float *num)
@ GPU_MATFLAG_BARYCENTRIC
Definition: GPU_material.h:85
void GPU_material_flag_set(GPUMaterial *mat, eGPUMaterialFlag flag)
Definition: gpu_material.c:596
bool GPU_link(GPUMaterial *mat, const char *name,...)
bool GPU_stack_link(GPUMaterial *mat, struct bNode *node, const char *name, GPUNodeStack *in, GPUNodeStack *out,...)
OperationNode * node
static void node_declare(NodeDeclarationBuilder &b)
static int node_shader_gpu_geometry(GPUMaterial *mat, bNode *node, bNodeExecData *UNUSED(execdata), GPUNodeStack *in, GPUNodeStack *out)
static const pxr::TfToken out("out", pxr::TfToken::Immortal)
static const pxr::TfToken b("b", pxr::TfToken::Immortal)
void register_node_type_sh_geometry()
void node_shader_gpu_bump_tex_coord(GPUMaterial *mat, bNode *UNUSED(node), GPUNodeLink **link)
void sh_node_type_base(struct bNodeType *ntype, int type, const char *name, short nclass)
Defines a node type.
Definition: BKE_node.h:226
NodeDeclareFunction declare
Definition: BKE_node.h:324
#define N_(msgid)