Blender  V3.3
node_shader_clamp.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 
8 #include "node_shader_util.hh"
9 
10 #include "UI_interface.h"
11 #include "UI_resources.h"
12 
14 
16 {
17  b.is_function_node();
18  b.add_input<decl::Float>(N_("Value")).default_value(1.0f);
19  b.add_input<decl::Float>(N_("Min")).default_value(0.0f).min(-10000.0f).max(10000.0f);
20  b.add_input<decl::Float>(N_("Max")).default_value(1.0f).min(-10000.0f).max(10000.0f);
21  b.add_output<decl::Float>(N_("Result"));
22 }
23 
25 {
26  uiItemR(layout, ptr, "clamp_type", UI_ITEM_R_SPLIT_EMPTY_NAME, "", ICON_NONE);
27 }
28 
30 {
31  node->custom1 = NODE_CLAMP_MINMAX; /* clamp type */
32 }
33 
34 static int gpu_shader_clamp(GPUMaterial *mat,
35  bNode *node,
36  bNodeExecData *UNUSED(execdata),
37  GPUNodeStack *in,
39 {
40  return (node->custom1 == NODE_CLAMP_MINMAX) ?
41  GPU_stack_link(mat, node, "clamp_minmax", in, out) :
42  GPU_stack_link(mat, node, "clamp_range", in, out);
43 }
44 
46 {
48  "Clamp (Min Max)",
49  [](float value, float min, float max) { return std::min(std::max(value, min), max); }};
51  "Clamp (Range)", [](float value, float a, float b) {
52  if (a < b) {
53  return clamp_f(value, a, b);
54  }
55 
56  return clamp_f(value, b, a);
57  }};
58 
59  int clamp_type = builder.node().custom1;
60  if (clamp_type == NODE_CLAMP_MINMAX) {
61  builder.set_matching_fn(minmax_fn);
62  }
63  else {
64  builder.set_matching_fn(range_fn);
65  }
66 }
67 
68 } // namespace blender::nodes::node_shader_clamp_cc
69 
71 {
72  namespace file_ns = blender::nodes::node_shader_clamp_cc;
73 
74  static bNodeType ntype;
75 
82 
83  nodeRegisterType(&ntype);
84 }
void node_type_gpu(struct bNodeType *ntype, NodeGPUExecFunction gpu_fn)
Definition: node.cc:4465
#define NODE_CLASS_CONVERTER
Definition: BKE_node.h:351
void node_type_init(struct bNodeType *ntype, void(*initfunc)(struct bNodeTree *ntree, struct bNode *node))
Definition: node.cc:4390
void nodeRegisterType(struct bNodeType *ntype)
Definition: node.cc:1357
MINLINE float clamp_f(float value, float min, float max)
#define UNUSED(x)
@ NODE_CLAMP_MINMAX
bool GPU_stack_link(GPUMaterial *mat, struct bNode *node, const char *name, GPUNodeStack *in, GPUNodeStack *out,...)
Group Output data from inside of a node group A color picker Mix two input colors RGB to Convert a color s luminance to a grayscale value Generate a normal vector and a dot product Bright Control the brightness and contrast of the input color Vector Map an input vectors to used to fine tune the interpolation of the input Camera Retrieve information about the camera and how it relates to the current shading point s position SH_NODE_CLAMP
@ UI_ITEM_R_SPLIT_EMPTY_NAME
void uiItemR(uiLayout *layout, struct PointerRNA *ptr, const char *propname, int flag, const char *name, int icon)
void set_matching_fn(const MultiFunction *fn)
OperationNode * node
bNodeTree * ntree
static unsigned a[3]
Definition: RandGen.cpp:78
static void node_shader_buts_clamp(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
static void node_shader_init_clamp(bNodeTree *UNUSED(ntree), bNode *node)
static void sh_node_clamp_build_multi_function(NodeMultiFunctionBuilder &builder)
static int gpu_shader_clamp(GPUMaterial *mat, bNode *node, bNodeExecData *UNUSED(execdata), GPUNodeStack *in, GPUNodeStack *out)
static void sh_node_clamp_declare(NodeDeclarationBuilder &b)
static const pxr::TfToken out("out", pxr::TfToken::Immortal)
static const pxr::TfToken b("b", pxr::TfToken::Immortal)
void register_node_type_sh_clamp()
void sh_fn_node_type_base(bNodeType *ntype, int type, const char *name, short nclass)
#define min(a, b)
Definition: sort.c:35
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
NodeMultiFunctionBuildFunction build_multi_function
Definition: BKE_node.h:313
NodeDeclareFunction declare
Definition: BKE_node.h:324
short custom1
float max
#define N_(msgid)
PointerRNA * ptr
Definition: wm_files.c:3480