From cbb5142be64f368f8906d71ad29c2a56f814884b Mon Sep 17 00:00:00 2001 From: Relintai Date: Sat, 18 Jun 2022 16:21:46 +0200 Subject: [PATCH] Cleaned up mat_maker_gd's noise classes. --- modules/material_maker/SCsub | 7 + modules/material_maker/config.py | 7 + .../nodes/noise/anisotropic_noise.cpp | 197 +++----- .../nodes/noise/anisotropic_noise.h | 65 ++- .../nodes/noise/color_noise.cpp | 124 ++--- .../material_maker/nodes/noise/color_noise.h | 54 +-- .../nodes/noise/color_value.cpp | 197 +++----- .../material_maker/nodes/noise/color_value.h | 65 ++- .../material_maker/nodes/noise/fbm_noise.cpp | 353 +++++--------- .../material_maker/nodes/noise/fbm_noise.h | 84 ++-- modules/material_maker/nodes/noise/noise.cpp | 159 ++---- modules/material_maker/nodes/noise/noise.h | 60 ++- .../material_maker/nodes/noise/voronoi.cpp | 456 +++++++----------- modules/material_maker/nodes/noise/voronoi.h | 98 ++-- modules/material_maker/register_types.cpp | 20 + 15 files changed, 732 insertions(+), 1214 deletions(-) diff --git a/modules/material_maker/SCsub b/modules/material_maker/SCsub index 2ff53eb66..b59607ddd 100644 --- a/modules/material_maker/SCsub +++ b/modules/material_maker/SCsub @@ -124,6 +124,13 @@ sources = [ "nodes/pattern/beehive.cpp", "nodes/other/output_image.cpp", + + "nodes/noise/voronoi.cpp", + "nodes/noise/noise.cpp", + "nodes/noise/fbm_noise.cpp", + "nodes/noise/color_value.cpp", + "nodes/noise/color_noise.cpp", + "nodes/noise/anisotropic_noise.cpp", ] if env["tools"]: diff --git a/modules/material_maker/config.py b/modules/material_maker/config.py index a9cd564c5..bfa6f8899 100644 --- a/modules/material_maker/config.py +++ b/modules/material_maker/config.py @@ -94,6 +94,13 @@ def get_doc_classes(): "MMBeehive", "MMOutputImage", + + "MMVoronoi", + "MMNoise", + "MMFbmNoise", + "MMColorValue", + "MMColorNoise", + "MMAnisotropicNoise", ] def get_doc_path(): diff --git a/modules/material_maker/nodes/noise/anisotropic_noise.cpp b/modules/material_maker/nodes/noise/anisotropic_noise.cpp index 6c3fe1d77..0ed53dbaa 100644 --- a/modules/material_maker/nodes/noise/anisotropic_noise.cpp +++ b/modules/material_maker/nodes/noise/anisotropic_noise.cpp @@ -1,168 +1,99 @@ #include "anisotropic_noise.h" +#include "../../algos/mm_algos.h" +#include "../../editor/mm_graph_node.h" +#include "../mm_material.h" -Ref AnisotropicNoise::get_image() { - return image; +Ref MMAnisotropicNoise::get_image() { + return image; } -void AnisotropicNoise::set_image(const Ref &val) { -image = val; +void MMAnisotropicNoise::set_image(const Ref &val) { + image = val; } - -Vector2 AnisotropicNoise::get_scale() { - return scale; +Vector2 MMAnisotropicNoise::get_scale() { + return scale; } -void AnisotropicNoise::set_scale(const Vector2 &val) { -scale = val; +void MMAnisotropicNoise::set_scale(const Vector2 &val) { + scale = val; + set_dirty(true); } - -float AnisotropicNoise::get_smoothness() const { - return smoothness; +float MMAnisotropicNoise::get_smoothness() const { + return smoothness; } -void AnisotropicNoise::set_smoothness(const float val) { -smoothness = val; +void MMAnisotropicNoise::set_smoothness(const float val) { + smoothness = val; + set_dirty(true); } - -float AnisotropicNoise::get_interpolation() const { - return interpolation; +float MMAnisotropicNoise::get_interpolation() const { + return interpolation; } -void AnisotropicNoise::set_interpolation(const float val) { -interpolation = val; +void MMAnisotropicNoise::set_interpolation(const float val) { + interpolation = val; + set_dirty(true); } +void MMAnisotropicNoise::_init_properties() { + if (!image.is_valid()) { + image.instance(); + image->set_default_type(MMNodeUniversalProperty::DEFAULT_TYPE_IMAGE); + } - - //tool; - //export(Resource) ; - Ref image; - //export(Vector2) ; - Vector2 scale = Vector2(4, 256); - //export(float) ; - float smoothness = 1; - //export(float) ; - float interpolation = 1; - - void AnisotropicNoise::_init_properties() { - - if (!image) { - image = MMNodeUniversalProperty.new(); - image.default_type = MMNodeUniversalProperty.DEFAULT_TYPE_IMAGE; + image->set_output_slot_type(MMNodeUniversalProperty::SLOT_TYPE_IMAGE); + register_output_property(image); } - image.output_slot_type = MMNodeUniversalProperty.SLOT_TYPE_IMAGE; - register_output_property(image); +void MMAnisotropicNoise::_register_methods(MMGraphNode *mm_graph_node) { + mm_graph_node->add_slot_texture_universal(image); + //, Vector2(1, 10)); + mm_graph_node->add_slot_vector2("get_scale", "set_scale", "Scale", 1); + //, Vector2(0, 1)); + mm_graph_node->add_slot_float("get_smoothness", "set_smoothness", "Smoothness", 0.01); + //, Vector2(0, 1)); + mm_graph_node->add_slot_float("get_interpolation", "set_interpolation", "Interpolation", 0.01); } - - void AnisotropicNoise::_register_methods(const Variant &mm_graph_node) { - mm_graph_node.add_slot_texture_universal(image); - //, Vector2(1, 10)); - mm_graph_node.add_slot_vector2("get_scale", "set_scale", "Scale", 1); - //, Vector2(0, 1)); - mm_graph_node.add_slot_float("get_smoothness", "set_smoothness", "Smoothness", 0.01); - //, Vector2(0, 1)); - mm_graph_node.add_slot_float("get_interpolation", "set_interpolation", "Interpolation", 0.01); +Color MMAnisotropicNoise::_get_value_for(const Vector2 &uv, const int pseed) { + float ps = 1.0 / float(pseed); + //anisotropic($(uv), vec2($(scale_x), $(scale_y)), $(seed), $(smoothness), $(interpolation)); + return MMAlgos::anisotropicc(uv, scale, ps, smoothness, interpolation); } - - Color AnisotropicNoise::_get_value_for(const Vector2 &uv, const int pseed) { - float ps = 1.0 / float(pseed); - //anisotropic($(uv), vec2($(scale_x), $(scale_y)), $(seed), $(smoothness), $(interpolation)); - return MMAlgos.anisotropicc(uv, scale, ps, smoothness, interpolation); +void MMAnisotropicNoise::_render(const Ref &material) { + Ref img = render_image(material); + image->set_value(img); } - - void AnisotropicNoise::_render(const Variant &material) { - Ref img = render_image(material); - image.set_value(img); +MMAnisotropicNoise::MMAnisotropicNoise() { + scale = Vector2(4, 256); + smoothness = 1; + interpolation = 1; } - - Vector2 AnisotropicNoise::get_scale() { - return scale; +MMAnisotropicNoise::~MMAnisotropicNoise() { } +void MMAnisotropicNoise::_bind_methods() { + ClassDB::bind_method(D_METHOD("get_image"), &MMAnisotropicNoise::get_image); + ClassDB::bind_method(D_METHOD("set_image", "value"), &MMAnisotropicNoise::set_image); + ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "image", PROPERTY_HINT_RESOURCE_TYPE, "MMNodeUniversalProperty"), "set_image", "get_image"); - void AnisotropicNoise::set_scale(const Vector2 &val) { - scale = val; - set_dirty(true); + ClassDB::bind_method(D_METHOD("get_scale"), &MMAnisotropicNoise::get_scale); + ClassDB::bind_method(D_METHOD("set_scale", "value"), &MMAnisotropicNoise::set_scale); + ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "scale"), "set_scale", "get_scale"); + + ClassDB::bind_method(D_METHOD("get_smoothness"), &MMAnisotropicNoise::get_smoothness); + ClassDB::bind_method(D_METHOD("set_smoothness", "value"), &MMAnisotropicNoise::set_smoothness); + ADD_PROPERTY(PropertyInfo(Variant::REAL, "smoothness"), "set_smoothness", "get_smoothness"); + + ClassDB::bind_method(D_METHOD("get_interpolation"), &MMAnisotropicNoise::get_interpolation); + ClassDB::bind_method(D_METHOD("set_interpolation", "value"), &MMAnisotropicNoise::set_interpolation); + ADD_PROPERTY(PropertyInfo(Variant::REAL, "interpolation"), "set_interpolation", "get_interpolation"); } - - - float AnisotropicNoise::get_smoothness() { - return smoothness; -} - - - void AnisotropicNoise::set_smoothness(const float val) { - smoothness = val; - set_dirty(true); -} - - - float AnisotropicNoise::get_interpolation() { - return interpolation; -} - - - void AnisotropicNoise::set_interpolation(const float val) { - interpolation = val; - set_dirty(true); -} - -} - - AnisotropicNoise::AnisotropicNoise() { - image; - scale = Vector2(4, 256); - smoothness = 1; - interpolation = 1; - } - - AnisotropicNoise::~AnisotropicNoise() { - } - - - static void AnisotropicNoise::_bind_methods() { - ClassDB::bind_method(D_METHOD("get_image"), &AnisotropicNoise::get_image); - ClassDB::bind_method(D_METHOD("set_image", "value"), &AnisotropicNoise::set_image); - ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "image", PROPERTY_HINT_RESOURCE_TYPE, "Ref"), "set_image", "get_image"); - - - ClassDB::bind_method(D_METHOD("get_scale"), &AnisotropicNoise::get_scale); - ClassDB::bind_method(D_METHOD("set_scale", "value"), &AnisotropicNoise::set_scale); - ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "scale"), "set_scale", "get_scale"); - - - ClassDB::bind_method(D_METHOD("get_smoothness"), &AnisotropicNoise::get_smoothness); - ClassDB::bind_method(D_METHOD("set_smoothness", "value"), &AnisotropicNoise::set_smoothness); - ADD_PROPERTY(PropertyInfo(Variant::REAL, "smoothness"), "set_smoothness", "get_smoothness"); - - - ClassDB::bind_method(D_METHOD("get_interpolation"), &AnisotropicNoise::get_interpolation); - ClassDB::bind_method(D_METHOD("set_interpolation", "value"), &AnisotropicNoise::set_interpolation); - ADD_PROPERTY(PropertyInfo(Variant::REAL, "interpolation"), "set_interpolation", "get_interpolation"); - - - ClassDB::bind_method(D_METHOD("_init_properties"), &AnisotropicNoise::_init_properties); - ClassDB::bind_method(D_METHOD("_register_methods", "mm_graph_node"), &AnisotropicNoise::_register_methods); - ClassDB::bind_method(D_METHOD("_get_value_for", "uv", "pseed"), &AnisotropicNoise::_get_value_for); - ClassDB::bind_method(D_METHOD("_render", "material"), &AnisotropicNoise::_render); - ClassDB::bind_method(D_METHOD("get_scale"), &AnisotropicNoise::get_scale); - ClassDB::bind_method(D_METHOD("set_scale", "val"), &AnisotropicNoise::set_scale); - ClassDB::bind_method(D_METHOD("get_smoothness"), &AnisotropicNoise::get_smoothness); - ClassDB::bind_method(D_METHOD("set_smoothness", "val"), &AnisotropicNoise::set_smoothness); - ClassDB::bind_method(D_METHOD("get_interpolation"), &AnisotropicNoise::get_interpolation); - ClassDB::bind_method(D_METHOD("set_interpolation", "val"), &AnisotropicNoise::set_interpolation); - - } - - - diff --git a/modules/material_maker/nodes/noise/anisotropic_noise.h b/modules/material_maker/nodes/noise/anisotropic_noise.h index 6d26b65a4..aa8ab065a 100644 --- a/modules/material_maker/nodes/noise/anisotropic_noise.h +++ b/modules/material_maker/nodes/noise/anisotropic_noise.h @@ -1,51 +1,40 @@ -#ifndef ANISOTROPIC_NOISE_H -#define ANISOTROPIC_NOISE_H +#ifndef MM_ANISOTROPIC_NOISE_H +#define MM_ANISOTROPIC_NOISE_H +#include "../mm_node.h" +#include "../mm_node_universal_property.h" -class AnisotropicNoise : public MMNode { - GDCLASS(AnisotropicNoise, MMNode); +class MMAnisotropicNoise : public MMNode { + GDCLASS(MMAnisotropicNoise, MMNode); - public: +public: + Ref get_image(); + void set_image(const Ref &val); - Ref get_image(); - void set_image(const Ref &val); + Vector2 get_scale(); + void set_scale(const Vector2 &val); - Vector2 get_scale(); - void set_scale(const Vector2 &val); + float get_smoothness() const; + void set_smoothness(const float val); - float get_smoothness() const; - void set_smoothness(const float val); + float get_interpolation() const; + void set_interpolation(const float val); - float get_interpolation() const; - void set_interpolation(const float val); + void _init_properties(); + void _register_methods(MMGraphNode *mm_graph_node); + Color _get_value_for(const Vector2 &uv, const int pseed); + void _render(const Ref &material); - void _init_properties(); - void _register_methods(const Variant &mm_graph_node); - Color _get_value_for(const Vector2 &uv, const int pseed); - void _render(const Variant &material); - Vector2 get_scale(); - void set_scale(const Vector2 &val); - float get_smoothness(); - void set_smoothness(const float val); - float get_interpolation(); - void set_interpolation(const float val); + MMAnisotropicNoise(); + ~MMAnisotropicNoise(); - AnisotropicNoise(); - ~AnisotropicNoise(); +protected: + static void _bind_methods(); - protected: - static void _bind_methods(); - - //tool - //export(Resource) - Ref image; - //export(Vector2) - Vector2 scale = Vector2(4, 256); - //export(float) - float smoothness = 1; - //export(float) - float interpolation = 1; + Ref image; + Vector2 scale; + float smoothness; + float interpolation; }; - #endif diff --git a/modules/material_maker/nodes/noise/color_noise.cpp b/modules/material_maker/nodes/noise/color_noise.cpp index 92251eaa4..5dd90bb4a 100644 --- a/modules/material_maker/nodes/noise/color_noise.cpp +++ b/modules/material_maker/nodes/noise/color_noise.cpp @@ -1,111 +1,67 @@ #include "color_noise.h" +#include "../../algos/mm_algos.h" +#include "../../editor/mm_graph_node.h" +#include "../mm_material.h" -Ref ColorNoise::get_image() { - return image; +Ref MMColorNoise::get_image() { + return image; } -void ColorNoise::set_image(const Ref &val) { -image = val; +void MMColorNoise::set_image(const Ref &val) { + image = val; } - -int ColorNoise::get_size() const { - return size; +int MMColorNoise::get_size() const { + return size; } -void ColorNoise::set_size(const int val) { -size = val; +void MMColorNoise::set_size(const int val) { + size = val; + set_dirty(true); } +void MMColorNoise::_init_properties() { + if (!image.is_valid()) { + image.instance(); + image->set_default_type(MMNodeUniversalProperty::DEFAULT_TYPE_IMAGE); + } - - //tool; - //export(Resource) ; - Ref image; - //export(int) ; - int size = 8; - //----------------------; - //color_noise.mmg; - //Outputs:; - //Output - (rgb) - Shows the noise pattern; - //color_dots($(uv), 1.0/$(size), $(seed)); - //Inputs:; - //size, float, default: 8, min: 2, max: 12, step: 1; - - void ColorNoise::_init_properties() { - - if (!image) { - image = MMNodeUniversalProperty.new(); - image.default_type = MMNodeUniversalProperty.DEFAULT_TYPE_IMAGE; + image->set_output_slot_type(MMNodeUniversalProperty::SLOT_TYPE_IMAGE); + register_output_property(image); } - image.output_slot_type = MMNodeUniversalProperty.SLOT_TYPE_IMAGE; - register_output_property(image); +void MMColorNoise::_register_methods(MMGraphNode *mm_graph_node) { + mm_graph_node->add_slot_texture_universal(image); + //, Vector2(1, 10)); + mm_graph_node->add_slot_int("get_size", "set_size", "Size"); } - - void ColorNoise::_register_methods(const Variant &mm_graph_node) { - mm_graph_node.add_slot_texture_universal(image); - //, Vector2(1, 10)); - mm_graph_node.add_slot_int("get_size", "set_size", "Size"); +Color MMColorNoise::_get_value_for(const Vector2 &uv, const int pseed) { + float ps = 1.0 / float(pseed); + //color_dots($(uv), 1.0/$(size), $(seed)); + return MMAlgos::noise_color(uv, float(size), ps); } - - Color ColorNoise::_get_value_for(const Vector2 &uv, const int pseed) { - float ps = 1.0 / float(pseed); - //color_dots($(uv), 1.0/$(size), $(seed)); - return MMAlgos.noise_color(uv, float(size), ps); +void MMColorNoise::_render(const Ref &material) { + Ref img = render_image(material); + image->set_value(img); } - - void ColorNoise::_render(const Variant &material) { - Ref img = render_image(material); - image.set_value(img); +MMColorNoise::MMColorNoise() { + size = 8; } - - int ColorNoise::get_size() { - return size; +MMColorNoise::~MMColorNoise() { } +void MMColorNoise::_bind_methods() { + ClassDB::bind_method(D_METHOD("get_image"), &MMColorNoise::get_image); + ClassDB::bind_method(D_METHOD("set_image", "value"), &MMColorNoise::set_image); + ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "image", PROPERTY_HINT_RESOURCE_TYPE, "MMNodeUniversalProperty"), "set_image", "get_image"); - void ColorNoise::set_size(const int val) { - size = val; - set_dirty(true); + ClassDB::bind_method(D_METHOD("get_size"), &MMColorNoise::get_size); + ClassDB::bind_method(D_METHOD("set_size", "value"), &MMColorNoise::set_size); + ADD_PROPERTY(PropertyInfo(Variant::INT, "size"), "set_size", "get_size"); } - -} - - ColorNoise::ColorNoise() { - image; - size = 8; - } - - ColorNoise::~ColorNoise() { - } - - - static void ColorNoise::_bind_methods() { - ClassDB::bind_method(D_METHOD("get_image"), &ColorNoise::get_image); - ClassDB::bind_method(D_METHOD("set_image", "value"), &ColorNoise::set_image); - ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "image", PROPERTY_HINT_RESOURCE_TYPE, "Ref"), "set_image", "get_image"); - - - ClassDB::bind_method(D_METHOD("get_size"), &ColorNoise::get_size); - ClassDB::bind_method(D_METHOD("set_size", "value"), &ColorNoise::set_size); - ADD_PROPERTY(PropertyInfo(Variant::INT, "size"), "set_size", "get_size"); - - - ClassDB::bind_method(D_METHOD("_init_properties"), &ColorNoise::_init_properties); - ClassDB::bind_method(D_METHOD("_register_methods", "mm_graph_node"), &ColorNoise::_register_methods); - ClassDB::bind_method(D_METHOD("_get_value_for", "uv", "pseed"), &ColorNoise::_get_value_for); - ClassDB::bind_method(D_METHOD("_render", "material"), &ColorNoise::_render); - ClassDB::bind_method(D_METHOD("get_size"), &ColorNoise::get_size); - ClassDB::bind_method(D_METHOD("set_size", "val"), &ColorNoise::set_size); - - } - - - diff --git a/modules/material_maker/nodes/noise/color_noise.h b/modules/material_maker/nodes/noise/color_noise.h index 796139259..964095876 100644 --- a/modules/material_maker/nodes/noise/color_noise.h +++ b/modules/material_maker/nodes/noise/color_noise.h @@ -1,44 +1,32 @@ -#ifndef COLOR_NOISE_H -#define COLOR_NOISE_H +#ifndef MM_COLOR_NOISE_H +#define MM_COLOR_NOISE_H +#include "../mm_node.h" +#include "../mm_node_universal_property.h" -class ColorNoise : public MMNode { - GDCLASS(ColorNoise, MMNode); +class MMColorNoise : public MMNode { + GDCLASS(MMColorNoise, MMNode); - public: +public: + Ref get_image(); + void set_image(const Ref &val); - Ref get_image(); - void set_image(const Ref &val); + int get_size() const; + void set_size(const int val); - int get_size() const; - void set_size(const int val); + void _init_properties(); + void _register_methods(MMGraphNode *mm_graph_node); + Color _get_value_for(const Vector2 &uv, const int pseed); + void _render(const Ref &material); - void _init_properties(); - void _register_methods(const Variant &mm_graph_node); - Color _get_value_for(const Vector2 &uv, const int pseed); - void _render(const Variant &material); - int get_size(); - void set_size(const int val); + MMColorNoise(); + ~MMColorNoise(); - ColorNoise(); - ~ColorNoise(); +protected: + static void _bind_methods(); - protected: - static void _bind_methods(); - - //tool - //export(Resource) - Ref image; - //export(int) - int size = 8; - //---------------------- - //color_noise.mmg - //Outputs: - //Output - (rgb) - Shows the noise pattern - //color_dots($(uv), 1.0/$(size), $(seed)) - //Inputs: - //size, float, default: 8, min: 2, max: 12, step: 1 + Ref image; + int size; }; - #endif diff --git a/modules/material_maker/nodes/noise/color_value.cpp b/modules/material_maker/nodes/noise/color_value.cpp index eff7a2312..7c80695f7 100644 --- a/modules/material_maker/nodes/noise/color_value.cpp +++ b/modules/material_maker/nodes/noise/color_value.cpp @@ -1,168 +1,99 @@ #include "color_value.h" +#include "../../algos/mm_algos.h" +#include "../../editor/mm_graph_node.h" +#include "../mm_material.h" -Ref ColorValue::get_image() { - return image; +Ref MMColorValue::get_image() { + return image; } -void ColorValue::set_image(const Ref &val) { -image = val; +void MMColorValue::set_image(const Ref &val) { + image = val; } - -Vector2 ColorValue::get_scale() { - return scale; +Vector2 MMColorValue::get_scale() { + return scale; } -void ColorValue::set_scale(const Vector2 &val) { -scale = val; +void MMColorValue::set_scale(const Vector2 &val) { + scale = val; + set_dirty(true); } - -int ColorValue::get_iterations() const { - return iterations; +int MMColorValue::get_iterations() const { + return iterations; } -void ColorValue::set_iterations(const int val) { -iterations = val; +void MMColorValue::set_iterations(const int val) { + iterations = val; + set_dirty(true); } - -float ColorValue::get_persistence() const { - return persistence; +float MMColorValue::get_persistence() const { + return persistence; } -void ColorValue::set_persistence(const float val) { -persistence = val; +void MMColorValue::set_persistence(const float val) { + persistence = val; + set_dirty(true); } +void MMColorValue::_init_properties() { + if (!image.is_valid()) { + image.instance(); + image->set_default_type(MMNodeUniversalProperty::DEFAULT_TYPE_IMAGE); + } - - //tool; - //export(Resource) ; - Ref image; - //export(Vector2) ; - Vector2 scale = Vector2(4, 4); - //export(int) ; - int iterations = 3; - //export(float) ; - float persistence = 0.5; - - void ColorValue::_init_properties() { - - if (!image) { - image = MMNodeUniversalProperty.new(); - image.default_type = MMNodeUniversalProperty.DEFAULT_TYPE_IMAGE; + image->set_output_slot_type(MMNodeUniversalProperty::SLOT_TYPE_IMAGE); + register_output_property(image); } - image.output_slot_type = MMNodeUniversalProperty.SLOT_TYPE_IMAGE; - register_output_property(image); +void MMColorValue::_register_methods(MMGraphNode *mm_graph_node) { + mm_graph_node->add_slot_texture_universal(image); + //, Vector2(1, 10)); + mm_graph_node->add_slot_vector2("get_scale", "set_scale", "Scale"); + //, Vector2(0, 1)); + mm_graph_node->add_slot_int("get_iterations", "set_iterations", "Iterations"); + //, Vector2(0, 1)); + mm_graph_node->add_slot_float("get_persistence", "set_persistence", "Persistence", 0.01); } - - void ColorValue::_register_methods(const Variant &mm_graph_node) { - mm_graph_node.add_slot_texture_universal(image); - //, Vector2(1, 10)); - mm_graph_node.add_slot_vector2("get_scale", "set_scale", "Scale"); - //, Vector2(0, 1)); - mm_graph_node.add_slot_int("get_iterations", "set_iterations", "Iterations"); - //, Vector2(0, 1)); - mm_graph_node.add_slot_float("get_persistence", "set_persistence", "Persistence", 0.01); +Color MMColorValue::_get_value_for(const Vector2 &uv, const int pseed) { + float ps = 1.0 / float(pseed); + //perlin_color($(uv), vec2($(scale_x), $(scale_y)), int($(iterations)), $(persistence), $(seed)); + return MMAlgos::perlin_colorc(uv, scale, iterations, persistence, ps); } - - Color ColorValue::_get_value_for(const Vector2 &uv, const int pseed) { - float ps = 1.0 / float(pseed); - //perlin_color($(uv), vec2($(scale_x), $(scale_y)), int($(iterations)), $(persistence), $(seed)); - return MMAlgos.perlin_colorc(uv, scale, iterations, persistence, ps); +void MMColorValue::_render(const Ref &material) { + Ref img = render_image(material); + image->set_value(img); } - - void ColorValue::_render(const Variant &material) { - Ref img = render_image(material); - image.set_value(img); +MMColorValue::MMColorValue() { + scale = Vector2(4, 4); + iterations = 3; + persistence = 0.5; } - - Vector2 ColorValue::get_scale() { - return scale; +MMColorValue::~MMColorValue() { } +void MMColorValue::_bind_methods() { + ClassDB::bind_method(D_METHOD("get_image"), &MMColorValue::get_image); + ClassDB::bind_method(D_METHOD("set_image", "value"), &MMColorValue::set_image); + ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "image", PROPERTY_HINT_RESOURCE_TYPE, "MMNodeUniversalProperty"), "set_image", "get_image"); - void ColorValue::set_scale(const Vector2 &val) { - scale = val; - set_dirty(true); + ClassDB::bind_method(D_METHOD("get_scale"), &MMColorValue::get_scale); + ClassDB::bind_method(D_METHOD("set_scale", "value"), &MMColorValue::set_scale); + ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "scale"), "set_scale", "get_scale"); + + ClassDB::bind_method(D_METHOD("get_iterations"), &MMColorValue::get_iterations); + ClassDB::bind_method(D_METHOD("set_iterations", "value"), &MMColorValue::set_iterations); + ADD_PROPERTY(PropertyInfo(Variant::INT, "iterations"), "set_iterations", "get_iterations"); + + ClassDB::bind_method(D_METHOD("get_persistence"), &MMColorValue::get_persistence); + ClassDB::bind_method(D_METHOD("set_persistence", "value"), &MMColorValue::set_persistence); + ADD_PROPERTY(PropertyInfo(Variant::REAL, "persistence"), "set_persistence", "get_persistence"); } - - - int ColorValue::get_iterations() { - return iterations; -} - - - void ColorValue::set_iterations(const int val) { - iterations = val; - set_dirty(true); -} - - - float ColorValue::get_persistence() { - return persistence; -} - - - void ColorValue::set_persistence(const float val) { - persistence = val; - set_dirty(true); -} - -} - - ColorValue::ColorValue() { - image; - scale = Vector2(4, 4); - iterations = 3; - persistence = 0.5; - } - - ColorValue::~ColorValue() { - } - - - static void ColorValue::_bind_methods() { - ClassDB::bind_method(D_METHOD("get_image"), &ColorValue::get_image); - ClassDB::bind_method(D_METHOD("set_image", "value"), &ColorValue::set_image); - ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "image", PROPERTY_HINT_RESOURCE_TYPE, "Ref"), "set_image", "get_image"); - - - ClassDB::bind_method(D_METHOD("get_scale"), &ColorValue::get_scale); - ClassDB::bind_method(D_METHOD("set_scale", "value"), &ColorValue::set_scale); - ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "scale"), "set_scale", "get_scale"); - - - ClassDB::bind_method(D_METHOD("get_iterations"), &ColorValue::get_iterations); - ClassDB::bind_method(D_METHOD("set_iterations", "value"), &ColorValue::set_iterations); - ADD_PROPERTY(PropertyInfo(Variant::INT, "iterations"), "set_iterations", "get_iterations"); - - - ClassDB::bind_method(D_METHOD("get_persistence"), &ColorValue::get_persistence); - ClassDB::bind_method(D_METHOD("set_persistence", "value"), &ColorValue::set_persistence); - ADD_PROPERTY(PropertyInfo(Variant::REAL, "persistence"), "set_persistence", "get_persistence"); - - - ClassDB::bind_method(D_METHOD("_init_properties"), &ColorValue::_init_properties); - ClassDB::bind_method(D_METHOD("_register_methods", "mm_graph_node"), &ColorValue::_register_methods); - ClassDB::bind_method(D_METHOD("_get_value_for", "uv", "pseed"), &ColorValue::_get_value_for); - ClassDB::bind_method(D_METHOD("_render", "material"), &ColorValue::_render); - ClassDB::bind_method(D_METHOD("get_scale"), &ColorValue::get_scale); - ClassDB::bind_method(D_METHOD("set_scale", "val"), &ColorValue::set_scale); - ClassDB::bind_method(D_METHOD("get_iterations"), &ColorValue::get_iterations); - ClassDB::bind_method(D_METHOD("set_iterations", "val"), &ColorValue::set_iterations); - ClassDB::bind_method(D_METHOD("get_persistence"), &ColorValue::get_persistence); - ClassDB::bind_method(D_METHOD("set_persistence", "val"), &ColorValue::set_persistence); - - } - - - diff --git a/modules/material_maker/nodes/noise/color_value.h b/modules/material_maker/nodes/noise/color_value.h index a04892091..b41c3c090 100644 --- a/modules/material_maker/nodes/noise/color_value.h +++ b/modules/material_maker/nodes/noise/color_value.h @@ -1,51 +1,40 @@ -#ifndef COLOR_VALUE_H -#define COLOR_VALUE_H +#ifndef MM_COLOR_VALUE_H +#define MM_COLOR_VALUE_H +#include "../mm_node.h" +#include "../mm_node_universal_property.h" -class ColorValue : public MMNode { - GDCLASS(ColorValue, MMNode); +class MMColorValue : public MMNode { + GDCLASS(MMColorValue, MMNode); - public: +public: + Ref get_image(); + void set_image(const Ref &val); - Ref get_image(); - void set_image(const Ref &val); + Vector2 get_scale(); + void set_scale(const Vector2 &val); - Vector2 get_scale(); - void set_scale(const Vector2 &val); + int get_iterations() const; + void set_iterations(const int val); - int get_iterations() const; - void set_iterations(const int val); + float get_persistence() const; + void set_persistence(const float val); - float get_persistence() const; - void set_persistence(const float val); + void _init_properties(); + void _register_methods(MMGraphNode *mm_graph_node); + Color _get_value_for(const Vector2 &uv, const int pseed); + void _render(const Ref &material); - void _init_properties(); - void _register_methods(const Variant &mm_graph_node); - Color _get_value_for(const Vector2 &uv, const int pseed); - void _render(const Variant &material); - Vector2 get_scale(); - void set_scale(const Vector2 &val); - int get_iterations(); - void set_iterations(const int val); - float get_persistence(); - void set_persistence(const float val); + MMColorValue(); + ~MMColorValue(); - ColorValue(); - ~ColorValue(); +protected: + static void _bind_methods(); - protected: - static void _bind_methods(); - - //tool - //export(Resource) - Ref image; - //export(Vector2) - Vector2 scale = Vector2(4, 4); - //export(int) - int iterations = 3; - //export(float) - float persistence = 0.5; + Ref image; + Vector2 scale; + int iterations; + float persistence; }; - #endif diff --git a/modules/material_maker/nodes/noise/fbm_noise.cpp b/modules/material_maker/nodes/noise/fbm_noise.cpp index 96d6d996f..20560a32f 100644 --- a/modules/material_maker/nodes/noise/fbm_noise.cpp +++ b/modules/material_maker/nodes/noise/fbm_noise.cpp @@ -1,277 +1,164 @@ #include "fbm_noise.h" +#include "../../algos/mm_algos.h" +#include "../../editor/mm_graph_node.h" +#include "../mm_material.h" -Ref FbmNoise::get_image() { - return image; +Ref MMFbmNoise::get_image() { + return image; } -void FbmNoise::set_image(const Ref &val) { -image = val; +void MMFbmNoise::set_image(const Ref &val) { + image = val; } - -int FbmNoise::get_type() const { - return type; +int MMFbmNoise::get_type() const { + return type; } -void FbmNoise::set_type(const int val) { -type = val; +void MMFbmNoise::set_type(const int val) { + type = val; + set_dirty(true); } - -Vector2 FbmNoise::get_scale() { - return scale; +Vector2 MMFbmNoise::get_scale() { + return scale; } -void FbmNoise::set_scale(const Vector2 &val) { -scale = val; +void MMFbmNoise::set_scale(const Vector2 &val) { + scale = val; + set_dirty(true); } - -int FbmNoise::get_folds() const { - return folds; +int MMFbmNoise::get_folds() const { + return folds; } -void FbmNoise::set_folds(const int val) { -folds = val; +void MMFbmNoise::set_folds(const int val) { + folds = val; + set_dirty(true); } - -int FbmNoise::get_iterations() const { - return iterations; +int MMFbmNoise::get_iterations() const { + return iterations; } -void FbmNoise::set_iterations(const int val) { -iterations = val; +void MMFbmNoise::set_iterations(const int val) { + iterations = val; + set_dirty(true); } - -float FbmNoise::get_persistence() const { - return persistence; +float MMFbmNoise::get_persistence() const { + return persistence; } -void FbmNoise::set_persistence(const float val) { -persistence = val; +void MMFbmNoise::set_persistence(const float val) { + persistence = val; + set_dirty(true); } +void MMFbmNoise::_init_properties() { + if (!image.is_valid()) { + image.instance(); + image->set_default_type(MMNodeUniversalProperty::DEFAULT_TYPE_IMAGE); + } - - //tool; - //export(Resource) ; - Ref image; - //export(int, "Value,Perlin,Simplex,Cellular1,Cellular2,Cellular3,Cellular4,Cellular5,Cellular6") ; - int type = 0; - //export(Vector2) ; - Vector2 scale = Vector2(2, 2); - //export(int) ; - int folds = 0; - //export(int) ; - int iterations = 5; - //export(float) ; - float persistence = 0.5; - - void FbmNoise::_init_properties() { - - if (!image) { - image = MMNodeUniversalProperty.new(); - image.default_type = MMNodeUniversalProperty.DEFAULT_TYPE_IMAGE; + image->set_output_slot_type(MMNodeUniversalProperty::SLOT_TYPE_IMAGE); + register_output_property(image); } - image.output_slot_type = MMNodeUniversalProperty.SLOT_TYPE_IMAGE; - register_output_property(image); +void MMFbmNoise::_register_methods(MMGraphNode *mm_graph_node) { + mm_graph_node->add_slot_texture_universal(image); + + Array arr; + arr.push_back("Value"); + arr.push_back("Perlin"); + arr.push_back("Simplex"); + arr.push_back("Cellular1"); + arr.push_back("Cellular2"); + arr.push_back("Cellular3"); + arr.push_back("Cellular4"); + arr.push_back("Cellular5"); + arr.push_back("Cellular6"); + + //, Vector2(0, 1)); + mm_graph_node->add_slot_enum("get_type", "set_type", "Type", arr); + //, Vector2(1, 10)); + mm_graph_node->add_slot_vector2("get_scale", "set_scale", "Scale"); + //, Vector2(0, 1)); + mm_graph_node->add_slot_int("get_folds", "set_folds", "folds"); + //, Vector2(0, 1)); + mm_graph_node->add_slot_int("get_iterations", "set_iterations", "Iterations"); + //, Vector2(0, 1)); + mm_graph_node->add_slot_float("get_persistence", "set_persistence", "Persistence", 0.01); } +Color MMFbmNoise::_get_value_for(const Vector2 &uv, const int pseed) { + float ps = 1.0 / float(pseed); + //"Value,Perlin,Simplex,Cellular1,Cellular2,Cellular3,Cellular4,Cellular5,Cellular6"; - void FbmNoise::_register_methods(const Variant &mm_graph_node) { - mm_graph_node.add_slot_texture_universal(image); - //, Vector2(0, 1)); - mm_graph_node.add_slot_enum("get_type", "set_type", "Type", [ "Value", "Perlin", "Simplex", "Cellular1", "Cellular2", "Cellular3", "Cellular4", "Cellular5", "Cellular6" ]); - //, Vector2(1, 10)); - mm_graph_node.add_slot_vector2("get_scale", "set_scale", "Scale"); - //, Vector2(0, 1)); - mm_graph_node.add_slot_int("get_folds", "set_folds", "folds"); - //, Vector2(0, 1)); - mm_graph_node.add_slot_int("get_iterations", "set_iterations", "Iterations"); - //, Vector2(0, 1)); - mm_graph_node.add_slot_float("get_persistence", "set_persistence", "Persistence", 0.01); + if (type == 0) { + return MMAlgos::fbmval(uv, scale, folds, iterations, persistence, ps); + } else if (type == 1) { + return MMAlgos::perlin(uv, scale, folds, iterations, persistence, ps); + } else if (type == 2) { + return MMAlgos::simplex(uv, scale, folds, iterations, persistence, ps); + } else if (type == 3) { + return MMAlgos::cellular(uv, scale, folds, iterations, persistence, ps); + } else if (type == 4) { + return MMAlgos::cellular2(uv, scale, folds, iterations, persistence, ps); + } else if (type == 5) { + return MMAlgos::cellular3(uv, scale, folds, iterations, persistence, ps); + } else if (type == 6) { + return MMAlgos::cellular4(uv, scale, folds, iterations, persistence, ps); + } else if (type == 7) { + return MMAlgos::cellular5(uv, scale, folds, iterations, persistence, ps); + } else if (type == 8) { + return MMAlgos::cellular6(uv, scale, folds, iterations, persistence, ps); + } + + return Color(); } - - Color FbmNoise::_get_value_for(const Vector2 &uv, const int pseed) { - float ps = 1.0 / float(pseed); - //"Value,Perlin,Simplex,Cellular1,Cellular2,Cellular3,Cellular4,Cellular5,Cellular6"; - - if (type == 0) { - return MMAlgos.fbmval(uv, scale, folds, iterations, persistence, ps); +void MMFbmNoise::_render(const Ref &material) { + Ref img = render_image(material); + image->set_value(img); } - - else if (type == 1) { - return MMAlgos.perlin(uv, scale, folds, iterations, persistence, ps); +MMFbmNoise::MMFbmNoise() { + type = 0; + scale = Vector2(2, 2); + folds = 0; + iterations = 5; + persistence = 0.5; } - - else if (type == 2) { - return MMAlgos.simplex(uv, scale, folds, iterations, persistence, ps); +MMFbmNoise::~MMFbmNoise() { } +void MMFbmNoise::_bind_methods() { + ClassDB::bind_method(D_METHOD("get_image"), &MMFbmNoise::get_image); + ClassDB::bind_method(D_METHOD("set_image", "value"), &MMFbmNoise::set_image); + ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "image", PROPERTY_HINT_RESOURCE_TYPE, "MMNodeUniversalProperty"), "set_image", "get_image"); - else if (type == 3) { - return MMAlgos.cellular(uv, scale, folds, iterations, persistence, ps); + ClassDB::bind_method(D_METHOD("get_type"), &MMFbmNoise::get_type); + ClassDB::bind_method(D_METHOD("set_type", "value"), &MMFbmNoise::set_type); + ADD_PROPERTY(PropertyInfo(Variant::INT, "type"), "set_type", "get_type"); + + ClassDB::bind_method(D_METHOD("get_scale"), &MMFbmNoise::get_scale); + ClassDB::bind_method(D_METHOD("set_scale", "value"), &MMFbmNoise::set_scale); + ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "scale"), "set_scale", "get_scale"); + + ClassDB::bind_method(D_METHOD("get_folds"), &MMFbmNoise::get_folds); + ClassDB::bind_method(D_METHOD("set_folds", "value"), &MMFbmNoise::set_folds); + ADD_PROPERTY(PropertyInfo(Variant::INT, "folds"), "set_folds", "get_folds"); + + ClassDB::bind_method(D_METHOD("get_iterations"), &MMFbmNoise::get_iterations); + ClassDB::bind_method(D_METHOD("set_iterations", "value"), &MMFbmNoise::set_iterations); + ADD_PROPERTY(PropertyInfo(Variant::INT, "iterations"), "set_iterations", "get_iterations"); + + ClassDB::bind_method(D_METHOD("get_persistence"), &MMFbmNoise::get_persistence); + ClassDB::bind_method(D_METHOD("set_persistence", "value"), &MMFbmNoise::set_persistence); + ADD_PROPERTY(PropertyInfo(Variant::REAL, "persistence"), "set_persistence", "get_persistence"); } - - - else if (type == 4) { - return MMAlgos.cellular2(uv, scale, folds, iterations, persistence, ps); -} - - - else if (type == 5) { - return MMAlgos.cellular3(uv, scale, folds, iterations, persistence, ps); -} - - - else if (type == 6) { - return MMAlgos.cellular4(uv, scale, folds, iterations, persistence, ps); -} - - - else if (type == 7) { - return MMAlgos.cellular5(uv, scale, folds, iterations, persistence, ps); -} - - - else if (type == 8) { - return MMAlgos.cellular6(uv, scale, folds, iterations, persistence, ps); -} - - return Color(); -} - - - void FbmNoise::_render(const Variant &material) { - Ref img = render_image(material); - image.set_value(img); -} - - - int FbmNoise::get_type() { - return type; -} - - - void FbmNoise::set_type(const int val) { - type = val; - set_dirty(true); -} - - - Vector2 FbmNoise::get_scale() { - return scale; -} - - - void FbmNoise::set_scale(const Vector2 &val) { - scale = val; - set_dirty(true); -} - - - int FbmNoise::get_folds() { - return folds; -} - - - void FbmNoise::set_folds(const int val) { - folds = val; - set_dirty(true); -} - - - int FbmNoise::get_iterations() { - return iterations; -} - - - void FbmNoise::set_iterations(const int val) { - iterations = val; - set_dirty(true); -} - - - float FbmNoise::get_persistence() { - return persistence; -} - - - void FbmNoise::set_persistence(const float val) { - persistence = val; - set_dirty(true); -} - -} - - FbmNoise::FbmNoise() { - image; - type = 0; - scale = Vector2(2, 2); - folds = 0; - iterations = 5; - persistence = 0.5; - } - - FbmNoise::~FbmNoise() { - } - - - static void FbmNoise::_bind_methods() { - ClassDB::bind_method(D_METHOD("get_image"), &FbmNoise::get_image); - ClassDB::bind_method(D_METHOD("set_image", "value"), &FbmNoise::set_image); - ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "image", PROPERTY_HINT_RESOURCE_TYPE, "Ref"), "set_image", "get_image"); - - - ClassDB::bind_method(D_METHOD("get_type"), &FbmNoise::get_type); - ClassDB::bind_method(D_METHOD("set_type", "value"), &FbmNoise::set_type); - ADD_PROPERTY(PropertyInfo(Variant::INT, "type"), "set_type", "get_type"); - - - ClassDB::bind_method(D_METHOD("get_scale"), &FbmNoise::get_scale); - ClassDB::bind_method(D_METHOD("set_scale", "value"), &FbmNoise::set_scale); - ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "scale"), "set_scale", "get_scale"); - - - ClassDB::bind_method(D_METHOD("get_folds"), &FbmNoise::get_folds); - ClassDB::bind_method(D_METHOD("set_folds", "value"), &FbmNoise::set_folds); - ADD_PROPERTY(PropertyInfo(Variant::INT, "folds"), "set_folds", "get_folds"); - - - ClassDB::bind_method(D_METHOD("get_iterations"), &FbmNoise::get_iterations); - ClassDB::bind_method(D_METHOD("set_iterations", "value"), &FbmNoise::set_iterations); - ADD_PROPERTY(PropertyInfo(Variant::INT, "iterations"), "set_iterations", "get_iterations"); - - - ClassDB::bind_method(D_METHOD("get_persistence"), &FbmNoise::get_persistence); - ClassDB::bind_method(D_METHOD("set_persistence", "value"), &FbmNoise::set_persistence); - ADD_PROPERTY(PropertyInfo(Variant::REAL, "persistence"), "set_persistence", "get_persistence"); - - - ClassDB::bind_method(D_METHOD("_init_properties"), &FbmNoise::_init_properties); - ClassDB::bind_method(D_METHOD("_register_methods", "mm_graph_node"), &FbmNoise::_register_methods); - ClassDB::bind_method(D_METHOD("_get_value_for", "uv", "pseed"), &FbmNoise::_get_value_for); - ClassDB::bind_method(D_METHOD("_render", "material"), &FbmNoise::_render); - ClassDB::bind_method(D_METHOD("get_type"), &FbmNoise::get_type); - ClassDB::bind_method(D_METHOD("set_type", "val"), &FbmNoise::set_type); - ClassDB::bind_method(D_METHOD("get_scale"), &FbmNoise::get_scale); - ClassDB::bind_method(D_METHOD("set_scale", "val"), &FbmNoise::set_scale); - ClassDB::bind_method(D_METHOD("get_folds"), &FbmNoise::get_folds); - ClassDB::bind_method(D_METHOD("set_folds", "val"), &FbmNoise::set_folds); - ClassDB::bind_method(D_METHOD("get_iterations"), &FbmNoise::get_iterations); - ClassDB::bind_method(D_METHOD("set_iterations", "val"), &FbmNoise::set_iterations); - ClassDB::bind_method(D_METHOD("get_persistence"), &FbmNoise::get_persistence); - ClassDB::bind_method(D_METHOD("set_persistence", "val"), &FbmNoise::set_persistence); - - } - - - diff --git a/modules/material_maker/nodes/noise/fbm_noise.h b/modules/material_maker/nodes/noise/fbm_noise.h index 062d6fb2a..4dc3db9e8 100644 --- a/modules/material_maker/nodes/noise/fbm_noise.h +++ b/modules/material_maker/nodes/noise/fbm_noise.h @@ -1,65 +1,49 @@ -#ifndef FBM_NOISE_H -#define FBM_NOISE_H +#ifndef MM_FBM_NOISE_H +#define MM_FBM_NOISE_H +#include "../mm_node.h" +#include "../mm_node_universal_property.h" -class FbmNoise : public MMNode { - GDCLASS(FbmNoise, MMNode); +class MMFbmNoise : public MMNode { + GDCLASS(MMFbmNoise, MMNode); - public: +public: + Ref get_image(); + void set_image(const Ref &val); - Ref get_image(); - void set_image(const Ref &val); + int get_type() const; + void set_type(const int val); - int get_type() const; - void set_type(const int val); + Vector2 get_scale(); + void set_scale(const Vector2 &val); - Vector2 get_scale(); - void set_scale(const Vector2 &val); + int get_folds() const; + void set_folds(const int val); - int get_folds() const; - void set_folds(const int val); + int get_iterations() const; + void set_iterations(const int val); - int get_iterations() const; - void set_iterations(const int val); + float get_persistence() const; + void set_persistence(const float val); - float get_persistence() const; - void set_persistence(const float val); + void _init_properties(); + void _register_methods(MMGraphNode *mm_graph_node); + Color _get_value_for(const Vector2 &uv, const int pseed); + void _render(const Ref &material); - void _init_properties(); - void _register_methods(const Variant &mm_graph_node); - Color _get_value_for(const Vector2 &uv, const int pseed); - void _render(const Variant &material); - int get_type(); - void set_type(const int val); - Vector2 get_scale(); - void set_scale(const Vector2 &val); - int get_folds(); - void set_folds(const int val); - int get_iterations(); - void set_iterations(const int val); - float get_persistence(); - void set_persistence(const float val); + MMFbmNoise(); + ~MMFbmNoise(); - FbmNoise(); - ~FbmNoise(); +protected: + static void _bind_methods(); - protected: - static void _bind_methods(); - - //tool - //export(Resource) - Ref image; - //export(int, "Value,Perlin,Simplex,Cellular1,Cellular2,Cellular3,Cellular4,Cellular5,Cellular6") - int type = 0; - //export(Vector2) - Vector2 scale = Vector2(2, 2); - //export(int) - int folds = 0; - //export(int) - int iterations = 5; - //export(float) - float persistence = 0.5; + Ref image; + //export(int, "Value,Perlin,Simplex,Cellular1,Cellular2,Cellular3,Cellular4,Cellular5,Cellular6") + int type; + Vector2 scale; + int folds; + int iterations; + float persistence; }; - #endif diff --git a/modules/material_maker/nodes/noise/noise.cpp b/modules/material_maker/nodes/noise/noise.cpp index 88aaed8f3..a67db9d75 100644 --- a/modules/material_maker/nodes/noise/noise.cpp +++ b/modules/material_maker/nodes/noise/noise.cpp @@ -1,137 +1,84 @@ #include "noise.h" +#include "../../algos/mm_algos.h" +#include "../../editor/mm_graph_node.h" +#include "../mm_material.h" -Ref Noise::get_image() { - return image; +Ref MMNoise::get_image() { + return image; } -void Noise::set_image(const Ref &val) { -image = val; +void MMNoise::set_image(const Ref &val) { + image = val; } - -int Noise::get_grid_size() const { - return grid_size; +int MMNoise::get_grid_size() const { + return grid_size; } -void Noise::set_grid_size(const int val) { -grid_size = val; +void MMNoise::set_grid_size(const int val) { + grid_size = val; + set_dirty(true); } - -float Noise::get_density() const { - return density; +float MMNoise::get_density() const { + return density; } -void Noise::set_density(const float val) { -density = val; +void MMNoise::set_density(const float val) { + density = val; + set_dirty(true); } +void MMNoise::_init_properties() { + if (!image.is_valid()) { + image.instance(); + image->set_default_type(MMNodeUniversalProperty::DEFAULT_TYPE_IMAGE); + } - - //tool; - //export(Resource) ; - Ref image; - //export(int) ; - int grid_size = 16; - //export(float) ; - float density = 0.5; - - void Noise::_init_properties() { - - if (!image) { - image = MMNodeUniversalProperty.new(); - image.default_type = MMNodeUniversalProperty.DEFAULT_TYPE_IMAGE; + image->set_output_slot_type(MMNodeUniversalProperty::SLOT_TYPE_IMAGE); + register_output_property(image); } - image.output_slot_type = MMNodeUniversalProperty.SLOT_TYPE_IMAGE; - register_output_property(image); +void MMNoise::_register_methods(MMGraphNode *mm_graph_node) { + mm_graph_node->add_slot_texture_universal(image); + //, Vector2(1, 10)); + mm_graph_node->add_slot_int("get_grid_size", "set_grid_size", "Grid Size"); + //, Vector2(0, 1)); + mm_graph_node->add_slot_float("get_density", "set_density", "Density", 0.01); } - - void Noise::_register_methods(const Variant &mm_graph_node) { - mm_graph_node.add_slot_texture_universal(image); - //, Vector2(1, 10)); - mm_graph_node.add_slot_int("get_grid_size", "set_grid_size", "Grid Size"); - //, Vector2(0, 1)); - mm_graph_node.add_slot_float("get_density", "set_density", "Density", 0.01); +Color MMNoise::_get_value_for(const Vector2 &uv, const int pseed) { + float ps = 1.0 / float(pseed); + //return dots(uv, 1.0/$(size), $(density), $(seed)); + float f = MMAlgos::dots(uv, 1.0 / float(grid_size), density, ps); + return Color(f, f, f, 1); } - - Color Noise::_get_value_for(const Vector2 &uv, const int pseed) { - float ps = 1.0 / float(pseed); - //return dots(uv, 1.0/$(size), $(density), $(seed)); - float f = MMAlgos.dots(uv, 1.0 / float(grid_size), density, ps); - return Color(f, f, f, 1); +void MMNoise::_render(const Ref &material) { + Ref img = render_image(material); + image->set_value(img); } - - void Noise::_render(const Variant &material) { - Ref img = render_image(material); - image.set_value(img); +MMNoise::MMNoise() { + grid_size = 16; + density = 0.5; } - - int Noise::get_grid_size() { - return grid_size; +MMNoise::~MMNoise() { } +void MMNoise::_bind_methods() { + ClassDB::bind_method(D_METHOD("get_image"), &MMNoise::get_image); + ClassDB::bind_method(D_METHOD("set_image", "value"), &MMNoise::set_image); + ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "image", PROPERTY_HINT_RESOURCE_TYPE, "MMNodeUniversalProperty"), "set_image", "get_image"); - void Noise::set_grid_size(const int val) { - grid_size = val; - set_dirty(true); + ClassDB::bind_method(D_METHOD("get_grid_size"), &MMNoise::get_grid_size); + ClassDB::bind_method(D_METHOD("set_grid_size", "value"), &MMNoise::set_grid_size); + ADD_PROPERTY(PropertyInfo(Variant::INT, "grid_size"), "set_grid_size", "get_grid_size"); + + ClassDB::bind_method(D_METHOD("get_density"), &MMNoise::get_density); + ClassDB::bind_method(D_METHOD("set_density", "value"), &MMNoise::set_density); + ADD_PROPERTY(PropertyInfo(Variant::REAL, "density"), "set_density", "get_density"); } - - - float Noise::get_density() { - return density; -} - - - void Noise::set_density(const float val) { - density = val; - set_dirty(true); -} - -} - - Noise::Noise() { - image; - grid_size = 16; - density = 0.5; - } - - Noise::~Noise() { - } - - - static void Noise::_bind_methods() { - ClassDB::bind_method(D_METHOD("get_image"), &Noise::get_image); - ClassDB::bind_method(D_METHOD("set_image", "value"), &Noise::set_image); - ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "image", PROPERTY_HINT_RESOURCE_TYPE, "Ref"), "set_image", "get_image"); - - - ClassDB::bind_method(D_METHOD("get_grid_size"), &Noise::get_grid_size); - ClassDB::bind_method(D_METHOD("set_grid_size", "value"), &Noise::set_grid_size); - ADD_PROPERTY(PropertyInfo(Variant::INT, "grid_size"), "set_grid_size", "get_grid_size"); - - - ClassDB::bind_method(D_METHOD("get_density"), &Noise::get_density); - ClassDB::bind_method(D_METHOD("set_density", "value"), &Noise::set_density); - ADD_PROPERTY(PropertyInfo(Variant::REAL, "density"), "set_density", "get_density"); - - - ClassDB::bind_method(D_METHOD("_init_properties"), &Noise::_init_properties); - ClassDB::bind_method(D_METHOD("_register_methods", "mm_graph_node"), &Noise::_register_methods); - ClassDB::bind_method(D_METHOD("_get_value_for", "uv", "pseed"), &Noise::_get_value_for); - ClassDB::bind_method(D_METHOD("_render", "material"), &Noise::_render); - ClassDB::bind_method(D_METHOD("get_grid_size"), &Noise::get_grid_size); - ClassDB::bind_method(D_METHOD("set_grid_size", "val"), &Noise::set_grid_size); - ClassDB::bind_method(D_METHOD("get_density"), &Noise::get_density); - ClassDB::bind_method(D_METHOD("set_density", "val"), &Noise::set_density); - - } - - - diff --git a/modules/material_maker/nodes/noise/noise.h b/modules/material_maker/nodes/noise/noise.h index 17b76ecf4..157f3694f 100644 --- a/modules/material_maker/nodes/noise/noise.h +++ b/modules/material_maker/nodes/noise/noise.h @@ -1,44 +1,40 @@ -#ifndef NOISE_H -#define NOISE_H +#ifndef MM_NOISE_H +#define MM_NOISE_H +#include "../mm_node.h" +#include "../mm_node_universal_property.h" -class Noise : public MMNode { - GDCLASS(Noise, MMNode); +class MMNoise : public MMNode { + GDCLASS(MMNoise, MMNode); - public: +public: + Ref get_image(); + void set_image(const Ref &val); - Ref get_image(); - void set_image(const Ref &val); + int get_grid_size() const; + void set_grid_size(const int val); - int get_grid_size() const; - void set_grid_size(const int val); + float get_density() const; + void set_density(const float val); - float get_density() const; - void set_density(const float val); + void _init_properties(); + void _register_methods(MMGraphNode *mm_graph_node); + Color _get_value_for(const Vector2 &uv, const int pseed); + void _render(const Ref &material); - void _init_properties(); - void _register_methods(const Variant &mm_graph_node); - Color _get_value_for(const Vector2 &uv, const int pseed); - void _render(const Variant &material); - int get_grid_size(); - void set_grid_size(const int val); - float get_density(); - void set_density(const float val); + MMNoise(); + ~MMNoise(); - Noise(); - ~Noise(); +protected: + static void _bind_methods(); - protected: - static void _bind_methods(); - - //tool - //export(Resource) - Ref image; - //export(int) - int grid_size = 16; - //export(float) - float density = 0.5; + //tool + //export(MMNodeUniversalProperty) + Ref image; + //export(int) + int grid_size = 16; + //export(float) + float density = 0.5; }; - #endif diff --git a/modules/material_maker/nodes/noise/voronoi.cpp b/modules/material_maker/nodes/noise/voronoi.cpp index 21e60fb54..04ba5a986 100644 --- a/modules/material_maker/nodes/noise/voronoi.cpp +++ b/modules/material_maker/nodes/noise/voronoi.cpp @@ -1,332 +1,238 @@ #include "voronoi.h" +#include "../../algos/mm_algos.h" +#include "../../editor/mm_graph_node.h" +#include "../mm_material.h" -Ref Voronoi::get_out_nodes() { - return out_nodes; +Ref MMVoronoi::get_out_nodes() { + return out_nodes; } -void Voronoi::set_out_nodes(const Ref &val) { -out_nodes = val; +void MMVoronoi::set_out_nodes(const Ref &val) { + out_nodes = val; } - -Ref Voronoi::get_out_borders() { - return out_borders; +Ref MMVoronoi::get_out_borders() { + return out_borders; } -void Voronoi::set_out_borders(const Ref &val) { -out_borders = val; +void MMVoronoi::set_out_borders(const Ref &val) { + out_borders = val; } - -Ref Voronoi::get_out_random_color() { - return out_random_color; +Ref MMVoronoi::get_out_random_color() { + return out_random_color; } -void Voronoi::set_out_random_color(const Ref &val) { -out_random_color = val; +void MMVoronoi::set_out_random_color(const Ref &val) { + out_random_color = val; } - -Ref Voronoi::get_out_fill() { - return out_fill; +Ref MMVoronoi::get_out_fill() { + return out_fill; } -void Voronoi::set_out_fill(const Ref &val) { -out_fill = val; +void MMVoronoi::set_out_fill(const Ref &val) { + out_fill = val; } - -Vector2 Voronoi::get_scale() { - return scale; +Vector2 MMVoronoi::get_scale() { + return scale; } -void Voronoi::set_scale(const Vector2 &val) { -scale = val; +void MMVoronoi::set_scale(const Vector2 &val) { + scale = val; + set_dirty(true); } - -Vector2 Voronoi::get_stretch() { - return stretch; +Vector2 MMVoronoi::get_stretch() { + return stretch; } -void Voronoi::set_stretch(const Vector2 &val) { -stretch = val; +void MMVoronoi::set_stretch(const Vector2 &val) { + stretch = val; + set_dirty(true); } - -float Voronoi::get_intensity() const { - return intensity; +float MMVoronoi::get_intensity() const { + return intensity; } -void Voronoi::set_intensity(const float val) { -intensity = val; +void MMVoronoi::set_intensity(const float val) { + intensity = val; + set_dirty(true); } - -float Voronoi::get_randomness() const { - return randomness; +float MMVoronoi::get_randomness() const { + return randomness; } -void Voronoi::set_randomness(const float val) { -randomness = val; +void MMVoronoi::set_randomness(const float val) { + randomness = val; + set_dirty(true); } +void MMVoronoi::_init_properties() { + if (!out_nodes.is_valid()) { + out_nodes.instance(); + out_nodes->set_default_type(MMNodeUniversalProperty::DEFAULT_TYPE_IMAGE); + } + out_nodes->set_output_slot_type(MMNodeUniversalProperty::SLOT_TYPE_IMAGE); - //tool; - //export(Resource) ; - Ref out_nodes; - //export(Resource) ; - Ref out_borders; - //export(Resource) ; - Ref out_random_color; - //export(Resource) ; - Ref out_fill; - //export(Vector2) ; - Vector2 scale = Vector2(4, 4); - //export(Vector2) ; - Vector2 stretch = Vector2(1, 1); - //export(float) ; - float intensity = 1; - //export(float) ; - float randomness = 0.85; + if (!out_borders.is_valid()) { + out_borders.instance(); + out_borders->set_default_type(MMNodeUniversalProperty::DEFAULT_TYPE_IMAGE); + } - void Voronoi::_init_properties() { + out_borders->set_output_slot_type(MMNodeUniversalProperty::SLOT_TYPE_IMAGE); - if (!out_nodes) { - out_nodes = MMNodeUniversalProperty.new(); - out_nodes.default_type = MMNodeUniversalProperty.DEFAULT_TYPE_IMAGE; + if (!out_random_color.is_valid()) { + out_random_color.instance(); + out_random_color->set_default_type(MMNodeUniversalProperty::DEFAULT_TYPE_IMAGE); + } + + out_random_color->set_output_slot_type(MMNodeUniversalProperty::SLOT_TYPE_IMAGE); + + if (!out_fill.is_valid()) { + out_fill.instance(); + out_fill->set_default_type(MMNodeUniversalProperty::DEFAULT_TYPE_IMAGE); + } + + out_fill->set_output_slot_type(MMNodeUniversalProperty::SLOT_TYPE_IMAGE); + + register_output_property(out_nodes); + register_output_property(out_borders); + register_output_property(out_random_color); + register_output_property(out_fill); } - out_nodes.output_slot_type = MMNodeUniversalProperty.SLOT_TYPE_IMAGE; - - if (!out_borders) { - out_borders = MMNodeUniversalProperty.new(); - out_borders.default_type = MMNodeUniversalProperty.DEFAULT_TYPE_IMAGE; +void MMVoronoi::_register_methods(MMGraphNode *mm_graph_node) { + mm_graph_node->add_slot_texture_universal(out_nodes); + mm_graph_node->add_slot_texture_universal(out_borders); + mm_graph_node->add_slot_texture_universal(out_random_color); + mm_graph_node->add_slot_texture_universal(out_fill); + //, Vector2(1, 32))//, Vector2(0, 32)); + mm_graph_node->add_slot_vector2("get_scale", "set_scale", "Scale", 0.1); + //, Vector2(1, 32))//, Vector2(0, 32)); + mm_graph_node->add_slot_vector2("get_stretch", "set_stretch", "stretch", 0.01); + //, Vector2(1, 32))//, Vector2(0, 32)); + mm_graph_node->add_slot_float("get_intensity", "set_intensity", "Intensity", 0.01); + //, Vector2(1, 32))//, Vector2(0, 32)); + mm_graph_node->add_slot_float("get_randomness", "set_randomness", "Randomness", 0.01); } - out_borders.output_slot_type = MMNodeUniversalProperty.SLOT_TYPE_IMAGE; +void MMVoronoi::_render(const Ref &material) { + Ref nodes; + Ref borders; + Ref random_color; + Ref fill; - if (!out_random_color) { - out_random_color = MMNodeUniversalProperty.new(); - out_random_color.default_type = MMNodeUniversalProperty.DEFAULT_TYPE_IMAGE; + nodes.instance(); + borders.instance(); + random_color.instance(); + fill.instance(); + + nodes->create(material->image_size.x, material->image_size.y, false, Image::FORMAT_RGBA8); + borders->create(material->image_size.x, material->image_size.y, false, Image::FORMAT_RGBA8); + random_color->create(material->image_size.x, material->image_size.y, false, Image::FORMAT_RGBA8); + fill->create(material->image_size.x, material->image_size.y, false, Image::FORMAT_RGBA8); + + nodes->lock(); + borders->lock(); + random_color->lock(); + fill->lock(); + + float w = material->image_size.x; + float h = material->image_size.y; + float pseed = Math::randf() + Math::rand(); + + for (int x = 0; x < material->image_size.x; ++x) { //x in range(material.image_size.x) + for (int y = 0; y < material->image_size.y; ++y) { //y in range(material.image_size.y) + + Vector2 uv = Vector2(x / w, y / h); + float ps = 1.0 / float(pseed); + //vec4 $(name_uv)_xyzw = voronoi($uv, vec2($scale_x, $scale_y), vec2($stretch_y, $stretch_x), $intensity, $randomness, $seed); + Color voronoi = MMAlgos::voronoi(uv, scale, stretch, intensity, randomness, ps); + //Nodes - float - A greyscale pattern based on the distance to cell centers; + //$(name_uv)_xyzw.z; + Color nodes_col = Color(voronoi.b, voronoi.b, voronoi.b, 1); + //Borders - float - A greyscale pattern based on the distance to borders; + //$(name_uv)_xyzw.w; + Color borders_col = Color(voronoi.a, voronoi.a, voronoi.a, 1); + //Random color - rgb - A color pattern that assigns a random color to each cell; + //rand3(fract(floor($(name_uv)_xyzw.xy)/vec2($scale_x, $scale_y))); + Vector3 rv3 = MMAlgos::rand3(MMAlgos::fractv2(Vector2(voronoi.r, voronoi.g) / scale)); + Color random_color_col = Color(rv3.x, rv3.y, rv3.z, 1); + //Fill - rgba - An output that should be plugged into a Fill companion node; + //vec4(fract(($(name_uv)_xyzw.xy-1.0)/vec2($scale_x, $scale_y)), vec2(2.0)/vec2($scale_x, $scale_y)); + Vector2 fv21 = MMAlgos::fractv2((Vector2(voronoi.r, voronoi.g) - Vector2(1, 1)) / scale); + Vector2 fv22 = Vector2(2, 2) / scale; + Color fill_col = Color(fv21.x, fv21.y, fv22.x, fv22.y); + + nodes->set_pixel(x, y, nodes_col); + borders->set_pixel(x, y, borders_col); + random_color->set_pixel(x, y, random_color_col); + fill->set_pixel(x, y, fill_col); + } + } + + nodes->unlock(); + borders->unlock(); + random_color->unlock(); + fill->unlock(); + + out_nodes->set_value(nodes); + out_borders->set_value(borders); + out_random_color->set_value(random_color); + out_fill->set_value(fill); } - out_random_color.output_slot_type = MMNodeUniversalProperty.SLOT_TYPE_IMAGE; - - if (!out_fill) { - out_fill = MMNodeUniversalProperty.new(); - out_fill.default_type = MMNodeUniversalProperty.DEFAULT_TYPE_IMAGE; +Color MMVoronoi::_get_value_for(const Vector2 &uv, const int pseed) { + return Color(); } - out_fill.output_slot_type = MMNodeUniversalProperty.SLOT_TYPE_IMAGE; - register_output_property(out_nodes); - register_output_property(out_borders); - register_output_property(out_random_color); - register_output_property(out_fill); +MMVoronoi::MMVoronoi() { + scale = Vector2(4, 4); + stretch = Vector2(1, 1); + intensity = 1; + randomness = 0.85; } - - void Voronoi::_register_methods(const Variant &mm_graph_node) { - mm_graph_node.add_slot_texture_universal(out_nodes); - mm_graph_node.add_slot_texture_universal(out_borders); - mm_graph_node.add_slot_texture_universal(out_random_color); - mm_graph_node.add_slot_texture_universal(out_fill); - //, Vector2(1, 32))//, Vector2(0, 32)); - mm_graph_node.add_slot_vector2("get_scale", "set_scale", "Scale", 0.1); - //, Vector2(1, 32))//, Vector2(0, 32)); - mm_graph_node.add_slot_vector2("get_stretch", "set_stretch", "stretch", 0.01); - //, Vector2(1, 32))//, Vector2(0, 32)); - mm_graph_node.add_slot_float("get_intensity", "set_intensity", "Intensity", 0.01); - //, Vector2(1, 32))//, Vector2(0, 32)); - mm_graph_node.add_slot_float("get_randomness", "set_randomness", "Randomness", 0.01); +MMVoronoi::~MMVoronoi() { } +void MMVoronoi::_bind_methods() { + ClassDB::bind_method(D_METHOD("get_out_nodes"), &MMVoronoi::get_out_nodes); + ClassDB::bind_method(D_METHOD("set_out_nodes", "value"), &MMVoronoi::set_out_nodes); + ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "out_nodes", PROPERTY_HINT_RESOURCE_TYPE, "MMNodeUniversalProperty"), "set_out_nodes", "get_out_nodes"); - void Voronoi::_render(const Variant &material) { - Ref nodes = Image.new(); - Ref borders = Image.new(); - Ref random_color = Image.new(); - Ref fill = Image.new(); - nodes.create(material.image_size.x, material.image_size.y, false, Image.FORMAT_RGBA8); - borders.create(material.image_size.x, material.image_size.y, false, Image.FORMAT_RGBA8); - random_color.create(material.image_size.x, material.image_size.y, false, Image.FORMAT_RGBA8); - fill.create(material.image_size.x, material.image_size.y, false, Image.FORMAT_RGBA8); - nodes.lock(); - borders.lock(); - random_color.lock(); - fill.lock(); - float w = material.image_size.x; - float h = material.image_size.y; - float pseed = randf() + randi(); + ClassDB::bind_method(D_METHOD("get_out_borders"), &MMVoronoi::get_out_borders); + ClassDB::bind_method(D_METHOD("set_out_borders", "value"), &MMVoronoi::set_out_borders); + ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "out_borders", PROPERTY_HINT_RESOURCE_TYPE, "MMNodeUniversalProperty"), "set_out_borders", "get_out_borders"); - for (int x = 0; x < material.image_size.x; ++x) { //x in range(material.image_size.x) + ClassDB::bind_method(D_METHOD("get_out_random_color"), &MMVoronoi::get_out_random_color); + ClassDB::bind_method(D_METHOD("set_out_random_color", "value"), &MMVoronoi::set_out_random_color); + ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "out_random_color", PROPERTY_HINT_RESOURCE_TYPE, "MMNodeUniversalProperty"), "set_out_random_color", "get_out_random_color"); - for (int y = 0; y < material.image_size.y; ++y) { //y in range(material.image_size.y) - Vector2 uv = Vector2(x / w, y / h); - float ps = 1.0 / float(pseed); - //vec4 $(name_uv)_xyzw = voronoi($uv, vec2($scale_x, $scale_y), vec2($stretch_y, $stretch_x), $intensity, $randomness, $seed); - Color voronoi = MMAlgos.voronoi(uv, scale, stretch, intensity, randomness, ps); - //Nodes - float - A greyscale pattern based on the distance to cell centers; - //$(name_uv)_xyzw.z; - Color nodes_col = Color(voronoi.b, voronoi.b, voronoi.b, 1); - //Borders - float - A greyscale pattern based on the distance to borders; - //$(name_uv)_xyzw.w; - Color borders_col = Color(voronoi.a, voronoi.a, voronoi.a, 1); - //Random color - rgb - A color pattern that assigns a random color to each cell; - //rand3(fract(floor($(name_uv)_xyzw.xy)/vec2($scale_x, $scale_y))); - Vector3 rv3 = MMAlgos.rand3(MMAlgos.fractv2(Vector2(voronoi.r, voronoi.g) / scale)); - Color random_color_col = Color(rv3.x, rv3.y, rv3.z, 1); - //Fill - rgba - An output that should be plugged into a Fill companion node; - //vec4(fract(($(name_uv)_xyzw.xy-1.0)/vec2($scale_x, $scale_y)), vec2(2.0)/vec2($scale_x, $scale_y)); - Vector2 fv21 = MMAlgos.fractv2((Vector2(voronoi.r, voronoi.g) - Vector2(1, 1)) / scale); - Vector2 fv22 = Vector2(2, 2) / scale; - Color fill_col = Color(fv21.x, fv21.y, fv22.x, fv22.y); - nodes.set_pixel(x, y, nodes_col); - borders.set_pixel(x, y, borders_col); - random_color.set_pixel(x, y, random_color_col); - fill.set_pixel(x, y, fill_col); + ClassDB::bind_method(D_METHOD("get_out_fill"), &MMVoronoi::get_out_fill); + ClassDB::bind_method(D_METHOD("set_out_fill", "value"), &MMVoronoi::set_out_fill); + ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "out_fill", PROPERTY_HINT_RESOURCE_TYPE, "MMNodeUniversalProperty"), "set_out_fill", "get_out_fill"); + + ClassDB::bind_method(D_METHOD("get_scale"), &MMVoronoi::get_scale); + ClassDB::bind_method(D_METHOD("set_scale", "value"), &MMVoronoi::set_scale); + ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "scale"), "set_scale", "get_scale"); + + ClassDB::bind_method(D_METHOD("get_stretch"), &MMVoronoi::get_stretch); + ClassDB::bind_method(D_METHOD("set_stretch", "value"), &MMVoronoi::set_stretch); + ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "stretch"), "set_stretch", "get_stretch"); + + ClassDB::bind_method(D_METHOD("get_intensity"), &MMVoronoi::get_intensity); + ClassDB::bind_method(D_METHOD("set_intensity", "value"), &MMVoronoi::set_intensity); + ADD_PROPERTY(PropertyInfo(Variant::REAL, "intensity"), "set_intensity", "get_intensity"); + + ClassDB::bind_method(D_METHOD("get_randomness"), &MMVoronoi::get_randomness); + ClassDB::bind_method(D_METHOD("set_randomness", "value"), &MMVoronoi::set_randomness); + ADD_PROPERTY(PropertyInfo(Variant::REAL, "randomness"), "set_randomness", "get_randomness"); } - -} - - nodes.unlock(); - borders.unlock(); - random_color.unlock(); - fill.unlock(); - out_nodes.set_value(nodes); - out_borders.set_value(borders); - out_random_color.set_value(random_color); - out_fill.set_value(fill); -} - - - Color Voronoi::_get_value_for(const Vector2 &uv, const int pseed) { - return Color(); -} - - //scale; - - Vector2 Voronoi::get_scale() { - return scale; -} - - - void Voronoi::set_scale(const Vector2 &val) { - scale = val; - set_dirty(true); -} - - //stretch; - - Vector2 Voronoi::get_stretch() { - return stretch; -} - - - void Voronoi::set_stretch(const Vector2 &val) { - stretch = val; - set_dirty(true); -} - - //intensity; - - float Voronoi::get_intensity() { - return intensity; -} - - - void Voronoi::set_intensity(const float val) { - intensity = val; - set_dirty(true); -} - - //randomness; - - float Voronoi::get_randomness() { - return randomness; -} - - - void Voronoi::set_randomness(const float val) { - randomness = val; - set_dirty(true); -} - -} - - Voronoi::Voronoi() { - out_nodes; - out_borders; - out_random_color; - out_fill; - scale = Vector2(4, 4); - stretch = Vector2(1, 1); - intensity = 1; - randomness = 0.85; - } - - Voronoi::~Voronoi() { - } - - - static void Voronoi::_bind_methods() { - ClassDB::bind_method(D_METHOD("get_out_nodes"), &Voronoi::get_out_nodes); - ClassDB::bind_method(D_METHOD("set_out_nodes", "value"), &Voronoi::set_out_nodes); - ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "out_nodes", PROPERTY_HINT_RESOURCE_TYPE, "Ref"), "set_out_nodes", "get_out_nodes"); - - - ClassDB::bind_method(D_METHOD("get_out_borders"), &Voronoi::get_out_borders); - ClassDB::bind_method(D_METHOD("set_out_borders", "value"), &Voronoi::set_out_borders); - ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "out_borders", PROPERTY_HINT_RESOURCE_TYPE, "Ref"), "set_out_borders", "get_out_borders"); - - - ClassDB::bind_method(D_METHOD("get_out_random_color"), &Voronoi::get_out_random_color); - ClassDB::bind_method(D_METHOD("set_out_random_color", "value"), &Voronoi::set_out_random_color); - ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "out_random_color", PROPERTY_HINT_RESOURCE_TYPE, "Ref"), "set_out_random_color", "get_out_random_color"); - - - ClassDB::bind_method(D_METHOD("get_out_fill"), &Voronoi::get_out_fill); - ClassDB::bind_method(D_METHOD("set_out_fill", "value"), &Voronoi::set_out_fill); - ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "out_fill", PROPERTY_HINT_RESOURCE_TYPE, "Ref"), "set_out_fill", "get_out_fill"); - - - ClassDB::bind_method(D_METHOD("get_scale"), &Voronoi::get_scale); - ClassDB::bind_method(D_METHOD("set_scale", "value"), &Voronoi::set_scale); - ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "scale"), "set_scale", "get_scale"); - - - ClassDB::bind_method(D_METHOD("get_stretch"), &Voronoi::get_stretch); - ClassDB::bind_method(D_METHOD("set_stretch", "value"), &Voronoi::set_stretch); - ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "stretch"), "set_stretch", "get_stretch"); - - - ClassDB::bind_method(D_METHOD("get_intensity"), &Voronoi::get_intensity); - ClassDB::bind_method(D_METHOD("set_intensity", "value"), &Voronoi::set_intensity); - ADD_PROPERTY(PropertyInfo(Variant::REAL, "intensity"), "set_intensity", "get_intensity"); - - - ClassDB::bind_method(D_METHOD("get_randomness"), &Voronoi::get_randomness); - ClassDB::bind_method(D_METHOD("set_randomness", "value"), &Voronoi::set_randomness); - ADD_PROPERTY(PropertyInfo(Variant::REAL, "randomness"), "set_randomness", "get_randomness"); - - - ClassDB::bind_method(D_METHOD("_init_properties"), &Voronoi::_init_properties); - ClassDB::bind_method(D_METHOD("_register_methods", "mm_graph_node"), &Voronoi::_register_methods); - ClassDB::bind_method(D_METHOD("_render", "material"), &Voronoi::_render); - ClassDB::bind_method(D_METHOD("_get_value_for", "uv", "pseed"), &Voronoi::_get_value_for); - ClassDB::bind_method(D_METHOD("get_scale"), &Voronoi::get_scale); - ClassDB::bind_method(D_METHOD("set_scale", "val"), &Voronoi::set_scale); - ClassDB::bind_method(D_METHOD("get_stretch"), &Voronoi::get_stretch); - ClassDB::bind_method(D_METHOD("set_stretch", "val"), &Voronoi::set_stretch); - ClassDB::bind_method(D_METHOD("get_intensity"), &Voronoi::get_intensity); - ClassDB::bind_method(D_METHOD("set_intensity", "val"), &Voronoi::set_intensity); - ClassDB::bind_method(D_METHOD("get_randomness"), &Voronoi::get_randomness); - ClassDB::bind_method(D_METHOD("set_randomness", "val"), &Voronoi::set_randomness); - - } - - - diff --git a/modules/material_maker/nodes/noise/voronoi.h b/modules/material_maker/nodes/noise/voronoi.h index e62b0c9b5..44ba4071c 100644 --- a/modules/material_maker/nodes/noise/voronoi.h +++ b/modules/material_maker/nodes/noise/voronoi.h @@ -1,77 +1,57 @@ -#ifndef VORONOI_H -#define VORONOI_H +#ifndef MM_VORONOI_H +#define MM_VORONOI_H +#include "../mm_node.h" +#include "../mm_node_universal_property.h" -class Voronoi : public MMNode { - GDCLASS(Voronoi, MMNode); +class MMVoronoi : public MMNode { + GDCLASS(MMVoronoi, MMNode); - public: +public: + Ref get_out_nodes(); + void set_out_nodes(const Ref &val); - Ref get_out_nodes(); - void set_out_nodes(const Ref &val); + Ref get_out_borders(); + void set_out_borders(const Ref &val); - Ref get_out_borders(); - void set_out_borders(const Ref &val); + Ref get_out_random_color(); + void set_out_random_color(const Ref &val); - Ref get_out_random_color(); - void set_out_random_color(const Ref &val); + Ref get_out_fill(); + void set_out_fill(const Ref &val); - Ref get_out_fill(); - void set_out_fill(const Ref &val); + Vector2 get_scale(); + void set_scale(const Vector2 &val); - Vector2 get_scale(); - void set_scale(const Vector2 &val); + Vector2 get_stretch(); + void set_stretch(const Vector2 &val); - Vector2 get_stretch(); - void set_stretch(const Vector2 &val); + float get_intensity() const; + void set_intensity(const float val); - float get_intensity() const; - void set_intensity(const float val); + float get_randomness() const; + void set_randomness(const float val); - float get_randomness() const; - void set_randomness(const float val); + void _init_properties(); + void _register_methods(MMGraphNode *mm_graph_node); + void _render(const Ref &material); - void _init_properties(); - void _register_methods(const Variant &mm_graph_node); - void _render(const Variant &material); - Color _get_value_for(const Vector2 &uv, const int pseed); - Vector2 get_scale(); - void set_scale(const Vector2 &val); - Vector2 get_stretch(); - void set_stretch(const Vector2 &val); - float get_intensity(); - void set_intensity(const float val); - float get_randomness(); - void set_randomness(const float val); + Color _get_value_for(const Vector2 &uv, const int pseed); - Voronoi(); - ~Voronoi(); + MMVoronoi(); + ~MMVoronoi(); - protected: - static void _bind_methods(); +protected: + static void _bind_methods(); - //tool - //export(Resource) - Ref out_nodes; - //export(Resource) - Ref out_borders; - //export(Resource) - Ref out_random_color; - //export(Resource) - Ref out_fill; - //export(Vector2) - Vector2 scale = Vector2(4, 4); - //export(Vector2) - Vector2 stretch = Vector2(1, 1); - //export(float) - float intensity = 1; - //export(float) - float randomness = 0.85; - //scale - //stretch - //intensity - //randomness + Ref out_nodes; + Ref out_borders; + Ref out_random_color; + Ref out_fill; + Vector2 scale; + Vector2 stretch; + float intensity; + float randomness; }; - #endif diff --git a/modules/material_maker/register_types.cpp b/modules/material_maker/register_types.cpp index 8ef92304c..2c1c642ad 100644 --- a/modules/material_maker/register_types.cpp +++ b/modules/material_maker/register_types.cpp @@ -119,6 +119,13 @@ SOFTWARE. #include "nodes/other/output_image.h" +#include "nodes/noise/anisotropic_noise.h" +#include "nodes/noise/color_noise.h" +#include "nodes/noise/color_value.h" +#include "nodes/noise/fbm_noise.h" +#include "nodes/noise/noise.h" +#include "nodes/noise/voronoi.h" + static _MMAlgos *_mm_algos_singleton = nullptr; void register_material_maker_types() { @@ -272,6 +279,19 @@ void register_material_maker_types() { ClassDB::register_class(); MMAlgos::register_node_class("Output", "MMOutputImage"); + ClassDB::register_class(); + MMAlgos::register_node_class("Noise", "MMVoronoi"); + ClassDB::register_class(); + MMAlgos::register_node_class("Noise", "MMNoise"); + ClassDB::register_class(); + MMAlgos::register_node_class("Noise", "MMFbmNoise"); + ClassDB::register_class(); + MMAlgos::register_node_class("Noise", "MMColorValue"); + ClassDB::register_class(); + MMAlgos::register_node_class("Noise", "MMColorNoise"); + ClassDB::register_class(); + MMAlgos::register_node_class("Noise", "MMAnisotropicNoise"); + _mm_algos_singleton = memnew(_MMAlgos); Engine::get_singleton()->add_singleton(Engine::Singleton("MMAlgos", _MMAlgos::get_singleton()));