Blender  V2.93
node_shader_geometry.c
Go to the documentation of this file.
1 /*
2  * This program is free software; you can redistribute it and/or
3  * modify it under the terms of the GNU General Public License
4  * as published by the Free Software Foundation; either version 2
5  * of the License, or (at your option) any later version.
6  *
7  * This program is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10  * GNU General Public License for more details.
11  *
12  * You should have received a copy of the GNU General Public License
13  * along with this program; if not, write to the Free Software Foundation,
14  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
15  *
16  * The Original Code is Copyright (C) 2005 Blender Foundation.
17  * All rights reserved.
18  */
19 
20 #include "../node_shader_util.h"
21 
22 /* **************** OUTPUT ******************** */
23 
25  {SOCK_VECTOR, N_("Position"), 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f},
26  {SOCK_VECTOR, N_("Normal"), 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f},
27  {SOCK_VECTOR, N_("Tangent"), 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f},
28  {SOCK_VECTOR, N_("True Normal"), 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f},
29  {SOCK_VECTOR, N_("Incoming"), 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f},
30  {SOCK_VECTOR, N_("Parametric"), 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f},
31  {SOCK_FLOAT, N_("Backfacing"), 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f},
32  {SOCK_FLOAT, N_("Pointiness"), 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f},
33  {SOCK_FLOAT, N_("Random Per Island"), 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f},
34  {-1, ""},
35 };
36 
38  bNode *node,
39  bNodeExecData *UNUSED(execdata),
40  GPUNodeStack *in,
41  GPUNodeStack *out)
42 {
43  /* HACK: Don't request GPU_BARYCENTRIC_TEXCO if not used because it will
44  * trigger the use of geometry shader (and the performance penalty it implies). */
45  const float val[4] = {0.0f, 0.0f, 0.0f, 0.0f};
46  GPUNodeLink *bary_link = (!out[5].hasoutput) ? GPU_constant(val) :
48  if (out[5].hasoutput) {
50  }
51  /* Opti: don't request orco if not needed. */
52  GPUNodeLink *orco_link = (!out[2].hasoutput) ? GPU_constant(val) :
53  GPU_attribute(mat, CD_ORCO, "");
54 
55  const bool success = GPU_stack_link(mat,
56  node,
57  "node_geometry",
58  in,
59  out,
62  orco_link,
65  bary_link);
66 
67  /* for each output */
68  for (int i = 0; sh_node_geometry_out[i].type != -1; i++) {
69  node_shader_gpu_bump_tex_coord(mat, node, &out[i].link);
70  /* Normalize some vectors after dFdx/dFdy offsets.
71  * This is the case for interpolated, non linear functions.
72  * The resulting vector can still be a bit wrong but not as much.
73  * (see T70644) */
74  if (node->branch_tag != 0 && ELEM(i, 1, 2, 4)) {
75  GPU_link(mat,
76  "vector_math_normalize",
77  out[i].link,
78  out[i].link,
79  out[i].link,
80  out[i].link,
81  &out[i].link,
82  NULL);
83  }
84  }
85 
86  return success;
87 }
88 
89 /* node type definition */
91 {
92  static bNodeType ntype;
93 
96  node_type_init(&ntype, NULL);
97  node_type_storage(&ntype, "", NULL, NULL);
99 
100  nodeRegisterType(&ntype);
101 }
void node_type_gpu(struct bNodeType *ntype, NodeGPUExecFunction gpu_fn)
Definition: node.cc:4645
void node_type_socket_templates(struct bNodeType *ntype, struct bNodeSocketTemplate *inputs, struct bNodeSocketTemplate *outputs)
Definition: node.cc:4527
void node_type_init(struct bNodeType *ntype, void(*initfunc)(struct bNodeTree *ntree, struct bNode *node))
Definition: node.cc:4559
void node_type_storage(struct bNodeType *ntype, const char *storagename, void(*freefunc)(struct bNode *node), void(*copyfunc)(struct bNodeTree *dest_ntree, struct bNode *dest_node, const struct bNode *src_node))
Definition: node.cc:4599
#define NODE_CLASS_INPUT
Definition: BKE_node.h:334
void nodeRegisterType(struct bNodeType *ntype)
Definition: node.cc:1298
#define UNUSED(x)
#define ELEM(...)
#define N_(msgid)
@ SOCK_VECTOR
@ SOCK_FLOAT
GPUNodeLink * GPU_builtin(eGPUBuiltin builtin)
GPUNodeLink * GPU_attribute(GPUMaterial *mat, CustomDataType type, const char *name)
@ GPU_MATFLAG_BARYCENTRIC
Definition: GPU_material.h:113
GPUNodeLink * GPU_constant(const float *num)
@ GPU_WORLD_NORMAL
Definition: GPU_material.h:105
@ GPU_VIEW_POSITION
Definition: GPU_material.h:91
@ GPU_BARYCENTRIC_TEXCO
Definition: GPU_material.h:103
@ GPU_OBJECT_MATRIX
Definition: GPU_material.h:88
@ GPU_INVERSE_VIEW_MATRIX
Definition: GPU_material.h:89
void GPU_material_flag_set(GPUMaterial *mat, eGPUMatFlag flag)
Definition: gpu_material.c:641
bool GPU_link(GPUMaterial *mat, const char *name,...)
bool GPU_stack_link(GPUMaterial *mat, struct bNode *node, const char *name, GPUNodeStack *in, GPUNodeStack *out,...)
Group RGB to Bright Vector Camera Vector Combine Material Light Line Style Layer Add Ambient Diffuse Glossy Refraction Transparent Toon Principled Hair Volume Principled SH_NODE_NEW_GEOMETRY
OperationNode * node
static bNodeSocketTemplate sh_node_geometry_out[]
void register_node_type_sh_geometry(void)
static int node_shader_gpu_geometry(GPUMaterial *mat, bNode *node, bNodeExecData *UNUSED(execdata), GPUNodeStack *in, GPUNodeStack *out)
void sh_node_type_base(struct bNodeType *ntype, int type, const char *name, short nclass, short flag)
void node_shader_gpu_bump_tex_coord(GPUMaterial *mat, bNode *node, GPUNodeLink **link)
Compact definition of a node socket.
Definition: BKE_node.h:95
Defines a node type.
Definition: BKE_node.h:221