Blender  V2.93
node_shader_vectTransform.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) 2013 Blender Foundation.
17  * All rights reserved.
18  */
19 
24 #include "../node_shader_util.h"
25 
26 /* **************** Vector Transform ******************** */
28  {SOCK_VECTOR, N_("Vector"), 0.5f, 0.5f, 0.5f, 1.0f, -10000.0f, 10000.0f, PROP_NONE}, {-1, ""}};
29 
31  {SOCK_VECTOR, N_("Vector")},
32  {-1, ""},
33 };
34 
36 {
38  "NodeShaderVectTransform");
39 
40  /* Convert World into Object Space per default */
41  vect->convert_to = 1;
42 
43  node->storage = vect;
44 }
45 
47  int UNUSED(thread),
48  bNode *UNUSED(node),
49  bNodeExecData *UNUSED(execdata),
50  bNodeStack **UNUSED(in),
51  bNodeStack **UNUSED(out))
52 {
53 }
54 
56 {
57  switch (from) {
59  switch (to) {
61  return NULL;
66  }
67  break;
69  switch (to) {
71  return NULL;
76  }
77  break;
79  switch (to) {
81  return NULL;
86  }
87  break;
88  }
89  return NULL;
90 }
92  bNode *node,
93  bNodeExecData *UNUSED(execdata),
94  GPUNodeStack *in,
95  GPUNodeStack *out)
96 {
97  struct GPUNodeLink *inputlink;
98  struct GPUNodeLink *fromto;
99 
100  const char *vtransform = "direction_transform_m4v3";
101  const char *ptransform = "point_transform_m4v3";
102  const char *func_name = 0;
103 
104  NodeShaderVectTransform *nodeprop = (NodeShaderVectTransform *)node->storage;
105 
106  if (in[0].hasinput) {
107  inputlink = in[0].link;
108  }
109  else {
110  inputlink = GPU_constant(in[0].vec);
111  }
112 
113  fromto = get_gpulink_matrix_from_to(nodeprop->convert_from, nodeprop->convert_to);
114 
115  func_name = (nodeprop->type == SHD_VECT_TRANSFORM_TYPE_POINT) ? ptransform : vtransform;
116  if (fromto) {
117  /* For cycles we have inverted Z */
118  /* TODO: pass here the correct matrices */
121  GPU_link(mat, "invert_z", inputlink, &inputlink);
122  }
123  GPU_link(mat, func_name, inputlink, fromto, &out[0].link);
124  if (nodeprop->convert_to == SHD_VECT_TRANSFORM_SPACE_CAMERA &&
126  GPU_link(mat, "invert_z", out[0].link, &out[0].link);
127  }
128  }
129  else {
130  GPU_link(mat, "set_rgb", inputlink, &out[0].link);
131  }
132 
133  if (nodeprop->type == SHD_VECT_TRANSFORM_TYPE_NORMAL) {
134  GPU_link(mat, "vector_normalize", out[0].link, &out[0].link);
135  }
136 
137  return true;
138 }
139 
141 {
142  static bNodeType ntype;
143 
144  sh_node_type_base(&ntype, SH_NODE_VECT_TRANSFORM, "Vector Transform", NODE_CLASS_OP_VECTOR, 0);
148  &ntype, "NodeShaderVectTransform", node_free_standard_storage, node_copy_standard_storage);
151 
152  nodeRegisterType(&ntype);
153 }
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_OP_VECTOR
Definition: BKE_node.h:337
void node_type_exec(struct bNodeType *ntype, NodeInitExecFunction init_exec_fn, NodeFreeExecFunction free_exec_fn, NodeExecFunction exec_fn)
Definition: node.cc:4635
void nodeRegisterType(struct bNodeType *ntype)
Definition: node.cc:1298
#define UNUSED(x)
#define N_(msgid)
#define SHD_VECT_TRANSFORM_TYPE_NORMAL
#define SHD_VECT_TRANSFORM_TYPE_POINT
#define SHD_VECT_TRANSFORM_SPACE_OBJECT
#define SHD_VECT_TRANSFORM_SPACE_CAMERA
@ SOCK_VECTOR
#define SHD_VECT_TRANSFORM_SPACE_WORLD
GPUNodeLink * GPU_builtin(eGPUBuiltin builtin)
GPUNodeLink * GPU_constant(const float *num)
@ GPU_INVERSE_OBJECT_MATRIX
Definition: GPU_material.h:90
@ GPU_OBJECT_MATRIX
Definition: GPU_material.h:88
@ GPU_INVERSE_VIEW_MATRIX
Definition: GPU_material.h:89
@ GPU_INVERSE_LOC_TO_VIEW_MATRIX
Definition: GPU_material.h:101
@ GPU_LOC_TO_VIEW_MATRIX
Definition: GPU_material.h:100
@ GPU_VIEW_MATRIX
Definition: GPU_material.h:87
bool GPU_link(GPUMaterial *mat, const char *name,...)
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 Texture SH_NODE_VECT_TRANSFORM
@ PROP_NONE
Definition: RNA_types.h:113
OperationNode * node
StackEntry * from
bNodeTree * ntree
void *(* MEM_callocN)(size_t len, const char *str)
Definition: mallocn.c:45
void sh_node_type_base(struct bNodeType *ntype, int type, const char *name, short nclass, short flag)
static GPUNodeLink * get_gpulink_matrix_from_to(short from, short to)
static bNodeSocketTemplate sh_node_vect_transform_out[]
static void node_shader_init_vect_transform(bNodeTree *UNUSED(ntree), bNode *node)
static void node_shader_exec_vect_transform(void *UNUSED(data), int UNUSED(thread), bNode *UNUSED(node), bNodeExecData *UNUSED(execdata), bNodeStack **UNUSED(in), bNodeStack **UNUSED(out))
static int gpu_shader_vect_transform(GPUMaterial *mat, bNode *node, bNodeExecData *UNUSED(execdata), GPUNodeStack *in, GPUNodeStack *out)
static bNodeSocketTemplate sh_node_vect_transform_in[]
void register_node_type_sh_vect_transform(void)
void node_copy_standard_storage(bNodeTree *UNUSED(dest_ntree), bNode *dest_node, const bNode *src_node)
Definition: node_util.c:67
void node_free_standard_storage(bNode *node)
Definition: node_util.c:55
struct GPUNodeLink * link
Definition: GPU_material.h:119
Compact definition of a node socket.
Definition: BKE_node.h:95
Defines a node type.
Definition: BKE_node.h:221