Blender  V3.3
node_shader_vector_transform.cc
Go to the documentation of this file.
1 /* SPDX-License-Identifier: GPL-2.0-or-later
2  * Copyright 2013 Blender Foundation. All rights reserved. */
3 
8 #include "node_shader_util.hh"
9 
10 #include "UI_interface.h"
11 #include "UI_resources.h"
12 
14 
16 {
17  b.add_input<decl::Vector>(N_("Vector"))
18  .default_value({0.5f, 0.5f, 0.5f})
19  .min(-10000.0f)
20  .max(10000.0f);
21  b.add_output<decl::Vector>(N_("Vector"));
22 }
23 
25 {
26  uiItemR(layout,
27  ptr,
28  "vector_type",
30  nullptr,
31  ICON_NONE);
32  uiItemR(layout, ptr, "convert_from", UI_ITEM_R_SPLIT_EMPTY_NAME, "", ICON_NONE);
33  uiItemR(layout, ptr, "convert_to", UI_ITEM_R_SPLIT_EMPTY_NAME, "", ICON_NONE);
34 }
35 
37 {
38  NodeShaderVectTransform *vect = MEM_cnew<NodeShaderVectTransform>("NodeShaderVectTransform");
39 
40  /* Convert World into Object Space per default */
41  vect->convert_to = 1;
42 
43  node->storage = vect;
44 }
45 
46 static const char *get_gpufn_name_from_to(short from, short to, bool is_direction)
47 {
48  switch (from) {
50  switch (to) {
52  return nullptr;
54  return is_direction ? "direction_transform_object_to_world" :
55  "point_transform_object_to_world";
57  return is_direction ? "direction_transform_object_to_view" :
58  "point_transform_object_to_view";
59  }
60  break;
62  switch (to) {
64  return nullptr;
66  return is_direction ? "direction_transform_world_to_view" :
67  "point_transform_world_to_view";
69  return is_direction ? "direction_transform_world_to_object" :
70  "point_transform_world_to_object";
71  }
72  break;
74  switch (to) {
76  return nullptr;
78  return is_direction ? "direction_transform_view_to_world" :
79  "point_transform_view_to_world";
81  return is_direction ? "direction_transform_view_to_object" :
82  "point_transform_view_to_object";
83  }
84  break;
85  }
86  return NULL;
87 }
88 
90  bNode *node,
91  bNodeExecData *UNUSED(execdata),
92  GPUNodeStack *in,
94 {
95  struct GPUNodeLink *inputlink;
96 
98 
99  if (in[0].hasinput) {
100  inputlink = in[0].link;
101  }
102  else {
103  inputlink = GPU_constant(in[0].vec);
104  }
105 
106  const bool is_direction = (nodeprop->type != SHD_VECT_TRANSFORM_TYPE_POINT);
107  const char *func_name = get_gpufn_name_from_to(
108  nodeprop->convert_from, nodeprop->convert_to, is_direction);
109 
110  if (func_name) {
111  /* For cycles we have inverted Z */
112  /* TODO: pass here the correct matrices */
115  GPU_link(mat, "invert_z", inputlink, &inputlink);
116  }
117 
118  GPU_link(mat, func_name, inputlink, &out[0].link);
119 
120  if (nodeprop->convert_to == SHD_VECT_TRANSFORM_SPACE_CAMERA &&
122  GPU_link(mat, "invert_z", out[0].link, &out[0].link);
123  }
124  }
125  else {
126  GPU_link(mat, "set_rgb", inputlink, &out[0].link);
127  }
128 
129  if (nodeprop->type == SHD_VECT_TRANSFORM_TYPE_NORMAL) {
130  GPU_link(mat, "vector_normalize", out[0].link, &out[0].link);
131  }
132 
133  return true;
134 }
135 
136 } // namespace blender::nodes::node_shader_vector_transform_cc
137 
139 {
141 
142  static bNodeType ntype;
143 
144  sh_node_type_base(&ntype, SH_NODE_VECT_TRANSFORM, "Vector Transform", NODE_CLASS_OP_VECTOR);
149  &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:4465
void node_type_init(struct bNodeType *ntype, void(*initfunc)(struct bNodeTree *ntree, struct bNode *node))
Definition: node.cc:4390
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:4426
#define NODE_CLASS_OP_VECTOR
Definition: BKE_node.h:348
void nodeRegisterType(struct bNodeType *ntype)
Definition: node.cc:1357
#define UNUSED(x)
#define SHD_VECT_TRANSFORM_TYPE_NORMAL
#define SHD_VECT_TRANSFORM_TYPE_POINT
#define SHD_VECT_TRANSFORM_SPACE_OBJECT
#define SHD_VECT_TRANSFORM_SPACE_CAMERA
#define SHD_VECT_TRANSFORM_SPACE_WORLD
GPUNodeLink * GPU_constant(const float *num)
bool GPU_link(GPUMaterial *mat, const char *name,...)
in reality light always falls off quadratically Particle Retrieve the data of the particle that spawned the object for example to give variation to multiple instances of an object Point Retrieve information about points in a point cloud Retrieve the edges of an object as it appears to Cycles topology will always appear triangulated Convert a blackbody temperature to an RGB value Normal Generate a perturbed normal from an RGB normal map image Typically used for faking highly detailed surfaces Generate an OSL shader from a file or text data block Image Sample an image file as a texture Sky Generate a procedural sky texture Noise Generate fractal Perlin noise Wave Generate procedural bands or rings with noise Voronoi Generate Worley noise based on the distance to random points Typically used to generate textures such as or biological cells Brick Generate a procedural texture producing bricks Texture Retrieve multiple types of texture coordinates nTypically used as inputs for texture nodes SH_NODE_VECT_TRANSFORM
@ UI_ITEM_R_SPLIT_EMPTY_NAME
@ UI_ITEM_R_EXPAND
void uiItemR(uiLayout *layout, struct PointerRNA *ptr, const char *propname, int flag, const char *name, int icon)
OperationNode * node
StackEntry * from
bNodeTree * ntree
static int gpu_shader_vect_transform(GPUMaterial *mat, bNode *node, bNodeExecData *UNUSED(execdata), GPUNodeStack *in, GPUNodeStack *out)
static void node_shader_init_vect_transform(bNodeTree *UNUSED(ntree), bNode *node)
static const char * get_gpufn_name_from_to(short from, short to, bool is_direction)
static void node_shader_buts_vect_transform(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
static const pxr::TfToken out("out", pxr::TfToken::Immortal)
static const pxr::TfToken b("b", pxr::TfToken::Immortal)
void sh_node_type_base(struct bNodeType *ntype, int type, const char *name, short nclass)
void register_node_type_sh_vect_transform()
void node_copy_standard_storage(bNodeTree *UNUSED(dest_ntree), bNode *dest_node, const bNode *src_node)
Definition: node_util.c:55
void node_free_standard_storage(bNode *node)
Definition: node_util.c:43
#define min(a, b)
Definition: sort.c:35
struct GPUNodeLink * link
Definition: GPU_material.h:106
Defines a node type.
Definition: BKE_node.h:226
void(* draw_buttons)(struct uiLayout *, struct bContext *C, struct PointerRNA *ptr)
Definition: BKE_node.h:244
NodeDeclareFunction declare
Definition: BKE_node.h:324
#define N_(msgid)
PointerRNA * ptr
Definition: wm_files.c:3480