Blender  V3.3
node_shader_tex_checker.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 
7 
9 {
10  b.is_function_node();
11  b.add_input<decl::Vector>(N_("Vector")).min(-10000.0f).max(10000.0f).implicit_field();
12  b.add_input<decl::Color>(N_("Color1")).default_value({0.8f, 0.8f, 0.8f, 1.0f});
13  b.add_input<decl::Color>(N_("Color2")).default_value({0.2f, 0.2f, 0.2f, 1.0f});
14  b.add_input<decl::Float>(N_("Scale"))
15  .min(-10000.0f)
16  .max(10000.0f)
17  .default_value(5.0f)
18  .no_muted_links();
19  b.add_output<decl::Color>(N_("Color"));
20  b.add_output<decl::Float>(N_("Fac"));
21 }
22 
24 {
25  NodeTexChecker *tex = MEM_cnew<NodeTexChecker>(__func__);
27  BKE_texture_colormapping_default(&tex->base.color_mapping);
28 
29  node->storage = tex;
30 }
31 
33  bNode *node,
34  bNodeExecData *UNUSED(execdata),
35  GPUNodeStack *in,
37 {
38  node_shader_gpu_default_tex_coord(mat, node, &in[0].link);
40 
41  return GPU_stack_link(mat, node, "node_tex_checker", in, out);
42 }
43 
45  public:
47  {
49  this->set_signature(&signature);
50  }
51 
53  {
55  signature.single_input<float3>("Vector");
56  signature.single_input<ColorGeometry4f>("Color1");
57  signature.single_input<ColorGeometry4f>("Color2");
58  signature.single_input<float>("Scale");
59  signature.single_output<ColorGeometry4f>("Color");
60  signature.single_output<float>("Fac");
61  return signature.build();
62  }
63 
65  {
66  const VArray<float3> &vector = params.readonly_single_input<float3>(0, "Vector");
67  const VArray<ColorGeometry4f> &color1 = params.readonly_single_input<ColorGeometry4f>(
68  1, "Color1");
69  const VArray<ColorGeometry4f> &color2 = params.readonly_single_input<ColorGeometry4f>(
70  2, "Color2");
71  const VArray<float> &scale = params.readonly_single_input<float>(3, "Scale");
73  params.uninitialized_single_output_if_required<ColorGeometry4f>(4, "Color");
74  MutableSpan<float> r_fac = params.uninitialized_single_output<float>(5, "Fac");
75 
76  for (int64_t i : mask) {
77  /* Avoid precision issues on unit coordinates. */
78  const float3 p = (vector[i] * scale[i] + 0.000001f) * 0.999999f;
79 
80  const int xi = abs((int)(floorf(p.x)));
81  const int yi = abs((int)(floorf(p.y)));
82  const int zi = abs((int)(floorf(p.z)));
83 
84  r_fac[i] = ((xi % 2 == yi % 2) == (zi % 2)) ? 1.0f : 0.0f;
85  }
86 
87  if (!r_color.is_empty()) {
88  for (int64_t i : mask) {
89  r_color[i] = (r_fac[i] == 1.0f) ? color1[i] : color2[i];
90  }
91  }
92  }
93 };
94 
96 {
97  static NodeTexChecker fn;
98  builder.set_matching_fn(fn);
99 }
100 
101 } // namespace blender::nodes::node_shader_tex_checker_cc
102 
104 {
105  namespace file_ns = blender::nodes::node_shader_tex_checker_cc;
106 
107  static bNodeType ntype;
108 
109  sh_fn_node_type_base(&ntype, SH_NODE_TEX_CHECKER, "Checker Texture", NODE_CLASS_TEXTURE);
113  &ntype, "NodeTexChecker", node_free_standard_storage, node_copy_standard_storage);
116 
117  nodeRegisterType(&ntype);
118 }
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 SH_NODE_TEX_CHECKER
Definition: BKE_node.h:1135
#define NODE_CLASS_TEXTURE
Definition: BKE_node.h:355
void nodeRegisterType(struct bNodeType *ntype)
Definition: node.cc:1357
void BKE_texture_mapping_default(struct TexMapping *texmap, int type)
Definition: texture.c:238
void BKE_texture_colormapping_default(struct ColorMapping *colormap)
Definition: texture.c:340
#define UNUSED(x)
#define TEXMAP_TYPE_POINT
bool GPU_stack_link(GPUMaterial *mat, struct bNode *node, const char *name, GPUNodeStack *in, GPUNodeStack *out,...)
void set_signature(const MFSignature *signature)
const MFSignature & signature() const
void set_matching_fn(const MultiFunction *fn)
void call(IndexMask mask, fn::MFParams params, fn::MFContext UNUSED(context)) const override
OperationNode * node
bNodeTree * ntree
uiWidgetBaseParameters params[MAX_WIDGET_BASE_BATCH]
ccl_device_inline float4 mask(const int4 &mask, const float4 &a)
Definition: math_float4.h:513
#define floorf(x)
Definition: metal/compat.h:224
T abs(const T &a)
static void sh_node_tex_checker_declare(NodeDeclarationBuilder &b)
static void sh_node_tex_checker_build_multi_function(NodeMultiFunctionBuilder &builder)
static void node_shader_init_tex_checker(bNodeTree *UNUSED(ntree), bNode *node)
static int node_shader_gpu_tex_checker(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_checker()
void node_shader_gpu_tex_mapping(GPUMaterial *mat, bNode *node, GPUNodeStack *in, GPUNodeStack *UNUSED(out))
void node_shader_gpu_default_tex_coord(GPUMaterial *mat, bNode *node, GPUNodeLink **link)
void sh_fn_node_type_base(bNodeType *ntype, int type, const char *name, short nclass)
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
__int64 int64_t
Definition: stdint.h:89
Defines a node type.
Definition: BKE_node.h:226
NodeMultiFunctionBuildFunction build_multi_function
Definition: BKE_node.h:313
NodeDeclareFunction declare
Definition: BKE_node.h:324
#define N_(msgid)