32 const bool is_compositor =
b.tree_or_null() &&
b.tree_or_null()->type ==
NTREE_COMPOSIT;
36 b.add_input<
decl::Vector>(
"Vector"_ustr).default_input_type(default_input_type);
42 .description(
"Overall texture scale");
47 .description(
"Amount of distortion of the wave");
52 .description(
"Amount of distortion noise detail");
57 .description(
"Scale of distortion noise");
63 .description(
"Blend between a smoother noise pattern, and rougher with sharper peaks");
69 "Position of the wave along the Bands Direction.\n"
70 "This can be used as an input for more control over the distortion");
71 b.add_output<
decl::Color>(
"Color"_ustr).no_muted_links();
72 b.add_output<
decl::Float>(
"Factor"_ustr,
"Fac"_ustr).no_muted_links();
130 int bands_direction_;
131 int rings_direction_;
135 WaveFunction(
int wave_type,
int bands_direction,
int rings_direction,
int wave_profile)
136 : wave_type_(wave_type),
137 bands_direction_(bands_direction),
138 rings_direction_(rings_direction),
139 wave_profile_(wave_profile)
141 static const mf::Signature
signature = []() {
143 mf::SignatureBuilder builder{
"MagicFunction",
signature};
144 builder.single_input<
float3>(
"Vector");
145 builder.single_input<
float>(
"Scale");
146 builder.single_input<
float>(
"Distortion");
147 builder.single_input<
float>(
"Detail");
148 builder.single_input<
float>(
"Detail Scale");
149 builder.single_input<
float>(
"Detail Roughness");
150 builder.single_input<
float>(
"Phase Offset");
151 builder.single_output<
ColorGeometry4f>(
"Color", mf::ParamFlag::SupportsUnusedOutput);
152 builder.single_output<
float>(
"Fac");
162 const VArray<float> &distortion = params.readonly_single_input<
float>(2,
"Distortion");
164 const VArray<float> &dscale = params.readonly_single_input<
float>(4,
"Detail Scale");
165 const VArray<float> &droughness = params.readonly_single_input<
float>(5,
"Detail Roughness");
166 const VArray<float> &phase = params.readonly_single_input<
float>(6,
"Phase Offset");
169 params.uninitialized_single_output_if_required<
ColorGeometry4f>(7,
"Color");
175 p = (p + 0.000001f) * 0.999999f;
180 switch (wave_type_) {
182 switch (bands_direction_) {
193 n = (p.x + p.y + p.z) * 10.0f;
199 switch (rings_direction_) {
201 rp *=
float3(0.0f, 1.0f, 1.0f);
204 rp *=
float3(1.0f, 0.0f, 1.0f);
207 rp *=
float3(1.0f, 1.0f, 0.0f);
219 if (distortion[i] != 0.0f) {
226 switch (wave_profile_) {
242 if (!r_color.is_empty()) {
251 static constexpr int8_t id = 0;
253 hash.add(wave_type_);
254 hash.add(bands_direction_);
255 hash.add(rings_direction_);
256 hash.add(wave_profile_);
273 NodeItem
scale = get_input_value(
"Scale", NodeItem::Type::Float);
274 NodeItem distortion = get_input_value(
"Distortion", NodeItem::Type::Float);
275 NodeItem
detail = get_input_default(
"Detail", NodeItem::Type::Float);
276 NodeItem detail_scale = get_input_value(
"Detail Scale", NodeItem::Type::Float);
277 NodeItem detail_rough = get_input_value(
"Detail Roughness", NodeItem::Type::Float);
278 NodeItem phase_offset = get_input_value(
"Phase Offset", NodeItem::Type::Float);
279 NodeItem vector = get_input_link(
"Vector", NodeItem::Type::Vector3);
281 vector = texcoord_node(NodeItem::Type::Vector3);
285 distortion = distortion * val(10.0f);
286 detail_scale = detail_scale * val(10.0f);
288 NodeItem pos = vector *
scale;
289 NodeItem fractal = create_node(
"fractal3d",
290 NodeItem::Type::Float,
292 {
"octaves", val(
int(
detail.value->asA<
float>()))},
293 {
"lacunarity", val(2.0f)}});
294 NodeItem value = val(0.0f);
295 switch (tex->wave_type) {
297 switch (tex->bands_direction) {
299 value = pos[0] * val(20.0f);
302 value = pos[1] * val(20.0f);
305 value = pos[2] * val(20.0f);
308 value = (pos[0] + pos[1] + pos[2]) * val(10.0f);
316 switch (tex->rings_direction) {
318 rpos = pos * val(MaterialX::Vector3(0.0f, 1.0f, 1.0f));
321 rpos = pos * val(MaterialX::Vector3(1.0f, 0.0f, 1.0f));
324 rpos = pos * val(MaterialX::Vector3(1.0f, 1.0f, 0.0f));
332 value = rpos.length() * val(20.0f);
335 value = value + phase_offset + distortion * detail_scale * fractal;
337 NodeItem res = empty();
338 switch (tex->wave_profile) {
340 res = val(0.5f) + val(0.5f) * (value - val(
float(
M_PI_2))).
sin();
343 value = value / val(
float(
M_PI * 2.0f));
344 res = value - value.floor();
347 value = value / val(
float(
M_PI * 2.0f));
348 res = (value - (value + val(0.5f)).floor()).abs() * val(2.0f);
367 ntype.
ui_name =
"Wave Texture";
368 ntype.
ui_description =
"Generate procedural bands or rings with noise";
371 ntype.
declare = file_ns::sh_node_tex_wave_declare;
372 ntype.
draw_buttons = file_ns::node_shader_buts_tex_wave;
374 ntype.
initfunc = file_ns::node_shader_init_tex_wave;
377 ntype.
gpu_fn = file_ns::node_shader_gpu_tex_wave;
#define NODE_CLASS_TEXTURE
#define BLI_assert_unreachable()
const Signature & signature() const
void set_signature(const Signature *signature)
void construct_and_set_matching_fn(Args &&...args)
void hash_unique(UniqueHashBytes &hash) const override
void call(const IndexMask &mask, mf::Params params, mf::Context) const override
WaveFunction(int wave_type, int bands_direction, int rings_direction, int wave_profile)
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))
static void sh_node_wave_tex_build_multi_function(NodeMultiFunctionBuilder &builder)
static void node_shader_init_tex_wave(bNodeTree *, bNode *node)
static void node_shader_buts_tex_wave(ui::Layout &layout, bContext *, PointerRNA *ptr)
static void sh_node_tex_wave_declare(NodeDeclarationBuilder &b)
static int node_shader_gpu_tex_wave(GPUMaterial *mat, bNode *node, bNodeExecData *, GPUNodeStack *in, GPUNodeStack *out)
template float perlin_fbm< float3 >(float3 p, const float detail, const float roughness, const float lacunarity, const bool normalize)
@ ITEM_R_SPLIT_EMPTY_NAME
bool GPU_stack_link(GPUMaterial *mat, const bNode *node, const char *name, GPUNodeStack *in, GPUNodeStack *out,...)
@ SHD_WAVE_BANDS_DIRECTION_Z
@ SHD_WAVE_BANDS_DIRECTION_DIAGONAL
@ SHD_WAVE_BANDS_DIRECTION_X
@ SHD_WAVE_BANDS_DIRECTION_Y
int RNA_enum_get(PointerRNA *ptr, const char *name)
void register_node_type_sh_tex_wave()
GPUNodeLink * GPU_constant(const float *num)
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)
@ SHD_WAVE_RINGS_DIRECTION_SPHERICAL
@ SHD_WAVE_RINGS_DIRECTION_X
@ SHD_WAVE_RINGS_DIRECTION_Y
@ SHD_WAVE_RINGS_DIRECTION_Z
MINLINE float len_v3(const float a[3]) ATTR_WARN_UNUSED_RESULT
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)