Blender  V2.93
node_shader_tex_coord.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 #include "DNA_customdata_types.h"
23 
24 /* **************** OUTPUT ******************** */
25 
27  {SOCK_VECTOR, N_("Generated"), 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f},
28  {SOCK_VECTOR, N_("Normal"), 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f},
29  {SOCK_VECTOR, N_("UV"), 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f},
30  {SOCK_VECTOR, N_("Object"), 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f},
31  {SOCK_VECTOR, N_("Camera"), 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f},
32  {SOCK_VECTOR, N_("Window"), 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f},
33  {SOCK_VECTOR, N_("Reflection"), 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  Object *ob = (Object *)node->id;
44 
45  GPUNodeLink *inv_obmat = (ob != NULL) ? GPU_uniform(&ob->imat[0][0]) :
47 
48  /* Opti: don't request orco if not needed. */
49  GPUNodeLink *orco = (!out[0].hasoutput) ? GPU_constant((float[4]){0.0f, 0.0f, 0.0f, 0.0f}) :
50  GPU_attribute(mat, CD_ORCO, "");
51  GPUNodeLink *mtface = GPU_attribute(mat, CD_MTFACE, "");
55 
56  if (out[0].hasoutput) {
57  GPU_link(mat, "generated_from_orco", orco, &orco);
58  }
59 
61  mat, node, "node_tex_coord", in, out, viewpos, worldnor, inv_obmat, texcofacs, orco, mtface);
62 
63  /* for each output. */
64  for (int i = 0; sh_node_tex_coord_out[i].type != -1; i++) {
65  node_shader_gpu_bump_tex_coord(mat, node, &out[i].link);
66  /* Normalize some vectors after dFdx/dFdy offsets.
67  * This is the case for interpolated, non linear functions.
68  * The resulting vector can still be a bit wrong but not as much.
69  * (see T70644) */
70  if (node->branch_tag != 0 && ELEM(i, 1, 6)) {
71  GPU_link(mat,
72  "vector_math_normalize",
73  out[i].link,
74  out[i].link,
75  out[i].link,
76  out[i].link,
77  &out[i].link,
78  NULL);
79  }
80  }
81 
82  return 1;
83 }
84 
85 /* node type definition */
87 {
88  static bNodeType ntype;
89 
90  sh_node_type_base(&ntype, SH_NODE_TEX_COORD, "Texture Coordinate", NODE_CLASS_INPUT, 0);
92  node_type_init(&ntype, NULL);
93  node_type_storage(&ntype, "", NULL, NULL);
95 
96  nodeRegisterType(&ntype);
97 }
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
GPUNodeLink * GPU_builtin(eGPUBuiltin builtin)
GPUNodeLink * GPU_attribute(GPUMaterial *mat, CustomDataType type, const char *name)
GPUNodeLink * GPU_constant(const float *num)
@ GPU_WORLD_NORMAL
Definition: GPU_material.h:105
@ GPU_VIEW_POSITION
Definition: GPU_material.h:91
@ GPU_INVERSE_OBJECT_MATRIX
Definition: GPU_material.h:90
@ GPU_CAMERA_TEXCO_FACTORS
Definition: GPU_material.h:95
GPUNodeLink * GPU_uniform(const float *num)
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 Light Particle Volume Image Sky Noise Wave Voronoi Brick SH_NODE_TEX_COORD
OperationNode * node
void register_node_type_sh_tex_coord(void)
static int node_shader_gpu_tex_coord(GPUMaterial *mat, bNode *node, bNodeExecData *UNUSED(execdata), GPUNodeStack *in, GPUNodeStack *out)
static bNodeSocketTemplate sh_node_tex_coord_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)
float imat[4][4]
Compact definition of a node socket.
Definition: BKE_node.h:95
Defines a node type.
Definition: BKE_node.h:221