Blender  V2.93
node_fn_random_float.cc
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 
17 #include "node_function_util.hh"
18 
19 #include "BLI_hash.h"
20 
22  {SOCK_FLOAT, N_("Min"), 0.0f, 0.0f, 0.0f, 0.0f, -10000.0f, 10000.0f, PROP_NONE},
23  {SOCK_FLOAT, N_("Max"), 1.0f, 0.0f, 0.0f, 0.0f, -10000.0f, 10000.0f, PROP_NONE},
24  {SOCK_INT, N_("Seed"), 0, 0, 0, 0, -10000, 10000},
25  {-1, ""},
26 };
27 
29  {SOCK_FLOAT, N_("Value")},
30  {-1, ""},
31 };
32 
34  public:
36  {
38  this->set_signature(&signature);
39  }
40 
42  {
44  signature.single_input<float>("Min");
45  signature.single_input<float>("Max");
46  signature.single_input<int>("Seed");
47  signature.single_output<float>("Value");
48  return signature.build();
49  }
50 
53  blender::fn::MFContext UNUSED(context)) const override
54  {
55  const blender::VArray<float> &min_values = params.readonly_single_input<float>(0, "Min");
56  const blender::VArray<float> &max_values = params.readonly_single_input<float>(1, "Max");
57  const blender::VArray<int> &seeds = params.readonly_single_input<int>(2, "Seed");
58  blender::MutableSpan<float> values = params.uninitialized_single_output<float>(3, "Value");
59 
60  for (int64_t i : mask) {
61  const float min_value = min_values[i];
62  const float max_value = max_values[i];
63  const int seed = seeds[i];
64  const float value = BLI_hash_int_01(static_cast<uint32_t>(seed));
65  values[i] = value * (max_value - min_value) + min_value;
66  }
67  }
68 };
69 
72 {
74 }
75 
77 {
78  static bNodeType ntype;
79 
80  fn_node_type_base(&ntype, FN_NODE_RANDOM_FLOAT, "Random Float", 0, 0);
83  nodeRegisterType(&ntype);
84 }
void node_type_socket_templates(struct bNodeType *ntype, struct bNodeSocketTemplate *inputs, struct bNodeSocketTemplate *outputs)
Definition: node.cc:4527
void nodeRegisterType(struct bNodeType *ntype)
Definition: node.cc:1298
BLI_INLINE float BLI_hash_int_01(unsigned int k)
Definition: BLI_hash.h:108
#define UNUSED(x)
#define N_(msgid)
@ SOCK_INT
@ SOCK_FLOAT
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 Vector Combine Vertex Separate Vector White RGB Map Separate Set Z Dilate Combine Combine Color Channel Split ID Combine Luminance Directional Alpha Distance Hue Movie Ellipse Bokeh View Corner Anti Mix RGB Hue Separate TEX_NODE_PROC TEX_NODE_PROC TEX_NODE_PROC TEX_NODE_PROC TEX_NODE_PROC Boolean FN_NODE_RANDOM_FLOAT
@ PROP_NONE
Definition: RNA_types.h:113
static unsigned long seed
Definition: btSoftBody.h:39
void call(blender::IndexMask mask, blender::fn::MFParams params, blender::fn::MFContext UNUSED(context)) const override
static blender::fn::MFSignature create_signature()
void set_signature(const MFSignature *signature)
const MFSignature & signature() const
uiWidgetBaseParameters params[MAX_WIDGET_BASE_BATCH]
static bNodeSocketTemplate fn_node_random_float_in[]
static bNodeSocketTemplate fn_node_random_float_out[]
static void fn_node_random_float_expand_in_mf_network(blender::nodes::NodeMFNetworkBuilder &builder)
void register_node_type_fn_random_float()
void fn_node_type_base(bNodeType *ntype, int type, const char *name, short nclass, short flag)
struct SELECTID_Context context
Definition: select_engine.c:47
unsigned int uint32_t
Definition: stdint.h:83
__int64 int64_t
Definition: stdint.h:92
Compact definition of a node socket.
Definition: BKE_node.h:95
Defines a node type.
Definition: BKE_node.h:221
NodeExpandInMFNetworkFunction expand_in_mf_network
Definition: BKE_node.h:324
ccl_device_inline float4 mask(const int4 &mask, const float4 &a)