29 node_storage(node).dimensions = 1;
31 b.add_input<
decl::Float>(
"Scale").min(-1000.0f).
max(1000.0f).default_value(5.0f).description(
32 "Scale of the base noise octave");
33 b.add_input<
decl::Float>(
"Detail").min(0.0f).
max(15.0f).default_value(2.0f).description(
34 "The number of noise octaves. Higher values give more detailed noise but increase render "
42 "Blend factor between an octave and its previous one. A value of zero corresponds to "
49 "The difference between the scale of each two consecutive octaves. Larger values "
50 "corresponds to larger scale for higher octaves");
57 "An added offset to each octave, determines the level where the highest octave will "
64 .
description(
"An extra multiplier to tune the magnitude of octaves");
69 .description(
"Amount of distortion");
70 b.add_output<
decl::Float>(
"Factor",
"Fac").no_muted_links();
102 return std::array{
"node_noise_tex_multi_fractal_1d",
103 "node_noise_tex_multi_fractal_2d",
104 "node_noise_tex_multi_fractal_3d",
105 "node_noise_tex_multi_fractal_4d"}[dimensions - 1];
107 return std::array{
"node_noise_tex_fbm_1d",
108 "node_noise_tex_fbm_2d",
109 "node_noise_tex_fbm_3d",
110 "node_noise_tex_fbm_4d"}[dimensions - 1];
112 return std::array{
"node_noise_tex_hybrid_multi_fractal_1d",
113 "node_noise_tex_hybrid_multi_fractal_2d",
114 "node_noise_tex_hybrid_multi_fractal_3d",
115 "node_noise_tex_hybrid_multi_fractal_4d"}[dimensions - 1];
117 return std::array{
"node_noise_tex_ridged_multi_fractal_1d",
118 "node_noise_tex_ridged_multi_fractal_2d",
119 "node_noise_tex_ridged_multi_fractal_3d",
120 "node_noise_tex_ridged_multi_fractal_4d"}[dimensions - 1];
122 return std::array{
"node_noise_tex_hetero_terrain_1d",
123 "node_noise_tex_hetero_terrain_2d",
124 "node_noise_tex_hetero_terrain_3d",
125 "node_noise_tex_hetero_terrain_4d"}[dimensions - 1];
175 : dimensions_(dimensions), type_(type), normalize_(
normalize)
177 BLI_assert(dimensions >= 1 && dimensions <= 4);
179 static std::array<mf::Signature, 20> signatures{
211 mf::SignatureBuilder builder{
"Noise",
signature};
213 if (
ELEM(dimensions, 2, 3, 4)) {
214 builder.single_input<
float3>(
"Vector");
216 if (
ELEM(dimensions, 1, 4)) {
217 builder.single_input<
float>(
"W");
220 builder.single_input<
float>(
"Scale");
221 builder.single_input<
float>(
"Detail");
222 builder.single_input<
float>(
"Roughness");
223 builder.single_input<
float>(
"Lacunarity");
229 builder.single_input<
float>(
"Offset");
232 builder.single_input<
float>(
"Gain");
234 builder.single_input<
float>(
"Distortion");
236 builder.single_output<
float>(
"Fac", mf::ParamFlag::SupportsUnusedOutput);
237 builder.single_output<
ColorGeometry4f>(
"Color", mf::ParamFlag::SupportsUnusedOutput);
244 int param =
ELEM(dimensions_, 2, 3, 4) +
ELEM(dimensions_, 1, 4);
247 const VArray<float> &roughness =
params.readonly_single_input<
float>(param++,
"Roughness");
248 const VArray<float> &lacunarity =
params.readonly_single_input<
float>(param++,
"Lacunarity");
254 params.readonly_single_input<
float>(param++,
"Offset") :
260 params.readonly_single_input<
float>(param++,
"Gain") :
262 const VArray<float> &distortion =
params.readonly_single_input<
float>(param++,
"Distortion");
269 const bool compute_factor = !r_factor.is_empty();
270 const bool compute_color = !r_color.is_empty();
272 switch (dimensions_) {
275 if (compute_factor) {
277 const float position =
w[
i] * scale[
i];
291 const float position =
w[
i] * scale[
i];
309 if (compute_factor) {
343 if (compute_factor) {
378 if (compute_factor) {
381 const float position_w =
w[
i] * scale[
i];
383 position_vector[0], position_vector[1], position_vector[2], position_w};
398 const float position_w =
w[
i] * scale[
i];
400 position_vector[0], position_vector[1], position_vector[2], position_w};
439 NodeItem scale = get_input_value(
"Scale", NodeItem::Type::Float);
440 NodeItem
detail = get_input_default(
"Detail", NodeItem::Type::Float);
441 NodeItem lacunarity = get_input_value(
"Lacunarity", NodeItem::Type::Float);
445 NodeItem position = create_node(
"position", NodeItem::Type::Vector3);
446 position = position * scale;
450 STREQ(socket_out_->identifier,
"Fac") ? NodeItem::Type::Float : NodeItem::Type::Color3,
451 {{
"position", position}, {
"octaves", val(octaves)}, {
"lacunarity", lacunarity}});
465 ntype.
ui_name =
"Noise Texture";
469 ntype.
declare = file_ns::sh_node_tex_noise_declare;
470 ntype.
draw_buttons = file_ns::node_shader_buts_tex_noise;
471 ntype.
initfunc = file_ns::node_shader_init_tex_noise;
474 ntype.
gpu_fn = file_ns::node_shader_gpu_tex_noise;
475 ntype.
updatefunc = file_ns::node_shader_update_tex_noise;
#define NODE_STORAGE_FUNCS(StorageT)
constexpr int NODE_DEFAULT_MAX_WIDTH
#define NODE_CLASS_TEXTURE
#define SH_NODE_TEX_NOISE
void BKE_texture_mapping_default(struct TexMapping *texmap, int type)
void BKE_texture_colormapping_default(struct ColorMapping *colormap)
@ NODE_DEFAULT_INPUT_POSITION_FIELD
@ SHD_NOISE_HYBRID_MULTIFRACTAL
@ SHD_NOISE_RIDGED_MULTIFRACTAL
@ SHD_NOISE_HETERO_TERRAIN
bool GPU_stack_link(GPUMaterial *mat, const bNode *node, const char *name, GPUNodeStack *in, GPUNodeStack *out,...)
GPUNodeLink * GPU_constant(const float *num)
@ UI_ITEM_R_SPLIT_EMPTY_NAME
SIMD_FORCE_INLINE const btScalar & w() const
Return the w value.
const Signature & signature() const
void set_signature(const Signature *signature)
void construct_and_set_matching_fn(Args &&...args)
static mf::Signature create_signature(int dimensions, int type)
NoiseFunction(int dimensions, int type, bool normalize)
ExecutionHints get_execution_hints() const override
void call(const IndexMask &mask, mf::Params params, mf::Context) const override
VecBase< float, D > normalize(VecOp< float, D >) RET
void * MEM_callocN(size_t len, const char *str)
ccl_device_inline float2 mask(const MaskType mask, const float2 a)
bNodeSocket * node_find_socket(bNode &node, eNodeSocketInOut in_out, StringRef identifier)
void node_type_size(bNodeType &ntype, int width, int minwidth, int maxwidth)
void node_register_type(bNodeType &ntype)
void node_set_socket_availability(bNodeTree &ntree, bNodeSocket &sock, bool is_available)
void node_type_storage(bNodeType &ntype, std::optional< StringRefNull > storagename, void(*freefunc)(bNode *node), void(*copyfunc)(bNodeTree *dest_ntree, bNode *dest_node, const bNode *src_node))
T clamp(const T &a, const T &min, const T &max)
T max(const T &a, const T &b)
static const char * gpu_shader_get_name(const int dimensions, const int type)
static void sh_node_noise_build_multi_function(NodeMultiFunctionBuilder &builder)
static void node_shader_buts_tex_noise(uiLayout *layout, bContext *, PointerRNA *ptr)
static void node_shader_init_tex_noise(bNodeTree *, bNode *node)
static void node_shader_update_tex_noise(bNodeTree *ntree, bNode *node)
static int node_shader_gpu_tex_noise(GPUMaterial *mat, bNode *node, bNodeExecData *, GPUNodeStack *in, GPUNodeStack *out)
static void sh_node_tex_noise_declare(NodeDeclarationBuilder &b)
float3 perlin_float3_fractal_distorted(float position, float detail, float roughness, float lacunarity, float offset, float gain, float distortion, int type, bool normalize)
float perlin_fractal_distorted(T position, float detail, float roughness, float lacunarity, float offset, float gain, float distortion, int type, bool normalize)
VecBase< float, 4 > float4
VecBase< float, 2 > float2
ColorSceneLinear4f< eAlpha::Premultiplied > ColorGeometry4f
VecBase< float, 3 > float3
#define NODE_SHADER_MATERIALX_BEGIN
#define NODE_SHADER_MATERIALX_END
void register_node_type_sh_tex_noise()
void node_shader_gpu_tex_mapping(GPUMaterial *mat, bNode *node, GPUNodeStack *in, GPUNodeStack *)
void node_shader_gpu_default_tex_coord(GPUMaterial *mat, bNode *node, GPUNodeLink **link)
void common_node_type_base(blender::bke::bNodeType *ntype, std::string idname, const std::optional< int16_t > legacy_type)
void node_free_standard_storage(bNode *node)
void node_copy_standard_storage(bNodeTree *, bNode *dest_node, const bNode *src_node)
int RNA_enum_get(PointerRNA *ptr, const char *name)
ColorMapping color_mapping
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)