33 const int dimensions =
b.node_or_null() ? node_storage(*
b.node_or_null()).dimensions : 3;
34 const bool is_compositor =
b.tree_or_null() &&
b.tree_or_null()->type ==
NTREE_COMPOSIT;
40 .available(dimensions != 1);
45 .available(
ELEM(dimensions, 1, 4))
48 node_storage(
node).dimensions = 1;
55 .description(
"Scale of the base noise octave");
61 "The number of noise octaves. Higher values give more detailed noise but increase "
70 "Blend factor between an octave and its previous one. A value of zero corresponds to "
77 "The difference between the scale of each two consecutive octaves. Larger values "
78 "corresponds to larger scale for higher octaves");
90 "An added offset to each octave, determines the level where the highest octave will "
98 .description(
"An extra multiplier to tune the magnitude of octaves");
103 .description(
"Amount of distortion");
104 b.add_output<
decl::Float>(
"Factor"_ustr,
"Fac"_ustr).no_muted_links();
105 b.add_output<
decl::Color>(
"Color"_ustr).no_muted_links();
136 return std::array{
"node_noise_tex_multi_fractal_1d",
137 "node_noise_tex_multi_fractal_2d",
138 "node_noise_tex_multi_fractal_3d",
139 "node_noise_tex_multi_fractal_4d"}[dimensions - 1];
141 return std::array{
"node_noise_tex_fbm_1d",
142 "node_noise_tex_fbm_2d",
143 "node_noise_tex_fbm_3d",
144 "node_noise_tex_fbm_4d"}[dimensions - 1];
146 return std::array{
"node_noise_tex_hybrid_multi_fractal_1d",
147 "node_noise_tex_hybrid_multi_fractal_2d",
148 "node_noise_tex_hybrid_multi_fractal_3d",
149 "node_noise_tex_hybrid_multi_fractal_4d"}[dimensions - 1];
151 return std::array{
"node_noise_tex_ridged_multi_fractal_1d",
152 "node_noise_tex_ridged_multi_fractal_2d",
153 "node_noise_tex_ridged_multi_fractal_3d",
154 "node_noise_tex_ridged_multi_fractal_4d"}[dimensions - 1];
156 return std::array{
"node_noise_tex_hetero_terrain_1d",
157 "node_noise_tex_hetero_terrain_2d",
158 "node_noise_tex_hetero_terrain_3d",
159 "node_noise_tex_hetero_terrain_4d"}[dimensions - 1];
175 float compute_color =
out[1].hasoutput;
190 : dimensions_(dimensions), type_(type), normalize_(
normalize)
192 BLI_assert(dimensions >= 1 && dimensions <= 4);
194 static std::array<mf::Signature, 20> signatures{
226 mf::SignatureBuilder builder{
"Noise",
signature};
228 if (
ELEM(dimensions, 2, 3, 4)) {
229 builder.single_input<
float3>(
"Vector");
231 if (
ELEM(dimensions, 1, 4)) {
232 builder.single_input<
float>(
"W");
235 builder.single_input<
float>(
"Scale");
236 builder.single_input<
float>(
"Detail");
237 builder.single_input<
float>(
"Roughness");
238 builder.single_input<
float>(
"Lacunarity");
244 builder.single_input<
float>(
"Offset");
247 builder.single_input<
float>(
"Gain");
249 builder.single_input<
float>(
"Distortion");
251 builder.single_output<
float>(
"Fac", mf::ParamFlag::SupportsUnusedOutput);
252 builder.single_output<
ColorGeometry4f>(
"Color", mf::ParamFlag::SupportsUnusedOutput);
259 int param =
ELEM(dimensions_, 2, 3, 4) +
ELEM(dimensions_, 1, 4);
262 const VArray<float> &roughness = params.readonly_single_input<
float>(param++,
"Roughness");
263 const VArray<float> &lacunarity = params.readonly_single_input<
float>(param++,
"Lacunarity");
269 params.readonly_single_input<
float>(param++,
"Offset") :
275 params.readonly_single_input<
float>(param++,
"Gain") :
277 const VArray<float> &distortion = params.readonly_single_input<
float>(param++,
"Distortion");
279 MutableSpan<float> r_factor = params.uninitialized_single_output_if_required<
float>(param++,
282 params.uninitialized_single_output_if_required<
ColorGeometry4f>(param++,
"Color");
284 const bool compute_factor = !r_factor.is_empty();
285 const bool compute_color = !r_color.is_empty();
287 switch (dimensions_) {
289 const VArray<float> &
w = params.readonly_single_input<
float>(0,
"W");
304 if (compute_factor) {
309 else if (compute_factor) {
341 if (compute_factor) {
346 else if (compute_factor) {
378 if (compute_factor) {
383 else if (compute_factor) {
401 const VArray<float> &
w = params.readonly_single_input<
float>(1,
"W");
404 const float3 position_vector = vector[i] *
scale[i];
405 const float position_w =
w[i] *
scale[i];
407 position_vector[0], position_vector[1], position_vector[2], position_w};
419 if (compute_factor) {
424 else if (compute_factor) {
426 const float3 position_vector = vector[i] *
scale[i];
427 const float position_w =
w[i] *
scale[i];
429 position_vector[0], position_vector[1], position_vector[2], position_w};
456 static constexpr int8_t id = 0;
458 hash.add(dimensions_);
460 hash.add(normalize_);
475 NodeItem
scale = get_input_value(
"Scale", NodeItem::Type::Float);
476 NodeItem
detail = get_input_default(
"Detail", NodeItem::Type::Float);
477 NodeItem lacunarity = get_input_value(
"Lacunarity", NodeItem::Type::Float);
481 NodeItem
position = create_node(
"position", NodeItem::Type::Vector3);
486 STREQ(socket_out_->identifier,
"Fac") ? NodeItem::Type::Float : NodeItem::Type::Color3,
487 {{
"position", position}, {
"octaves", val(octaves)}, {
"lacunarity", lacunarity}});
501 ntype.
ui_name =
"Noise Texture";
505 ntype.
declare = file_ns::sh_node_tex_noise_declare;
506 ntype.
draw_buttons = file_ns::node_shader_buts_tex_noise;
507 ntype.
initfunc = file_ns::node_shader_init_tex_noise;
510 ntype.
gpu_fn = file_ns::node_shader_gpu_tex_noise;
#define NODE_STORAGE_FUNCS(StorageT)
#define NODE_CLASS_TEXTURE
#define SH_NODE_TEX_NOISE
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)
NodeDefaultInputType default_input_type
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
void hash_unique(UniqueHashBytes &hash) const override
#define storage(slot, qualifiers)
VecBase< float, D > normalize(VecOp< float, D >) RET
float3x3 scale(float3x3 mat, float2 scale)
void node_register_type(bNodeType &ntype)
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 void node_shader_init_tex_noise(bNodeTree *node_tree, bNode *node)
static const char * gpu_shader_get_name(const int dimensions, const int type)
static void sh_node_noise_build_multi_function(NodeMultiFunctionBuilder &builder)
static int node_shader_gpu_tex_noise(GPUMaterial *mat, bNode *node, bNodeExecData *, GPUNodeStack *in, GPUNodeStack *out)
static void node_shader_buts_tex_noise(ui::Layout &layout, bContext *, PointerRNA *ptr)
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)
@ 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,...)
int RNA_enum_get(PointerRNA *ptr, const char *name)
void register_node_type_sh_tex_noise()
@ SHD_NOISE_RIDGED_MULTIFRACTAL
@ SHD_NOISE_HETERO_TERRAIN
@ SHD_NOISE_HYBRID_MULTIFRACTAL
VecBase< float, 4 > float4
GPUNodeLink * GPU_constant(const float *num)
VecBase< float, 2 > float2
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 BKE_texture_mapping_default(struct TexMapping *texmap, int type)
@ NODE_DEFAULT_INPUT_POSITION_FIELD
@ NODE_DEFAULT_INPUT_UNIFORM_IMAGE_COORDINATES
void node_copy_standard_storage(bNodeTree *, bNode *dest_node, const bNode *src_node)
ColorSceneLinear4f< eAlpha::Premultiplied > ColorGeometry4f
void node_free_standard_storage(bNode *node)
VecBase< float, 3 > float3
void BKE_texture_colormapping_default(struct ColorMapping *colormap)
void common_node_type_base(bke::bNodeType *ntype, UString idname, const std::optional< int16_t > legacy_type)
#define NODE_SHADER_MATERIALX_BEGIN
#define NODE_SHADER_MATERIALX_END
ColorMapping color_mapping
static constexpr int _160
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)