21 b.add_input<
decl::Vector>(
"Vector").
min(-10000.0f).max(10000.0f).implicit_field(
30 .description(
"Value used as seed in 1D and 4D dimensions");
47 BLI_assert(dimensions >= 1 && dimensions <= 4);
48 return std::array{
"node_white_noise_1d",
49 "node_white_noise_2d",
50 "node_white_noise_3d",
51 "node_white_noise_4d"}[dimensions - 1];
80 BLI_assert(dimensions >= 1 && dimensions <= 4);
81 static std::array<mf::Signature, 4> signatures{
93 mf::SignatureBuilder builder{
"WhiteNoise",
signature};
95 if (
ELEM(dimensions, 2, 3, 4)) {
96 builder.single_input<
float3>(
"Vector");
98 if (
ELEM(dimensions, 1, 4)) {
99 builder.single_input<
float>(
"W");
102 builder.single_output<
float>(
"Value", mf::ParamFlag::SupportsUnusedOutput);
103 builder.single_output<
ColorGeometry4f>(
"Color", mf::ParamFlag::SupportsUnusedOutput);
110 int param =
ELEM(dimensions_, 2, 3, 4) +
ELEM(dimensions_, 1, 4);
117 const bool compute_value = !r_value.
is_empty();
118 const bool compute_color = !r_color.is_empty();
120 switch (dimensions_) {
198 const float LARGE_NUMBER = 10000.0f;
200 NodeItem
noise = empty();
201 NodeItem
vector = empty();
202 NodeItem
w = empty();
204 int dimension = node_->custom1;
207 w = get_input_value(
"W", NodeItem::Type::Vector2);
209 "cellnoise2d", NodeItem::Type::Float, {{
"texcoord",
w * val(LARGE_NUMBER)}});
212 vector = get_input_link(
"Vector", NodeItem::Type::Vector2);
217 "cellnoise2d", NodeItem::Type::Float, {{
"texcoord",
vector * val(LARGE_NUMBER)}});
220 vector = get_input_link(
"Vector", NodeItem::Type::Vector3);
222 vector = texcoord_node(NodeItem::Type::Vector3);
225 "cellnoise3d", NodeItem::Type::Float, {{
"position",
vector * val(LARGE_NUMBER)}});
228 vector = get_input_link(
"Vector", NodeItem::Type::Vector3);
230 vector = texcoord_node(NodeItem::Type::Vector3);
232 w = get_input_value(
"W", NodeItem::Type::Float);
234 "cellnoise3d", NodeItem::Type::Float, {{
"position", (
vector +
w) * val(LARGE_NUMBER)}});
241 if (
STREQ(socket_out_->identifier,
"Value")) {
247 NodeItem combine = create_node(
"combine3",
248 NodeItem::Type::Color3,
249 {{
"in1", noise}, {
"in2", val(1.0f)}, {
"in3", val(0.5f)}});
250 return create_node(
"hsvtorgb", NodeItem::Type::Color3, {{
"in", combine}});
264 ntype.
ui_name =
"White Noise Texture";
265 ntype.
ui_description =
"Calculate a random value or color based on an input seed";
268 ntype.
declare = file_ns::sh_node_tex_white_noise_declare;
269 ntype.
draw_buttons = file_ns::node_shader_buts_white_noise;
270 ntype.
initfunc = file_ns::node_shader_init_tex_white_noise;
271 ntype.
gpu_fn = file_ns::gpu_shader_tex_white_noise;
272 ntype.
updatefunc = file_ns::node_shader_update_tex_white_noise;
#define NODE_CLASS_TEXTURE
#define SH_NODE_TEX_WHITE_NOISE
#define BLI_assert_unreachable()
@ NODE_DEFAULT_INPUT_POSITION_FIELD
bool GPU_stack_link(GPUMaterial *mat, const bNode *node, const char *name, GPUNodeStack *in, GPUNodeStack *out,...)
@ UI_ITEM_R_SPLIT_EMPTY_NAME
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 make_available(bNode &node) const
void call(const IndexMask &mask, mf::Params params, mf::Context) const override
static mf::Signature create_signature(int dimensions)
WhiteNoiseFunction(int dimensions)
ccl_device_inline float2 mask(const MaskType mask, const float2 a)
bNodeSocket * node_find_socket(bNode &node, eNodeSocketInOut in_out, StringRef identifier)
void node_register_type(bNodeType &ntype)
void node_set_socket_availability(bNodeTree &ntree, bNodeSocket &sock, bool is_available)
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(uiLayout *layout, bContext *, PointerRNA *ptr)
static void node_shader_update_tex_white_noise(bNodeTree *ntree, bNode *node)
static int gpu_shader_tex_white_noise(GPUMaterial *mat, bNode *node, bNodeExecData *, GPUNodeStack *in, GPUNodeStack *out)
static void sh_node_noise_build_multi_function(NodeMultiFunctionBuilder &builder)
static void node_shader_init_tex_white_noise(bNodeTree *, bNode *node)
float hash_float_to_float(float k)
float3 hash_float_to_float3(float k)
VecBase< float, 4 > float4
VecBase< float, 2 > float2
ColorSceneLinear4f< eAlpha::Premultiplied > ColorGeometry4f
VecBase< float, 3 > float3
std::vector< ElementType, Eigen::aligned_allocator< ElementType > > vector
#define NODE_SHADER_MATERIALX_BEGIN
#define NODE_SHADER_MATERIALX_END
void register_node_type_sh_tex_white_noise()
void common_node_type_base(blender::bke::bNodeType *ntype, std::string idname, const std::optional< int16_t > legacy_type)
NodeMaterialXFunction materialx_fn
std::string ui_description
void(* initfunc)(bNodeTree *ntree, bNode *node)
NodeGPUExecFunction gpu_fn
NodeMultiFunctionBuildFunction build_multi_function
const char * enum_name_legacy
void(* draw_buttons)(uiLayout *, bContext *C, PointerRNA *ptr)
NodeDeclareFunction declare
void(* updatefunc)(bNodeTree *ntree, bNode *node)
void prop(PointerRNA *ptr, PropertyRNA *prop, int index, int value, eUI_Item_Flag flag, std::optional< blender::StringRef > name_opt, int icon, std::optional< blender::StringRef > placeholder=std::nullopt)