Blender  V3.3
node_shader_tex_coord.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 
6 #include "DNA_customdata_types.h"
7 
8 #include "UI_interface.h"
9 #include "UI_resources.h"
10 
12 
14 {
15  b.add_output<decl::Vector>(N_("Generated"));
16  b.add_output<decl::Vector>(N_("Normal"));
17  b.add_output<decl::Vector>(N_("UV"));
18  b.add_output<decl::Vector>(N_("Object"));
19  b.add_output<decl::Vector>(N_("Camera"));
20  b.add_output<decl::Vector>(N_("Window"));
21  b.add_output<decl::Vector>(N_("Reflection"));
22 }
23 
25 {
26  uiItemR(layout, ptr, "object", UI_ITEM_R_SPLIT_EMPTY_NAME, nullptr, 0);
27  uiItemR(layout, ptr, "from_instancer", UI_ITEM_R_SPLIT_EMPTY_NAME, nullptr, 0);
28 }
29 
31  bNode *node,
32  bNodeExecData *UNUSED(execdata),
33  GPUNodeStack *in,
35 {
36  Object *ob = (Object *)node->id;
37 
38  /* Use special matrix to let the shader branch to using the render object's matrix. */
39  float dummy_matrix[4][4];
40  dummy_matrix[3][3] = 0.0f;
41  GPUNodeLink *inv_obmat = (ob != NULL) ? GPU_uniform(&ob->imat[0][0]) :
42  GPU_uniform(&dummy_matrix[0][0]);
43 
44  /* Opti: don't request orco if not needed. */
45  float4 zero(0.0f);
46  GPUNodeLink *orco = (!out[0].hasoutput) ? GPU_constant(zero) : GPU_attribute(mat, CD_ORCO, "");
47  GPUNodeLink *mtface = GPU_attribute(mat, CD_AUTO_FROM_NAME, "");
48 
49  GPU_stack_link(mat, node, "node_tex_coord", in, out, inv_obmat, orco, mtface);
50 
51  int i;
52  LISTBASE_FOREACH_INDEX (bNodeSocket *, sock, &node->outputs, i) {
53  node_shader_gpu_bump_tex_coord(mat, node, &out[i].link);
54  /* Normalize some vectors after dFdx/dFdy offsets.
55  * This is the case for interpolated, non linear functions.
56  * The resulting vector can still be a bit wrong but not as much.
57  * (see T70644) */
58  if (ELEM(i, 1, 6)) {
59  GPU_link(mat,
60  "vector_math_normalize",
61  out[i].link,
62  out[i].link,
63  out[i].link,
64  out[i].link,
65  &out[i].link,
66  nullptr);
67  }
68  }
69 
70  return 1;
71 }
72 
73 } // namespace blender::nodes::node_shader_tex_coord_cc
74 
75 /* node type definition */
77 {
78  namespace file_ns = blender::nodes::node_shader_tex_coord_cc;
79 
80  static bNodeType ntype;
81 
82  sh_node_type_base(&ntype, SH_NODE_TEX_COORD, "Texture Coordinate", NODE_CLASS_INPUT);
86 
87  nodeRegisterType(&ntype);
88 }
void node_type_gpu(struct bNodeType *ntype, NodeGPUExecFunction gpu_fn)
Definition: node.cc:4465
#define NODE_CLASS_INPUT
Definition: BKE_node.h:345
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(...)
@ CD_AUTO_FROM_NAME
GPUNodeLink * GPU_attribute(GPUMaterial *mat, eCustomDataType type, const char *name)
GPUNodeLink * GPU_constant(const float *num)
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,...)
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 SH_NODE_TEX_COORD
@ UI_ITEM_R_SPLIT_EMPTY_NAME
void uiItemR(uiLayout *layout, struct PointerRNA *ptr, const char *propname, int flag, const char *name, int icon)
OperationNode * node
static void node_shader_buts_tex_coord(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
static void node_declare(NodeDeclarationBuilder &b)
static int node_shader_gpu_tex_coord(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_tex_coord()
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)
float imat[4][4]
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