28 const int dimensions =
b.node_or_null() ?
b.node_or_null()->custom1 : 3;
29 const bool is_compositor =
b.tree_or_null() &&
b.tree_or_null()->type ==
NTREE_COMPOSIT;
36 .default_input_type(default_input_type)
37 .available(dimensions != 1);
42 .available(
ELEM(dimensions, 1, 4))
47 .description(
"Value used as seed in 1D and 4D dimensions");
65 BLI_assert(dimensions >= 1 && dimensions <= 4);
66 return std::array{
"node_white_noise_1d",
67 "node_white_noise_2d",
68 "node_white_noise_3d",
69 "node_white_noise_4d"}[dimensions - 1];
89 BLI_assert(dimensions >= 1 && dimensions <= 4);
90 static std::array<mf::Signature, 4> signatures{
102 mf::SignatureBuilder builder{
"WhiteNoise",
signature};
104 if (
ELEM(dimensions, 2, 3, 4)) {
105 builder.single_input<
float3>(
"Vector");
107 if (
ELEM(dimensions, 1, 4)) {
108 builder.single_input<
float>(
"W");
111 builder.single_output<
float>(
"Value", mf::ParamFlag::SupportsUnusedOutput);
112 builder.single_output<
ColorGeometry4f>(
"Color", mf::ParamFlag::SupportsUnusedOutput);
119 int param =
ELEM(dimensions_, 2, 3, 4) +
ELEM(dimensions_, 1, 4);
121 MutableSpan<float> r_value = params.uninitialized_single_output_if_required<
float>(param++,
124 params.uninitialized_single_output_if_required<
ColorGeometry4f>(param++,
"Color");
126 const bool compute_value = !r_value.
is_empty();
127 const bool compute_color = !r_color.is_empty();
129 switch (dimensions_) {
131 const VArray<float> &
w = params.readonly_single_input<
float>(0,
"W");
175 const VArray<float> &
w = params.readonly_single_input<
float>(1,
"W");
179 float4(vector[i].
x, vector[i].
y, vector[i].
z,
w[i]));
186 float4(vector[i].
x, vector[i].
y, vector[i].
z,
w[i]));
196 static constexpr int8_t id = 0;
198 hash.add(dimensions_);
214 const float LARGE_NUMBER = 10000.0f;
216 NodeItem
noise = empty();
217 NodeItem vector = empty();
218 NodeItem
w = empty();
220 int dimension = node_->custom1;
223 w = get_input_value(
"W", NodeItem::Type::Vector2);
225 "cellnoise2d", NodeItem::Type::Float, {{
"texcoord",
w * val(LARGE_NUMBER)}});
228 vector = get_input_link(
"Vector", NodeItem::Type::Vector2);
233 "cellnoise2d", NodeItem::Type::Float, {{
"texcoord",
vector * val(LARGE_NUMBER)}});
236 vector = get_input_link(
"Vector", NodeItem::Type::Vector3);
238 vector = texcoord_node(NodeItem::Type::Vector3);
241 "cellnoise3d", NodeItem::Type::Float, {{
"position",
vector * val(LARGE_NUMBER)}});
244 vector = get_input_link(
"Vector", NodeItem::Type::Vector3);
246 vector = texcoord_node(NodeItem::Type::Vector3);
248 w = get_input_value(
"W", NodeItem::Type::Float);
250 "cellnoise3d", NodeItem::Type::Float, {{
"position", (
vector +
w) * val(LARGE_NUMBER)}});
257 if (
STREQ(socket_out_->identifier,
"Value")) {
263 NodeItem combine = create_node(
"combine3",
264 NodeItem::Type::Color3,
265 {{
"in1",
noise}, {
"in2", val(1.0f)}, {
"in3", val(0.5f)}});
266 return create_node(
"hsvtorgb", NodeItem::Type::Color3, {{
"in", combine}});
280 ntype.
ui_name =
"White Noise Texture";
281 ntype.
ui_description =
"Calculate a random value or color based on an input seed";
284 ntype.
declare = file_ns::sh_node_tex_white_noise_declare;
285 ntype.
draw_buttons = file_ns::node_shader_buts_white_noise;
286 ntype.
initfunc = file_ns::node_shader_init_tex_white_noise;
287 ntype.
gpu_fn = file_ns::gpu_shader_tex_white_noise;
#define NODE_CLASS_TEXTURE
#define SH_NODE_TEX_WHITE_NOISE
#define BLI_assert_unreachable()
SIMD_FORCE_INLINE const btScalar & z() const
Return the z value.
SIMD_FORCE_INLINE const btScalar & w() const
Return the w value.
constexpr bool is_empty() const
const Signature & signature() const
void set_signature(const Signature *signature)
void construct_and_set_matching_fn(Args &&...args)
void call(const IndexMask &mask, mf::Params params, mf::Context) const override
static mf::Signature create_signature(int dimensions)
void hash_unique(UniqueHashBytes &hash) const override
WhiteNoiseFunction(int dimensions)
void node_register_type(bNodeType &ntype)
static const char * gpu_shader_get_name(const int dimensions)
static void sh_node_tex_white_noise_declare(NodeDeclarationBuilder &b)
static void node_shader_buts_white_noise(ui::Layout &layout, bContext *, PointerRNA *ptr)
static int gpu_shader_tex_white_noise(GPUMaterial *mat, bNode *node, bNodeExecData *, GPUNodeStack *in, GPUNodeStack *out)
static void node_shader_init_tex_white_noise(bNodeTree *node_tree, bNode *node)
static void sh_node_noise_build_multi_function(NodeMultiFunctionBuilder &builder)
float hash_float_to_float(float k)
float3 hash_float_to_float3(float k)
@ ITEM_R_SPLIT_EMPTY_NAME
BLI_assert(slot->slot_subtype.map==BMO_OP_SLOT_SUBTYPE_MAP_FLT)
bool GPU_stack_link(GPUMaterial *mat, const bNode *node, const char *name, GPUNodeStack *in, GPUNodeStack *out,...)
void register_node_type_sh_tex_white_noise()
VecBase< float, 4 > float4
VecBase< float, 2 > float2
@ NODE_DEFAULT_INPUT_POSITION_FIELD
@ NODE_DEFAULT_INPUT_UNIFORM_IMAGE_COORDINATES
ColorSceneLinear4f< eAlpha::Premultiplied > ColorGeometry4f
VecBase< float, 3 > float3
void common_node_type_base(bke::bNodeType *ntype, UString idname, const std::optional< int16_t > legacy_type)
std::vector< ElementType, Eigen::aligned_allocator< ElementType > > vector
#define NODE_SHADER_MATERIALX_BEGIN
#define NODE_SHADER_MATERIALX_END
NodeMaterialXFunction materialx_fn
void(*) draw_buttons(ui::Layout &, bContext *C, PointerRNA *ptr)
std::string ui_description
NodeGPUExecFunction gpu_fn
NodeMultiFunctionBuildFunction build_multi_function
void(*) initfunc(bNodeTree *ntree, bNode *node)
const char * enum_name_legacy
NodeDeclareFunction declare
void prop(PointerRNA *ptr, PropertyRNA *prop, int index, int value, eUI_Item_Flag flag, std::optional< StringRef > name_opt, int icon, std::optional< StringRef > placeholder=std::nullopt)