diff --git a/modules/material_maker/nodes/filter/adjust_hsv.cpp b/modules/material_maker/nodes/filter/adjust_hsv.cpp new file mode 100644 index 000000000..dbbdf4f7a --- /dev/null +++ b/modules/material_maker/nodes/filter/adjust_hsv.cpp @@ -0,0 +1,197 @@ + +#include "adjust_hsv.h" + + +Ref AdjustHsv::get_image() { + return image; +} + +void AdjustHsv::set_image(const Ref &val) { +image = val; +} + + +Ref AdjustHsv::get_input() { + return input; +} + +void AdjustHsv::set_input(const Ref &val) { +input = val; +} + + +float AdjustHsv::get_hue() const { + return hue; +} + +void AdjustHsv::set_hue(const float val) { +hue = val; +} + + +float AdjustHsv::get_saturation() const { + return saturation; +} + +void AdjustHsv::set_saturation(const float val) { +saturation = val; +} + + +float AdjustHsv::get_value() const { + return value; +} + +void AdjustHsv::set_value(const float val) { +value = val; +} + + + + //tool; + //export(Resource) ; + Ref image; + //export(Resource) ; + Ref input; + //export(float) ; + float hue = 0; + //export(float) ; + float saturation = 1; + //export(float) ; + float value = 1; + + void AdjustHsv::_init_properties() { + + if (!input) { + input = MMNodeUniversalProperty.new(); + input.default_type = MMNodeUniversalProperty.DEFAULT_TYPE_COLOR; + input.set_default_value(Color(0, 0, 0, 1)); +} + + input.input_slot_type = MMNodeUniversalProperty.SLOT_TYPE_UNIVERSAL; + input.slot_name = ">>> Input1 "; + + if (!image) { + image = MMNodeUniversalProperty.new(); + image.default_type = MMNodeUniversalProperty.DEFAULT_TYPE_IMAGE; +} + + //image.input_slot_type = MMNodeUniversalProperty.SLOT_TYPE_FLOAT; + image.output_slot_type = MMNodeUniversalProperty.SLOT_TYPE_IMAGE; + //image.force_override = true; + register_input_property(input); + register_output_property(image); +} + + + void AdjustHsv::_register_methods(const Variant &mm_graph_node) { + mm_graph_node.add_slot_label_universal(input); + mm_graph_node.add_slot_texture_universal(image); + mm_graph_node.add_slot_float("get_hue", "set_hue", "Hue", 0.01); + mm_graph_node.add_slot_float("get_saturation", "set_saturation", "Saturation", 0.01); + mm_graph_node.add_slot_float("get_value", "set_value", "Value", 0.01); +} + + + void AdjustHsv::_render(const Variant &material) { + Ref img = render_image(material); + image.set_value(img); +} + + + Color AdjustHsv::_get_value_for(const Vector2 &uv, const int pseed) { + Color c = input.get_value(uv); + return MMAlgos.adjust_hsv(c, hue, saturation, value); +} + + //hue; + + float AdjustHsv::get_hue() { + return hue; +} + + + void AdjustHsv::set_hue(const float val) { + hue = val; + set_dirty(true); +} + + //saturation; + + float AdjustHsv::get_saturation() { + return saturation; +} + + + void AdjustHsv::set_saturation(const float val) { + saturation = val; + set_dirty(true); +} + + //value; + + float AdjustHsv::get_value() { + return value; +} + + + void AdjustHsv::set_value(const float val) { + value = val; + set_dirty(true); +} + +} + + AdjustHsv::AdjustHsv() { + image; + input; + hue = 0; + saturation = 1; + value = 1; + } + + AdjustHsv::~AdjustHsv() { + } + + + static void AdjustHsv::_bind_methods() { + ClassDB::bind_method(D_METHOD("get_image"), &AdjustHsv::get_image); + ClassDB::bind_method(D_METHOD("set_image", "value"), &AdjustHsv::set_image); + ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "image", PROPERTY_HINT_RESOURCE_TYPE, "Ref"), "set_image", "get_image"); + + + ClassDB::bind_method(D_METHOD("get_input"), &AdjustHsv::get_input); + ClassDB::bind_method(D_METHOD("set_input", "value"), &AdjustHsv::set_input); + ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "input", PROPERTY_HINT_RESOURCE_TYPE, "Ref"), "set_input", "get_input"); + + + ClassDB::bind_method(D_METHOD("get_hue"), &AdjustHsv::get_hue); + ClassDB::bind_method(D_METHOD("set_hue", "value"), &AdjustHsv::set_hue); + ADD_PROPERTY(PropertyInfo(Variant::REAL, "hue"), "set_hue", "get_hue"); + + + ClassDB::bind_method(D_METHOD("get_saturation"), &AdjustHsv::get_saturation); + ClassDB::bind_method(D_METHOD("set_saturation", "value"), &AdjustHsv::set_saturation); + ADD_PROPERTY(PropertyInfo(Variant::REAL, "saturation"), "set_saturation", "get_saturation"); + + + ClassDB::bind_method(D_METHOD("get_value"), &AdjustHsv::get_value); + ClassDB::bind_method(D_METHOD("set_value", "value"), &AdjustHsv::set_value); + ADD_PROPERTY(PropertyInfo(Variant::REAL, "value"), "set_value", "get_value"); + + + ClassDB::bind_method(D_METHOD("_init_properties"), &AdjustHsv::_init_properties); + ClassDB::bind_method(D_METHOD("_register_methods", "mm_graph_node"), &AdjustHsv::_register_methods); + ClassDB::bind_method(D_METHOD("_render", "material"), &AdjustHsv::_render); + ClassDB::bind_method(D_METHOD("_get_value_for", "uv", "pseed"), &AdjustHsv::_get_value_for); + ClassDB::bind_method(D_METHOD("get_hue"), &AdjustHsv::get_hue); + ClassDB::bind_method(D_METHOD("set_hue", "val"), &AdjustHsv::set_hue); + ClassDB::bind_method(D_METHOD("get_saturation"), &AdjustHsv::get_saturation); + ClassDB::bind_method(D_METHOD("set_saturation", "val"), &AdjustHsv::set_saturation); + ClassDB::bind_method(D_METHOD("get_value"), &AdjustHsv::get_value); + ClassDB::bind_method(D_METHOD("set_value", "val"), &AdjustHsv::set_value); + + } + + + diff --git a/modules/material_maker/nodes/filter/adjust_hsv.h b/modules/material_maker/nodes/filter/adjust_hsv.h new file mode 100644 index 000000000..3c971e773 --- /dev/null +++ b/modules/material_maker/nodes/filter/adjust_hsv.h @@ -0,0 +1,59 @@ +#ifndef ADJUST_HSV_H +#define ADJUST_HSV_H + + +class AdjustHsv : public MMNode { + GDCLASS(AdjustHsv, MMNode); + + public: + + Ref get_image(); + void set_image(const Ref &val); + + Ref get_input(); + void set_input(const Ref &val); + + float get_hue() const; + void set_hue(const float val); + + float get_saturation() const; + void set_saturation(const float val); + + float get_value() const; + void set_value(const float val); + + 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); + float get_hue(); + void set_hue(const float val); + float get_saturation(); + void set_saturation(const float val); + float get_value(); + void set_value(const float val); + + AdjustHsv(); + ~AdjustHsv(); + + protected: + static void _bind_methods(); + + //tool + //export(Resource) + Ref image; + //export(Resource) + Ref input; + //export(float) + float hue = 0; + //export(float) + float saturation = 1; + //export(float) + float value = 1; + //hue + //saturation + //value +}; + + +#endif diff --git a/modules/material_maker/nodes/filter/blend.cpp b/modules/material_maker/nodes/filter/blend.cpp new file mode 100644 index 000000000..d10705c70 --- /dev/null +++ b/modules/material_maker/nodes/filter/blend.cpp @@ -0,0 +1,257 @@ + +#include "blend.h" + + +Ref Blend::get_image() { + return image; +} + +void Blend::set_image(const Ref &val) { +image = val; +} + + +Ref Blend::get_input1() { + return input1; +} + +void Blend::set_input1(const Ref &val) { +input1 = val; +} + + +Ref Blend::get_input2() { + return input2; +} + +void Blend::set_input2(const Ref &val) { +input2 = val; +} + + +int Blend::get_blend_type() const { + return blend_type; +} + +void Blend::set_blend_type(const int val) { +blend_type = val; +} + + +Ref Blend::get_opacity() { + return opacity; +} + +void Blend::set_opacity(const Ref &val) { +opacity = val; +} + + + + //tool; + }; + //export(Resource) ; + Ref image; + //export(Resource) ; + Ref input1; + //export(Resource) ; + Ref input2; + //export(int, "Normal,Dissolve,Multiply,Screen,Overlay,Hard Light,Soft Light,Burn,Dodge,Lighten,Darken,Difference") ; + int blend_type = 0; + //export(Resource) ; + Ref opacity; + + void Blend::_init_properties() { + + if (!image) { + image = MMNodeUniversalProperty.new(); + image.default_type = MMNodeUniversalProperty.DEFAULT_TYPE_IMAGE; +} + + image.output_slot_type = MMNodeUniversalProperty.SLOT_TYPE_IMAGE; + + if (!input1) { + input1 = MMNodeUniversalProperty.new(); + input1.default_type = MMNodeUniversalProperty.DEFAULT_TYPE_COLOR; + input1.set_default_value(Color(1, 1, 1, 1)); +} + + input1.input_slot_type = MMNodeUniversalProperty.SLOT_TYPE_UNIVERSAL; + input1.slot_name = ">>> Input1 "; + + if (!input2) { + input2 = MMNodeUniversalProperty.new(); + input2.default_type = MMNodeUniversalProperty.DEFAULT_TYPE_COLOR; + input2.set_default_value(Color(1, 1, 1, 1)); +} + + input2.input_slot_type = MMNodeUniversalProperty.SLOT_TYPE_UNIVERSAL; + input2.slot_name = ">>> Input2 "; + + if (!opacity) { + opacity = MMNodeUniversalProperty.new(); + opacity.default_type = MMNodeUniversalProperty.DEFAULT_TYPE_FLOAT; + opacity.set_default_value(0.5); + opacity.value_range = Vector2(0, 1); + opacity.value_step = 0.01; +} + + opacity.input_slot_type = MMNodeUniversalProperty.SLOT_TYPE_UNIVERSAL; + opacity.slot_name = "opacity"; + register_input_property(input1); + register_input_property(input2); + register_output_property(image); + register_input_property(opacity); +} + + + void Blend::_register_methods(const Variant &mm_graph_node) { + mm_graph_node.add_slot_texture_universal(image); + mm_graph_node.add_slot_enum("get_blend_type", "set_blend_type", "blend_type", [ "Normal", "Dissolve", "Multiply", "Screen", "Overlay", "Hard Light", "Soft Light", "Burn", "Dodge", "Lighten", "Darken", "Difference" ]); + mm_graph_node.add_slot_label_universal(input1); + mm_graph_node.add_slot_label_universal(input2); + mm_graph_node.add_slot_float_universal(opacity); +} + + + void Blend::_render(const Variant &material) { + Ref img = render_image(material); + image.set_value(img); +} + + + Color Blend::_get_value_for(const Vector2 &uv, const int pseed) { + Vector3 b = Vector3(); + //vec4 $(name_uv)_s1 = $s1($uv); + Color s1 = input1.get_value(uv); + //vec4 $(name_uv)_s2 = $s2($uv); + Color s2 = input2.get_value(uv); + //float $(name_uv)_a = $amount*$a($uv); + float a = opacity.get_value(uv); + //vec4(blend_$blend_type($uv, $(name_uv)_s1.rgb, $(name_uv)_s2.rgb, $(name_uv)_a*$(name_uv)_s1.a), min(1.0, $(name_uv)_s2.a+$(name_uv)_a*$(name_uv)_s1.a)); + //"Normal,Dissolve,Multiply,Screen,Overlay,Hard Light,Soft Light,Burn,Dodge,Lighten,Darken,Difference"; + + if (blend_type == BlendType.NORMAL) { + b = MMAlgos.blend_normal(uv, Vector3(s1.r, s1.g, s1.b), Vector3(s2.r, s2.g, s2.b), a * s1.a); +} + + + else if (blend_type == BlendType.DISSOLVE) { + b = MMAlgos.blend_dissolve(uv, Vector3(s1.r, s1.g, s1.b), Vector3(s2.r, s2.g, s2.b), a * s1.a); +} + + + else if (blend_type == BlendType.MULTIPLY) { + b = MMAlgos.blend_multiply(uv, Vector3(s1.r, s1.g, s1.b), Vector3(s2.r, s2.g, s2.b), a * s1.a); +} + + + else if (blend_type == BlendType.SCREEN) { + b = MMAlgos.blend_screen(uv, Vector3(s1.r, s1.g, s1.b), Vector3(s2.r, s2.g, s2.b), a * s1.a); +} + + + else if (blend_type == BlendType.OVERLAY) { + b = MMAlgos.blend_overlay(uv, Vector3(s1.r, s1.g, s1.b), Vector3(s2.r, s2.g, s2.b), a * s1.a); +} + + + else if (blend_type == BlendType.HARD_LIGHT) { + b = MMAlgos.blend_hard_light(uv, Vector3(s1.r, s1.g, s1.b), Vector3(s2.r, s2.g, s2.b), a * s1.a); +} + + + else if (blend_type == BlendType.SOFT_LIGHT) { + b = MMAlgos.blend_soft_light(uv, Vector3(s1.r, s1.g, s1.b), Vector3(s2.r, s2.g, s2.b), a * s1.a); +} + + + else if (blend_type == BlendType.BURN) { + b = MMAlgos.blend_burn(uv, Vector3(s1.r, s1.g, s1.b), Vector3(s2.r, s2.g, s2.b), a * s1.a); +} + + + else if (blend_type == BlendType.DODGE) { + b = MMAlgos.blend_dodge(uv, Vector3(s1.r, s1.g, s1.b), Vector3(s2.r, s2.g, s2.b), a * s1.a); +} + + + else if (blend_type == BlendType.LIGHTEN) { + b = MMAlgos.blend_lighten(uv, Vector3(s1.r, s1.g, s1.b), Vector3(s2.r, s2.g, s2.b), a * s1.a); +} + + + else if (blend_type == BlendType.DARKEN) { + b = MMAlgos.blend_darken(uv, Vector3(s1.r, s1.g, s1.b), Vector3(s2.r, s2.g, s2.b), a * s1.a); +} + + + else if (blend_type == BlendType.DIFFRENCE) { + b = MMAlgos.blend_difference(uv, Vector3(s1.r, s1.g, s1.b), Vector3(s2.r, s2.g, s2.b), a * s1.a); +} + + return Color(b.x, b.y, b.z, min(1, s2.a + a * s1.a)); +} + + + int Blend::get_blend_type() { + return blend_type; +} + + + void Blend::set_blend_type(const int val) { + blend_type = val; + set_dirty(true); +} + +} + + Blend::Blend() { + image; + input1; + input2; + blend_type = 0; + opacity; + } + + Blend::~Blend() { + } + + + static void Blend::_bind_methods() { + ClassDB::bind_method(D_METHOD("get_image"), &Blend::get_image); + ClassDB::bind_method(D_METHOD("set_image", "value"), &Blend::set_image); + ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "image", PROPERTY_HINT_RESOURCE_TYPE, "Ref"), "set_image", "get_image"); + + + ClassDB::bind_method(D_METHOD("get_input1"), &Blend::get_input1); + ClassDB::bind_method(D_METHOD("set_input1", "value"), &Blend::set_input1); + ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "input1", PROPERTY_HINT_RESOURCE_TYPE, "Ref"), "set_input1", "get_input1"); + + + ClassDB::bind_method(D_METHOD("get_input2"), &Blend::get_input2); + ClassDB::bind_method(D_METHOD("set_input2", "value"), &Blend::set_input2); + ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "input2", PROPERTY_HINT_RESOURCE_TYPE, "Ref"), "set_input2", "get_input2"); + + + ClassDB::bind_method(D_METHOD("get_blend_type"), &Blend::get_blend_type); + ClassDB::bind_method(D_METHOD("set_blend_type", "value"), &Blend::set_blend_type); + ADD_PROPERTY(PropertyInfo(Variant::INT, "blend_type"), "set_blend_type", "get_blend_type"); + + + ClassDB::bind_method(D_METHOD("get_opacity"), &Blend::get_opacity); + ClassDB::bind_method(D_METHOD("set_opacity", "value"), &Blend::set_opacity); + ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "opacity", PROPERTY_HINT_RESOURCE_TYPE, "Ref"), "set_opacity", "get_opacity"); + + + ClassDB::bind_method(D_METHOD("_init_properties"), &Blend::_init_properties); + ClassDB::bind_method(D_METHOD("_register_methods", "mm_graph_node"), &Blend::_register_methods); + ClassDB::bind_method(D_METHOD("_render", "material"), &Blend::_render); + ClassDB::bind_method(D_METHOD("_get_value_for", "uv", "pseed"), &Blend::_get_value_for); + ClassDB::bind_method(D_METHOD("get_blend_type"), &Blend::get_blend_type); + ClassDB::bind_method(D_METHOD("set_blend_type", "val"), &Blend::set_blend_type); + + } + + + diff --git a/modules/material_maker/nodes/filter/blend.h b/modules/material_maker/nodes/filter/blend.h new file mode 100644 index 000000000..6d322b95b --- /dev/null +++ b/modules/material_maker/nodes/filter/blend.h @@ -0,0 +1,69 @@ +#ifndef BLEND_H +#define BLEND_H + + +class Blend : public MMNode { + GDCLASS(Blend, MMNode); + + public: + + Ref get_image(); + void set_image(const Ref &val); + + Ref get_input1(); + void set_input1(const Ref &val); + + Ref get_input2(); + void set_input2(const Ref &val); + + int get_blend_type() const; + void set_blend_type(const int val); + + Ref get_opacity(); + void set_opacity(const Ref &val); + + enum BlendType { + + NORMAL = 0, + DISSOLVE, + MULTIPLY, + SCREEN, + OVERLAY, + HARD_LIGHT, + SOFT_LIGHT, + BURN, + DODGE, + LIGHTEN, + DARKEN, + DIFFRENCE +}; + + 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); + int get_blend_type(); + void set_blend_type(const int val); + + Blend(); + ~Blend(); + + protected: + static void _bind_methods(); + + //tool + }; + //export(Resource) + Ref image; + //export(Resource) + Ref input1; + //export(Resource) + Ref input2; + //export(int, "Normal,Dissolve,Multiply,Screen,Overlay,Hard Light,Soft Light,Burn,Dodge,Lighten,Darken,Difference") + int blend_type = 0; + //export(Resource) + Ref opacity; +}; + + +#endif diff --git a/modules/material_maker/nodes/filter/blur_gaussian.cpp b/modules/material_maker/nodes/filter/blur_gaussian.cpp new file mode 100644 index 000000000..0957687e1 --- /dev/null +++ b/modules/material_maker/nodes/filter/blur_gaussian.cpp @@ -0,0 +1,362 @@ + +#include "blur_gaussian.h" + + +Ref BlurGaussian::get_image() { + return image; +} + +void BlurGaussian::set_image(const Ref &val) { +image = val; +} + + +Ref BlurGaussian::get_input() { + return input; +} + +void BlurGaussian::set_input(const Ref &val) { +input = val; +} + + +Ref BlurGaussian::get_sigma() { + return sigma; +} + +void BlurGaussian::set_sigma(const Ref &val) { +sigma = val; +} + + +int BlurGaussian::get_direction() const { + return direction; +} + +void BlurGaussian::set_direction(const int val) { +direction = val; +} + + +int BlurGaussian::get_size() const { + return size; +} + +void BlurGaussian::set_size(const int val) { +size = val; +} + + + + //tool; + //export(Resource) ; + Ref image; + //export(Resource) ; + Ref input; + //export(Resource) ; + Ref sigma; + //export(int, "Both,X,Y") ; + int direction = 0; + int size = 0; + + void BlurGaussian::_init_properties() { + + if (!image) { + image = MMNodeUniversalProperty.new(); + image.default_type = MMNodeUniversalProperty.DEFAULT_TYPE_IMAGE; +} + + image.output_slot_type = MMNodeUniversalProperty.SLOT_TYPE_IMAGE; + + if (!input) { + input = MMNodeUniversalProperty.new(); + input.default_type = MMNodeUniversalProperty.DEFAULT_TYPE_COLOR; + input.set_default_value(Color()); +} + + input.input_slot_type = MMNodeUniversalProperty.SLOT_TYPE_UNIVERSAL; + input.slot_name = ">>> Input1 "; + + if (!sigma) { + sigma = MMNodeUniversalProperty.new(); + sigma.default_type = MMNodeUniversalProperty.DEFAULT_TYPE_FLOAT; + sigma.set_default_value(50); +} + + sigma.input_slot_type = MMNodeUniversalProperty.SLOT_TYPE_UNIVERSAL; + sigma.slot_name = "Sigma"; + register_input_property(input); + register_output_property(image); + register_input_property(sigma); +} + + + void BlurGaussian::_register_methods(const Variant &mm_graph_node) { + mm_graph_node.add_slot_texture_universal(image); + mm_graph_node.add_slot_label_universal(input); + mm_graph_node.add_slot_int_universal(sigma); + mm_graph_node.add_slot_enum("get_direction", "set_direction", "Direction", [ "Both", "X", "Y" ]); +} + + + void BlurGaussian::_render(const Variant &material) { + size = max(material.image_size.x, material.image_size.y); + Ref img = render_image(material); + image.set_value(img); +} + + + Image BlurGaussian::_render_image(const Variant &material) { + Ref img = Image.new(); + img.create(material.image_size.x, material.image_size.y, false, Image.FORMAT_RGBA8); + img.lock(); + float w = img.get_width(); + float h = img.get_width(); + float pseed = randf() + randi(); + + if (direction == 0) { + + for (int x = 0; x < img.get_width(); ++x) { //x in range(img.get_width()) + + for (int y = 0; y < img.get_height(); ++y) { //y in range(img.get_height()) + Vector2 v = Vector2(x / w, y / h); + Color col = get_value_x(v, pseed); + img.set_pixel(x, y, col); +} + +} + + img.unlock(); + image.set_value(img); + Ref image2 = Image.new(); + image2.create(material.image_size.x, material.image_size.y, false, Image.FORMAT_RGBA8); + image2.lock(); + + for (int x = 0; x < img.get_width(); ++x) { //x in range(img.get_width()) + + for (int y = 0; y < img.get_height(); ++y) { //y in range(img.get_height()) + Vector2 v = Vector2(x / w, y / h); + Color col = get_value_y_img(v, pseed); + image2.set_pixel(x, y, col); +} + +} + + image2.unlock(); + return image2; +} + + + if (direction == 1) { + + for (int x = 0; x < img.get_width(); ++x) { //x in range(img.get_width()) + + for (int y = 0; y < img.get_height(); ++y) { //y in range(img.get_height()) + Vector2 v = Vector2(x / w, y / h); + Color col = get_value_x(v, pseed); + img.set_pixel(x, y, col); +} + +} + +} + + + if (direction == 2) { + + for (int x = 0; x < img.get_width(); ++x) { //x in range(img.get_width()) + + for (int y = 0; y < img.get_height(); ++y) { //y in range(img.get_height()) + Vector2 v = Vector2(x / w, y / h); + Color col = get_value_y(v, pseed); + img.set_pixel(x, y, col); +} + +} + +} + + img.unlock(); + return img; +} + + + Color BlurGaussian::get_value_x(const Vector2 &uv, const int pseed) { + float sig_def = sigma.get_default_value(uv); + float sig = sigma.get_value(uv); + return gaussian_blur_x(uv, size, sig_def, sig); +} + + + Color BlurGaussian::get_value_y(const Vector2 &uv, const int pseed) { + float sig_def = sigma.get_default_value(uv); + float sig = sigma.get_value(uv); + return gaussian_blur_y(uv, size, sig_def, sig); +} + + + Color BlurGaussian::get_value_y_img(const Vector2 &uv, const int pseed) { + float sig_def = sigma.get_default_value(uv); + float sig = sigma.get_value(uv); + return gaussian_blur_y_img(uv, size, sig_def, sig); +} + + + int BlurGaussian::get_direction() { + return direction; +} + + + void BlurGaussian::set_direction(const int val) { + direction = val; + set_dirty(true); +} + + //----------------------; + //gaussian_blur_x.mmg; + //vec4 $(name)_fct(vec2 uv) {; + // float e = 1.0 / $size; + // vec4 rv = vec4(0.0); + // float sum = 0.0; + // float sigma = max(0.000001, $sigma * $amount(uv)); + //; + // for (float i = -50.0; i <= 50.0; i += 1.0) {; + // float coef = exp(-0.5 * (pow(i / sigma, 2.0))) / (6.28318530718 * sigma * sigma); + // rv += $in(uv+vec2(i*e, 0.0))*coef; + // sum += coef; + // }; + //; + // return rv/sum; + //}; + + Color BlurGaussian::gaussian_blur_x(const Vector2 &uv, const float psize, const float psigma, const float pamount) { + float e = 1.0 / psize; + Color rv = Color(); + float sum = 0.0; + //pamount(uv)); + float sigma = max(0.000001, psigma * pamount); + float i = -50; + //for (float i = -50.0; i <= 50.0; i += 1.0) {; + + while (i <= 50) { + float coef = exp(-0.5 * (pow(i / sigma, 2.0))) / (6.28318530718 * sigma * sigma); + rv += input.get_value(uv + Vector2(i*e, 0.0)) * coef; + sum += coef; + i += 1; +} + + return rv / sum; +} + + //----------------------; + //gaussian_blur_y.mmg; + //vec4 $(name)_fct(vec2 uv) {; + // float e = 1.0/$size; + // vec4 rv = vec4(0.0); + // float sum = 0.0; + // float sigma = max(0.000001, $sigma*$amount(uv)); + // for (float i = -50.0; i <= 50.0; i += 1.0) {; + // float coef = exp(-0.5 * (pow(i / sigma, 2.0))) / (6.28318530718*sigma*sigma); + // rv += $in(uv+vec2(0.0, i*e))*coef; + // sum += coef; + // }; + //; + // return rv/sum; + //}; + + Color BlurGaussian::gaussian_blur_y(const Vector2 &uv, const float psize, const float psigma, const float pamount) { + float e = 1.0 / psize; + Color rv = Color(); + float sum = 0.0; + //pamount(uv)); + float sigma = max(0.000001, psigma * pamount); + float i = -50; + //for (float i = -50.0; i <= 50.0; i += 1.0) {; + + while (i <= 50) { + float coef = exp(-0.5 * (pow(i / sigma, 2.0))) / (6.28318530718 * sigma * sigma); + rv += input.get_value(uv + Vector2(0.0, i * e)) * coef; + sum += coef; + i += 1; +} + + return rv / sum; +} + + + Color BlurGaussian::gaussian_blur_y_img(const Vector2 &uv, const float psize, const float psigma, const float pamount) { + float e = 1.0 / psize; + Color rv = Color(); + float sum = 0.0; + //pamount(uv)); + float sigma = max(0.000001, psigma * pamount); + float i = -50; + //for (float i = -50.0; i <= 50.0; i += 1.0) {; + + while (i <= 50) { + float coef = exp(-0.5 * (pow(i / sigma, 2.0))) / (6.28318530718 * sigma * sigma); + rv += image.get_value(uv + Vector2(0.0, i * e)) * coef; + sum += coef; + i += 1; +} + + return rv / sum; +} + +} + + BlurGaussian::BlurGaussian() { + image; + input; + sigma; + direction = 0; + size = 0; + } + + BlurGaussian::~BlurGaussian() { + } + + + static void BlurGaussian::_bind_methods() { + ClassDB::bind_method(D_METHOD("get_image"), &BlurGaussian::get_image); + ClassDB::bind_method(D_METHOD("set_image", "value"), &BlurGaussian::set_image); + ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "image", PROPERTY_HINT_RESOURCE_TYPE, "Ref"), "set_image", "get_image"); + + + ClassDB::bind_method(D_METHOD("get_input"), &BlurGaussian::get_input); + ClassDB::bind_method(D_METHOD("set_input", "value"), &BlurGaussian::set_input); + ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "input", PROPERTY_HINT_RESOURCE_TYPE, "Ref"), "set_input", "get_input"); + + + ClassDB::bind_method(D_METHOD("get_sigma"), &BlurGaussian::get_sigma); + ClassDB::bind_method(D_METHOD("set_sigma", "value"), &BlurGaussian::set_sigma); + ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "sigma", PROPERTY_HINT_RESOURCE_TYPE, "Ref"), "set_sigma", "get_sigma"); + + + ClassDB::bind_method(D_METHOD("get_direction"), &BlurGaussian::get_direction); + ClassDB::bind_method(D_METHOD("set_direction", "value"), &BlurGaussian::set_direction); + ADD_PROPERTY(PropertyInfo(Variant::INT, "direction"), "set_direction", "get_direction"); + + + ClassDB::bind_method(D_METHOD("get_size"), &BlurGaussian::get_size); + ClassDB::bind_method(D_METHOD("set_size", "value"), &BlurGaussian::set_size); + ADD_PROPERTY(PropertyInfo(Variant::INT, "size"), "set_size", "get_size"); + + + ClassDB::bind_method(D_METHOD("_init_properties"), &BlurGaussian::_init_properties); + ClassDB::bind_method(D_METHOD("_register_methods", "mm_graph_node"), &BlurGaussian::_register_methods); + ClassDB::bind_method(D_METHOD("_render", "material"), &BlurGaussian::_render); + ClassDB::bind_method(D_METHOD("_render_image", "material"), &BlurGaussian::_render_image); + ClassDB::bind_method(D_METHOD("get_value_x", "uv", "pseed"), &BlurGaussian::get_value_x); + ClassDB::bind_method(D_METHOD("get_value_y", "uv", "pseed"), &BlurGaussian::get_value_y); + ClassDB::bind_method(D_METHOD("get_value_y_img", "uv", "pseed"), &BlurGaussian::get_value_y_img); + ClassDB::bind_method(D_METHOD("get_direction"), &BlurGaussian::get_direction); + ClassDB::bind_method(D_METHOD("set_direction", "val"), &BlurGaussian::set_direction); + ClassDB::bind_method(D_METHOD("gaussian_blur_x", "uv", "psize", "psigma", "pamount"), &BlurGaussian::gaussian_blur_x); + ClassDB::bind_method(D_METHOD("gaussian_blur_y", "uv", "psize", "psigma", "pamount"), &BlurGaussian::gaussian_blur_y); + ClassDB::bind_method(D_METHOD("gaussian_blur_y_img", "uv", "psize", "psigma", "pamount"), &BlurGaussian::gaussian_blur_y_img); + + } + + + diff --git a/modules/material_maker/nodes/filter/blur_gaussian.h b/modules/material_maker/nodes/filter/blur_gaussian.h new file mode 100644 index 000000000..49f5bcba3 --- /dev/null +++ b/modules/material_maker/nodes/filter/blur_gaussian.h @@ -0,0 +1,88 @@ +#ifndef BLUR_GAUSSIAN_H +#define BLUR_GAUSSIAN_H + + +class BlurGaussian : public MMNode { + GDCLASS(BlurGaussian, MMNode); + + public: + + Ref get_image(); + void set_image(const Ref &val); + + Ref get_input(); + void set_input(const Ref &val); + + Ref get_sigma(); + void set_sigma(const Ref &val); + + int get_direction() const; + void set_direction(const int val); + + int get_size() const; + void set_size(const int val); + + void _init_properties(); + void _register_methods(const Variant &mm_graph_node); + void _render(const Variant &material); + Image _render_image(const Variant &material); + Color get_value_x(const Vector2 &uv, const int pseed); + Color get_value_y(const Vector2 &uv, const int pseed); + Color get_value_y_img(const Vector2 &uv, const int pseed); + int get_direction(); + void set_direction(const int val); + Color gaussian_blur_x(const Vector2 &uv, const float psize, const float psigma, const float pamount); + Color gaussian_blur_y(const Vector2 &uv, const float psize, const float psigma, const float pamount); + Color gaussian_blur_y_img(const Vector2 &uv, const float psize, const float psigma, const float pamount); + + BlurGaussian(); + ~BlurGaussian(); + + protected: + static void _bind_methods(); + + //tool + //export(Resource) + Ref image; + //export(Resource) + Ref input; + //export(Resource) + Ref sigma; + //export(int, "Both,X,Y") + int direction = 0; + int size = 0; + //---------------------- + //gaussian_blur_x.mmg + //vec4 $(name)_fct(vec2 uv) { + // float e = 1.0 / $size; + // vec4 rv = vec4(0.0); + // float sum = 0.0; + // float sigma = max(0.000001, $sigma * $amount(uv)); + // + // for (float i = -50.0; i <= 50.0; i += 1.0) { + // float coef = exp(-0.5 * (pow(i / sigma, 2.0))) / (6.28318530718 * sigma * sigma); + // rv += $in(uv+vec2(i*e, 0.0))*coef; + // sum += coef; + // } + // + // return rv/sum; + //} + //---------------------- + //gaussian_blur_y.mmg + //vec4 $(name)_fct(vec2 uv) { + // float e = 1.0/$size; + // vec4 rv = vec4(0.0); + // float sum = 0.0; + // float sigma = max(0.000001, $sigma*$amount(uv)); + // for (float i = -50.0; i <= 50.0; i += 1.0) { + // float coef = exp(-0.5 * (pow(i / sigma, 2.0))) / (6.28318530718*sigma*sigma); + // rv += $in(uv+vec2(0.0, i*e))*coef; + // sum += coef; + // } + // + // return rv/sum; + //} +}; + + +#endif diff --git a/modules/material_maker/nodes/filter/brightness_contrast.cpp b/modules/material_maker/nodes/filter/brightness_contrast.cpp new file mode 100644 index 000000000..c05aecc8b --- /dev/null +++ b/modules/material_maker/nodes/filter/brightness_contrast.cpp @@ -0,0 +1,165 @@ + +#include "brightness_contrast.h" + + +Ref BrightnessContrast::get_image() { + return image; +} + +void BrightnessContrast::set_image(const Ref &val) { +image = val; +} + + +Ref BrightnessContrast::get_input() { + return input; +} + +void BrightnessContrast::set_input(const Ref &val) { +input = val; +} + + +float BrightnessContrast::get_brightness() const { + return brightness; +} + +void BrightnessContrast::set_brightness(const float val) { +brightness = val; +} + + +float BrightnessContrast::get_contrast() const { + return contrast; +} + +void BrightnessContrast::set_contrast(const float val) { +contrast = val; +} + + + + //tool; + //export(Resource) ; + Ref image; + //export(Resource) ; + Ref input; + //export(float) ; + float brightness = 0; + //export(float) ; + float contrast = 1; + + void BrightnessContrast::_init_properties() { + + if (!input) { + input = MMNodeUniversalProperty.new(); + input.default_type = MMNodeUniversalProperty.DEFAULT_TYPE_COLOR; + input.set_default_value(Color(0, 0, 0, 1)); +} + + input.input_slot_type = MMNodeUniversalProperty.SLOT_TYPE_UNIVERSAL; + input.slot_name = ">>> Input1 "; + + if (!image) { + image = MMNodeUniversalProperty.new(); + image.default_type = MMNodeUniversalProperty.DEFAULT_TYPE_IMAGE; +} + + //image.input_slot_type = MMNodeUniversalProperty.SLOT_TYPE_FLOAT; + image.output_slot_type = MMNodeUniversalProperty.SLOT_TYPE_IMAGE; + //image.force_override = true; + register_input_property(input); + register_output_property(image); +} + + + void BrightnessContrast::_register_methods(const Variant &mm_graph_node) { + mm_graph_node.add_slot_label_universal(input); + mm_graph_node.add_slot_texture_universal(image); + mm_graph_node.add_slot_float("get_brightness", "set_brightness", "Brightness", 0.01); + mm_graph_node.add_slot_float("get_contrast", "set_contrast", "Contrast", 0.01); +} + + + void BrightnessContrast::_render(const Variant &material) { + Ref img = render_image(material); + image.set_value(img); +} + + + Color BrightnessContrast::_get_value_for(const Vector2 &uv, const int pseed) { + Color c = input.get_value(uv); + return MMAlgos.brightness_contrast(c, brightness, contrast); +} + + //brightness; + + float BrightnessContrast::get_brightness() { + return brightness; +} + + + void BrightnessContrast::set_brightness(const float val) { + brightness = val; + set_dirty(true); +} + + //contrast; + + float BrightnessContrast::get_contrast() { + return contrast; +} + + + void BrightnessContrast::set_contrast(const float val) { + contrast = val; + set_dirty(true); +} + +} + + BrightnessContrast::BrightnessContrast() { + image; + input; + brightness = 0; + contrast = 1; + } + + BrightnessContrast::~BrightnessContrast() { + } + + + static void BrightnessContrast::_bind_methods() { + ClassDB::bind_method(D_METHOD("get_image"), &BrightnessContrast::get_image); + ClassDB::bind_method(D_METHOD("set_image", "value"), &BrightnessContrast::set_image); + ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "image", PROPERTY_HINT_RESOURCE_TYPE, "Ref"), "set_image", "get_image"); + + + ClassDB::bind_method(D_METHOD("get_input"), &BrightnessContrast::get_input); + ClassDB::bind_method(D_METHOD("set_input", "value"), &BrightnessContrast::set_input); + ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "input", PROPERTY_HINT_RESOURCE_TYPE, "Ref"), "set_input", "get_input"); + + + ClassDB::bind_method(D_METHOD("get_brightness"), &BrightnessContrast::get_brightness); + ClassDB::bind_method(D_METHOD("set_brightness", "value"), &BrightnessContrast::set_brightness); + ADD_PROPERTY(PropertyInfo(Variant::REAL, "brightness"), "set_brightness", "get_brightness"); + + + ClassDB::bind_method(D_METHOD("get_contrast"), &BrightnessContrast::get_contrast); + ClassDB::bind_method(D_METHOD("set_contrast", "value"), &BrightnessContrast::set_contrast); + ADD_PROPERTY(PropertyInfo(Variant::REAL, "contrast"), "set_contrast", "get_contrast"); + + + ClassDB::bind_method(D_METHOD("_init_properties"), &BrightnessContrast::_init_properties); + ClassDB::bind_method(D_METHOD("_register_methods", "mm_graph_node"), &BrightnessContrast::_register_methods); + ClassDB::bind_method(D_METHOD("_render", "material"), &BrightnessContrast::_render); + ClassDB::bind_method(D_METHOD("_get_value_for", "uv", "pseed"), &BrightnessContrast::_get_value_for); + ClassDB::bind_method(D_METHOD("get_brightness"), &BrightnessContrast::get_brightness); + ClassDB::bind_method(D_METHOD("set_brightness", "val"), &BrightnessContrast::set_brightness); + ClassDB::bind_method(D_METHOD("get_contrast"), &BrightnessContrast::get_contrast); + ClassDB::bind_method(D_METHOD("set_contrast", "val"), &BrightnessContrast::set_contrast); + + } + + + diff --git a/modules/material_maker/nodes/filter/brightness_contrast.h b/modules/material_maker/nodes/filter/brightness_contrast.h new file mode 100644 index 000000000..ada152479 --- /dev/null +++ b/modules/material_maker/nodes/filter/brightness_contrast.h @@ -0,0 +1,51 @@ +#ifndef BRIGHTNESS_CONTRAST_H +#define BRIGHTNESS_CONTRAST_H + + +class BrightnessContrast : public MMNode { + GDCLASS(BrightnessContrast, MMNode); + + public: + + Ref get_image(); + void set_image(const Ref &val); + + Ref get_input(); + void set_input(const Ref &val); + + float get_brightness() const; + void set_brightness(const float val); + + float get_contrast() const; + void set_contrast(const float val); + + 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); + float get_brightness(); + void set_brightness(const float val); + float get_contrast(); + void set_contrast(const float val); + + BrightnessContrast(); + ~BrightnessContrast(); + + protected: + static void _bind_methods(); + + //tool + //export(Resource) + Ref image; + //export(Resource) + Ref input; + //export(float) + float brightness = 0; + //export(float) + float contrast = 1; + //brightness + //contrast +}; + + +#endif diff --git a/modules/material_maker/nodes/filter/colorize.cpp b/modules/material_maker/nodes/filter/colorize.cpp new file mode 100644 index 000000000..b2aa5a718 --- /dev/null +++ b/modules/material_maker/nodes/filter/colorize.cpp @@ -0,0 +1,129 @@ + +#include "colorize.h" + + +Ref Colorize::get_image() { + return image; +} + +void Colorize::set_image(const Ref &val) { +image = val; +} + + +Ref Colorize::get_input() { + return input; +} + +void Colorize::set_input(const Ref &val) { +input = val; +} + + + + //tool; + //export(Resource) ; + Ref image; + //export(Resource) ; + Ref input; + + void Colorize::_init_properties() { + + if (!input) { + input = MMNodeUniversalProperty.new(); + input.default_type = MMNodeUniversalProperty.DEFAULT_TYPE_FLOAT; + input.set_default_value(1); +} + + input.input_slot_type = MMNodeUniversalProperty.SLOT_TYPE_UNIVERSAL; + input.slot_name = ">>> Input1 "; + + if (!image) { + image = MMNodeUniversalProperty.new(); + image.default_type = MMNodeUniversalProperty.DEFAULT_TYPE_IMAGE; +} + + //image.input_slot_type = MMNodeUniversalProperty.SLOT_TYPE_FLOAT; + image.output_slot_type = MMNodeUniversalProperty.SLOT_TYPE_IMAGE; + //image.force_override = true; + register_input_property(input); + register_output_property(image); +} + + + void Colorize::_register_methods(const Variant &mm_graph_node) { + mm_graph_node.add_slot_label_universal(input); + mm_graph_node.add_slot_texture_universal(image); + mm_graph_node.add_slot_gradient(); +} + + + void Colorize::_render(const Variant &material) { + Ref img = render_image(material); + image.set_value(img); +} + + + Color Colorize::_get_value_for(const Vector2 &uv, const int pseed) { + float f = input.get_value(uv); + return get_gradient_color(f); +} + + // return Color(0.5, 0.5, 0.5, 1); + + Color Colorize::get_gradient_color(const float x) { + + if (interpolation_type == 0) { + return MMAlgos.gradient_type_1(x, points); +} + + + else if (interpolation_type == 1) { + return MMAlgos.gradient_type_2(x, points); +} + + + else if (interpolation_type == 2) { + return MMAlgos.gradient_type_3(x, points); +} + + + else if (interpolation_type == 3) { + return MMAlgos.gradient_type_4(x, points); +} + + return Color(1, 1, 1, 1); +} + +} + + Colorize::Colorize() { + image; + input; + } + + Colorize::~Colorize() { + } + + + static void Colorize::_bind_methods() { + ClassDB::bind_method(D_METHOD("get_image"), &Colorize::get_image); + ClassDB::bind_method(D_METHOD("set_image", "value"), &Colorize::set_image); + ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "image", PROPERTY_HINT_RESOURCE_TYPE, "Ref"), "set_image", "get_image"); + + + ClassDB::bind_method(D_METHOD("get_input"), &Colorize::get_input); + ClassDB::bind_method(D_METHOD("set_input", "value"), &Colorize::set_input); + ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "input", PROPERTY_HINT_RESOURCE_TYPE, "Ref"), "set_input", "get_input"); + + + ClassDB::bind_method(D_METHOD("_init_properties"), &Colorize::_init_properties); + ClassDB::bind_method(D_METHOD("_register_methods", "mm_graph_node"), &Colorize::_register_methods); + ClassDB::bind_method(D_METHOD("_render", "material"), &Colorize::_render); + ClassDB::bind_method(D_METHOD("_get_value_for", "uv", "pseed"), &Colorize::_get_value_for); + ClassDB::bind_method(D_METHOD("get_gradient_color", "x"), &Colorize::get_gradient_color); + + } + + + diff --git a/modules/material_maker/nodes/filter/colorize.h b/modules/material_maker/nodes/filter/colorize.h new file mode 100644 index 000000000..6179852b0 --- /dev/null +++ b/modules/material_maker/nodes/filter/colorize.h @@ -0,0 +1,37 @@ +#ifndef COLORIZE_H +#define COLORIZE_H + + +class Colorize : public GradientBase { + GDCLASS(Colorize, GradientBase); + + public: + + Ref get_image(); + void set_image(const Ref &val); + + Ref get_input(); + void set_input(const Ref &val); + + 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); + Color get_gradient_color(const float x); + + Colorize(); + ~Colorize(); + + protected: + static void _bind_methods(); + + //tool + //export(Resource) + Ref image; + //export(Resource) + Ref input; + // return Color(0.5, 0.5, 0.5, 1) +}; + + +#endif diff --git a/modules/material_maker/nodes/filter/combine.cpp b/modules/material_maker/nodes/filter/combine.cpp new file mode 100644 index 000000000..7db1c5bb3 --- /dev/null +++ b/modules/material_maker/nodes/filter/combine.cpp @@ -0,0 +1,188 @@ + +#include "combine.h" + + +Ref Combine::get_image() { + return image; +} + +void Combine::set_image(const Ref &val) { +image = val; +} + + +Ref Combine::get_input_r() { + return input_r; +} + +void Combine::set_input_r(const Ref &val) { +input_r = val; +} + + +Ref Combine::get_input_g() { + return input_g; +} + +void Combine::set_input_g(const Ref &val) { +input_g = val; +} + + +Ref Combine::get_input_b() { + return input_b; +} + +void Combine::set_input_b(const Ref &val) { +input_b = val; +} + + +Ref Combine::get_input_a() { + return input_a; +} + +void Combine::set_input_a(const Ref &val) { +input_a = val; +} + + + + //tool; + //export(Resource) ; + Ref image; + //export(Resource) ; + Ref input_r; + //export(Resource) ; + Ref input_g; + //export(Resource) ; + Ref input_b; + //export(Resource) ; + Ref input_a; + + void Combine::_init_properties() { + + if (!input_r) { + input_r = MMNodeUniversalProperty.new(); + input_r.default_type = MMNodeUniversalProperty.DEFAULT_TYPE_FLOAT; + input_r.set_default_value(0); +} + + input_r.input_slot_type = MMNodeUniversalProperty.SLOT_TYPE_UNIVERSAL; + input_r.slot_name = ">>> R "; + + if (!input_g) { + input_g = MMNodeUniversalProperty.new(); + input_g.default_type = MMNodeUniversalProperty.DEFAULT_TYPE_FLOAT; + input_g.set_default_value(0); +} + + input_g.input_slot_type = MMNodeUniversalProperty.SLOT_TYPE_UNIVERSAL; + input_g.slot_name = ">>> G "; + + if (!input_b) { + input_b = MMNodeUniversalProperty.new(); + input_b.default_type = MMNodeUniversalProperty.DEFAULT_TYPE_FLOAT; + input_b.set_default_value(0); +} + + input_b.input_slot_type = MMNodeUniversalProperty.SLOT_TYPE_UNIVERSAL; + input_b.slot_name = ">>> B "; + + if (!input_a) { + input_a = MMNodeUniversalProperty.new(); + input_a.default_type = MMNodeUniversalProperty.DEFAULT_TYPE_FLOAT; + input_a.set_default_value(1); +} + + input_a.input_slot_type = MMNodeUniversalProperty.SLOT_TYPE_UNIVERSAL; + input_a.slot_name = ">>> A "; + + if (!image) { + image = MMNodeUniversalProperty.new(); + image.default_type = MMNodeUniversalProperty.DEFAULT_TYPE_IMAGE; +} + + //image.input_slot_type = MMNodeUniversalProperty.SLOT_TYPE_FLOAT; + image.output_slot_type = MMNodeUniversalProperty.SLOT_TYPE_IMAGE; + //image.force_override = true; + register_input_property(input_r); + register_input_property(input_g); + register_input_property(input_b); + register_input_property(input_a); + register_output_property(image); +} + + + void Combine::_register_methods(const Variant &mm_graph_node) { + mm_graph_node.add_slot_label_universal(input_r); + mm_graph_node.add_slot_label_universal(input_g); + mm_graph_node.add_slot_label_universal(input_b); + mm_graph_node.add_slot_label_universal(input_a); + mm_graph_node.add_slot_texture_universal(image); +} + + + void Combine::_render(const Variant &material) { + Ref img = render_image(material); + image.set_value(img); +} + + + Color Combine::_get_value_for(const Vector2 &uv, const int pseed) { + float r = input_r.get_value(uv); + float g = input_g.get_value(uv); + float b = input_b.get_value(uv); + float a = input_a.get_value(uv); + return Color(r, g, b, a); +} + +} + + Combine::Combine() { + image; + input_r; + input_g; + input_b; + input_a; + } + + Combine::~Combine() { + } + + + static void Combine::_bind_methods() { + ClassDB::bind_method(D_METHOD("get_image"), &Combine::get_image); + ClassDB::bind_method(D_METHOD("set_image", "value"), &Combine::set_image); + ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "image", PROPERTY_HINT_RESOURCE_TYPE, "Ref"), "set_image", "get_image"); + + + ClassDB::bind_method(D_METHOD("get_input_r"), &Combine::get_input_r); + ClassDB::bind_method(D_METHOD("set_input_r", "value"), &Combine::set_input_r); + ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "input_r", PROPERTY_HINT_RESOURCE_TYPE, "Ref"), "set_input_r", "get_input_r"); + + + ClassDB::bind_method(D_METHOD("get_input_g"), &Combine::get_input_g); + ClassDB::bind_method(D_METHOD("set_input_g", "value"), &Combine::set_input_g); + ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "input_g", PROPERTY_HINT_RESOURCE_TYPE, "Ref"), "set_input_g", "get_input_g"); + + + ClassDB::bind_method(D_METHOD("get_input_b"), &Combine::get_input_b); + ClassDB::bind_method(D_METHOD("set_input_b", "value"), &Combine::set_input_b); + ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "input_b", PROPERTY_HINT_RESOURCE_TYPE, "Ref"), "set_input_b", "get_input_b"); + + + ClassDB::bind_method(D_METHOD("get_input_a"), &Combine::get_input_a); + ClassDB::bind_method(D_METHOD("set_input_a", "value"), &Combine::set_input_a); + ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "input_a", PROPERTY_HINT_RESOURCE_TYPE, "Ref"), "set_input_a", "get_input_a"); + + + ClassDB::bind_method(D_METHOD("_init_properties"), &Combine::_init_properties); + ClassDB::bind_method(D_METHOD("_register_methods", "mm_graph_node"), &Combine::_register_methods); + ClassDB::bind_method(D_METHOD("_render", "material"), &Combine::_render); + ClassDB::bind_method(D_METHOD("_get_value_for", "uv", "pseed"), &Combine::_get_value_for); + + } + + + diff --git a/modules/material_maker/nodes/filter/combine.h b/modules/material_maker/nodes/filter/combine.h new file mode 100644 index 000000000..9fd0e1b4c --- /dev/null +++ b/modules/material_maker/nodes/filter/combine.h @@ -0,0 +1,50 @@ +#ifndef COMBINE_H +#define COMBINE_H + + +class Combine : public MMNode { + GDCLASS(Combine, MMNode); + + public: + + Ref get_image(); + void set_image(const Ref &val); + + Ref get_input_r(); + void set_input_r(const Ref &val); + + Ref get_input_g(); + void set_input_g(const Ref &val); + + Ref get_input_b(); + void set_input_b(const Ref &val); + + Ref get_input_a(); + void set_input_a(const Ref &val); + + 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); + + Combine(); + ~Combine(); + + protected: + static void _bind_methods(); + + //tool + //export(Resource) + Ref image; + //export(Resource) + Ref input_r; + //export(Resource) + Ref input_g; + //export(Resource) + Ref input_b; + //export(Resource) + Ref input_a; +}; + + +#endif diff --git a/modules/material_maker/nodes/filter/decompose.cpp b/modules/material_maker/nodes/filter/decompose.cpp new file mode 100644 index 000000000..65e878fda --- /dev/null +++ b/modules/material_maker/nodes/filter/decompose.cpp @@ -0,0 +1,211 @@ + +#include "decompose.h" + + +Ref Decompose::get_input() { + return input; +} + +void Decompose::set_input(const Ref &val) { +input = val; +} + + +Ref Decompose::get_out_r() { + return out_r; +} + +void Decompose::set_out_r(const Ref &val) { +out_r = val; +} + + +Ref Decompose::get_out_g() { + return out_g; +} + +void Decompose::set_out_g(const Ref &val) { +out_g = val; +} + + +Ref Decompose::get_out_b() { + return out_b; +} + +void Decompose::set_out_b(const Ref &val) { +out_b = val; +} + + +Ref Decompose::get_out_a() { + return out_a; +} + +void Decompose::set_out_a(const Ref &val) { +out_a = val; +} + + + + //tool; + //export(Resource) ; + Ref input; + //export(Resource) ; + Ref out_r; + //export(Resource) ; + Ref out_g; + //export(Resource) ; + Ref out_b; + //export(Resource) ; + Ref out_a; + + void Decompose::_init_properties() { + + if (!input) { + input = MMNodeUniversalProperty.new(); + input.default_type = MMNodeUniversalProperty.DEFAULT_TYPE_COLOR; + input.set_default_value(Color(0, 0, 0, 1)); +} + + input.input_slot_type = MMNodeUniversalProperty.SLOT_TYPE_UNIVERSAL; + input.slot_name = ">>> Input "; + + if (!out_r) { + out_r = MMNodeUniversalProperty.new(); + out_r.default_type = MMNodeUniversalProperty.DEFAULT_TYPE_IMAGE; +} + + out_r.output_slot_type = MMNodeUniversalProperty.SLOT_TYPE_IMAGE; + + if (!out_g) { + out_g = MMNodeUniversalProperty.new(); + out_g.default_type = MMNodeUniversalProperty.DEFAULT_TYPE_IMAGE; +} + + out_g.output_slot_type = MMNodeUniversalProperty.SLOT_TYPE_IMAGE; + + if (!out_b) { + out_b = MMNodeUniversalProperty.new(); + out_b.default_type = MMNodeUniversalProperty.DEFAULT_TYPE_IMAGE; +} + + out_b.output_slot_type = MMNodeUniversalProperty.SLOT_TYPE_IMAGE; + + if (!out_a) { + out_a = MMNodeUniversalProperty.new(); + out_a.default_type = MMNodeUniversalProperty.DEFAULT_TYPE_IMAGE; +} + + out_a.output_slot_type = MMNodeUniversalProperty.SLOT_TYPE_IMAGE; + register_input_property(input); + register_output_property(out_r); + register_output_property(out_g); + register_output_property(out_b); + register_output_property(out_a); +} + + + void Decompose::_register_methods(const Variant &mm_graph_node) { + mm_graph_node.add_slot_label_universal(input); + mm_graph_node.add_slot_texture_universal(out_r); + mm_graph_node.add_slot_texture_universal(out_g); + mm_graph_node.add_slot_texture_universal(out_b); + mm_graph_node.add_slot_texture_universal(out_a); +} + + + void Decompose::_render(const Variant &material) { + Ref img_r = Image.new(); + Ref img_g = Image.new(); + Ref img_b = Image.new(); + Ref img_a = Image.new(); + img_r.create(material.image_size.x, material.image_size.y, false, Image.FORMAT_RGBA8); + img_g.create(material.image_size.x, material.image_size.y, false, Image.FORMAT_RGBA8); + img_b.create(material.image_size.x, material.image_size.y, false, Image.FORMAT_RGBA8); + img_a.create(material.image_size.x, material.image_size.y, false, Image.FORMAT_RGBA8); + img_r.lock(); + img_g.lock(); + img_b.lock(); + img_a.lock(); + float w = material.image_size.x; + float h = material.image_size.y; + float pseed = randf() + randi(); + + 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); + Color c = input.get_value(uv); + img_r.set_pixel(x, y, Color(c.r, c.r, c.r, 1)); + img_g.set_pixel(x, y, Color(c.g, c.g, c.g, 1)); + img_b.set_pixel(x, y, Color(c.b, c.b, c.b, 1)); + img_a.set_pixel(x, y, Color(c.a, c.a, c.a, c.a)); +} + +} + + img_r.unlock(); + img_g.unlock(); + img_b.unlock(); + img_a.unlock(); + out_r.set_value(img_r); + out_g.set_value(img_g); + out_b.set_value(img_b); + out_a.set_value(img_a); +} + + + Color Decompose::_get_value_for(const Vector2 &uv, const int pseed) { + return Color(); +} + +} + + Decompose::Decompose() { + input; + out_r; + out_g; + out_b; + out_a; + } + + Decompose::~Decompose() { + } + + + static void Decompose::_bind_methods() { + ClassDB::bind_method(D_METHOD("get_input"), &Decompose::get_input); + ClassDB::bind_method(D_METHOD("set_input", "value"), &Decompose::set_input); + ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "input", PROPERTY_HINT_RESOURCE_TYPE, "Ref"), "set_input", "get_input"); + + + ClassDB::bind_method(D_METHOD("get_out_r"), &Decompose::get_out_r); + ClassDB::bind_method(D_METHOD("set_out_r", "value"), &Decompose::set_out_r); + ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "out_r", PROPERTY_HINT_RESOURCE_TYPE, "Ref"), "set_out_r", "get_out_r"); + + + ClassDB::bind_method(D_METHOD("get_out_g"), &Decompose::get_out_g); + ClassDB::bind_method(D_METHOD("set_out_g", "value"), &Decompose::set_out_g); + ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "out_g", PROPERTY_HINT_RESOURCE_TYPE, "Ref"), "set_out_g", "get_out_g"); + + + ClassDB::bind_method(D_METHOD("get_out_b"), &Decompose::get_out_b); + ClassDB::bind_method(D_METHOD("set_out_b", "value"), &Decompose::set_out_b); + ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "out_b", PROPERTY_HINT_RESOURCE_TYPE, "Ref"), "set_out_b", "get_out_b"); + + + ClassDB::bind_method(D_METHOD("get_out_a"), &Decompose::get_out_a); + ClassDB::bind_method(D_METHOD("set_out_a", "value"), &Decompose::set_out_a); + ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "out_a", PROPERTY_HINT_RESOURCE_TYPE, "Ref"), "set_out_a", "get_out_a"); + + + ClassDB::bind_method(D_METHOD("_init_properties"), &Decompose::_init_properties); + ClassDB::bind_method(D_METHOD("_register_methods", "mm_graph_node"), &Decompose::_register_methods); + ClassDB::bind_method(D_METHOD("_render", "material"), &Decompose::_render); + ClassDB::bind_method(D_METHOD("_get_value_for", "uv", "pseed"), &Decompose::_get_value_for); + + } + + + diff --git a/modules/material_maker/nodes/filter/decompose.h b/modules/material_maker/nodes/filter/decompose.h new file mode 100644 index 000000000..46af67952 --- /dev/null +++ b/modules/material_maker/nodes/filter/decompose.h @@ -0,0 +1,50 @@ +#ifndef DECOMPOSE_H +#define DECOMPOSE_H + + +class Decompose : public MMNode { + GDCLASS(Decompose, MMNode); + + public: + + Ref get_input(); + void set_input(const Ref &val); + + Ref get_out_r(); + void set_out_r(const Ref &val); + + Ref get_out_g(); + void set_out_g(const Ref &val); + + Ref get_out_b(); + void set_out_b(const Ref &val); + + Ref get_out_a(); + void set_out_a(const Ref &val); + + 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); + + Decompose(); + ~Decompose(); + + protected: + static void _bind_methods(); + + //tool + //export(Resource) + Ref input; + //export(Resource) + Ref out_r; + //export(Resource) + Ref out_g; + //export(Resource) + Ref out_b; + //export(Resource) + Ref out_a; +}; + + +#endif diff --git a/modules/material_maker/nodes/filter/emboss.cpp b/modules/material_maker/nodes/filter/emboss.cpp new file mode 100644 index 000000000..1bf10a753 --- /dev/null +++ b/modules/material_maker/nodes/filter/emboss.cpp @@ -0,0 +1,253 @@ + +#include "emboss.h" + + +Ref Emboss::get_image() { + return image; +} + +void Emboss::set_image(const Ref &val) { +image = val; +} + + +Ref Emboss::get_input() { + return input; +} + +void Emboss::set_input(const Ref &val) { +input = val; +} + + +float Emboss::get_angle() const { + return angle; +} + +void Emboss::set_angle(const float val) { +angle = val; +} + + +float Emboss::get_amount() const { + return amount; +} + +void Emboss::set_amount(const float val) { +amount = val; +} + + +float Emboss::get_width() const { + return width; +} + +void Emboss::set_width(const float val) { +width = val; +} + + +int Emboss::get_size() const { + return size; +} + +void Emboss::set_size(const int val) { +size = val; +} + + + + //tool; + //export(Resource) ; + Ref image; + //export(Resource) ; + Ref input; + //export(float) ; + float angle = 0; + //export(float) ; + float amount = 5; + //export(float) ; + float width = 1; + int size = 0; + + void Emboss::_init_properties() { + + if (!image) { + image = MMNodeUniversalProperty.new(); + image.default_type = MMNodeUniversalProperty.DEFAULT_TYPE_IMAGE; +} + + image.output_slot_type = MMNodeUniversalProperty.SLOT_TYPE_IMAGE; + + if (!input) { + input = MMNodeUniversalProperty.new(); + input.default_type = MMNodeUniversalProperty.DEFAULT_TYPE_FLOAT; + input.set_default_value(1); +} + + input.input_slot_type = MMNodeUniversalProperty.SLOT_TYPE_UNIVERSAL; + input.slot_name = ">>> Input1 "; + register_input_property(input); + register_output_property(image); +} + + + void Emboss::_register_methods(const Variant &mm_graph_node) { + mm_graph_node.add_slot_texture_universal(image); + mm_graph_node.add_slot_label_universal(input); + mm_graph_node.add_slot_float("get_angle", "set_angle", "Angle", 0.1); + mm_graph_node.add_slot_float("get_amount", "set_amount", "Amount", 0.1); + mm_graph_node.add_slot_float("get_width", "set_width", "Width", 1); +} + + + void Emboss::_render(const Variant &material) { + size = max(material.image_size.x, material.image_size.y); + Ref img = render_image(material); + image.set_value(img); +} + + + Color Emboss::_get_value_for(const Vector2 &uv, const int pseed) { + float f = 0; + f = emboss(uv, size, angle, amount, width); + return Color(f, f, f, 1); +} + + + float Emboss::get_angle() { + return angle; +} + + + void Emboss::set_angle(const float val) { + angle = val; + set_dirty(true); +} + + + float Emboss::get_amount() { + return amount; +} + + + void Emboss::set_amount(const float val) { + amount = val; + set_dirty(true); +} + + + float Emboss::get_width() { + return width; +} + + + void Emboss::set_width(const float val) { + width = val; + set_dirty(true); +} + + //float $(name)_fct(vec2 uv) {; + // float pixels = max(1.0, $width); + // float e = 1.0/$size; + // float rv = 0.0; + //; + // for (float dx = -pixels; dx <= pixels; dx += 1.0) {; + // for (float dy = -pixels; dy <= pixels; dy += 1.0) {; + // if (abs(dx) > 0.5 || abs(dy) > 0.5) {; + // rv += $in(uv+e*vec2(dx, dy))*cos(atan(dy, dx)-$angle*3.14159265359/180.0)/length(vec2(dx, dy)); + // }; + // }; + // }; + //; + // return $amount*rv/pixels+0.5; + //}; + + float Emboss::emboss(const Vector2 &uv, const float psize, const float pangle, const float pamount, const float pwidth) { + float pixels = max(1.0, pwidth); + float e = 1.0 / psize; + float rv = 0.0; + float dx = -pixels; + float dy = -pixels; + //for (float dx = -pixels; dx <= pixels; dx += 1.0) {; + + while (dx <= pixels) { + //for (float dy = -pixels; dy <= pixels; dy += 1.0) {; + + while (dy <= pixels) { + + if ((abs(dx) > 0.5 || abs(dy) > 0.5)) { + rv += input.get_value(uv + e * Vector2(dx, dy)) * cos(atan2(dy, dx) - pangle * 3.14159265359 / 180.0) / Vector2(dx, dy).length(); +} + + dx += 1; + dy += 1; +} + +} + + return pamount * rv / pixels + 0.5; +} + +} + + Emboss::Emboss() { + image; + input; + angle = 0; + amount = 5; + width = 1; + size = 0; + } + + Emboss::~Emboss() { + } + + + static void Emboss::_bind_methods() { + ClassDB::bind_method(D_METHOD("get_image"), &Emboss::get_image); + ClassDB::bind_method(D_METHOD("set_image", "value"), &Emboss::set_image); + ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "image", PROPERTY_HINT_RESOURCE_TYPE, "Ref"), "set_image", "get_image"); + + + ClassDB::bind_method(D_METHOD("get_input"), &Emboss::get_input); + ClassDB::bind_method(D_METHOD("set_input", "value"), &Emboss::set_input); + ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "input", PROPERTY_HINT_RESOURCE_TYPE, "Ref"), "set_input", "get_input"); + + + ClassDB::bind_method(D_METHOD("get_angle"), &Emboss::get_angle); + ClassDB::bind_method(D_METHOD("set_angle", "value"), &Emboss::set_angle); + ADD_PROPERTY(PropertyInfo(Variant::REAL, "angle"), "set_angle", "get_angle"); + + + ClassDB::bind_method(D_METHOD("get_amount"), &Emboss::get_amount); + ClassDB::bind_method(D_METHOD("set_amount", "value"), &Emboss::set_amount); + ADD_PROPERTY(PropertyInfo(Variant::REAL, "amount"), "set_amount", "get_amount"); + + + ClassDB::bind_method(D_METHOD("get_width"), &Emboss::get_width); + ClassDB::bind_method(D_METHOD("set_width", "value"), &Emboss::set_width); + ADD_PROPERTY(PropertyInfo(Variant::REAL, "width"), "set_width", "get_width"); + + + ClassDB::bind_method(D_METHOD("get_size"), &Emboss::get_size); + ClassDB::bind_method(D_METHOD("set_size", "value"), &Emboss::set_size); + ADD_PROPERTY(PropertyInfo(Variant::INT, "size"), "set_size", "get_size"); + + + ClassDB::bind_method(D_METHOD("_init_properties"), &Emboss::_init_properties); + ClassDB::bind_method(D_METHOD("_register_methods", "mm_graph_node"), &Emboss::_register_methods); + ClassDB::bind_method(D_METHOD("_render", "material"), &Emboss::_render); + ClassDB::bind_method(D_METHOD("_get_value_for", "uv", "pseed"), &Emboss::_get_value_for); + ClassDB::bind_method(D_METHOD("get_angle"), &Emboss::get_angle); + ClassDB::bind_method(D_METHOD("set_angle", "val"), &Emboss::set_angle); + ClassDB::bind_method(D_METHOD("get_amount"), &Emboss::get_amount); + ClassDB::bind_method(D_METHOD("set_amount", "val"), &Emboss::set_amount); + ClassDB::bind_method(D_METHOD("get_width"), &Emboss::get_width); + ClassDB::bind_method(D_METHOD("set_width", "val"), &Emboss::set_width); + ClassDB::bind_method(D_METHOD("emboss", "uv", "psize", "pangle", "pamount", "pwidth"), &Emboss::emboss); + + } + + + diff --git a/modules/material_maker/nodes/filter/emboss.h b/modules/material_maker/nodes/filter/emboss.h new file mode 100644 index 000000000..6e67e305d --- /dev/null +++ b/modules/material_maker/nodes/filter/emboss.h @@ -0,0 +1,76 @@ +#ifndef EMBOSS_H +#define EMBOSS_H + + +class Emboss : public MMNode { + GDCLASS(Emboss, MMNode); + + public: + + Ref get_image(); + void set_image(const Ref &val); + + Ref get_input(); + void set_input(const Ref &val); + + float get_angle() const; + void set_angle(const float val); + + float get_amount() const; + void set_amount(const float val); + + float get_width() const; + void set_width(const float val); + + int get_size() const; + void set_size(const int val); + + 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); + float get_angle(); + void set_angle(const float val); + float get_amount(); + void set_amount(const float val); + float get_width(); + void set_width(const float val); + float emboss(const Vector2 &uv, const float psize, const float pangle, const float pamount, const float pwidth); + + Emboss(); + ~Emboss(); + + protected: + static void _bind_methods(); + + //tool + //export(Resource) + Ref image; + //export(Resource) + Ref input; + //export(float) + float angle = 0; + //export(float) + float amount = 5; + //export(float) + float width = 1; + int size = 0; + //float $(name)_fct(vec2 uv) { + // float pixels = max(1.0, $width); + // float e = 1.0/$size; + // float rv = 0.0; + // + // for (float dx = -pixels; dx <= pixels; dx += 1.0) { + // for (float dy = -pixels; dy <= pixels; dy += 1.0) { + // if (abs(dx) > 0.5 || abs(dy) > 0.5) { + // rv += $in(uv+e*vec2(dx, dy))*cos(atan(dy, dx)-$angle*3.14159265359/180.0)/length(vec2(dx, dy)); + // } + // } + // } + // + // return $amount*rv/pixels+0.5; + //} +}; + + +#endif diff --git a/modules/material_maker/nodes/filter/fill_channel.cpp b/modules/material_maker/nodes/filter/fill_channel.cpp new file mode 100644 index 000000000..64c4c7cce --- /dev/null +++ b/modules/material_maker/nodes/filter/fill_channel.cpp @@ -0,0 +1,179 @@ + +#include "fill_channel.h" + + +Ref FillChannel::get_image() { + return image; +} + +void FillChannel::set_image(const Ref &val) { +image = val; +} + + +Ref FillChannel::get_input() { + return input; +} + +void FillChannel::set_input(const Ref &val) { +input = val; +} + + +Ref FillChannel::get_value() { + return value; +} + +void FillChannel::set_value(const Ref &val) { +value = val; +} + + +int FillChannel::get_channel() const { + return channel; +} + +void FillChannel::set_channel(const int val) { +channel = val; +} + + + + //tool; + //export(Resource) ; + Ref image; + //export(Resource) ; + Ref input; + //export(Resource) ; + Ref value; + //export(int, "R,G,B,A") ; + int channel = 3; + + void FillChannel::_init_properties() { + + if (!image) { + image = MMNodeUniversalProperty.new(); + image.default_type = MMNodeUniversalProperty.DEFAULT_TYPE_IMAGE; +} + + image.output_slot_type = MMNodeUniversalProperty.SLOT_TYPE_IMAGE; + + if (!input) { + input = MMNodeUniversalProperty.new(); + input.default_type = MMNodeUniversalProperty.DEFAULT_TYPE_COLOR; + input.set_default_value(Color()); +} + + input.input_slot_type = MMNodeUniversalProperty.SLOT_TYPE_UNIVERSAL; + input.slot_name = ">>> Input1 "; + + if (!value) { + value = MMNodeUniversalProperty.new(); + value.default_type = MMNodeUniversalProperty.DEFAULT_TYPE_FLOAT; + value.set_default_value(1); +} + + value.input_slot_type = MMNodeUniversalProperty.SLOT_TYPE_UNIVERSAL; + value.value_step = 0.01; + value.value_range = Vector2(0, 1); + register_input_property(input); + register_output_property(image); + register_input_property(value); +} + + + void FillChannel::_register_methods(const Variant &mm_graph_node) { + mm_graph_node.add_slot_label_universal(input); + mm_graph_node.add_slot_texture_universal(image); + mm_graph_node.add_slot_float_universal(value); + mm_graph_node.add_slot_enum("get_channel", "set_channel", "Channel", [ "R", "G", "B", "A" ]); +} + + + void FillChannel::_render(const Variant &material) { + Ref img = render_image(material); + image.set_value(img); +} + + + Color FillChannel::_get_value_for(const Vector2 &uv, const int pseed) { + Color col = input.get_value(uv); + + if (channel == 0) { + col.r = value.get_value(uv); +} + + + if (channel == 1) { + col.g = value.get_value(uv); +} + + + if (channel == 2) { + col.b = value.get_value(uv); +} + + + if (channel == 3) { + col.a = value.get_value(uv); +} + + return col; +} + + + int FillChannel::get_channel() { + return channel; +} + + + void FillChannel::set_channel(const int val) { + channel = val; + set_dirty(true); +} + +} + + FillChannel::FillChannel() { + image; + input; + value; + channel = 3; + } + + FillChannel::~FillChannel() { + } + + + static void FillChannel::_bind_methods() { + ClassDB::bind_method(D_METHOD("get_image"), &FillChannel::get_image); + ClassDB::bind_method(D_METHOD("set_image", "value"), &FillChannel::set_image); + ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "image", PROPERTY_HINT_RESOURCE_TYPE, "Ref"), "set_image", "get_image"); + + + ClassDB::bind_method(D_METHOD("get_input"), &FillChannel::get_input); + ClassDB::bind_method(D_METHOD("set_input", "value"), &FillChannel::set_input); + ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "input", PROPERTY_HINT_RESOURCE_TYPE, "Ref"), "set_input", "get_input"); + + + ClassDB::bind_method(D_METHOD("get_value"), &FillChannel::get_value); + ClassDB::bind_method(D_METHOD("set_value", "value"), &FillChannel::set_value); + ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "value", PROPERTY_HINT_RESOURCE_TYPE, "Ref"), "set_value", "get_value"); + + + ClassDB::bind_method(D_METHOD("get_channel"), &FillChannel::get_channel); + ClassDB::bind_method(D_METHOD("set_channel", "value"), &FillChannel::set_channel); + ADD_PROPERTY(PropertyInfo(Variant::INT, "channel"), "set_channel", "get_channel"); + + + ClassDB::bind_method(D_METHOD("_init_properties"), &FillChannel::_init_properties); + ClassDB::bind_method(D_METHOD("_register_methods", "mm_graph_node"), &FillChannel::_register_methods); + ClassDB::bind_method(D_METHOD("_render", "material"), &FillChannel::_render); + ClassDB::bind_method(D_METHOD("_get_value_for", "uv", "pseed"), &FillChannel::_get_value_for); + ClassDB::bind_method(D_METHOD("get_channel"), &FillChannel::get_channel); + ClassDB::bind_method(D_METHOD("set_channel", "val"), &FillChannel::set_channel); + + } + + + diff --git a/modules/material_maker/nodes/filter/fill_channel.h b/modules/material_maker/nodes/filter/fill_channel.h new file mode 100644 index 000000000..a8364e418 --- /dev/null +++ b/modules/material_maker/nodes/filter/fill_channel.h @@ -0,0 +1,47 @@ +#ifndef FILL_CHANNEL_H +#define FILL_CHANNEL_H + + +class FillChannel : public MMNode { + GDCLASS(FillChannel, MMNode); + + public: + + Ref get_image(); + void set_image(const Ref &val); + + Ref get_input(); + void set_input(const Ref &val); + + Ref get_value(); + void set_value(const Ref &val); + + int get_channel() const; + void set_channel(const int val); + + 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); + int get_channel(); + void set_channel(const int val); + + FillChannel(); + ~FillChannel(); + + protected: + static void _bind_methods(); + + //tool + //export(Resource) + Ref image; + //export(Resource) + Ref input; + //export(Resource) + Ref value; + //export(int, "R,G,B,A") + int channel = 3; +}; + + +#endif diff --git a/modules/material_maker/nodes/filter/fill_to_color.cpp b/modules/material_maker/nodes/filter/fill_to_color.cpp new file mode 100644 index 000000000..aaec02979 --- /dev/null +++ b/modules/material_maker/nodes/filter/fill_to_color.cpp @@ -0,0 +1,165 @@ + +#include "fill_to_color.h" + + +Ref FillToColor::get_image() { + return image; +} + +void FillToColor::set_image(const Ref &val) { +image = val; +} + + +Ref FillToColor::get_input() { + return input; +} + +void FillToColor::set_input(const Ref &val) { +input = val; +} + + +Ref FillToColor::get_color_map() { + return color_map; +} + +void FillToColor::set_color_map(const Ref &val) { +color_map = val; +} + + +Color FillToColor::get_edge_color() { + return edge_color; +} + +void FillToColor::set_edge_color(const Color &val) { +edge_color = val; +} + + + + //tool; + //export(Resource) ; + Ref image; + //export(Resource) ; + Ref input; + //export(Resource) ; + Ref color_map; + //export(Color) ; + Color edge_color = Color(1, 1, 1, 1); + + void FillToColor::_init_properties() { + + if (!input) { + input = MMNodeUniversalProperty.new(); + input.default_type = MMNodeUniversalProperty.DEFAULT_TYPE_COLOR; + input.set_default_value(Color(0, 0, 0, 1)); +} + + input.input_slot_type = MMNodeUniversalProperty.SLOT_TYPE_UNIVERSAL; + input.slot_name = ">>> Input "; + + if (!color_map) { + color_map = MMNodeUniversalProperty.new(); + color_map.default_type = MMNodeUniversalProperty.DEFAULT_TYPE_COLOR; + color_map.set_default_value(Color(1, 1, 1, 1)); +} + + color_map.input_slot_type = MMNodeUniversalProperty.SLOT_TYPE_UNIVERSAL; + color_map.slot_name = ">>> Color Map "; + + if (!image) { + image = MMNodeUniversalProperty.new(); + image.default_type = MMNodeUniversalProperty.DEFAULT_TYPE_IMAGE; +} + + //image.input_slot_type = MMNodeUniversalProperty.SLOT_TYPE_FLOAT; + image.output_slot_type = MMNodeUniversalProperty.SLOT_TYPE_IMAGE; + //image.force_override = true; + register_input_property(input); + register_input_property(color_map); + register_output_property(image); +} + + + void FillToColor::_register_methods(const Variant &mm_graph_node) { + mm_graph_node.add_slot_label_universal(input); + mm_graph_node.add_slot_label_universal(color_map); + mm_graph_node.add_slot_texture_universal(image); + mm_graph_node.add_slot_color("get_edge_color", "set_edge_color"); +} + + + void FillToColor::_render(const Variant &material) { + Ref img = render_image(material); + image.set_value(img); +} + + + Color FillToColor::_get_value_for(const Vector2 &uv, const int pseed) { + //vec4 $(name_uv)_bb = $in($uv); + Color c = input.get_value(uv); + //mix($edgecolor, $map(fract($(name_uv)_bb.xy+0.5*$(name_uv)_bb.zw)), step(0.0000001, dot($(name_uv)_bb.zw, vec2(1.0)))); + Color rc = color_map.get_value(MMAlgos.fractv2(Vector2(c.r, c.g) + 0.5 * Vector2(c.b, c.a))); + float s = MMAlgos.step(0.0000001, Vector2(c.b, c.a).dot(Vector2(1, 1))); + return lerp(edge_color, rc, s); +} + + //edge_color; + + Color FillToColor::get_edge_color() { + return edge_color; +} + + + void FillToColor::set_edge_color(const Color &val) { + edge_color = val; + set_dirty(true); +} + +} + + FillToColor::FillToColor() { + image; + input; + color_map; + edge_color = Color(1, 1, 1, 1); + } + + FillToColor::~FillToColor() { + } + + + static void FillToColor::_bind_methods() { + ClassDB::bind_method(D_METHOD("get_image"), &FillToColor::get_image); + ClassDB::bind_method(D_METHOD("set_image", "value"), &FillToColor::set_image); + ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "image", PROPERTY_HINT_RESOURCE_TYPE, "Ref"), "set_image", "get_image"); + + + ClassDB::bind_method(D_METHOD("get_input"), &FillToColor::get_input); + ClassDB::bind_method(D_METHOD("set_input", "value"), &FillToColor::set_input); + ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "input", PROPERTY_HINT_RESOURCE_TYPE, "Ref"), "set_input", "get_input"); + + + ClassDB::bind_method(D_METHOD("get_color_map"), &FillToColor::get_color_map); + ClassDB::bind_method(D_METHOD("set_color_map", "value"), &FillToColor::set_color_map); + ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "color_map", PROPERTY_HINT_RESOURCE_TYPE, "Ref"), "set_color_map", "get_color_map"); + + + ClassDB::bind_method(D_METHOD("get_edge_color"), &FillToColor::get_edge_color); + ClassDB::bind_method(D_METHOD("set_edge_color", "value"), &FillToColor::set_edge_color); + ADD_PROPERTY(PropertyInfo(Variant::COLOR, "edge_color"), "set_edge_color", "get_edge_color"); + + + ClassDB::bind_method(D_METHOD("_init_properties"), &FillToColor::_init_properties); + ClassDB::bind_method(D_METHOD("_register_methods", "mm_graph_node"), &FillToColor::_register_methods); + ClassDB::bind_method(D_METHOD("_render", "material"), &FillToColor::_render); + ClassDB::bind_method(D_METHOD("_get_value_for", "uv", "pseed"), &FillToColor::_get_value_for); + ClassDB::bind_method(D_METHOD("get_edge_color"), &FillToColor::get_edge_color); + ClassDB::bind_method(D_METHOD("set_edge_color", "val"), &FillToColor::set_edge_color); + + } + + + diff --git a/modules/material_maker/nodes/filter/fill_to_color.h b/modules/material_maker/nodes/filter/fill_to_color.h new file mode 100644 index 000000000..2bb1ed90b --- /dev/null +++ b/modules/material_maker/nodes/filter/fill_to_color.h @@ -0,0 +1,48 @@ +#ifndef FILL_TO_COLOR_H +#define FILL_TO_COLOR_H + + +class FillToColor : public MMNode { + GDCLASS(FillToColor, MMNode); + + public: + + Ref get_image(); + void set_image(const Ref &val); + + Ref get_input(); + void set_input(const Ref &val); + + Ref get_color_map(); + void set_color_map(const Ref &val); + + Color get_edge_color(); + void set_edge_color(const Color &val); + + 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); + Color get_edge_color(); + void set_edge_color(const Color &val); + + FillToColor(); + ~FillToColor(); + + protected: + static void _bind_methods(); + + //tool + //export(Resource) + Ref image; + //export(Resource) + Ref input; + //export(Resource) + Ref color_map; + //export(Color) + Color edge_color = Color(1, 1, 1, 1); + //edge_color +}; + + +#endif diff --git a/modules/material_maker/nodes/filter/fill_to_position.cpp b/modules/material_maker/nodes/filter/fill_to_position.cpp new file mode 100644 index 000000000..aacafee92 --- /dev/null +++ b/modules/material_maker/nodes/filter/fill_to_position.cpp @@ -0,0 +1,154 @@ + +#include "fill_to_position.h" + + +Ref FillToPosition::get_image() { + return image; +} + +void FillToPosition::set_image(const Ref &val) { +image = val; +} + + +Ref FillToPosition::get_input() { + return input; +} + +void FillToPosition::set_input(const Ref &val) { +input = val; +} + + +int FillToPosition::get_axis() const { + return axis; +} + +void FillToPosition::set_axis(const int val) { +axis = val; +} + + + + //tool; + //export(Resource) ; + Ref image; + //export(Resource) ; + Ref input; + //export(int, "X,Y,Radial") ; + int axis = 2; + + void FillToPosition::_init_properties() { + + if (!input) { + input = MMNodeUniversalProperty.new(); + input.default_type = MMNodeUniversalProperty.DEFAULT_TYPE_COLOR; + input.set_default_value(Color(0, 0, 0, 1)); +} + + input.input_slot_type = MMNodeUniversalProperty.SLOT_TYPE_UNIVERSAL; + input.slot_name = ">>> Input "; + + if (!image) { + image = MMNodeUniversalProperty.new(); + image.default_type = MMNodeUniversalProperty.DEFAULT_TYPE_IMAGE; +} + + //image.input_slot_type = MMNodeUniversalProperty.SLOT_TYPE_FLOAT; + image.output_slot_type = MMNodeUniversalProperty.SLOT_TYPE_IMAGE; + //image.force_override = true; + register_input_property(input); + register_output_property(image); +} + + + void FillToPosition::_register_methods(const Variant &mm_graph_node) { + mm_graph_node.add_slot_label_universal(input); + mm_graph_node.add_slot_texture_universal(image); + mm_graph_node.add_slot_enum("get_axis", "set_axis", "Axis", [ "X", "Y", "Radial" ]); +} + + + void FillToPosition::_render(const Variant &material) { + Ref img = render_image(material); + image.set_value(img); +} + + + Color FillToPosition::_get_value_for(const Vector2 &uv, const int pseed) { + Color c = input.get_value(uv); + //vec2 $(name_uv)_c = fract($in($uv).xy+0.5*$in($uv).zw); + Vector2 cnv = MMAlgos.fractv2(Vector2(c.r, c.g) + 0.5 * Vector2(c.b, c.a)); + //X, $(name_uv)_c.x; + //Y, $(name_uv)_c.y; + //Radial, length($(name_uv)_c-vec2(0.5)); + + if (axis == 0) { + return Color(cnv.x, cnv.x, cnv.x, 1); +} + + + else if (axis == 1) { + return Color(cnv.y, cnv.y, cnv.y, 1); +} + + + else if (axis == 2) { + float f = (cnv - Vector2(0.5, 0.5)).length(); + return Color(f, f, f, 1); +} + + return Color(0, 0, 0, 1); +} + + //axis; + + int FillToPosition::get_axis() { + return axis; +} + + + void FillToPosition::set_axis(const int val) { + axis = val; + set_dirty(true); +} + +} + + FillToPosition::FillToPosition() { + image; + input; + axis = 2; + } + + FillToPosition::~FillToPosition() { + } + + + static void FillToPosition::_bind_methods() { + ClassDB::bind_method(D_METHOD("get_image"), &FillToPosition::get_image); + ClassDB::bind_method(D_METHOD("set_image", "value"), &FillToPosition::set_image); + ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "image", PROPERTY_HINT_RESOURCE_TYPE, "Ref"), "set_image", "get_image"); + + + ClassDB::bind_method(D_METHOD("get_input"), &FillToPosition::get_input); + ClassDB::bind_method(D_METHOD("set_input", "value"), &FillToPosition::set_input); + ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "input", PROPERTY_HINT_RESOURCE_TYPE, "Ref"), "set_input", "get_input"); + + + ClassDB::bind_method(D_METHOD("get_axis"), &FillToPosition::get_axis); + ClassDB::bind_method(D_METHOD("set_axis", "value"), &FillToPosition::set_axis); + ADD_PROPERTY(PropertyInfo(Variant::INT, "axis"), "set_axis", "get_axis"); + + + ClassDB::bind_method(D_METHOD("_init_properties"), &FillToPosition::_init_properties); + ClassDB::bind_method(D_METHOD("_register_methods", "mm_graph_node"), &FillToPosition::_register_methods); + ClassDB::bind_method(D_METHOD("_render", "material"), &FillToPosition::_render); + ClassDB::bind_method(D_METHOD("_get_value_for", "uv", "pseed"), &FillToPosition::_get_value_for); + ClassDB::bind_method(D_METHOD("get_axis"), &FillToPosition::get_axis); + ClassDB::bind_method(D_METHOD("set_axis", "val"), &FillToPosition::set_axis); + + } + + + diff --git a/modules/material_maker/nodes/filter/fill_to_position.h b/modules/material_maker/nodes/filter/fill_to_position.h new file mode 100644 index 000000000..aed2c8f84 --- /dev/null +++ b/modules/material_maker/nodes/filter/fill_to_position.h @@ -0,0 +1,43 @@ +#ifndef FILL_TO_POSITION_H +#define FILL_TO_POSITION_H + + +class FillToPosition : public MMNode { + GDCLASS(FillToPosition, MMNode); + + public: + + Ref get_image(); + void set_image(const Ref &val); + + Ref get_input(); + void set_input(const Ref &val); + + int get_axis() const; + void set_axis(const int val); + + 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); + int get_axis(); + void set_axis(const int val); + + FillToPosition(); + ~FillToPosition(); + + protected: + static void _bind_methods(); + + //tool + //export(Resource) + Ref image; + //export(Resource) + Ref input; + //export(int, "X,Y,Radial") + int axis = 2; + //axis +}; + + +#endif diff --git a/modules/material_maker/nodes/filter/fill_to_random_color.cpp b/modules/material_maker/nodes/filter/fill_to_random_color.cpp new file mode 100644 index 000000000..d868d50ec --- /dev/null +++ b/modules/material_maker/nodes/filter/fill_to_random_color.cpp @@ -0,0 +1,139 @@ + +#include "fill_to_random_color.h" + + +Ref FillToRandomColor::get_image() { + return image; +} + +void FillToRandomColor::set_image(const Ref &val) { +image = val; +} + + +Ref FillToRandomColor::get_input() { + return input; +} + +void FillToRandomColor::set_input(const Ref &val) { +input = val; +} + + +Color FillToRandomColor::get_edge_color() { + return edge_color; +} + +void FillToRandomColor::set_edge_color(const Color &val) { +edge_color = val; +} + + + + //tool; + //export(Resource) ; + Ref image; + //export(Resource) ; + Ref input; + //export(Color) ; + Color edge_color = Color(1, 1, 1, 1); + + void FillToRandomColor::_init_properties() { + + if (!input) { + input = MMNodeUniversalProperty.new(); + input.default_type = MMNodeUniversalProperty.DEFAULT_TYPE_COLOR; + input.set_default_value(Color(0, 0, 0, 1)); +} + + input.input_slot_type = MMNodeUniversalProperty.SLOT_TYPE_UNIVERSAL; + input.slot_name = ">>> Input "; + + if (!image) { + image = MMNodeUniversalProperty.new(); + image.default_type = MMNodeUniversalProperty.DEFAULT_TYPE_IMAGE; +} + + //image.input_slot_type = MMNodeUniversalProperty.SLOT_TYPE_FLOAT; + image.output_slot_type = MMNodeUniversalProperty.SLOT_TYPE_IMAGE; + //image.force_override = true; + register_input_property(input); + register_output_property(image); +} + + + void FillToRandomColor::_register_methods(const Variant &mm_graph_node) { + mm_graph_node.add_slot_label_universal(input); + mm_graph_node.add_slot_texture_universal(image); + mm_graph_node.add_slot_color("get_edge_color", "set_edge_color"); +} + + + void FillToRandomColor::_render(const Variant &material) { + Ref img = render_image(material); + image.set_value(img); +} + + + Color FillToRandomColor::_get_value_for(const Vector2 &uv, const int pseed) { + //vec4 $(name_uv)_bb = $in($uv); + Color c = input.get_value(uv); + //mix($edgecolor.rgb, rand3(vec2(float($seed), rand(vec2(rand($(name_uv)_bb.xy), rand($(name_uv)_bb.zw))))), step(0.0000001, dot($(name_uv)_bb.zw, vec2(1.0)))); + float r1 = MMAlgos.rand(Vector2(c.r, c.g)); + float r2 = MMAlgos.rand(Vector2(c.b, c.a)); + float s = MMAlgos.step(0.0000001, Vector2(c.b, c.a).dot(Vector2(1, 1))); + Vector3 f = lerp(Vector3(edge_color.r, edge_color.g, edge_color.b), MMAlgos.rand3(Vector2(1.0 / float(pseed), MMAlgos.rand(Vector2(r1, r2)))), s); + return Color(f.x, f.y, f.z, 1); +} + + //edge_color; + + Color FillToRandomColor::get_edge_color() { + return edge_color; +} + + + void FillToRandomColor::set_edge_color(const Color &val) { + edge_color = val; + set_dirty(true); +} + +} + + FillToRandomColor::FillToRandomColor() { + image; + input; + edge_color = Color(1, 1, 1, 1); + } + + FillToRandomColor::~FillToRandomColor() { + } + + + static void FillToRandomColor::_bind_methods() { + ClassDB::bind_method(D_METHOD("get_image"), &FillToRandomColor::get_image); + ClassDB::bind_method(D_METHOD("set_image", "value"), &FillToRandomColor::set_image); + ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "image", PROPERTY_HINT_RESOURCE_TYPE, "Ref"), "set_image", "get_image"); + + + ClassDB::bind_method(D_METHOD("get_input"), &FillToRandomColor::get_input); + ClassDB::bind_method(D_METHOD("set_input", "value"), &FillToRandomColor::set_input); + ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "input", PROPERTY_HINT_RESOURCE_TYPE, "Ref"), "set_input", "get_input"); + + + ClassDB::bind_method(D_METHOD("get_edge_color"), &FillToRandomColor::get_edge_color); + ClassDB::bind_method(D_METHOD("set_edge_color", "value"), &FillToRandomColor::set_edge_color); + ADD_PROPERTY(PropertyInfo(Variant::COLOR, "edge_color"), "set_edge_color", "get_edge_color"); + + + ClassDB::bind_method(D_METHOD("_init_properties"), &FillToRandomColor::_init_properties); + ClassDB::bind_method(D_METHOD("_register_methods", "mm_graph_node"), &FillToRandomColor::_register_methods); + ClassDB::bind_method(D_METHOD("_render", "material"), &FillToRandomColor::_render); + ClassDB::bind_method(D_METHOD("_get_value_for", "uv", "pseed"), &FillToRandomColor::_get_value_for); + ClassDB::bind_method(D_METHOD("get_edge_color"), &FillToRandomColor::get_edge_color); + ClassDB::bind_method(D_METHOD("set_edge_color", "val"), &FillToRandomColor::set_edge_color); + + } + + + diff --git a/modules/material_maker/nodes/filter/fill_to_random_color.h b/modules/material_maker/nodes/filter/fill_to_random_color.h new file mode 100644 index 000000000..a49607713 --- /dev/null +++ b/modules/material_maker/nodes/filter/fill_to_random_color.h @@ -0,0 +1,43 @@ +#ifndef FILL_TO_RANDOM_COLOR_H +#define FILL_TO_RANDOM_COLOR_H + + +class FillToRandomColor : public MMNode { + GDCLASS(FillToRandomColor, MMNode); + + public: + + Ref get_image(); + void set_image(const Ref &val); + + Ref get_input(); + void set_input(const Ref &val); + + Color get_edge_color(); + void set_edge_color(const Color &val); + + 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); + Color get_edge_color(); + void set_edge_color(const Color &val); + + FillToRandomColor(); + ~FillToRandomColor(); + + protected: + static void _bind_methods(); + + //tool + //export(Resource) + Ref image; + //export(Resource) + Ref input; + //export(Color) + Color edge_color = Color(1, 1, 1, 1); + //edge_color +}; + + +#endif diff --git a/modules/material_maker/nodes/filter/fill_to_random_grey.cpp b/modules/material_maker/nodes/filter/fill_to_random_grey.cpp new file mode 100644 index 000000000..addc65b24 --- /dev/null +++ b/modules/material_maker/nodes/filter/fill_to_random_grey.cpp @@ -0,0 +1,139 @@ + +#include "fill_to_random_grey.h" + + +Ref FillToRandomGrey::get_image() { + return image; +} + +void FillToRandomGrey::set_image(const Ref &val) { +image = val; +} + + +Ref FillToRandomGrey::get_input() { + return input; +} + +void FillToRandomGrey::set_input(const Ref &val) { +input = val; +} + + +float FillToRandomGrey::get_edge_color() const { + return edge_color; +} + +void FillToRandomGrey::set_edge_color(const float val) { +edge_color = val; +} + + + + //tool; + //export(Resource) ; + Ref image; + //export(Resource) ; + Ref input; + //export(float) ; + float edge_color = 1; + + void FillToRandomGrey::_init_properties() { + + if (!input) { + input = MMNodeUniversalProperty.new(); + input.default_type = MMNodeUniversalProperty.DEFAULT_TYPE_COLOR; + input.set_default_value(Color(0, 0, 0, 1)); +} + + input.input_slot_type = MMNodeUniversalProperty.SLOT_TYPE_UNIVERSAL; + input.slot_name = ">>> Input "; + + if (!image) { + image = MMNodeUniversalProperty.new(); + image.default_type = MMNodeUniversalProperty.DEFAULT_TYPE_IMAGE; +} + + //image.input_slot_type = MMNodeUniversalProperty.SLOT_TYPE_FLOAT; + image.output_slot_type = MMNodeUniversalProperty.SLOT_TYPE_IMAGE; + //image.force_override = true; + register_input_property(input); + register_output_property(image); +} + + + void FillToRandomGrey::_register_methods(const Variant &mm_graph_node) { + mm_graph_node.add_slot_label_universal(input); + mm_graph_node.add_slot_texture_universal(image); + mm_graph_node.add_slot_float("get_edge_color", "set_edge_color", "Edge color", 0.01); +} + + + void FillToRandomGrey::_render(const Variant &material) { + Ref img = render_image(material); + image.set_value(img); +} + + + Color FillToRandomGrey::_get_value_for(const Vector2 &uv, const int pseed) { + //vec4 $(name_uv)_bb = $in($uv); + Color c = input.get_value(uv); + //mix($edgecolor, rand(vec2(float($seed), rand(vec2(rand($(name_uv)_bb.xy), rand($(name_uv)_bb.zw))))), step(0.0000001, dot($(name_uv)_bb.zw, vec2(1.0)))); + float r1 = MMAlgos.rand(Vector2(c.r, c.g)); + float r2 = MMAlgos.rand(Vector2(c.b, c.a)); + float s = MMAlgos.step(0.0000001, Vector2(c.b, c.a).dot(Vector2(1, 1))); + float f = lerp(edge_color, MMAlgos.rand(Vector2(1.0 / float(pseed), MMAlgos.rand(Vector2(r1, r2)))), s); + return Color(f, f, f, 1); +} + + //edge_color; + + float FillToRandomGrey::get_edge_color() { + return edge_color; +} + + + void FillToRandomGrey::set_edge_color(const float val) { + edge_color = val; + set_dirty(true); +} + +} + + FillToRandomGrey::FillToRandomGrey() { + image; + input; + edge_color = 1; + } + + FillToRandomGrey::~FillToRandomGrey() { + } + + + static void FillToRandomGrey::_bind_methods() { + ClassDB::bind_method(D_METHOD("get_image"), &FillToRandomGrey::get_image); + ClassDB::bind_method(D_METHOD("set_image", "value"), &FillToRandomGrey::set_image); + ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "image", PROPERTY_HINT_RESOURCE_TYPE, "Ref"), "set_image", "get_image"); + + + ClassDB::bind_method(D_METHOD("get_input"), &FillToRandomGrey::get_input); + ClassDB::bind_method(D_METHOD("set_input", "value"), &FillToRandomGrey::set_input); + ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "input", PROPERTY_HINT_RESOURCE_TYPE, "Ref"), "set_input", "get_input"); + + + ClassDB::bind_method(D_METHOD("get_edge_color"), &FillToRandomGrey::get_edge_color); + ClassDB::bind_method(D_METHOD("set_edge_color", "value"), &FillToRandomGrey::set_edge_color); + ADD_PROPERTY(PropertyInfo(Variant::REAL, "edge_color"), "set_edge_color", "get_edge_color"); + + + ClassDB::bind_method(D_METHOD("_init_properties"), &FillToRandomGrey::_init_properties); + ClassDB::bind_method(D_METHOD("_register_methods", "mm_graph_node"), &FillToRandomGrey::_register_methods); + ClassDB::bind_method(D_METHOD("_render", "material"), &FillToRandomGrey::_render); + ClassDB::bind_method(D_METHOD("_get_value_for", "uv", "pseed"), &FillToRandomGrey::_get_value_for); + ClassDB::bind_method(D_METHOD("get_edge_color"), &FillToRandomGrey::get_edge_color); + ClassDB::bind_method(D_METHOD("set_edge_color", "val"), &FillToRandomGrey::set_edge_color); + + } + + + diff --git a/modules/material_maker/nodes/filter/fill_to_random_grey.h b/modules/material_maker/nodes/filter/fill_to_random_grey.h new file mode 100644 index 000000000..6cd369987 --- /dev/null +++ b/modules/material_maker/nodes/filter/fill_to_random_grey.h @@ -0,0 +1,43 @@ +#ifndef FILL_TO_RANDOM_GREY_H +#define FILL_TO_RANDOM_GREY_H + + +class FillToRandomGrey : public MMNode { + GDCLASS(FillToRandomGrey, MMNode); + + public: + + Ref get_image(); + void set_image(const Ref &val); + + Ref get_input(); + void set_input(const Ref &val); + + float get_edge_color() const; + void set_edge_color(const float val); + + 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); + float get_edge_color(); + void set_edge_color(const float val); + + FillToRandomGrey(); + ~FillToRandomGrey(); + + protected: + static void _bind_methods(); + + //tool + //export(Resource) + Ref image; + //export(Resource) + Ref input; + //export(float) + float edge_color = 1; + //edge_color +}; + + +#endif diff --git a/modules/material_maker/nodes/filter/fill_to_size.cpp b/modules/material_maker/nodes/filter/fill_to_size.cpp new file mode 100644 index 000000000..9676bfc0e --- /dev/null +++ b/modules/material_maker/nodes/filter/fill_to_size.cpp @@ -0,0 +1,159 @@ + +#include "fill_to_size.h" + + +Ref FillToSize::get_image() { + return image; +} + +void FillToSize::set_image(const Ref &val) { +image = val; +} + + +Ref FillToSize::get_input() { + return input; +} + +void FillToSize::set_input(const Ref &val) { +input = val; +} + + +int FillToSize::get_formula() const { + return formula; +} + +void FillToSize::set_formula(const int val) { +formula = val; +} + + + + //tool; + //export(Resource) ; + Ref image; + //export(Resource) ; + Ref input; + //export(int, "Area,Width,Height,Max(W,H)") ; + int formula = 0; + + void FillToSize::_init_properties() { + + if (!input) { + input = MMNodeUniversalProperty.new(); + input.default_type = MMNodeUniversalProperty.DEFAULT_TYPE_COLOR; + input.set_default_value(Color(0, 0, 0, 1)); +} + + input.input_slot_type = MMNodeUniversalProperty.SLOT_TYPE_UNIVERSAL; + input.slot_name = ">>> Input "; + + if (!image) { + image = MMNodeUniversalProperty.new(); + image.default_type = MMNodeUniversalProperty.DEFAULT_TYPE_IMAGE; +} + + //image.input_slot_type = MMNodeUniversalProperty.SLOT_TYPE_FLOAT; + image.output_slot_type = MMNodeUniversalProperty.SLOT_TYPE_IMAGE; + //image.force_override = true; + register_input_property(input); + register_output_property(image); +} + + + void FillToSize::_register_methods(const Variant &mm_graph_node) { + mm_graph_node.add_slot_label_universal(input); + mm_graph_node.add_slot_texture_universal(image); + mm_graph_node.add_slot_enum("get_formula", "set_formula", "Formula", [ "Area", "Width", "Height", "Max(W,H)" ]); +} + + + void FillToSize::_render(const Variant &material) { + Ref img = render_image(material); + image.set_value(img); +} + + + Color FillToSize::_get_value_for(const Vector2 &uv, const int pseed) { + //vec4 $(name_uv)_bb = $in($uv); + Color c = input.get_value(uv); + float f = 0; + //"Area" sqrt($(name_uv)_bb.z*$(name_uv)_bb.w); + //"Width" $(name_uv)_bb.z; + //"Height" $(name_uv)_bb.w; + //"max(W, H)" max($(name_uv)_bb.z, $(name_uv)_bb.w); + + if (formula == 0) { + f = sqrt(c.b * c.a); +} + + + else if (formula == 1) { + f = c.b; +} + + + else if (formula == 2) { + f = c.a; +} + + + else if (formula == 3) { + f = max(c.b, c.a); +} + + return Color(f, f, f, 1); +} + + //formula; + + int FillToSize::get_formula() { + return formula; +} + + + void FillToSize::set_formula(const int val) { + formula = val; + set_dirty(true); +} + +} + + FillToSize::FillToSize() { + image; + input; + formula = 0; + } + + FillToSize::~FillToSize() { + } + + + static void FillToSize::_bind_methods() { + ClassDB::bind_method(D_METHOD("get_image"), &FillToSize::get_image); + ClassDB::bind_method(D_METHOD("set_image", "value"), &FillToSize::set_image); + ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "image", PROPERTY_HINT_RESOURCE_TYPE, "Ref"), "set_image", "get_image"); + + + ClassDB::bind_method(D_METHOD("get_input"), &FillToSize::get_input); + ClassDB::bind_method(D_METHOD("set_input", "value"), &FillToSize::set_input); + ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "input", PROPERTY_HINT_RESOURCE_TYPE, "Ref"), "set_input", "get_input"); + + + ClassDB::bind_method(D_METHOD("get_formula"), &FillToSize::get_formula); + ClassDB::bind_method(D_METHOD("set_formula", "value"), &FillToSize::set_formula); + ADD_PROPERTY(PropertyInfo(Variant::INT, "formula"), "set_formula", "get_formula"); + + + ClassDB::bind_method(D_METHOD("_init_properties"), &FillToSize::_init_properties); + ClassDB::bind_method(D_METHOD("_register_methods", "mm_graph_node"), &FillToSize::_register_methods); + ClassDB::bind_method(D_METHOD("_render", "material"), &FillToSize::_render); + ClassDB::bind_method(D_METHOD("_get_value_for", "uv", "pseed"), &FillToSize::_get_value_for); + ClassDB::bind_method(D_METHOD("get_formula"), &FillToSize::get_formula); + ClassDB::bind_method(D_METHOD("set_formula", "val"), &FillToSize::set_formula); + + } + + + diff --git a/modules/material_maker/nodes/filter/fill_to_size.h b/modules/material_maker/nodes/filter/fill_to_size.h new file mode 100644 index 000000000..1c4db9c95 --- /dev/null +++ b/modules/material_maker/nodes/filter/fill_to_size.h @@ -0,0 +1,43 @@ +#ifndef FILL_TO_SIZE_H +#define FILL_TO_SIZE_H + + +class FillToSize : public MMNode { + GDCLASS(FillToSize, MMNode); + + public: + + Ref get_image(); + void set_image(const Ref &val); + + Ref get_input(); + void set_input(const Ref &val); + + int get_formula() const; + void set_formula(const int val); + + 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); + int get_formula(); + void set_formula(const int val); + + FillToSize(); + ~FillToSize(); + + protected: + static void _bind_methods(); + + //tool + //export(Resource) + Ref image; + //export(Resource) + Ref input; + //export(int, "Area,Width,Height,Max(W,H)") + int formula = 0; + //formula +}; + + +#endif diff --git a/modules/material_maker/nodes/filter/fill_to_uv.cpp b/modules/material_maker/nodes/filter/fill_to_uv.cpp new file mode 100644 index 000000000..157d9e105 --- /dev/null +++ b/modules/material_maker/nodes/filter/fill_to_uv.cpp @@ -0,0 +1,146 @@ + +#include "fill_to_uv.h" + + +Ref FillToUv::get_image() { + return image; +} + +void FillToUv::set_image(const Ref &val) { +image = val; +} + + +Ref FillToUv::get_input() { + return input; +} + +void FillToUv::set_input(const Ref &val) { +input = val; +} + + +int FillToUv::get_mode() const { + return mode; +} + +void FillToUv::set_mode(const int val) { +mode = val; +} + + + + //tool; + //export(Resource) ; + Ref image; + //export(Resource) ; + Ref input; + //export(int, "Stretch,Square") ; + int mode = 0; + + void FillToUv::_init_properties() { + + if (!input) { + input = MMNodeUniversalProperty.new(); + input.default_type = MMNodeUniversalProperty.DEFAULT_TYPE_COLOR; + input.set_default_value(Color(0, 0, 0, 1)); +} + + input.input_slot_type = MMNodeUniversalProperty.SLOT_TYPE_UNIVERSAL; + input.slot_name = ">>> Input "; + + if (!image) { + image = MMNodeUniversalProperty.new(); + image.default_type = MMNodeUniversalProperty.DEFAULT_TYPE_IMAGE; +} + + //image.input_slot_type = MMNodeUniversalProperty.SLOT_TYPE_FLOAT; + image.output_slot_type = MMNodeUniversalProperty.SLOT_TYPE_IMAGE; + //image.force_override = true; + register_input_property(input); + register_output_property(image); +} + + + void FillToUv::_register_methods(const Variant &mm_graph_node) { + mm_graph_node.add_slot_label_universal(input); + mm_graph_node.add_slot_texture_universal(image); + mm_graph_node.add_slot_enum("get_mode", "set_mode", "Mode", [ "Stretch", "Square" ]); +} + + + void FillToUv::_render(const Variant &material) { + Ref img = render_image(material); + image.set_value(img); +} + + + Color FillToUv::_get_value_for(const Vector2 &uv, const int pseed) { + //vec4 $(name_uv)_bb = $in($uv); + Color c = input.get_value(uv); + //fill_to_uv_$mode($uv, $(name_uv)_bb, float($seed)); + Vector3 r = Vector3(); + + if (mode == 0) { + r = MMAlgos.fill_to_uv_stretch(uv, c, float(pseed)); +} + + + else if (mode == 1) { + r = MMAlgos.fill_to_uv_square(uv, c, float(pseed)); +} + + return Color(r.x, r.y, r.z, 1); +} + + //mode; + + int FillToUv::get_mode() { + return mode; +} + + + void FillToUv::set_mode(const int val) { + mode = val; + set_dirty(true); +} + +} + + FillToUv::FillToUv() { + image; + input; + mode = 0; + } + + FillToUv::~FillToUv() { + } + + + static void FillToUv::_bind_methods() { + ClassDB::bind_method(D_METHOD("get_image"), &FillToUv::get_image); + ClassDB::bind_method(D_METHOD("set_image", "value"), &FillToUv::set_image); + ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "image", PROPERTY_HINT_RESOURCE_TYPE, "Ref"), "set_image", "get_image"); + + + ClassDB::bind_method(D_METHOD("get_input"), &FillToUv::get_input); + ClassDB::bind_method(D_METHOD("set_input", "value"), &FillToUv::set_input); + ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "input", PROPERTY_HINT_RESOURCE_TYPE, "Ref"), "set_input", "get_input"); + + + ClassDB::bind_method(D_METHOD("get_mode"), &FillToUv::get_mode); + ClassDB::bind_method(D_METHOD("set_mode", "value"), &FillToUv::set_mode); + ADD_PROPERTY(PropertyInfo(Variant::INT, "mode"), "set_mode", "get_mode"); + + + ClassDB::bind_method(D_METHOD("_init_properties"), &FillToUv::_init_properties); + ClassDB::bind_method(D_METHOD("_register_methods", "mm_graph_node"), &FillToUv::_register_methods); + ClassDB::bind_method(D_METHOD("_render", "material"), &FillToUv::_render); + ClassDB::bind_method(D_METHOD("_get_value_for", "uv", "pseed"), &FillToUv::_get_value_for); + ClassDB::bind_method(D_METHOD("get_mode"), &FillToUv::get_mode); + ClassDB::bind_method(D_METHOD("set_mode", "val"), &FillToUv::set_mode); + + } + + + diff --git a/modules/material_maker/nodes/filter/fill_to_uv.h b/modules/material_maker/nodes/filter/fill_to_uv.h new file mode 100644 index 000000000..a10442c30 --- /dev/null +++ b/modules/material_maker/nodes/filter/fill_to_uv.h @@ -0,0 +1,43 @@ +#ifndef FILL_TO_UV_H +#define FILL_TO_UV_H + + +class FillToUv : public MMNode { + GDCLASS(FillToUv, MMNode); + + public: + + Ref get_image(); + void set_image(const Ref &val); + + Ref get_input(); + void set_input(const Ref &val); + + int get_mode() const; + void set_mode(const int val); + + 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); + int get_mode(); + void set_mode(const int val); + + FillToUv(); + ~FillToUv(); + + protected: + static void _bind_methods(); + + //tool + //export(Resource) + Ref image; + //export(Resource) + Ref input; + //export(int, "Stretch,Square") + int mode = 0; + //mode +}; + + +#endif diff --git a/modules/material_maker/nodes/filter/greyscale.cpp b/modules/material_maker/nodes/filter/greyscale.cpp new file mode 100644 index 000000000..65ddea934 --- /dev/null +++ b/modules/material_maker/nodes/filter/greyscale.cpp @@ -0,0 +1,159 @@ + +#include "greyscale.h" + + +Ref Greyscale::get_image() { + return image; +} + +void Greyscale::set_image(const Ref &val) { +image = val; +} + + +Ref Greyscale::get_input() { + return input; +} + +void Greyscale::set_input(const Ref &val) { +input = val; +} + + +int Greyscale::get_type() const { + return type; +} + +void Greyscale::set_type(const int val) { +type = val; +} + + + + //tool; + //export(Resource) ; + Ref image; + //export(Resource) ; + Ref input; + //export(int, "Lightness,Average,Luminosity,Min,Max") ; + int type = 2; + + void Greyscale::_init_properties() { + + if (!input) { + input = MMNodeUniversalProperty.new(); + input.default_type = MMNodeUniversalProperty.DEFAULT_TYPE_COLOR; + input.set_default_value(Color(0, 0, 0, 1)); +} + + input.input_slot_type = MMNodeUniversalProperty.SLOT_TYPE_UNIVERSAL; + input.slot_name = ">>> Input1 "; + + if (!image) { + image = MMNodeUniversalProperty.new(); + image.default_type = MMNodeUniversalProperty.DEFAULT_TYPE_IMAGE; +} + + //image.input_slot_type = MMNodeUniversalProperty.SLOT_TYPE_FLOAT; + image.output_slot_type = MMNodeUniversalProperty.SLOT_TYPE_IMAGE; + //image.force_override = true; + register_input_property(input); + register_output_property(image); +} + + + void Greyscale::_register_methods(const Variant &mm_graph_node) { + mm_graph_node.add_slot_label_universal(input); + mm_graph_node.add_slot_texture_universal(image); + mm_graph_node.add_slot_enum("get_type", "set_type", "Type", [ "Lightness", "Average", "Luminosity", "Min", "Max" ]); +} + + + void Greyscale::_render(const Variant &material) { + Ref img = render_image(material); + image.set_value(img); +} + + + Color Greyscale::_get_value_for(const Vector2 &uv, const int pseed) { + Color c = input.get_value(uv); + float f = 0; + + if (type == 0) { + f = MMAlgos.grayscale_lightness(Vector3(c.r, c.g, c.b)); +} + + + else if (type == 1) { + f = MMAlgos.grayscale_average(Vector3(c.r, c.g, c.b)); +} + + + else if (type == 2) { + f = MMAlgos.grayscale_luminosity(Vector3(c.r, c.g, c.b)); +} + + + else if (type == 3) { + f = MMAlgos.grayscale_min(Vector3(c.r, c.g, c.b)); +} + + + else if (type == 4) { + f = MMAlgos.grayscale_max(Vector3(c.r, c.g, c.b)); +} + + return Color(f, f, f, c.a); +} + + //type; + + int Greyscale::get_type() { + return type; +} + + + void Greyscale::set_type(const int val) { + type = val; + set_dirty(true); +} + +} + + Greyscale::Greyscale() { + image; + input; + type = 2; + } + + Greyscale::~Greyscale() { + } + + + static void Greyscale::_bind_methods() { + ClassDB::bind_method(D_METHOD("get_image"), &Greyscale::get_image); + ClassDB::bind_method(D_METHOD("set_image", "value"), &Greyscale::set_image); + ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "image", PROPERTY_HINT_RESOURCE_TYPE, "Ref"), "set_image", "get_image"); + + + ClassDB::bind_method(D_METHOD("get_input"), &Greyscale::get_input); + ClassDB::bind_method(D_METHOD("set_input", "value"), &Greyscale::set_input); + ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "input", PROPERTY_HINT_RESOURCE_TYPE, "Ref"), "set_input", "get_input"); + + + ClassDB::bind_method(D_METHOD("get_type"), &Greyscale::get_type); + ClassDB::bind_method(D_METHOD("set_type", "value"), &Greyscale::set_type); + ADD_PROPERTY(PropertyInfo(Variant::INT, "type"), "set_type", "get_type"); + + + ClassDB::bind_method(D_METHOD("_init_properties"), &Greyscale::_init_properties); + ClassDB::bind_method(D_METHOD("_register_methods", "mm_graph_node"), &Greyscale::_register_methods); + ClassDB::bind_method(D_METHOD("_render", "material"), &Greyscale::_render); + ClassDB::bind_method(D_METHOD("_get_value_for", "uv", "pseed"), &Greyscale::_get_value_for); + ClassDB::bind_method(D_METHOD("get_type"), &Greyscale::get_type); + ClassDB::bind_method(D_METHOD("set_type", "val"), &Greyscale::set_type); + + } + + + diff --git a/modules/material_maker/nodes/filter/greyscale.h b/modules/material_maker/nodes/filter/greyscale.h new file mode 100644 index 000000000..39e9ef743 --- /dev/null +++ b/modules/material_maker/nodes/filter/greyscale.h @@ -0,0 +1,43 @@ +#ifndef GREYSCALE_H +#define GREYSCALE_H + + +class Greyscale : public MMNode { + GDCLASS(Greyscale, MMNode); + + public: + + Ref get_image(); + void set_image(const Ref &val); + + Ref get_input(); + void set_input(const Ref &val); + + int get_type() const; + void set_type(const int val); + + 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); + int get_type(); + void set_type(const int val); + + Greyscale(); + ~Greyscale(); + + protected: + static void _bind_methods(); + + //tool + //export(Resource) + Ref image; + //export(Resource) + Ref input; + //export(int, "Lightness,Average,Luminosity,Min,Max") + int type = 2; + //type +}; + + +#endif diff --git a/modules/material_maker/nodes/filter/invert.cpp b/modules/material_maker/nodes/filter/invert.cpp new file mode 100644 index 000000000..b4d9fc6da --- /dev/null +++ b/modules/material_maker/nodes/filter/invert.cpp @@ -0,0 +1,101 @@ + +#include "invert.h" + + +Ref Invert::get_image() { + return image; +} + +void Invert::set_image(const Ref &val) { +image = val; +} + + +Ref Invert::get_input() { + return input; +} + +void Invert::set_input(const Ref &val) { +input = val; +} + + + + //tool; + //export(Resource) ; + Ref image; + //export(Resource) ; + Ref input; + + void Invert::_init_properties() { + + if (!input) { + input = MMNodeUniversalProperty.new(); + input.default_type = MMNodeUniversalProperty.DEFAULT_TYPE_COLOR; + input.set_default_value(Color(0, 0, 0, 1)); +} + + input.input_slot_type = MMNodeUniversalProperty.SLOT_TYPE_UNIVERSAL; + input.slot_name = ">>> Input1 "; + + if (!image) { + image = MMNodeUniversalProperty.new(); + image.default_type = MMNodeUniversalProperty.DEFAULT_TYPE_IMAGE; +} + + //image.input_slot_type = MMNodeUniversalProperty.SLOT_TYPE_FLOAT; + image.output_slot_type = MMNodeUniversalProperty.SLOT_TYPE_IMAGE; + //image.force_override = true; + register_input_property(input); + register_output_property(image); +} + + + void Invert::_register_methods(const Variant &mm_graph_node) { + mm_graph_node.add_slot_label_universal(input); + mm_graph_node.add_slot_texture_universal(image); +} + + + void Invert::_render(const Variant &material) { + Ref img = render_image(material); + image.set_value(img); +} + + + Color Invert::_get_value_for(const Vector2 &uv, const int pseed) { + Color c = input.get_value(uv); + return MMAlgos.invert(c); +} + +} + + Invert::Invert() { + image; + input; + } + + Invert::~Invert() { + } + + + static void Invert::_bind_methods() { + ClassDB::bind_method(D_METHOD("get_image"), &Invert::get_image); + ClassDB::bind_method(D_METHOD("set_image", "value"), &Invert::set_image); + ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "image", PROPERTY_HINT_RESOURCE_TYPE, "Ref"), "set_image", "get_image"); + + + ClassDB::bind_method(D_METHOD("get_input"), &Invert::get_input); + ClassDB::bind_method(D_METHOD("set_input", "value"), &Invert::set_input); + ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "input", PROPERTY_HINT_RESOURCE_TYPE, "Ref"), "set_input", "get_input"); + + + ClassDB::bind_method(D_METHOD("_init_properties"), &Invert::_init_properties); + ClassDB::bind_method(D_METHOD("_register_methods", "mm_graph_node"), &Invert::_register_methods); + ClassDB::bind_method(D_METHOD("_render", "material"), &Invert::_render); + ClassDB::bind_method(D_METHOD("_get_value_for", "uv", "pseed"), &Invert::_get_value_for); + + } + + + diff --git a/modules/material_maker/nodes/filter/invert.h b/modules/material_maker/nodes/filter/invert.h new file mode 100644 index 000000000..2e333ae01 --- /dev/null +++ b/modules/material_maker/nodes/filter/invert.h @@ -0,0 +1,35 @@ +#ifndef INVERT_H +#define INVERT_H + + +class Invert : public MMNode { + GDCLASS(Invert, MMNode); + + public: + + Ref get_image(); + void set_image(const Ref &val); + + Ref get_input(); + void set_input(const Ref &val); + + 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); + + Invert(); + ~Invert(); + + protected: + static void _bind_methods(); + + //tool + //export(Resource) + Ref image; + //export(Resource) + Ref input; +}; + + +#endif diff --git a/modules/material_maker/nodes/filter/make_tileable.cpp b/modules/material_maker/nodes/filter/make_tileable.cpp new file mode 100644 index 000000000..cee190d48 --- /dev/null +++ b/modules/material_maker/nodes/filter/make_tileable.cpp @@ -0,0 +1,168 @@ + +#include "make_tileable.h" + + +Ref MakeTileable::get_image() { + return image; +} + +void MakeTileable::set_image(const Ref &val) { +image = val; +} + + +Ref MakeTileable::get_input() { + return input; +} + +void MakeTileable::set_input(const Ref &val) { +input = val; +} + + +float MakeTileable::get_width() const { + return width; +} + +void MakeTileable::set_width(const float val) { +width = val; +} + + +int MakeTileable::get_size() const { + return size; +} + +void MakeTileable::set_size(const int val) { +size = val; +} + + + + //tool; + //export(Resource) ; + Ref image; + //export(Resource) ; + Ref input; + //export(float) ; + float width = 0.1; + int size = 0; + + void MakeTileable::_init_properties() { + + if (!image) { + image = MMNodeUniversalProperty.new(); + image.default_type = MMNodeUniversalProperty.DEFAULT_TYPE_IMAGE; +} + + image.output_slot_type = MMNodeUniversalProperty.SLOT_TYPE_IMAGE; + + if (!input) { + input = MMNodeUniversalProperty.new(); + input.default_type = MMNodeUniversalProperty.DEFAULT_TYPE_COLOR; + input.set_default_value(Color()); +} + + input.input_slot_type = MMNodeUniversalProperty.SLOT_TYPE_UNIVERSAL; + input.slot_name = ">>> Input1 "; + register_input_property(input); + register_output_property(image); +} + + + void MakeTileable::_register_methods(const Variant &mm_graph_node) { + mm_graph_node.add_slot_texture_universal(image); + mm_graph_node.add_slot_label_universal(input); + mm_graph_node.add_slot_float("get_width", "set_width", "Width", 0.01); +} + + + void MakeTileable::_render(const Variant &material) { + size = max(material.image_size.x, material.image_size.y); + Ref img = render_image(material); + image.set_value(img); +} + + + Color MakeTileable::_get_value_for(const Vector2 &uv, const int pseed) { + //make_tileable_$(name)($uv, 0.5*$w); + return make_tileable(uv, 0.5 * width); +} + + + float MakeTileable::get_width() { + return width; +} + + + void MakeTileable::set_width(const float val) { + width = val; + set_dirty(true); +} + + //----------------------; + //make_tileable.mmg; + //vec4 make_tileable_$(name)(vec2 uv, float w) {; + // vec4 a = $in(uv); + // vec4 b = $in(fract(uv+vec2(0.5))); + // float coef_ab = sin(1.57079632679*clamp((length(uv-vec2(0.5))-0.5+w)/w, 0.0, 1.0)); + // vec4 c = $in(fract(uv+vec2(0.25))); + // float coef_abc = sin(1.57079632679*clamp((min(min(length(uv-vec2(0.0, 0.5)), length(uv-vec2(0.5, 0.0))), min(length(uv-vec2(1.0, 0.5)), length(uv-vec2(0.5, 1.0))))-w)/w, 0.0, 1.0)); + // return mix(c, mix(a, b, coef_ab), coef_abc); + //}; + + Color MakeTileable::make_tileable(const Vector2 &uv, const float w) { + Color a = input.get_value(uv); + Color b = input.get_value(MMAlgos.fractv2(uv + Vector2(0.5, 0.5))); + float coef_ab = sin(1.57079632679 * clamp(((uv - Vector2(0.5, 0.5)).length() - 0.5 + w) / w, 0.0, 1.0)); + Color c = input.get_value(MMAlgos.fractv2(uv + Vector2(0.25, 0.25))); + float coef_abc = sin(1.57079632679 * clamp((min(min((uv - Vector2(0.0, 0.5)).length(), (uv - Vector2(0.5, 0.0)).length()), min((uv- Vector2(1.0, 0.5)).length(), (uv - Vector2(0.5, 1.0)).length())) - w) / w, 0.0, 1.0)); + return lerp(c, lerp(a, b, coef_ab), coef_abc); +} + +} + + MakeTileable::MakeTileable() { + image; + input; + width = 0.1; + size = 0; + } + + MakeTileable::~MakeTileable() { + } + + + static void MakeTileable::_bind_methods() { + ClassDB::bind_method(D_METHOD("get_image"), &MakeTileable::get_image); + ClassDB::bind_method(D_METHOD("set_image", "value"), &MakeTileable::set_image); + ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "image", PROPERTY_HINT_RESOURCE_TYPE, "Ref"), "set_image", "get_image"); + + + ClassDB::bind_method(D_METHOD("get_input"), &MakeTileable::get_input); + ClassDB::bind_method(D_METHOD("set_input", "value"), &MakeTileable::set_input); + ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "input", PROPERTY_HINT_RESOURCE_TYPE, "Ref"), "set_input", "get_input"); + + + ClassDB::bind_method(D_METHOD("get_width"), &MakeTileable::get_width); + ClassDB::bind_method(D_METHOD("set_width", "value"), &MakeTileable::set_width); + ADD_PROPERTY(PropertyInfo(Variant::REAL, "width"), "set_width", "get_width"); + + + ClassDB::bind_method(D_METHOD("get_size"), &MakeTileable::get_size); + ClassDB::bind_method(D_METHOD("set_size", "value"), &MakeTileable::set_size); + ADD_PROPERTY(PropertyInfo(Variant::INT, "size"), "set_size", "get_size"); + + + ClassDB::bind_method(D_METHOD("_init_properties"), &MakeTileable::_init_properties); + ClassDB::bind_method(D_METHOD("_register_methods", "mm_graph_node"), &MakeTileable::_register_methods); + ClassDB::bind_method(D_METHOD("_render", "material"), &MakeTileable::_render); + ClassDB::bind_method(D_METHOD("_get_value_for", "uv", "pseed"), &MakeTileable::_get_value_for); + ClassDB::bind_method(D_METHOD("get_width"), &MakeTileable::get_width); + ClassDB::bind_method(D_METHOD("set_width", "val"), &MakeTileable::set_width); + ClassDB::bind_method(D_METHOD("make_tileable", "uv", "w"), &MakeTileable::make_tileable); + + } + + + diff --git a/modules/material_maker/nodes/filter/make_tileable.h b/modules/material_maker/nodes/filter/make_tileable.h new file mode 100644 index 000000000..7b6e29125 --- /dev/null +++ b/modules/material_maker/nodes/filter/make_tileable.h @@ -0,0 +1,57 @@ +#ifndef MAKE_TILEABLE_H +#define MAKE_TILEABLE_H + + +class MakeTileable : public MMNode { + GDCLASS(MakeTileable, MMNode); + + public: + + Ref get_image(); + void set_image(const Ref &val); + + Ref get_input(); + void set_input(const Ref &val); + + float get_width() const; + void set_width(const float val); + + int get_size() const; + void set_size(const int val); + + 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); + float get_width(); + void set_width(const float val); + Color make_tileable(const Vector2 &uv, const float w); + + MakeTileable(); + ~MakeTileable(); + + protected: + static void _bind_methods(); + + //tool + //export(Resource) + Ref image; + //export(Resource) + Ref input; + //export(float) + float width = 0.1; + int size = 0; + //---------------------- + //make_tileable.mmg + //vec4 make_tileable_$(name)(vec2 uv, float w) { + // vec4 a = $in(uv); + // vec4 b = $in(fract(uv+vec2(0.5))); + // float coef_ab = sin(1.57079632679*clamp((length(uv-vec2(0.5))-0.5+w)/w, 0.0, 1.0)); + // vec4 c = $in(fract(uv+vec2(0.25))); + // float coef_abc = sin(1.57079632679*clamp((min(min(length(uv-vec2(0.0, 0.5)), length(uv-vec2(0.5, 0.0))), min(length(uv-vec2(1.0, 0.5)), length(uv-vec2(0.5, 1.0))))-w)/w, 0.0, 1.0)); + // return mix(c, mix(a, b, coef_ab), coef_abc); + //} +}; + + +#endif diff --git a/modules/material_maker/nodes/filter/math.cpp b/modules/material_maker/nodes/filter/math.cpp new file mode 100644 index 000000000..f802da556 --- /dev/null +++ b/modules/material_maker/nodes/filter/math.cpp @@ -0,0 +1,369 @@ + +#include "math.h" + + +Ref Math::get_image() { + return image; +} + +void Math::set_image(const Ref &val) { +image = val; +} + + +Ref Math::get_a() { + return a; +} + +void Math::set_a(const Ref &val) { +a = val; +} + + +Ref Math::get_b() { + return b; +} + +void Math::set_b(const Ref &val) { +b = val; +} + + +Ref Math::get_output() { + return output; +} + +void Math::set_output(const Ref &val) { +output = val; +} + + +int Math::get_operation() const { + return operation; +} + +void Math::set_operation(const int val) { +operation = val; +} + + +bool Math::get_clamp_result() const { + return clamp_result; +} + +void Math::set_clamp_result(const bool val) { +clamp_result = val; +} + + + + //tool; + //export(Resource) ; + Ref image; + //export(Resource) ; + Ref a; + //export(Resource) ; + Ref b; + //export(Resource) ; + Ref output; + //export(int, "A+B,A-B,A*B,A/B,log(A),log2(A),pow(A; B),abs(A),round(A),floor(A),ceil(A),trunc(A),fract(A),min(A; B),max(A; B),A img = render_image(material); + image.set_value(img); +} + + + Color Math::_get_value_for(const Vector2 &uv, const int pseed) { + float f = get_property_value(uv); + return Color(f, f, f, 1); +} + + //operation; + + int Math::get_operation() { + return operation; +} + + + void Math::set_operation(const int val) { + operation = val; + set_dirty(true); + output.emit_changed(); +} + + //clamp_result; + + bool Math::get_clamp_result() { + return clamp_result; +} + + + void Math::set_clamp_result(const bool val) { + clamp_result = val; + set_dirty(true); + output.emit_changed(); +} + +} + + Math::Math() { + image; + a; + b; + output; + operation = 0; + clamp_result = false; + } + + Math::~Math() { + } + + + static void Math::_bind_methods() { + ClassDB::bind_method(D_METHOD("get_image"), &Math::get_image); + ClassDB::bind_method(D_METHOD("set_image", "value"), &Math::set_image); + ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "image", PROPERTY_HINT_RESOURCE_TYPE, "Ref"), "set_image", "get_image"); + + + ClassDB::bind_method(D_METHOD("get_a"), &Math::get_a); + ClassDB::bind_method(D_METHOD("set_a", "value"), &Math::set_a); + ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "a", PROPERTY_HINT_RESOURCE_TYPE, "Ref"), "set_a", "get_a"); + + + ClassDB::bind_method(D_METHOD("get_b"), &Math::get_b); + ClassDB::bind_method(D_METHOD("set_b", "value"), &Math::set_b); + ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "b", PROPERTY_HINT_RESOURCE_TYPE, "Ref"), "set_b", "get_b"); + + + ClassDB::bind_method(D_METHOD("get_output"), &Math::get_output); + ClassDB::bind_method(D_METHOD("set_output", "value"), &Math::set_output); + ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "output", PROPERTY_HINT_RESOURCE_TYPE, "Ref"), "set_output", "get_output"); + + + ClassDB::bind_method(D_METHOD("get_operation"), &Math::get_operation); + ClassDB::bind_method(D_METHOD("set_operation", "value"), &Math::set_operation); + ADD_PROPERTY(PropertyInfo(Variant::INT, "operation"), "set_operation", "get_operation"); + + + ClassDB::bind_method(D_METHOD("get_clamp_result"), &Math::get_clamp_result); + ClassDB::bind_method(D_METHOD("set_clamp_result", "value"), &Math::set_clamp_result); + ADD_PROPERTY(PropertyInfo(Variant::BOOL, "clamp_result"), "set_clamp_result", "get_clamp_result"); + + + ClassDB::bind_method(D_METHOD("_init_properties"), &Math::_init_properties); + ClassDB::bind_method(D_METHOD("_register_methods", "mm_graph_node"), &Math::_register_methods); + ClassDB::bind_method(D_METHOD("_get_property_value", "uv"), &Math::_get_property_value); + ClassDB::bind_method(D_METHOD("_render", "material"), &Math::_render); + ClassDB::bind_method(D_METHOD("_get_value_for", "uv", "pseed"), &Math::_get_value_for); + ClassDB::bind_method(D_METHOD("get_operation"), &Math::get_operation); + ClassDB::bind_method(D_METHOD("set_operation", "val"), &Math::set_operation); + ClassDB::bind_method(D_METHOD("get_clamp_result"), &Math::get_clamp_result); + ClassDB::bind_method(D_METHOD("set_clamp_result", "val"), &Math::set_clamp_result); + + } + + + diff --git a/modules/material_maker/nodes/filter/math.h b/modules/material_maker/nodes/filter/math.h new file mode 100644 index 000000000..6ed4208e5 --- /dev/null +++ b/modules/material_maker/nodes/filter/math.h @@ -0,0 +1,62 @@ +#ifndef MATH_H +#define MATH_H + + +class Math : public MMNode { + GDCLASS(Math, MMNode); + + public: + + Ref get_image(); + void set_image(const Ref &val); + + Ref get_a(); + void set_a(const Ref &val); + + Ref get_b(); + void set_b(const Ref &val); + + Ref get_output(); + void set_output(const Ref &val); + + int get_operation() const; + void set_operation(const int val); + + bool get_clamp_result() const; + void set_clamp_result(const bool val); + + void _init_properties(); + void _register_methods(const Variant &mm_graph_node); + float _get_property_value(const Vector2 &uv); + void _render(const Variant &material); + Color _get_value_for(const Vector2 &uv, const int pseed); + int get_operation(); + void set_operation(const int val); + bool get_clamp_result(); + void set_clamp_result(const bool val); + + Math(); + ~Math(); + + protected: + static void _bind_methods(); + + //tool + //export(Resource) + Ref image; + //export(Resource) + Ref a; + //export(Resource) + Ref b; + //export(Resource) + Ref output; + //export(int, "A+B,A-B,A*B,A/B,log(A),log2(A),pow(A; B),abs(A),round(A),floor(A),ceil(A),trunc(A),fract(A),min(A; B),max(A; B),A Quantize::get_image() { + return image; +} + +void Quantize::set_image(const Ref &val) { +image = val; +} + + +Ref Quantize::get_input() { + return input; +} + +void Quantize::set_input(const Ref &val) { +input = val; +} + + +int Quantize::get_steps() const { + return steps; +} + +void Quantize::set_steps(const int val) { +steps = val; +} + + + + //tool; + //export(Resource) ; + Ref image; + //export(Resource) ; + Ref input; + //export(int) ; + int steps = 4; + + void Quantize::_init_properties() { + + if (!input) { + input = MMNodeUniversalProperty.new(); + input.default_type = MMNodeUniversalProperty.DEFAULT_TYPE_COLOR; + input.set_default_value(Color(0, 0, 0, 1)); +} + + input.input_slot_type = MMNodeUniversalProperty.SLOT_TYPE_UNIVERSAL; + input.slot_name = ">>> Input "; + + if (!image) { + image = MMNodeUniversalProperty.new(); + image.default_type = MMNodeUniversalProperty.DEFAULT_TYPE_IMAGE; +} + + //image.input_slot_type = MMNodeUniversalProperty.SLOT_TYPE_FLOAT; + image.output_slot_type = MMNodeUniversalProperty.SLOT_TYPE_IMAGE; + //image.force_override = true; + register_input_property(input); + register_output_property(image); +} + + + void Quantize::_register_methods(const Variant &mm_graph_node) { + mm_graph_node.add_slot_label_universal(input); + mm_graph_node.add_slot_texture_universal(image); + mm_graph_node.add_slot_int("get_steps", "set_steps", "Steps"); +} + + + void Quantize::_render(const Variant &material) { + Ref img = render_image(material); + image.set_value(img); +} + + + Color Quantize::_get_value_for(const Vector2 &uv, const int pseed) { + Color c = input.get_value(uv); + //vec4(floor($in($uv).rgb*$steps)/$steps, $in($uv).a); + Vector3 v = MMAlgos.floorv3(Vector3(c.r, c.g, c.b) * steps) / float(steps); + return Color(v.x, v.y, v.z, c.a); +} + + //steps; + + int Quantize::get_steps() { + return steps; +} + + + void Quantize::set_steps(const int val) { + steps = val; + set_dirty(true); +} + +} + + Quantize::Quantize() { + image; + input; + steps = 4; + } + + Quantize::~Quantize() { + } + + + static void Quantize::_bind_methods() { + ClassDB::bind_method(D_METHOD("get_image"), &Quantize::get_image); + ClassDB::bind_method(D_METHOD("set_image", "value"), &Quantize::set_image); + ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "image", PROPERTY_HINT_RESOURCE_TYPE, "Ref"), "set_image", "get_image"); + + + ClassDB::bind_method(D_METHOD("get_input"), &Quantize::get_input); + ClassDB::bind_method(D_METHOD("set_input", "value"), &Quantize::set_input); + ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "input", PROPERTY_HINT_RESOURCE_TYPE, "Ref"), "set_input", "get_input"); + + + ClassDB::bind_method(D_METHOD("get_steps"), &Quantize::get_steps); + ClassDB::bind_method(D_METHOD("set_steps", "value"), &Quantize::set_steps); + ADD_PROPERTY(PropertyInfo(Variant::INT, "steps"), "set_steps", "get_steps"); + + + ClassDB::bind_method(D_METHOD("_init_properties"), &Quantize::_init_properties); + ClassDB::bind_method(D_METHOD("_register_methods", "mm_graph_node"), &Quantize::_register_methods); + ClassDB::bind_method(D_METHOD("_render", "material"), &Quantize::_render); + ClassDB::bind_method(D_METHOD("_get_value_for", "uv", "pseed"), &Quantize::_get_value_for); + ClassDB::bind_method(D_METHOD("get_steps"), &Quantize::get_steps); + ClassDB::bind_method(D_METHOD("set_steps", "val"), &Quantize::set_steps); + + } + + + diff --git a/modules/material_maker/nodes/filter/quantize.h b/modules/material_maker/nodes/filter/quantize.h new file mode 100644 index 000000000..c9028c4d2 --- /dev/null +++ b/modules/material_maker/nodes/filter/quantize.h @@ -0,0 +1,43 @@ +#ifndef QUANTIZE_H +#define QUANTIZE_H + + +class Quantize : public MMNode { + GDCLASS(Quantize, MMNode); + + public: + + Ref get_image(); + void set_image(const Ref &val); + + Ref get_input(); + void set_input(const Ref &val); + + int get_steps() const; + void set_steps(const int val); + + 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); + int get_steps(); + void set_steps(const int val); + + Quantize(); + ~Quantize(); + + protected: + static void _bind_methods(); + + //tool + //export(Resource) + Ref image; + //export(Resource) + Ref input; + //export(int) + int steps = 4; + //steps +}; + + +#endif diff --git a/modules/material_maker/nodes/filter/swap_channels.cpp b/modules/material_maker/nodes/filter/swap_channels.cpp new file mode 100644 index 000000000..5ba97e5c8 --- /dev/null +++ b/modules/material_maker/nodes/filter/swap_channels.cpp @@ -0,0 +1,285 @@ + +#include "swap_channels.h" + + +Ref SwapChannels::get_image() { + return image; +} + +void SwapChannels::set_image(const Ref &val) { +image = val; +} + + +Ref SwapChannels::get_input() { + return input; +} + +void SwapChannels::set_input(const Ref &val) { +input = val; +} + + +int SwapChannels::get_op_r() const { + return op_r; +} + +void SwapChannels::set_op_r(const int val) { +op_r = val; +} + + +int SwapChannels::get_op_g() const { + return op_g; +} + +void SwapChannels::set_op_g(const int val) { +op_g = val; +} + + +int SwapChannels::get_op_b() const { + return op_b; +} + +void SwapChannels::set_op_b(const int val) { +op_b = val; +} + + +int SwapChannels::get_op_a() const { + return op_a; +} + +void SwapChannels::set_op_a(const int val) { +op_a = val; +} + + + + //tool; + //export(Resource) ; + Ref image; + //export(Resource) ; + Ref input; + //export(int, "0,1,R,-R,G,-G,B,-B,A,-A") ; + int op_r = 2; + //export(int, "0,1,R,-R,G,-G,B,-B,A,-A") ; + int op_g = 4; + //export(int, "0,1,R,-R,G,-G,B,-B,A,-A") ; + int op_b = 6; + //export(int, "0,1,R,-R,G,-G,B,-B,A,-A") ; + int op_a = 8; + + void SwapChannels::_init_properties() { + + if (!input) { + input = MMNodeUniversalProperty.new(); + input.default_type = MMNodeUniversalProperty.DEFAULT_TYPE_COLOR; + input.set_default_value(Color(0, 0, 0, 1)); +} + + input.input_slot_type = MMNodeUniversalProperty.SLOT_TYPE_UNIVERSAL; + input.slot_name = ">>> Input "; + + if (!image) { + image = MMNodeUniversalProperty.new(); + image.default_type = MMNodeUniversalProperty.DEFAULT_TYPE_IMAGE; +} + + //image.input_slot_type = MMNodeUniversalProperty.SLOT_TYPE_FLOAT; + image.output_slot_type = MMNodeUniversalProperty.SLOT_TYPE_IMAGE; + //image.force_override = true; + register_input_property(input); + register_output_property(image); +} + + + void SwapChannels::_register_methods(const Variant &mm_graph_node) { + mm_graph_node.add_slot_label_universal(input); + mm_graph_node.add_slot_texture_universal(image); + mm_graph_node.add_slot_enum("get_op_r", "set_op_r", "R", [ "0", "1", "R", "-R", "G", "-G", "B", "-B", "A","-A" ]); + mm_graph_node.add_slot_enum("get_op_g", "set_op_g", "G", [ "0", "1", "R", "-R", "G", "-G", "B", "-B", "A","-A" ]); + mm_graph_node.add_slot_enum("get_op_b", "set_op_b", "B", [ "0", "1", "R", "-R", "G", "-G", "B", "-B", "A","-A" ]); + mm_graph_node.add_slot_enum("get_op_a", "set_op_a", "A", [ "0", "1", "R", "-R", "G", "-G", "B", "-B", "A","-A" ]); +} + + + void SwapChannels::_render(const Variant &material) { + Ref img = render_image(material); + image.set_value(img); +} + + + float SwapChannels::apply(const int op, const Color &val) { + + if (op == 0) { + return 0.0; +} + + + else if (op == 1) { + return 1.0; +} + + + else if (op == 2) { + return val.r; +} + + + else if (op == 3) { + return 1.0 - val.r; +} + + + else if (op == 4) { + return val.g; +} + + + else if (op == 5) { + return 1.0 - val.g; +} + + + else if (op == 6) { + return val.b; +} + + + else if (op == 7) { + return 1.0 - val.b; +} + + + else if (op == 8) { + return val.a; +} + + + else if (op == 9) { + return 1.0 - val.a; +} + + return 0.0; +} + + + Color SwapChannels::_get_value_for(const Vector2 &uv, const int pseed) { + Color c = input.get_value(uv); + return Color(apply(op_r, c), apply(op_g, c), apply(op_b, c), apply(op_a, c)); +} + + //op_r; + + int SwapChannels::get_op_r() { + return op_r; +} + + + void SwapChannels::set_op_r(const int val) { + op_r = val; + set_dirty(true); +} + + //op_g; + + int SwapChannels::get_op_g() { + return op_g; +} + + + void SwapChannels::set_op_g(const int val) { + op_g = val; + set_dirty(true); +} + + //op_b; + + int SwapChannels::get_op_b() { + return op_b; +} + + + void SwapChannels::set_op_b(const int val) { + op_b = val; + set_dirty(true); +} + + //op_a; + + int SwapChannels::get_op_a() { + return op_a; +} + + + void SwapChannels::set_op_a(const int val) { + op_a = val; + set_dirty(true); +} + +} + + SwapChannels::SwapChannels() { + image; + input; + op_r = 2; + op_g = 4; + op_b = 6; + op_a = 8; + } + + SwapChannels::~SwapChannels() { + } + + + static void SwapChannels::_bind_methods() { + ClassDB::bind_method(D_METHOD("get_image"), &SwapChannels::get_image); + ClassDB::bind_method(D_METHOD("set_image", "value"), &SwapChannels::set_image); + ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "image", PROPERTY_HINT_RESOURCE_TYPE, "Ref"), "set_image", "get_image"); + + + ClassDB::bind_method(D_METHOD("get_input"), &SwapChannels::get_input); + ClassDB::bind_method(D_METHOD("set_input", "value"), &SwapChannels::set_input); + ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "input", PROPERTY_HINT_RESOURCE_TYPE, "Ref"), "set_input", "get_input"); + + + ClassDB::bind_method(D_METHOD("get_op_r"), &SwapChannels::get_op_r); + ClassDB::bind_method(D_METHOD("set_op_r", "value"), &SwapChannels::set_op_r); + ADD_PROPERTY(PropertyInfo(Variant::INT, "op_r"), "set_op_r", "get_op_r"); + + + ClassDB::bind_method(D_METHOD("get_op_g"), &SwapChannels::get_op_g); + ClassDB::bind_method(D_METHOD("set_op_g", "value"), &SwapChannels::set_op_g); + ADD_PROPERTY(PropertyInfo(Variant::INT, "op_g"), "set_op_g", "get_op_g"); + + + ClassDB::bind_method(D_METHOD("get_op_b"), &SwapChannels::get_op_b); + ClassDB::bind_method(D_METHOD("set_op_b", "value"), &SwapChannels::set_op_b); + ADD_PROPERTY(PropertyInfo(Variant::INT, "op_b"), "set_op_b", "get_op_b"); + + + ClassDB::bind_method(D_METHOD("get_op_a"), &SwapChannels::get_op_a); + ClassDB::bind_method(D_METHOD("set_op_a", "value"), &SwapChannels::set_op_a); + ADD_PROPERTY(PropertyInfo(Variant::INT, "op_a"), "set_op_a", "get_op_a"); + + + ClassDB::bind_method(D_METHOD("_init_properties"), &SwapChannels::_init_properties); + ClassDB::bind_method(D_METHOD("_register_methods", "mm_graph_node"), &SwapChannels::_register_methods); + ClassDB::bind_method(D_METHOD("_render", "material"), &SwapChannels::_render); + ClassDB::bind_method(D_METHOD("apply", "op", "val"), &SwapChannels::apply); + ClassDB::bind_method(D_METHOD("_get_value_for", "uv", "pseed"), &SwapChannels::_get_value_for); + ClassDB::bind_method(D_METHOD("get_op_r"), &SwapChannels::get_op_r); + ClassDB::bind_method(D_METHOD("set_op_r", "val"), &SwapChannels::set_op_r); + ClassDB::bind_method(D_METHOD("get_op_g"), &SwapChannels::get_op_g); + ClassDB::bind_method(D_METHOD("set_op_g", "val"), &SwapChannels::set_op_g); + ClassDB::bind_method(D_METHOD("get_op_b"), &SwapChannels::get_op_b); + ClassDB::bind_method(D_METHOD("set_op_b", "val"), &SwapChannels::set_op_b); + ClassDB::bind_method(D_METHOD("get_op_a"), &SwapChannels::get_op_a); + ClassDB::bind_method(D_METHOD("set_op_a", "val"), &SwapChannels::set_op_a); + + } + + + diff --git a/modules/material_maker/nodes/filter/swap_channels.h b/modules/material_maker/nodes/filter/swap_channels.h new file mode 100644 index 000000000..617798e2b --- /dev/null +++ b/modules/material_maker/nodes/filter/swap_channels.h @@ -0,0 +1,68 @@ +#ifndef SWAP_CHANNELS_H +#define SWAP_CHANNELS_H + + +class SwapChannels : public MMNode { + GDCLASS(SwapChannels, MMNode); + + public: + + Ref get_image(); + void set_image(const Ref &val); + + Ref get_input(); + void set_input(const Ref &val); + + int get_op_r() const; + void set_op_r(const int val); + + int get_op_g() const; + void set_op_g(const int val); + + int get_op_b() const; + void set_op_b(const int val); + + int get_op_a() const; + void set_op_a(const int val); + + void _init_properties(); + void _register_methods(const Variant &mm_graph_node); + void _render(const Variant &material); + float apply(const int op, const Color &val); + Color _get_value_for(const Vector2 &uv, const int pseed); + int get_op_r(); + void set_op_r(const int val); + int get_op_g(); + void set_op_g(const int val); + int get_op_b(); + void set_op_b(const int val); + int get_op_a(); + void set_op_a(const int val); + + SwapChannels(); + ~SwapChannels(); + + protected: + static void _bind_methods(); + + //tool + //export(Resource) + Ref image; + //export(Resource) + Ref input; + //export(int, "0,1,R,-R,G,-G,B,-B,A,-A") + int op_r = 2; + //export(int, "0,1,R,-R,G,-G,B,-B,A,-A") + int op_g = 4; + //export(int, "0,1,R,-R,G,-G,B,-B,A,-A") + int op_b = 6; + //export(int, "0,1,R,-R,G,-G,B,-B,A,-A") + int op_a = 8; + //op_r + //op_g + //op_b + //op_a +}; + + +#endif diff --git a/modules/material_maker/nodes/filter/tonality.cpp b/modules/material_maker/nodes/filter/tonality.cpp new file mode 100644 index 000000000..feb5a50f1 --- /dev/null +++ b/modules/material_maker/nodes/filter/tonality.cpp @@ -0,0 +1,115 @@ + +#include "tonality.h" + + +Ref Tonality::get_image() { + return image; +} + +void Tonality::set_image(const Ref &val) { +image = val; +} + + +Ref Tonality::get_input() { + return input; +} + +void Tonality::set_input(const Ref &val) { +input = val; +} + + + + //tool; + //export(Resource) ; + Ref image; + //export(Resource) ; + Ref input; + + void Tonality::_init() { + init_points_01(); +} + + + void Tonality::_init_properties() { + + if (!input) { + input = MMNodeUniversalProperty.new(); + input.default_type = MMNodeUniversalProperty.DEFAULT_TYPE_FLOAT; + input.set_default_value(0); +} + + input.input_slot_type = MMNodeUniversalProperty.SLOT_TYPE_UNIVERSAL; + input.slot_name = ">>> Input "; + + if (!image) { + image = MMNodeUniversalProperty.new(); + image.default_type = MMNodeUniversalProperty.DEFAULT_TYPE_IMAGE; +} + + //image.input_slot_type = MMNodeUniversalProperty.SLOT_TYPE_FLOAT; + image.output_slot_type = MMNodeUniversalProperty.SLOT_TYPE_IMAGE; + //image.force_override = true; + register_input_property(input); + register_output_property(image); +} + + + void Tonality::_register_methods(const Variant &mm_graph_node) { + mm_graph_node.add_slot_label_universal(input); + mm_graph_node.add_slot_texture_universal(image); + mm_graph_node.add_slot_curve(); +} + + + void Tonality::_render(const Variant &material) { + Ref img = render_image(material); + image.set_value(img); +} + + + Color Tonality::_get_value_for(const Vector2 &uv, const int pseed) { + float f = input.get_value(uv); + float cf = MMAlgos.curve(f, points_array); + return Color(cf, cf, cf, 1); +} + + + void Tonality::_curve_changed() { + set_dirty(true); +} + +} + + Tonality::Tonality() { + image; + input; + } + + Tonality::~Tonality() { + } + + + static void Tonality::_bind_methods() { + ClassDB::bind_method(D_METHOD("get_image"), &Tonality::get_image); + ClassDB::bind_method(D_METHOD("set_image", "value"), &Tonality::set_image); + ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "image", PROPERTY_HINT_RESOURCE_TYPE, "Ref"), "set_image", "get_image"); + + + ClassDB::bind_method(D_METHOD("get_input"), &Tonality::get_input); + ClassDB::bind_method(D_METHOD("set_input", "value"), &Tonality::set_input); + ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "input", PROPERTY_HINT_RESOURCE_TYPE, "Ref"), "set_input", "get_input"); + + + ClassDB::bind_method(D_METHOD("_init"), &Tonality::_init); + ClassDB::bind_method(D_METHOD("_init_properties"), &Tonality::_init_properties); + ClassDB::bind_method(D_METHOD("_register_methods", "mm_graph_node"), &Tonality::_register_methods); + ClassDB::bind_method(D_METHOD("_render", "material"), &Tonality::_render); + ClassDB::bind_method(D_METHOD("_get_value_for", "uv", "pseed"), &Tonality::_get_value_for); + ClassDB::bind_method(D_METHOD("_curve_changed"), &Tonality::_curve_changed); + + } + + + diff --git a/modules/material_maker/nodes/filter/tonality.h b/modules/material_maker/nodes/filter/tonality.h new file mode 100644 index 000000000..8ba2757e6 --- /dev/null +++ b/modules/material_maker/nodes/filter/tonality.h @@ -0,0 +1,37 @@ +#ifndef TONALITY_H +#define TONALITY_H + + +class Tonality : public CurveBase { + GDCLASS(Tonality, CurveBase); + + public: + + Ref get_image(); + void set_image(const Ref &val); + + Ref get_input(); + void set_input(const Ref &val); + + void _init(); + 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); + void _curve_changed(); + + Tonality(); + ~Tonality(); + + protected: + static void _bind_methods(); + + //tool + //export(Resource) + Ref image; + //export(Resource) + Ref input; +}; + + +#endif diff --git a/modules/material_maker/nodes/gradient/circular_gradient.cpp b/modules/material_maker/nodes/gradient/circular_gradient.cpp new file mode 100644 index 000000000..da3754f67 --- /dev/null +++ b/modules/material_maker/nodes/gradient/circular_gradient.cpp @@ -0,0 +1,148 @@ + +#include "circular_gradient.h" + + +Ref CircularGradient::get_image() { + return image; +} + +void CircularGradient::set_image(const Ref &val) { +image = val; +} + + +float CircularGradient::get_repeat() const { + return repeat; +} + +void CircularGradient::set_repeat(const float val) { +repeat = val; +} + + + + //tool; + //export(Resource) ; + Ref image; + //export(float) ; + float repeat = 1; + + void CircularGradient::_init_properties() { + + if (!image) { + image = MMNodeUniversalProperty.new(); + image.default_type = MMNodeUniversalProperty.DEFAULT_TYPE_IMAGE; +} + + image.output_slot_type = MMNodeUniversalProperty.SLOT_TYPE_IMAGE; + register_output_property(image); +} + + + void CircularGradient::_register_methods(const Variant &mm_graph_node) { + mm_graph_node.add_slot_texture_universal(image); + mm_graph_node.add_slot_float("get_repeat", "set_repeat", "repeat"); + mm_graph_node.add_slot_gradient(); +} + + + void CircularGradient::_render(const Variant &material) { + Ref img = render_image(material); + image.set_value(img); +} + + + Color CircularGradient::_get_value_for(const Vector2 &uv, const int pseed) { + + if (interpolation_type == 0) { + return MMAlgos.circular_gradient_type_1(uv, repeat, points); +} + + + else if (interpolation_type == 1) { + return MMAlgos.circular_gradient_type_2(uv, repeat, points); +} + + + else if (interpolation_type == 2) { + return MMAlgos.circular_gradient_type_3(uv, repeat, points); +} + + + else if (interpolation_type == 3) { + return MMAlgos.circular_gradient_type_4(uv, repeat, points); +} + + return Color(1, 1, 1, 1); +} + + + Color CircularGradient::_get_gradient_color(const float x) { + + if (interpolation_type == 0) { + return MMAlgos.gradient_type_1(x, points); +} + + + else if (interpolation_type == 1) { + return MMAlgos.gradient_type_2(x, points); +} + + + else if (interpolation_type == 2) { + return MMAlgos.gradient_type_3(x, points); +} + + + else if (interpolation_type == 3) { + return MMAlgos.gradient_type_4(x, points); +} + + return Color(1, 1, 1, 1); +} + + + float CircularGradient::get_repeat() { + return repeat; +} + + + void CircularGradient::set_repeat(const float val) { + repeat = val; + set_dirty(true); +} + +} + + CircularGradient::CircularGradient() { + image; + repeat = 1; + } + + CircularGradient::~CircularGradient() { + } + + + static void CircularGradient::_bind_methods() { + ClassDB::bind_method(D_METHOD("get_image"), &CircularGradient::get_image); + ClassDB::bind_method(D_METHOD("set_image", "value"), &CircularGradient::set_image); + ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "image", PROPERTY_HINT_RESOURCE_TYPE, "Ref"), "set_image", "get_image"); + + + ClassDB::bind_method(D_METHOD("get_repeat"), &CircularGradient::get_repeat); + ClassDB::bind_method(D_METHOD("set_repeat", "value"), &CircularGradient::set_repeat); + ADD_PROPERTY(PropertyInfo(Variant::REAL, "repeat"), "set_repeat", "get_repeat"); + + + ClassDB::bind_method(D_METHOD("_init_properties"), &CircularGradient::_init_properties); + ClassDB::bind_method(D_METHOD("_register_methods", "mm_graph_node"), &CircularGradient::_register_methods); + ClassDB::bind_method(D_METHOD("_render", "material"), &CircularGradient::_render); + ClassDB::bind_method(D_METHOD("_get_value_for", "uv", "pseed"), &CircularGradient::_get_value_for); + ClassDB::bind_method(D_METHOD("_get_gradient_color", "x"), &CircularGradient::_get_gradient_color); + ClassDB::bind_method(D_METHOD("get_repeat"), &CircularGradient::get_repeat); + ClassDB::bind_method(D_METHOD("set_repeat", "val"), &CircularGradient::set_repeat); + + } + + + diff --git a/modules/material_maker/nodes/gradient/circular_gradient.h b/modules/material_maker/nodes/gradient/circular_gradient.h new file mode 100644 index 000000000..0b0818a52 --- /dev/null +++ b/modules/material_maker/nodes/gradient/circular_gradient.h @@ -0,0 +1,38 @@ +#ifndef CIRCULAR_GRADIENT_H +#define CIRCULAR_GRADIENT_H + + +class CircularGradient : public GradientBase { + GDCLASS(CircularGradient, GradientBase); + + public: + + Ref get_image(); + void set_image(const Ref &val); + + float get_repeat() const; + void set_repeat(const float val); + + 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); + Color _get_gradient_color(const float x); + float get_repeat(); + void set_repeat(const float val); + + CircularGradient(); + ~CircularGradient(); + + protected: + static void _bind_methods(); + + //tool + //export(Resource) + Ref image; + //export(float) + float repeat = 1; +}; + + +#endif diff --git a/modules/material_maker/nodes/gradient/gradient.cpp b/modules/material_maker/nodes/gradient/gradient.cpp new file mode 100644 index 000000000..fa27fccfa --- /dev/null +++ b/modules/material_maker/nodes/gradient/gradient.cpp @@ -0,0 +1,179 @@ + +#include "gradient.h" + + +Ref Gradient::get_image() { + return image; +} + +void Gradient::set_image(const Ref &val) { +image = val; +} + + +float Gradient::get_repeat() const { + return repeat; +} + +void Gradient::set_repeat(const float val) { +repeat = val; +} + + +float Gradient::get_rotate() const { + return rotate; +} + +void Gradient::set_rotate(const float val) { +rotate = val; +} + + + + //tool; + //export(Resource) ; + Ref image; + //export(float) ; + float repeat = 1; + //export(float) ; + float rotate = 0; + + void Gradient::_init_properties() { + + if (!image) { + image = MMNodeUniversalProperty.new(); + image.default_type = MMNodeUniversalProperty.DEFAULT_TYPE_IMAGE; +} + + image.output_slot_type = MMNodeUniversalProperty.SLOT_TYPE_IMAGE; + register_output_property(image); +} + + + void Gradient::_register_methods(const Variant &mm_graph_node) { + mm_graph_node.add_slot_texture_universal(image); + mm_graph_node.add_slot_float("get_repeat", "set_repeat", "repeat"); + mm_graph_node.add_slot_float("get_rotate", "set_rotate", "rotate"); + mm_graph_node.add_slot_gradient(); +} + + + void Gradient::_render(const Variant &material) { + Ref img = render_image(material); + image.set_value(img); +} + + + Color Gradient::_get_value_for(const Vector2 &uv, const int pseed) { + + if (interpolation_type == 0) { + return MMAlgos.normal_gradient_type_1(uv, repeat, rotate, points); +} + + + else if (interpolation_type == 1) { + return MMAlgos.normal_gradient_type_2(uv, repeat, rotate, points); +} + + + else if (interpolation_type == 2) { + return MMAlgos.normal_gradient_type_3(uv, repeat, rotate, points); +} + + + else if (interpolation_type == 3) { + return MMAlgos.normal_gradient_type_4(uv, repeat, rotate, points); +} + + return Color(1, 1, 1, 1); +} + + + Color Gradient::_get_gradient_color(const float x) { + + if (interpolation_type == 0) { + return MMAlgos.gradient_type_1(x, points); +} + + + else if (interpolation_type == 1) { + return MMAlgos.gradient_type_2(x, points); +} + + + else if (interpolation_type == 2) { + return MMAlgos.gradient_type_3(x, points); +} + + + else if (interpolation_type == 3) { + return MMAlgos.gradient_type_4(x, points); +} + + return Color(1, 1, 1, 1); +} + + + float Gradient::get_repeat() { + return repeat; +} + + + void Gradient::set_repeat(const float val) { + repeat = val; + set_dirty(true); +} + + + float Gradient::get_rotate() { + return rotate; +} + + + void Gradient::set_rotate(const float val) { + rotate = val; + set_dirty(true); +} + +} + + Gradient::Gradient() { + image; + repeat = 1; + rotate = 0; + } + + Gradient::~Gradient() { + } + + + static void Gradient::_bind_methods() { + ClassDB::bind_method(D_METHOD("get_image"), &Gradient::get_image); + ClassDB::bind_method(D_METHOD("set_image", "value"), &Gradient::set_image); + ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "image", PROPERTY_HINT_RESOURCE_TYPE, "Ref"), "set_image", "get_image"); + + + ClassDB::bind_method(D_METHOD("get_repeat"), &Gradient::get_repeat); + ClassDB::bind_method(D_METHOD("set_repeat", "value"), &Gradient::set_repeat); + ADD_PROPERTY(PropertyInfo(Variant::REAL, "repeat"), "set_repeat", "get_repeat"); + + + ClassDB::bind_method(D_METHOD("get_rotate"), &Gradient::get_rotate); + ClassDB::bind_method(D_METHOD("set_rotate", "value"), &Gradient::set_rotate); + ADD_PROPERTY(PropertyInfo(Variant::REAL, "rotate"), "set_rotate", "get_rotate"); + + + ClassDB::bind_method(D_METHOD("_init_properties"), &Gradient::_init_properties); + ClassDB::bind_method(D_METHOD("_register_methods", "mm_graph_node"), &Gradient::_register_methods); + ClassDB::bind_method(D_METHOD("_render", "material"), &Gradient::_render); + ClassDB::bind_method(D_METHOD("_get_value_for", "uv", "pseed"), &Gradient::_get_value_for); + ClassDB::bind_method(D_METHOD("_get_gradient_color", "x"), &Gradient::_get_gradient_color); + ClassDB::bind_method(D_METHOD("get_repeat"), &Gradient::get_repeat); + ClassDB::bind_method(D_METHOD("set_repeat", "val"), &Gradient::set_repeat); + ClassDB::bind_method(D_METHOD("get_rotate"), &Gradient::get_rotate); + ClassDB::bind_method(D_METHOD("set_rotate", "val"), &Gradient::set_rotate); + + } + + + diff --git a/modules/material_maker/nodes/gradient/gradient.h b/modules/material_maker/nodes/gradient/gradient.h new file mode 100644 index 000000000..64b70a2d5 --- /dev/null +++ b/modules/material_maker/nodes/gradient/gradient.h @@ -0,0 +1,45 @@ +#ifndef GRADIENT_H +#define GRADIENT_H + + +class Gradient : public GradientBase { + GDCLASS(Gradient, GradientBase); + + public: + + Ref get_image(); + void set_image(const Ref &val); + + float get_repeat() const; + void set_repeat(const float val); + + float get_rotate() const; + void set_rotate(const float val); + + 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); + Color _get_gradient_color(const float x); + float get_repeat(); + void set_repeat(const float val); + float get_rotate(); + void set_rotate(const float val); + + Gradient(); + ~Gradient(); + + protected: + static void _bind_methods(); + + //tool + //export(Resource) + Ref image; + //export(float) + float repeat = 1; + //export(float) + float rotate = 0; +}; + + +#endif diff --git a/modules/material_maker/nodes/gradient/radial_gradient.cpp b/modules/material_maker/nodes/gradient/radial_gradient.cpp new file mode 100644 index 000000000..b5dcb4eb4 --- /dev/null +++ b/modules/material_maker/nodes/gradient/radial_gradient.cpp @@ -0,0 +1,148 @@ + +#include "radial_gradient.h" + + +Ref RadialGradient::get_image() { + return image; +} + +void RadialGradient::set_image(const Ref &val) { +image = val; +} + + +float RadialGradient::get_repeat() const { + return repeat; +} + +void RadialGradient::set_repeat(const float val) { +repeat = val; +} + + + + //tool; + //export(Resource) ; + Ref image; + //export(float) ; + float repeat = 1; + + void RadialGradient::_init_properties() { + + if (!image) { + image = MMNodeUniversalProperty.new(); + image.default_type = MMNodeUniversalProperty.DEFAULT_TYPE_IMAGE; +} + + image.output_slot_type = MMNodeUniversalProperty.SLOT_TYPE_IMAGE; + register_output_property(image); +} + + + void RadialGradient::_register_methods(const Variant &mm_graph_node) { + mm_graph_node.add_slot_texture_universal(image); + mm_graph_node.add_slot_float("get_repeat", "set_repeat", "repeat"); + mm_graph_node.add_slot_gradient(); +} + + + void RadialGradient::_render(const Variant &material) { + Ref img = render_image(material); + image.set_value(img); +} + + + Color RadialGradient::_get_value_for(const Vector2 &uv, const int pseed) { + + if (interpolation_type == 0) { + return MMAlgos.radial_gradient_type_1(uv, repeat, points); +} + + + else if (interpolation_type == 1) { + return MMAlgos.radial_gradient_type_2(uv, repeat, points); +} + + + else if (interpolation_type == 2) { + return MMAlgos.radial_gradient_type_3(uv, repeat, points); +} + + + else if (interpolation_type == 3) { + return MMAlgos.radial_gradient_type_4(uv, repeat, points); +} + + return Color(1, 1, 1, 1); +} + + + Color RadialGradient::_get_gradient_color(const float x) { + + if (interpolation_type == 0) { + return MMAlgos.gradient_type_1(x, points); +} + + + else if (interpolation_type == 1) { + return MMAlgos.gradient_type_2(x, points); +} + + + else if (interpolation_type == 2) { + return MMAlgos.gradient_type_3(x, points); +} + + + else if (interpolation_type == 3) { + return MMAlgos.gradient_type_4(x, points); +} + + return Color(1, 1, 1, 1); +} + + + float RadialGradient::get_repeat() { + return repeat; +} + + + void RadialGradient::set_repeat(const float val) { + repeat = val; + set_dirty(true); +} + +} + + RadialGradient::RadialGradient() { + image; + repeat = 1; + } + + RadialGradient::~RadialGradient() { + } + + + static void RadialGradient::_bind_methods() { + ClassDB::bind_method(D_METHOD("get_image"), &RadialGradient::get_image); + ClassDB::bind_method(D_METHOD("set_image", "value"), &RadialGradient::set_image); + ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "image", PROPERTY_HINT_RESOURCE_TYPE, "Ref"), "set_image", "get_image"); + + + ClassDB::bind_method(D_METHOD("get_repeat"), &RadialGradient::get_repeat); + ClassDB::bind_method(D_METHOD("set_repeat", "value"), &RadialGradient::set_repeat); + ADD_PROPERTY(PropertyInfo(Variant::REAL, "repeat"), "set_repeat", "get_repeat"); + + + ClassDB::bind_method(D_METHOD("_init_properties"), &RadialGradient::_init_properties); + ClassDB::bind_method(D_METHOD("_register_methods", "mm_graph_node"), &RadialGradient::_register_methods); + ClassDB::bind_method(D_METHOD("_render", "material"), &RadialGradient::_render); + ClassDB::bind_method(D_METHOD("_get_value_for", "uv", "pseed"), &RadialGradient::_get_value_for); + ClassDB::bind_method(D_METHOD("_get_gradient_color", "x"), &RadialGradient::_get_gradient_color); + ClassDB::bind_method(D_METHOD("get_repeat"), &RadialGradient::get_repeat); + ClassDB::bind_method(D_METHOD("set_repeat", "val"), &RadialGradient::set_repeat); + + } + + + diff --git a/modules/material_maker/nodes/gradient/radial_gradient.h b/modules/material_maker/nodes/gradient/radial_gradient.h new file mode 100644 index 000000000..408f5396f --- /dev/null +++ b/modules/material_maker/nodes/gradient/radial_gradient.h @@ -0,0 +1,38 @@ +#ifndef RADIAL_GRADIENT_H +#define RADIAL_GRADIENT_H + + +class RadialGradient : public GradientBase { + GDCLASS(RadialGradient, GradientBase); + + public: + + Ref get_image(); + void set_image(const Ref &val); + + float get_repeat() const; + void set_repeat(const float val); + + 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); + Color _get_gradient_color(const float x); + float get_repeat(); + void set_repeat(const float val); + + RadialGradient(); + ~RadialGradient(); + + protected: + static void _bind_methods(); + + //tool + //export(Resource) + Ref image; + //export(float) + float repeat = 1; +}; + + +#endif diff --git a/modules/material_maker/nodes/noise/anisotropic_noise.cpp b/modules/material_maker/nodes/noise/anisotropic_noise.cpp new file mode 100644 index 000000000..6c3fe1d77 --- /dev/null +++ b/modules/material_maker/nodes/noise/anisotropic_noise.cpp @@ -0,0 +1,168 @@ + +#include "anisotropic_noise.h" + + +Ref AnisotropicNoise::get_image() { + return image; +} + +void AnisotropicNoise::set_image(const Ref &val) { +image = val; +} + + +Vector2 AnisotropicNoise::get_scale() { + return scale; +} + +void AnisotropicNoise::set_scale(const Vector2 &val) { +scale = val; +} + + +float AnisotropicNoise::get_smoothness() const { + return smoothness; +} + +void AnisotropicNoise::set_smoothness(const float val) { +smoothness = val; +} + + +float AnisotropicNoise::get_interpolation() const { + return interpolation; +} + +void AnisotropicNoise::set_interpolation(const float val) { +interpolation = val; +} + + + + //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.output_slot_type = MMNodeUniversalProperty.SLOT_TYPE_IMAGE; + register_output_property(image); +} + + + 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 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 AnisotropicNoise::_render(const Variant &material) { + Ref img = render_image(material); + image.set_value(img); +} + + + Vector2 AnisotropicNoise::get_scale() { + return scale; +} + + + void AnisotropicNoise::set_scale(const Vector2 &val) { + scale = val; + set_dirty(true); +} + + + 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 new file mode 100644 index 000000000..6d26b65a4 --- /dev/null +++ b/modules/material_maker/nodes/noise/anisotropic_noise.h @@ -0,0 +1,51 @@ +#ifndef ANISOTROPIC_NOISE_H +#define ANISOTROPIC_NOISE_H + + +class AnisotropicNoise : public MMNode { + GDCLASS(AnisotropicNoise, MMNode); + + public: + + Ref get_image(); + void set_image(const Ref &val); + + Vector2 get_scale(); + void set_scale(const Vector2 &val); + + float get_smoothness() const; + void set_smoothness(const float val); + + float get_interpolation() const; + void set_interpolation(const float val); + + 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); + + AnisotropicNoise(); + ~AnisotropicNoise(); + + 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; +}; + + +#endif diff --git a/modules/material_maker/nodes/noise/color_noise.cpp b/modules/material_maker/nodes/noise/color_noise.cpp new file mode 100644 index 000000000..92251eaa4 --- /dev/null +++ b/modules/material_maker/nodes/noise/color_noise.cpp @@ -0,0 +1,111 @@ + +#include "color_noise.h" + + +Ref ColorNoise::get_image() { + return image; +} + +void ColorNoise::set_image(const Ref &val) { +image = val; +} + + +int ColorNoise::get_size() const { + return size; +} + +void ColorNoise::set_size(const int val) { +size = val; +} + + + + //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.output_slot_type = MMNodeUniversalProperty.SLOT_TYPE_IMAGE; + register_output_property(image); +} + + + 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 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 ColorNoise::_render(const Variant &material) { + Ref img = render_image(material); + image.set_value(img); +} + + + int ColorNoise::get_size() { + return size; +} + + + void ColorNoise::set_size(const int val) { + size = val; + set_dirty(true); +} + +} + + 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 new file mode 100644 index 000000000..796139259 --- /dev/null +++ b/modules/material_maker/nodes/noise/color_noise.h @@ -0,0 +1,44 @@ +#ifndef COLOR_NOISE_H +#define COLOR_NOISE_H + + +class ColorNoise : public MMNode { + GDCLASS(ColorNoise, MMNode); + + public: + + Ref get_image(); + void set_image(const Ref &val); + + int get_size() const; + void set_size(const int val); + + 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); + + ColorNoise(); + ~ColorNoise(); + + 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 +}; + + +#endif diff --git a/modules/material_maker/nodes/noise/color_value.cpp b/modules/material_maker/nodes/noise/color_value.cpp new file mode 100644 index 000000000..eff7a2312 --- /dev/null +++ b/modules/material_maker/nodes/noise/color_value.cpp @@ -0,0 +1,168 @@ + +#include "color_value.h" + + +Ref ColorValue::get_image() { + return image; +} + +void ColorValue::set_image(const Ref &val) { +image = val; +} + + +Vector2 ColorValue::get_scale() { + return scale; +} + +void ColorValue::set_scale(const Vector2 &val) { +scale = val; +} + + +int ColorValue::get_iterations() const { + return iterations; +} + +void ColorValue::set_iterations(const int val) { +iterations = val; +} + + +float ColorValue::get_persistence() const { + return persistence; +} + +void ColorValue::set_persistence(const float val) { +persistence = val; +} + + + + //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.output_slot_type = MMNodeUniversalProperty.SLOT_TYPE_IMAGE; + register_output_property(image); +} + + + 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 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 ColorValue::_render(const Variant &material) { + Ref img = render_image(material); + image.set_value(img); +} + + + Vector2 ColorValue::get_scale() { + return scale; +} + + + void ColorValue::set_scale(const Vector2 &val) { + scale = val; + set_dirty(true); +} + + + 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 new file mode 100644 index 000000000..a04892091 --- /dev/null +++ b/modules/material_maker/nodes/noise/color_value.h @@ -0,0 +1,51 @@ +#ifndef COLOR_VALUE_H +#define COLOR_VALUE_H + + +class ColorValue : public MMNode { + GDCLASS(ColorValue, MMNode); + + public: + + Ref get_image(); + void set_image(const Ref &val); + + Vector2 get_scale(); + void set_scale(const Vector2 &val); + + int get_iterations() const; + void set_iterations(const int val); + + float get_persistence() const; + void set_persistence(const float val); + + 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); + + ColorValue(); + ~ColorValue(); + + 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; +}; + + +#endif diff --git a/modules/material_maker/nodes/noise/fbm_noise.cpp b/modules/material_maker/nodes/noise/fbm_noise.cpp new file mode 100644 index 000000000..96d6d996f --- /dev/null +++ b/modules/material_maker/nodes/noise/fbm_noise.cpp @@ -0,0 +1,277 @@ + +#include "fbm_noise.h" + + +Ref FbmNoise::get_image() { + return image; +} + +void FbmNoise::set_image(const Ref &val) { +image = val; +} + + +int FbmNoise::get_type() const { + return type; +} + +void FbmNoise::set_type(const int val) { +type = val; +} + + +Vector2 FbmNoise::get_scale() { + return scale; +} + +void FbmNoise::set_scale(const Vector2 &val) { +scale = val; +} + + +int FbmNoise::get_folds() const { + return folds; +} + +void FbmNoise::set_folds(const int val) { +folds = val; +} + + +int FbmNoise::get_iterations() const { + return iterations; +} + +void FbmNoise::set_iterations(const int val) { +iterations = val; +} + + +float FbmNoise::get_persistence() const { + return persistence; +} + +void FbmNoise::set_persistence(const float val) { +persistence = val; +} + + + + //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.output_slot_type = MMNodeUniversalProperty.SLOT_TYPE_IMAGE; + register_output_property(image); +} + + + 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); +} + + + 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); +} + + + 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(); +} + + + 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 new file mode 100644 index 000000000..062d6fb2a --- /dev/null +++ b/modules/material_maker/nodes/noise/fbm_noise.h @@ -0,0 +1,65 @@ +#ifndef FBM_NOISE_H +#define FBM_NOISE_H + + +class FbmNoise : public MMNode { + GDCLASS(FbmNoise, MMNode); + + public: + + Ref get_image(); + void set_image(const Ref &val); + + int get_type() const; + void set_type(const int val); + + Vector2 get_scale(); + void set_scale(const Vector2 &val); + + int get_folds() const; + void set_folds(const int val); + + int get_iterations() const; + void set_iterations(const int val); + + float get_persistence() const; + void set_persistence(const float val); + + 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); + + FbmNoise(); + ~FbmNoise(); + + 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; +}; + + +#endif diff --git a/modules/material_maker/nodes/noise/noise.cpp b/modules/material_maker/nodes/noise/noise.cpp new file mode 100644 index 000000000..88aaed8f3 --- /dev/null +++ b/modules/material_maker/nodes/noise/noise.cpp @@ -0,0 +1,137 @@ + +#include "noise.h" + + +Ref Noise::get_image() { + return image; +} + +void Noise::set_image(const Ref &val) { +image = val; +} + + +int Noise::get_grid_size() const { + return grid_size; +} + +void Noise::set_grid_size(const int val) { +grid_size = val; +} + + +float Noise::get_density() const { + return density; +} + +void Noise::set_density(const float val) { +density = val; +} + + + + //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.output_slot_type = MMNodeUniversalProperty.SLOT_TYPE_IMAGE; + register_output_property(image); +} + + + 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 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 Noise::_render(const Variant &material) { + Ref img = render_image(material); + image.set_value(img); +} + + + int Noise::get_grid_size() { + return grid_size; +} + + + void Noise::set_grid_size(const int val) { + grid_size = val; + set_dirty(true); +} + + + 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 new file mode 100644 index 000000000..17b76ecf4 --- /dev/null +++ b/modules/material_maker/nodes/noise/noise.h @@ -0,0 +1,44 @@ +#ifndef NOISE_H +#define NOISE_H + + +class Noise : public MMNode { + GDCLASS(Noise, MMNode); + + public: + + Ref get_image(); + void set_image(const Ref &val); + + int get_grid_size() const; + void set_grid_size(const int val); + + float get_density() const; + void set_density(const float val); + + 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); + + Noise(); + ~Noise(); + + protected: + static void _bind_methods(); + + //tool + //export(Resource) + 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 new file mode 100644 index 000000000..21e60fb54 --- /dev/null +++ b/modules/material_maker/nodes/noise/voronoi.cpp @@ -0,0 +1,332 @@ + +#include "voronoi.h" + + +Ref Voronoi::get_out_nodes() { + return out_nodes; +} + +void Voronoi::set_out_nodes(const Ref &val) { +out_nodes = val; +} + + +Ref Voronoi::get_out_borders() { + return out_borders; +} + +void Voronoi::set_out_borders(const Ref &val) { +out_borders = val; +} + + +Ref Voronoi::get_out_random_color() { + return out_random_color; +} + +void Voronoi::set_out_random_color(const Ref &val) { +out_random_color = val; +} + + +Ref Voronoi::get_out_fill() { + return out_fill; +} + +void Voronoi::set_out_fill(const Ref &val) { +out_fill = val; +} + + +Vector2 Voronoi::get_scale() { + return scale; +} + +void Voronoi::set_scale(const Vector2 &val) { +scale = val; +} + + +Vector2 Voronoi::get_stretch() { + return stretch; +} + +void Voronoi::set_stretch(const Vector2 &val) { +stretch = val; +} + + +float Voronoi::get_intensity() const { + return intensity; +} + +void Voronoi::set_intensity(const float val) { +intensity = val; +} + + +float Voronoi::get_randomness() const { + return randomness; +} + +void Voronoi::set_randomness(const float val) { +randomness = val; +} + + + + //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; + + void Voronoi::_init_properties() { + + if (!out_nodes) { + out_nodes = MMNodeUniversalProperty.new(); + out_nodes.default_type = MMNodeUniversalProperty.DEFAULT_TYPE_IMAGE; +} + + out_nodes.output_slot_type = MMNodeUniversalProperty.SLOT_TYPE_IMAGE; + + if (!out_borders) { + out_borders = MMNodeUniversalProperty.new(); + out_borders.default_type = MMNodeUniversalProperty.DEFAULT_TYPE_IMAGE; +} + + out_borders.output_slot_type = MMNodeUniversalProperty.SLOT_TYPE_IMAGE; + + if (!out_random_color) { + out_random_color = MMNodeUniversalProperty.new(); + out_random_color.default_type = MMNodeUniversalProperty.DEFAULT_TYPE_IMAGE; +} + + 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; +} + + 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); +} + + + 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); +} + + + 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(); + + 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); +} + + + 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 new file mode 100644 index 000000000..e62b0c9b5 --- /dev/null +++ b/modules/material_maker/nodes/noise/voronoi.h @@ -0,0 +1,77 @@ +#ifndef VORONOI_H +#define VORONOI_H + + +class Voronoi : public MMNode { + GDCLASS(Voronoi, MMNode); + + public: + + 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_random_color(); + void set_out_random_color(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_stretch(); + void set_stretch(const Vector2 &val); + + float get_intensity() const; + void set_intensity(const float val); + + float get_randomness() const; + void set_randomness(const float val); + + 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); + + Voronoi(); + ~Voronoi(); + + 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 +}; + + +#endif diff --git a/modules/material_maker/nodes/other/output_image.cpp b/modules/material_maker/nodes/other/output_image.cpp new file mode 100644 index 000000000..23b6acd13 --- /dev/null +++ b/modules/material_maker/nodes/other/output_image.cpp @@ -0,0 +1,110 @@ + +#include "output_image.h" + + +Ref OutputImage::get_image() { + return image; +} + +void OutputImage::set_image(const Ref &val) { +image = val; +} + + +String OutputImage::get_postfix() { + return postfix; +} + +void OutputImage::set_postfix(const String &val) { +postfix = val; +} + + + + //tool; + //export(Resource) ; + Ref image; + //export(String) ; + String postfix = ""; + + void OutputImage::_init_properties() { + image = MMNodeUniversalProperty.new(); + image.default_type = MMNodeUniversalProperty.DEFAULT_TYPE_IMAGE; + image.input_slot_type = MMNodeUniversalProperty.SLOT_TYPE_UNIVERSAL; + image.slot_name = "image"; + register_input_property(image); +} + + + void OutputImage::_register_methods(const Variant &mm_graph_node) { + mm_graph_node.add_slot_texture_universal(image); + mm_graph_node.add_slot_line_edit("get_postfix", "set_postfix", "postfix"); +} + + + void OutputImage::_render(const Variant &material) { + + if (!image) { + return; +} + + Ref img = image.get_active_image(); + + if (!img) { + return; +} + + String matpath = material.get_path(); + + if (matpath == "") { + return; +} + + String matbn = matpath.get_basename(); + String final_file_name = matbn + postfix + ".png"; + img.save_png(final_file_name); +} + + + String OutputImage::get_postfix() { + return postfix; +} + + + void OutputImage::set_postfix(const String &pf) { + postfix = pf; + set_dirty(true); +} + +} + + OutputImage::OutputImage() { + image; + postfix = ""; + } + + OutputImage::~OutputImage() { + } + + + static void OutputImage::_bind_methods() { + ClassDB::bind_method(D_METHOD("get_image"), &OutputImage::get_image); + ClassDB::bind_method(D_METHOD("set_image", "value"), &OutputImage::set_image); + ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "image", PROPERTY_HINT_RESOURCE_TYPE, "Ref"), "set_image", "get_image"); + + + ClassDB::bind_method(D_METHOD("get_postfix"), &OutputImage::get_postfix); + ClassDB::bind_method(D_METHOD("set_postfix", "value"), &OutputImage::set_postfix); + ADD_PROPERTY(PropertyInfo(Variant::STRING, "postfix"), "set_postfix", "get_postfix"); + + + ClassDB::bind_method(D_METHOD("_init_properties"), &OutputImage::_init_properties); + ClassDB::bind_method(D_METHOD("_register_methods", "mm_graph_node"), &OutputImage::_register_methods); + ClassDB::bind_method(D_METHOD("_render", "material"), &OutputImage::_render); + ClassDB::bind_method(D_METHOD("get_postfix"), &OutputImage::get_postfix); + ClassDB::bind_method(D_METHOD("set_postfix", "pf"), &OutputImage::set_postfix); + + } + + + diff --git a/modules/material_maker/nodes/other/output_image.h b/modules/material_maker/nodes/other/output_image.h new file mode 100644 index 000000000..120108f60 --- /dev/null +++ b/modules/material_maker/nodes/other/output_image.h @@ -0,0 +1,36 @@ +#ifndef OUTPUT_IMAGE_H +#define OUTPUT_IMAGE_H + + +class OutputImage : public MMNode { + GDCLASS(OutputImage, MMNode); + + public: + + Ref get_image(); + void set_image(const Ref &val); + + String get_postfix(); + void set_postfix(const String &val); + + void _init_properties(); + void _register_methods(const Variant &mm_graph_node); + void _render(const Variant &material); + String get_postfix(); + void set_postfix(const String &pf); + + OutputImage(); + ~OutputImage(); + + protected: + static void _bind_methods(); + + //tool + //export(Resource) + Ref image; + //export(String) + String postfix = ""; +}; + + +#endif diff --git a/modules/material_maker/nodes/pattern/beehive.cpp b/modules/material_maker/nodes/pattern/beehive.cpp new file mode 100644 index 000000000..e94eacccb --- /dev/null +++ b/modules/material_maker/nodes/pattern/beehive.cpp @@ -0,0 +1,201 @@ + +#include "beehive.h" + + +Ref Beehive::get_out_main() { + return out_main; +} + +void Beehive::set_out_main(const Ref &val) { +out_main = val; +} + + +Ref Beehive::get_out_random_color() { + return out_random_color; +} + +void Beehive::set_out_random_color(const Ref &val) { +out_random_color = val; +} + + +Ref Beehive::get_out_uv_map() { + return out_uv_map; +} + +void Beehive::set_out_uv_map(const Ref &val) { +out_uv_map = val; +} + + +Vector2 Beehive::get_size() { + return size; +} + +void Beehive::set_size(const Vector2 &val) { +size = val; +} + + + + //tool; + //export(Resource) ; + Ref out_main; + //export(Resource) ; + Ref out_random_color; + //export(Resource) ; + Ref out_uv_map; + //export(Vector2) ; + Vector2 size = Vector2(4, 4); + + void Beehive::_init_properties() { + + if (!out_main) { + out_main = MMNodeUniversalProperty.new(); + out_main.default_type = MMNodeUniversalProperty.DEFAULT_TYPE_IMAGE; +} + + out_main.output_slot_type = MMNodeUniversalProperty.SLOT_TYPE_IMAGE; + + if (!out_random_color) { + out_random_color = MMNodeUniversalProperty.new(); + out_random_color.default_type = MMNodeUniversalProperty.DEFAULT_TYPE_IMAGE; +} + + out_random_color.output_slot_type = MMNodeUniversalProperty.SLOT_TYPE_IMAGE; + + if (!out_uv_map) { + out_uv_map = MMNodeUniversalProperty.new(); + out_uv_map.default_type = MMNodeUniversalProperty.DEFAULT_TYPE_IMAGE; +} + + out_uv_map.output_slot_type = MMNodeUniversalProperty.SLOT_TYPE_IMAGE; + register_output_property(out_main); + register_output_property(out_random_color); + register_output_property(out_uv_map); +} + + + void Beehive::_register_methods(const Variant &mm_graph_node) { + mm_graph_node.add_slot_texture_universal(out_main); + mm_graph_node.add_slot_texture_universal(out_random_color); + mm_graph_node.add_slot_texture_universal(out_uv_map); + //, Vector2(1, 32))//, Vector2(0, 32)); + mm_graph_node.add_slot_vector2("get_size", "set_size", "Size"); +} + + + void Beehive::_render(const Variant &material) { + Ref main_pattern = Image.new(); + Ref random_color = Image.new(); + Ref uv_map = Image.new(); + main_pattern.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); + uv_map.create(material.image_size.x, material.image_size.y, false, Image.FORMAT_RGBA8); + main_pattern.lock(); + random_color.lock(); + uv_map.lock(); + float w = material.image_size.x; + float h = material.image_size.y; + float pseed = randf() + randi(); + + 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); + //vec2 $(name_uv)_uv = $uv*vec2($sx, $sy*1.73205080757); + //vec4 $(name_uv)_center = beehive_center($(name_uv)_uv); + Vector2 beehive_uv = uv * size; + Color beehive_uv_center = MMAlgos.beehive_center(beehive_uv); + //Output (float) - Shows the greyscale pattern; + //1.0-2.0*beehive_dist($(name_uv)_center.xy); + float f = 1.0 - 2.0 * MMAlgos.beehive_dist(Vector2(beehive_uv_center.r, beehive_uv_center.g)); + Color main_pattern_col = Color(f, f, f, 1); + //Random color (rgb) - Shows a random color for each hexagonal tile; + //rand3(fract($(name_uv)_center.zw/vec2($sx, $sy))+vec2(float($seed))); + Vector3 rcv3 = MMAlgos.rand3(MMAlgos.fractv2(Vector2(beehive_uv_center.b, beehive_uv_center.a) / size) + Vector2(ps, ps)); + Color random_color_col = Color(rcv3.x, rcv3.y, rcv3.z, 1); + //UV map (rgb) - Shows an UV map to be connected to the UV map port of the Custom UV node; + //vec3(vec2(0.5)+$(name_uv)_center.xy, rand(fract($(name_uv)_center.zw/vec2($sx, $sy))+vec2(float($seed)))); + Vector2 uvm1 = Vector2(0.5, 0.5) + Vector2(beehive_uv_center.r, beehive_uv_center.g); + Vector2 uvm2 = MMAlgos.rand2(MMAlgos.fractv2(Vector2(beehive_uv_center.b, beehive_uv_center.a) / size) + Vector2(ps, ps)); + Color uv_map_col = Color(uvm1.x, uvm1.y, uvm2.x, 1); + main_pattern.set_pixel(x, y, main_pattern_col); + random_color.set_pixel(x, y, random_color_col); + uv_map.set_pixel(x, y, uv_map_col); +} + +} + + main_pattern.unlock(); + random_color.unlock(); + uv_map.unlock(); + out_main.set_value(main_pattern); + out_random_color.set_value(random_color); + out_uv_map.set_value(uv_map); +} + + + Color Beehive::_get_value_for(const Vector2 &uv, const int pseed) { + return Color(); +} + + //size; + + Vector2 Beehive::get_size() { + return size; +} + + + void Beehive::set_size(const Vector2 &val) { + size = val; + set_dirty(true); +} + +} + + Beehive::Beehive() { + out_main; + out_random_color; + out_uv_map; + size = Vector2(4, 4); + } + + Beehive::~Beehive() { + } + + + static void Beehive::_bind_methods() { + ClassDB::bind_method(D_METHOD("get_out_main"), &Beehive::get_out_main); + ClassDB::bind_method(D_METHOD("set_out_main", "value"), &Beehive::set_out_main); + ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "out_main", PROPERTY_HINT_RESOURCE_TYPE, "Ref"), "set_out_main", "get_out_main"); + + + ClassDB::bind_method(D_METHOD("get_out_random_color"), &Beehive::get_out_random_color); + ClassDB::bind_method(D_METHOD("set_out_random_color", "value"), &Beehive::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_uv_map"), &Beehive::get_out_uv_map); + ClassDB::bind_method(D_METHOD("set_out_uv_map", "value"), &Beehive::set_out_uv_map); + ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "out_uv_map", PROPERTY_HINT_RESOURCE_TYPE, "Ref"), "set_out_uv_map", "get_out_uv_map"); + + + ClassDB::bind_method(D_METHOD("get_size"), &Beehive::get_size); + ClassDB::bind_method(D_METHOD("set_size", "value"), &Beehive::set_size); + ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "size"), "set_size", "get_size"); + + + ClassDB::bind_method(D_METHOD("_init_properties"), &Beehive::_init_properties); + ClassDB::bind_method(D_METHOD("_register_methods", "mm_graph_node"), &Beehive::_register_methods); + ClassDB::bind_method(D_METHOD("_render", "material"), &Beehive::_render); + ClassDB::bind_method(D_METHOD("_get_value_for", "uv", "pseed"), &Beehive::_get_value_for); + ClassDB::bind_method(D_METHOD("get_size"), &Beehive::get_size); + ClassDB::bind_method(D_METHOD("set_size", "val"), &Beehive::set_size); + + } + + + diff --git a/modules/material_maker/nodes/pattern/beehive.h b/modules/material_maker/nodes/pattern/beehive.h new file mode 100644 index 000000000..c387ece2f --- /dev/null +++ b/modules/material_maker/nodes/pattern/beehive.h @@ -0,0 +1,48 @@ +#ifndef BEEHIVE_H +#define BEEHIVE_H + + +class Beehive : public MMNode { + GDCLASS(Beehive, MMNode); + + public: + + Ref get_out_main(); + void set_out_main(const Ref &val); + + Ref get_out_random_color(); + void set_out_random_color(const Ref &val); + + Ref get_out_uv_map(); + void set_out_uv_map(const Ref &val); + + Vector2 get_size(); + void set_size(const Vector2 &val); + + 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_size(); + void set_size(const Vector2 &val); + + Beehive(); + ~Beehive(); + + protected: + static void _bind_methods(); + + //tool + //export(Resource) + Ref out_main; + //export(Resource) + Ref out_random_color; + //export(Resource) + Ref out_uv_map; + //export(Vector2) + Vector2 size = Vector2(4, 4); + //size +}; + + +#endif diff --git a/modules/material_maker/nodes/pattern/bricks.cpp b/modules/material_maker/nodes/pattern/bricks.cpp new file mode 100644 index 000000000..45ca02071 --- /dev/null +++ b/modules/material_maker/nodes/pattern/bricks.cpp @@ -0,0 +1,584 @@ + +#include "bricks.h" + + +Ref Bricks::get_out_bricks_pattern() { + return out_bricks_pattern; +} + +void Bricks::set_out_bricks_pattern(const Ref &val) { +out_bricks_pattern = val; +} + + +Ref Bricks::get_out_random_color() { + return out_random_color; +} + +void Bricks::set_out_random_color(const Ref &val) { +out_random_color = val; +} + + +Ref Bricks::get_out_position_x() { + return out_position_x; +} + +void Bricks::set_out_position_x(const Ref &val) { +out_position_x = val; +} + + +Ref Bricks::get_out_position_y() { + return out_position_y; +} + +void Bricks::set_out_position_y(const Ref &val) { +out_position_y = val; +} + + +Ref Bricks::get_out_brick_uv() { + return out_brick_uv; +} + +void Bricks::set_out_brick_uv(const Ref &val) { +out_brick_uv = val; +} + + +Ref Bricks::get_out_corner_uv() { + return out_corner_uv; +} + +void Bricks::set_out_corner_uv(const Ref &val) { +out_corner_uv = val; +} + + +Ref Bricks::get_out_direction() { + return out_direction; +} + +void Bricks::set_out_direction(const Ref &val) { +out_direction = val; +} + + +int Bricks::get_type() const { + return type; +} + +void Bricks::set_type(const int val) { +type = val; +} + + +int Bricks::get_repeat() const { + return repeat; +} + +void Bricks::set_repeat(const int val) { +repeat = val; +} + + +Vector2 Bricks::get_col_row() { + return col_row; +} + +void Bricks::set_col_row(const Vector2 &val) { +col_row = val; +} + + +float Bricks::get_offset() const { + return offset; +} + +void Bricks::set_offset(const float val) { +offset = val; +} + + +Ref Bricks::get_mortar() { + return mortar; +} + +void Bricks::set_mortar(const Ref &val) { +mortar = val; +} + + +Ref Bricks::get_bevel() { + return bevel; +} + +void Bricks::set_bevel(const Ref &val) { +bevel = val; +} + + +Ref Bricks::get_roundness() { + return roundness; +} + +void Bricks::set_roundness(const Ref &val) { +roundness = val; +} + + +float Bricks::get_corner() const { + return corner; +} + +void Bricks::set_corner(const float val) { +corner = val; +} + + + + //tool; + //export(Resource) ; + Ref out_bricks_pattern; + //export(Resource) ; + Ref out_random_color; + //export(Resource) ; + Ref out_position_x; + //export(Resource) ; + Ref out_position_y; + //export(Resource) ; + Ref out_brick_uv; + //export(Resource) ; + Ref out_corner_uv; + //export(Resource) ; + Ref out_direction; + //export(int, "Running Bond,Running Bond (2),HerringBone,Basket Weave,Spanish Bond") ; + int type = 0; + //export(int) ; + int repeat = 1; + //export(Vector2) ; + Vector2 col_row = Vector2(4, 4); + //export(float) ; + float offset = 0.5; + //export(Resource) ; + Ref mortar; + //export(Resource) ; + Ref bevel; + //export(Resource) ; + Ref roundness; + //export(float) ; + float corner = 0.3; + + void Bricks::_init_properties() { + + if (!out_bricks_pattern) { + out_bricks_pattern = MMNodeUniversalProperty.new(); + out_bricks_pattern.default_type = MMNodeUniversalProperty.DEFAULT_TYPE_IMAGE; +} + + out_bricks_pattern.output_slot_type = MMNodeUniversalProperty.SLOT_TYPE_IMAGE; + + if (!out_random_color) { + out_random_color = MMNodeUniversalProperty.new(); + out_random_color.default_type = MMNodeUniversalProperty.DEFAULT_TYPE_IMAGE; +} + + out_random_color.output_slot_type = MMNodeUniversalProperty.SLOT_TYPE_IMAGE; + + if (!out_position_x) { + out_position_x = MMNodeUniversalProperty.new(); + out_position_x.default_type = MMNodeUniversalProperty.DEFAULT_TYPE_IMAGE; +} + + out_position_x.output_slot_type = MMNodeUniversalProperty.SLOT_TYPE_IMAGE; + + if (!out_position_y) { + out_position_y = MMNodeUniversalProperty.new(); + out_position_y.default_type = MMNodeUniversalProperty.DEFAULT_TYPE_IMAGE; +} + + out_position_y.output_slot_type = MMNodeUniversalProperty.SLOT_TYPE_IMAGE; + + if (!out_brick_uv) { + out_brick_uv = MMNodeUniversalProperty.new(); + out_brick_uv.default_type = MMNodeUniversalProperty.DEFAULT_TYPE_IMAGE; +} + + out_brick_uv.output_slot_type = MMNodeUniversalProperty.SLOT_TYPE_IMAGE; + + if (!out_corner_uv) { + out_corner_uv = MMNodeUniversalProperty.new(); + out_corner_uv.default_type = MMNodeUniversalProperty.DEFAULT_TYPE_IMAGE; +} + + out_corner_uv.output_slot_type = MMNodeUniversalProperty.SLOT_TYPE_IMAGE; + + if (!out_direction) { + out_direction = MMNodeUniversalProperty.new(); + out_direction.default_type = MMNodeUniversalProperty.DEFAULT_TYPE_IMAGE; +} + + out_direction.output_slot_type = MMNodeUniversalProperty.SLOT_TYPE_IMAGE; + + if (!mortar) { + mortar = MMNodeUniversalProperty.new(); + mortar.default_type = MMNodeUniversalProperty.DEFAULT_TYPE_FLOAT; + mortar.set_default_value(0.1); +} + + mortar.input_slot_type = MMNodeUniversalProperty.SLOT_TYPE_UNIVERSAL; + mortar.slot_name = "Mortar"; + mortar.value_step = 0.01; + mortar.value_range = Vector2(0, 0.5); + + if (!bevel) { + bevel = MMNodeUniversalProperty.new(); + bevel.default_type = MMNodeUniversalProperty.DEFAULT_TYPE_FLOAT; + bevel.set_default_value(0.1); +} + + bevel.input_slot_type = MMNodeUniversalProperty.SLOT_TYPE_UNIVERSAL; + bevel.slot_name = "Bevel"; + bevel.value_step = 0.01; + bevel.value_range = Vector2(0, 0.5); + + if (!roundness) { + roundness = MMNodeUniversalProperty.new(); + roundness.default_type = MMNodeUniversalProperty.DEFAULT_TYPE_FLOAT; + roundness.set_default_value(0.1); +} + + roundness.input_slot_type = MMNodeUniversalProperty.SLOT_TYPE_UNIVERSAL; + roundness.slot_name = "Roundness"; + roundness.value_step = 0.01; + roundness.value_range = Vector2(0, 0.5); + register_output_property(out_bricks_pattern); + register_output_property(out_random_color); + register_output_property(out_position_x); + register_output_property(out_position_y); + register_output_property(out_brick_uv); + register_output_property(out_corner_uv); + register_output_property(out_direction); + register_input_property(mortar); + register_input_property(bevel); + register_input_property(roundness); +} + + + void Bricks::_register_methods(const Variant &mm_graph_node) { + mm_graph_node.add_slot_texture_universal(out_bricks_pattern); + mm_graph_node.add_slot_texture_universal(out_random_color); + mm_graph_node.add_slot_texture_universal(out_position_x); + mm_graph_node.add_slot_texture_universal(out_position_y); + mm_graph_node.add_slot_texture_universal(out_brick_uv); + mm_graph_node.add_slot_texture_universal(out_corner_uv); + mm_graph_node.add_slot_texture_universal(out_direction); + mm_graph_node.add_slot_enum("get_type", "set_type", "Type", [ "Running Bond", "Running Bond (2)", "HerringBone", "Basket Weave", "Spanish Bond" ]); + mm_graph_node.add_slot_int("get_repeat", "set_repeat", "Repeat"); + //, Vector2(1, 32))//, Vector2(0, 32)); + mm_graph_node.add_slot_vector2("get_col_row", "set_col_row", "Col, Row"); + mm_graph_node.add_slot_float("get_offset", "set_offset", "Offset"); + mm_graph_node.add_slot_float_universal(mortar); + mm_graph_node.add_slot_float_universal(bevel); + mm_graph_node.add_slot_float_universal(roundness); + mm_graph_node.add_slot_float("get_corner", "set_corner", "Corner"); +} + + + void Bricks::_render(const Variant &material) { + Ref bricks_pattern = Image.new(); + Ref random_color = Image.new(); + Ref position_x = Image.new(); + Ref position_y = Image.new(); + Ref brick_uv = Image.new(); + Ref corner_uv = Image.new(); + Ref direction = Image.new(); + bricks_pattern.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); + position_x.create(material.image_size.x, material.image_size.y, false, Image.FORMAT_RGBA8); + position_y.create(material.image_size.x, material.image_size.y, false, Image.FORMAT_RGBA8); + brick_uv.create(material.image_size.x, material.image_size.y, false, Image.FORMAT_RGBA8); + corner_uv.create(material.image_size.x, material.image_size.y, false, Image.FORMAT_RGBA8); + direction.create(material.image_size.x, material.image_size.y, false, Image.FORMAT_RGBA8); + bricks_pattern.lock(); + random_color.lock(); + position_x.lock(); + position_y.lock(); + brick_uv.lock(); + corner_uv.lock(); + direction.lock(); + float w = material.image_size.x; + float h = material.image_size.y; + float pseed = randf() + randi(); + + 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); + //vec4 $(name_uv)_rect = bricks_$pattern($uv, vec2($columns, $rows), $repeat, $row_offset); + Color brick_rect = Color(); + //"Running Bond,Running Bond (2),HerringBone,Basket Weave,Spanish Bond"; + + if (type == 0) { + brick_rect = MMAlgos.bricks_rb(uv, col_row, repeat, offset); +} + + + else if (type == 1) { + brick_rect = MMAlgos.bricks_rb2(uv, col_row, repeat, offset); +} + + + else if (type == 2) { + brick_rect = MMAlgos.bricks_hb(uv, col_row, repeat, offset); +} + + + else if (type == 3) { + brick_rect = MMAlgos.bricks_bw(uv, col_row, repeat, offset); +} + + + else if (type == 4) { + brick_rect = MMAlgos.bricks_sb(uv, col_row, repeat, offset); +} + + //vec4 $(name_uv) = brick($uv, $(name_uv)_rect.xy, $(name_uv)_rect.zw, $mortar*$mortar_map($uv), $round*$round_map($uv), max(0.001, $bevel*$bevel_map($uv))); + Color brick = MMAlgos.brick(uv, Vector2(brick_rect.r, brick_rect.g), Vector2(brick_rect.b, brick_rect.a), mortar.get_value(uv), roundness.get_value(uv), max(0.001, bevel.get_value(uv))); + //Bricks pattern (float) - A greyscale image that shows the bricks pattern; + //$(name_uv).x; + Color bricks_pattern_col = Color(brick.r, brick.r, brick.r, 1); + //Random color (rgb) - A random color for each brick; + //brick_random_color($(name_uv)_rect.xy, $(name_uv)_rect.zw, float($seed)); + Vector3 brc = MMAlgos.brick_random_color(Vector2(brick_rect.r, brick_rect.g), Vector2(brick_rect.b, brick_rect.a), 1 / float(pseed)); + Color random_color_col = Color(brc.x, brc.y, brc.z, 1); + //Position.x (float) - The position of each brick along the X axis",; + //$(name_uv).y; + Color position_x_col = Color(brick.g, brick.g, brick.g, 1); + //Position.y (float) - The position of each brick along the Y axis; + //$(name_uv).z; + Color position_y_col = Color(brick.b, brick.b, brick.b, 1); + //Brick UV (rgb) - An UV map output for each brick, to be connected to the Map input of a CustomUV node; + //brick_uv($uv, $(name_uv)_rect.xy, $(name_uv)_rect.zw, float($seed)); + Vector3 buv = MMAlgos.brick_uv(uv, Vector2(brick_rect.r, brick_rect.g), Vector2(brick_rect.b, brick_rect.a), pseed); + Color brick_uv_col = Color(buv.x, buv.y, buv.z, 1); + //Corner UV (rgb) - An UV map output for each brick corner, to be connected to the Map input of a CustomUV node; + //brick_corner_uv($uv, $(name_uv)_rect.xy, $(name_uv)_rect.zw, $mortar*$mortar_map($uv), $corner, float($seed)); + Vector3 bcuv = MMAlgos.brick_corner_uv(uv, Vector2(brick_rect.r, brick_rect.g), Vector2(brick_rect.b, brick_rect.a), mortar.get_value(uv), corner, pseed); + Color corner_uv_col = Color(bcuv.x, bcuv.y, bcuv.z, 1); + //Direction (float) - The direction of each brick (white: horizontal, black: vertical); + //0.5*(sign($(name_uv)_rect.z-$(name_uv)_rect.x-$(name_uv)_rect.w+$(name_uv)_rect.y)+1.0); + float d = 0.5 * (sign(brick_rect.b - brick_rect.r - brick_rect.a + brick_rect.g) + 1.0); + Color direction_col = Color(d, d, d, 1); + bricks_pattern.set_pixel(x, y, bricks_pattern_col); + random_color.set_pixel(x, y, random_color_col); + position_x.set_pixel(x, y, position_x_col); + position_y.set_pixel(x, y, position_y_col); + brick_uv.set_pixel(x, y, brick_uv_col); + corner_uv.set_pixel(x, y, corner_uv_col); + direction.set_pixel(x, y, direction_col); +} + +} + + bricks_pattern.unlock(); + random_color.unlock(); + position_x.unlock(); + position_y.unlock(); + brick_uv.unlock(); + corner_uv.unlock(); + direction.unlock(); + out_bricks_pattern.set_value(bricks_pattern); + out_random_color.set_value(random_color); + out_position_x.set_value(position_x); + out_position_y.set_value(position_y); + out_brick_uv.set_value(brick_uv); + out_corner_uv.set_value(corner_uv); + out_direction.set_value(direction); +} + + + Color Bricks::_get_value_for(const Vector2 &uv, const int pseed) { + return Color(); +} + + //type; + + int Bricks::get_type() { + return type; +} + + + void Bricks::set_type(const int val) { + type = val; + set_dirty(true); +} + + //repeat; + + int Bricks::get_repeat() { + return repeat; +} + + + void Bricks::set_repeat(const int val) { + repeat = val; + set_dirty(true); +} + + //col_row; + + Vector2 Bricks::get_col_row() { + return col_row; +} + + + void Bricks::set_col_row(const Vector2 &val) { + col_row = val; + set_dirty(true); +} + + //offset; + + float Bricks::get_offset() { + return offset; +} + + + void Bricks::set_offset(const float val) { + offset = val; + set_dirty(true); +} + + //corner; + + float Bricks::get_corner() { + return corner; +} + + + void Bricks::set_corner(const float val) { + corner = val; + set_dirty(true); +} + +} + + Bricks::Bricks() { + out_bricks_pattern; + out_random_color; + out_position_x; + out_position_y; + out_brick_uv; + out_corner_uv; + out_direction; + type = 0; + repeat = 1; + col_row = Vector2(4, 4); + offset = 0.5; + mortar; + bevel; + roundness; + corner = 0.3; + } + + Bricks::~Bricks() { + } + + + static void Bricks::_bind_methods() { + ClassDB::bind_method(D_METHOD("get_out_bricks_pattern"), &Bricks::get_out_bricks_pattern); + ClassDB::bind_method(D_METHOD("set_out_bricks_pattern", "value"), &Bricks::set_out_bricks_pattern); + ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "out_bricks_pattern", PROPERTY_HINT_RESOURCE_TYPE, "Ref"), "set_out_bricks_pattern", "get_out_bricks_pattern"); + + + ClassDB::bind_method(D_METHOD("get_out_random_color"), &Bricks::get_out_random_color); + ClassDB::bind_method(D_METHOD("set_out_random_color", "value"), &Bricks::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_position_x"), &Bricks::get_out_position_x); + ClassDB::bind_method(D_METHOD("set_out_position_x", "value"), &Bricks::set_out_position_x); + ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "out_position_x", PROPERTY_HINT_RESOURCE_TYPE, "Ref"), "set_out_position_x", "get_out_position_x"); + + + ClassDB::bind_method(D_METHOD("get_out_position_y"), &Bricks::get_out_position_y); + ClassDB::bind_method(D_METHOD("set_out_position_y", "value"), &Bricks::set_out_position_y); + ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "out_position_y", PROPERTY_HINT_RESOURCE_TYPE, "Ref"), "set_out_position_y", "get_out_position_y"); + + + ClassDB::bind_method(D_METHOD("get_out_brick_uv"), &Bricks::get_out_brick_uv); + ClassDB::bind_method(D_METHOD("set_out_brick_uv", "value"), &Bricks::set_out_brick_uv); + ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "out_brick_uv", PROPERTY_HINT_RESOURCE_TYPE, "Ref"), "set_out_brick_uv", "get_out_brick_uv"); + + + ClassDB::bind_method(D_METHOD("get_out_corner_uv"), &Bricks::get_out_corner_uv); + ClassDB::bind_method(D_METHOD("set_out_corner_uv", "value"), &Bricks::set_out_corner_uv); + ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "out_corner_uv", PROPERTY_HINT_RESOURCE_TYPE, "Ref"), "set_out_corner_uv", "get_out_corner_uv"); + + + ClassDB::bind_method(D_METHOD("get_out_direction"), &Bricks::get_out_direction); + ClassDB::bind_method(D_METHOD("set_out_direction", "value"), &Bricks::set_out_direction); + ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "out_direction", PROPERTY_HINT_RESOURCE_TYPE, "Ref"), "set_out_direction", "get_out_direction"); + + + ClassDB::bind_method(D_METHOD("get_type"), &Bricks::get_type); + ClassDB::bind_method(D_METHOD("set_type", "value"), &Bricks::set_type); + ADD_PROPERTY(PropertyInfo(Variant::INT, "type"), "set_type", "get_type"); + + + ClassDB::bind_method(D_METHOD("get_repeat"), &Bricks::get_repeat); + ClassDB::bind_method(D_METHOD("set_repeat", "value"), &Bricks::set_repeat); + ADD_PROPERTY(PropertyInfo(Variant::INT, "repeat"), "set_repeat", "get_repeat"); + + + ClassDB::bind_method(D_METHOD("get_col_row"), &Bricks::get_col_row); + ClassDB::bind_method(D_METHOD("set_col_row", "value"), &Bricks::set_col_row); + ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "col_row"), "set_col_row", "get_col_row"); + + + ClassDB::bind_method(D_METHOD("get_offset"), &Bricks::get_offset); + ClassDB::bind_method(D_METHOD("set_offset", "value"), &Bricks::set_offset); + ADD_PROPERTY(PropertyInfo(Variant::REAL, "offset"), "set_offset", "get_offset"); + + + ClassDB::bind_method(D_METHOD("get_mortar"), &Bricks::get_mortar); + ClassDB::bind_method(D_METHOD("set_mortar", "value"), &Bricks::set_mortar); + ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "mortar", PROPERTY_HINT_RESOURCE_TYPE, "Ref"), "set_mortar", "get_mortar"); + + + ClassDB::bind_method(D_METHOD("get_bevel"), &Bricks::get_bevel); + ClassDB::bind_method(D_METHOD("set_bevel", "value"), &Bricks::set_bevel); + ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "bevel", PROPERTY_HINT_RESOURCE_TYPE, "Ref"), "set_bevel", "get_bevel"); + + + ClassDB::bind_method(D_METHOD("get_roundness"), &Bricks::get_roundness); + ClassDB::bind_method(D_METHOD("set_roundness", "value"), &Bricks::set_roundness); + ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "roundness", PROPERTY_HINT_RESOURCE_TYPE, "Ref"), "set_roundness", "get_roundness"); + + + ClassDB::bind_method(D_METHOD("get_corner"), &Bricks::get_corner); + ClassDB::bind_method(D_METHOD("set_corner", "value"), &Bricks::set_corner); + ADD_PROPERTY(PropertyInfo(Variant::REAL, "corner"), "set_corner", "get_corner"); + + + ClassDB::bind_method(D_METHOD("_init_properties"), &Bricks::_init_properties); + ClassDB::bind_method(D_METHOD("_register_methods", "mm_graph_node"), &Bricks::_register_methods); + ClassDB::bind_method(D_METHOD("_render", "material"), &Bricks::_render); + ClassDB::bind_method(D_METHOD("_get_value_for", "uv", "pseed"), &Bricks::_get_value_for); + ClassDB::bind_method(D_METHOD("get_type"), &Bricks::get_type); + ClassDB::bind_method(D_METHOD("set_type", "val"), &Bricks::set_type); + ClassDB::bind_method(D_METHOD("get_repeat"), &Bricks::get_repeat); + ClassDB::bind_method(D_METHOD("set_repeat", "val"), &Bricks::set_repeat); + ClassDB::bind_method(D_METHOD("get_col_row"), &Bricks::get_col_row); + ClassDB::bind_method(D_METHOD("set_col_row", "val"), &Bricks::set_col_row); + ClassDB::bind_method(D_METHOD("get_offset"), &Bricks::get_offset); + ClassDB::bind_method(D_METHOD("set_offset", "val"), &Bricks::set_offset); + ClassDB::bind_method(D_METHOD("get_corner"), &Bricks::get_corner); + ClassDB::bind_method(D_METHOD("set_corner", "val"), &Bricks::set_corner); + + } + + + diff --git a/modules/material_maker/nodes/pattern/bricks.h b/modules/material_maker/nodes/pattern/bricks.h new file mode 100644 index 000000000..eb1fa0d54 --- /dev/null +++ b/modules/material_maker/nodes/pattern/bricks.h @@ -0,0 +1,115 @@ +#ifndef BRICKS_H +#define BRICKS_H + + +class Bricks : public MMNode { + GDCLASS(Bricks, MMNode); + + public: + + Ref get_out_bricks_pattern(); + void set_out_bricks_pattern(const Ref &val); + + Ref get_out_random_color(); + void set_out_random_color(const Ref &val); + + Ref get_out_position_x(); + void set_out_position_x(const Ref &val); + + Ref get_out_position_y(); + void set_out_position_y(const Ref &val); + + Ref get_out_brick_uv(); + void set_out_brick_uv(const Ref &val); + + Ref get_out_corner_uv(); + void set_out_corner_uv(const Ref &val); + + Ref get_out_direction(); + void set_out_direction(const Ref &val); + + int get_type() const; + void set_type(const int val); + + int get_repeat() const; + void set_repeat(const int val); + + Vector2 get_col_row(); + void set_col_row(const Vector2 &val); + + float get_offset() const; + void set_offset(const float val); + + Ref get_mortar(); + void set_mortar(const Ref &val); + + Ref get_bevel(); + void set_bevel(const Ref &val); + + Ref get_roundness(); + void set_roundness(const Ref &val); + + float get_corner() const; + void set_corner(const float val); + + 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); + int get_type(); + void set_type(const int val); + int get_repeat(); + void set_repeat(const int val); + Vector2 get_col_row(); + void set_col_row(const Vector2 &val); + float get_offset(); + void set_offset(const float val); + float get_corner(); + void set_corner(const float val); + + Bricks(); + ~Bricks(); + + protected: + static void _bind_methods(); + + //tool + //export(Resource) + Ref out_bricks_pattern; + //export(Resource) + Ref out_random_color; + //export(Resource) + Ref out_position_x; + //export(Resource) + Ref out_position_y; + //export(Resource) + Ref out_brick_uv; + //export(Resource) + Ref out_corner_uv; + //export(Resource) + Ref out_direction; + //export(int, "Running Bond,Running Bond (2),HerringBone,Basket Weave,Spanish Bond") + int type = 0; + //export(int) + int repeat = 1; + //export(Vector2) + Vector2 col_row = Vector2(4, 4); + //export(float) + float offset = 0.5; + //export(Resource) + Ref mortar; + //export(Resource) + Ref bevel; + //export(Resource) + Ref roundness; + //export(float) + float corner = 0.3; + //type + //repeat + //col_row + //offset + //corner +}; + + +#endif diff --git a/modules/material_maker/nodes/pattern/iching.cpp b/modules/material_maker/nodes/pattern/iching.cpp new file mode 100644 index 000000000..b20ccce59 --- /dev/null +++ b/modules/material_maker/nodes/pattern/iching.cpp @@ -0,0 +1,104 @@ + +#include "iching.h" + + +Ref Iching::get_image() { + return image; +} + +void Iching::set_image(const Ref &val) { +image = val; +} + + +Vector2 Iching::get_size() { + return size; +} + +void Iching::set_size(const Vector2 &val) { +size = val; +} + + + + //tool; + //export(Resource) ; + Ref image; + //export(Vector2) ; + Vector2 size = Vector2(4, 4); + + void Iching::_init_properties() { + + if (!image) { + image = MMNodeUniversalProperty.new(); + image.default_type = MMNodeUniversalProperty.DEFAULT_TYPE_IMAGE; +} + + image.output_slot_type = MMNodeUniversalProperty.SLOT_TYPE_IMAGE; + register_output_property(image); +} + + + void Iching::_register_methods(const Variant &mm_graph_node) { + mm_graph_node.add_slot_texture_universal(image); + mm_graph_node.add_slot_vector2("get_size", "set_size", "Size", 1); +} + + + void Iching::_render(const Variant &material) { + Ref img = render_image(material); + image.set_value(img); +} + + + Color Iching::_get_value_for(const Vector2 &uv, const int pseed) { + float ps = 1.0 / float(pseed); + //IChing(vec2($columns, $rows)*$uv, float($seed)); + return MMAlgos.IChingc(uv, size, ps); +} + + //size; + + Vector2 Iching::get_size() { + return size; +} + + + void Iching::set_size(const Vector2 &val) { + size = val; + set_dirty(true); +} + +} + + Iching::Iching() { + image; + size = Vector2(4, 4); + } + + Iching::~Iching() { + } + + + static void Iching::_bind_methods() { + ClassDB::bind_method(D_METHOD("get_image"), &Iching::get_image); + ClassDB::bind_method(D_METHOD("set_image", "value"), &Iching::set_image); + ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "image", PROPERTY_HINT_RESOURCE_TYPE, "Ref"), "set_image", "get_image"); + + + ClassDB::bind_method(D_METHOD("get_size"), &Iching::get_size); + ClassDB::bind_method(D_METHOD("set_size", "value"), &Iching::set_size); + ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "size"), "set_size", "get_size"); + + + ClassDB::bind_method(D_METHOD("_init_properties"), &Iching::_init_properties); + ClassDB::bind_method(D_METHOD("_register_methods", "mm_graph_node"), &Iching::_register_methods); + ClassDB::bind_method(D_METHOD("_render", "material"), &Iching::_render); + ClassDB::bind_method(D_METHOD("_get_value_for", "uv", "pseed"), &Iching::_get_value_for); + ClassDB::bind_method(D_METHOD("get_size"), &Iching::get_size); + ClassDB::bind_method(D_METHOD("set_size", "val"), &Iching::set_size); + + } + + + diff --git a/modules/material_maker/nodes/pattern/iching.h b/modules/material_maker/nodes/pattern/iching.h new file mode 100644 index 000000000..727ae3231 --- /dev/null +++ b/modules/material_maker/nodes/pattern/iching.h @@ -0,0 +1,38 @@ +#ifndef ICHING_H +#define ICHING_H + + +class Iching : public MMNode { + GDCLASS(Iching, MMNode); + + public: + + Ref get_image(); + void set_image(const Ref &val); + + Vector2 get_size(); + void set_size(const Vector2 &val); + + 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_size(); + void set_size(const Vector2 &val); + + Iching(); + ~Iching(); + + protected: + static void _bind_methods(); + + //tool + //export(Resource) + Ref image; + //export(Vector2) + Vector2 size = Vector2(4, 4); + //size +}; + + +#endif diff --git a/modules/material_maker/nodes/pattern/pattern.cpp b/modules/material_maker/nodes/pattern/pattern.cpp new file mode 100644 index 000000000..238de46a7 --- /dev/null +++ b/modules/material_maker/nodes/pattern/pattern.cpp @@ -0,0 +1,200 @@ + +#include "pattern.h" + + +Ref Pattern::get_image() { + return image; +} + +void Pattern::set_image(const Ref &val) { +image = val; +} + + +int Pattern::get_combiner_type() const { + return combiner_type; +} + +void Pattern::set_combiner_type(const int val) { +combiner_type = val; +} + + +int Pattern::get_combiner_axis_type_x() const { + return combiner_axis_type_x; +} + +void Pattern::set_combiner_axis_type_x(const int val) { +combiner_axis_type_x = val; +} + + +int Pattern::get_combiner_axis_type_y() const { + return combiner_axis_type_y; +} + +void Pattern::set_combiner_axis_type_y(const int val) { +combiner_axis_type_y = val; +} + + +Vector2 Pattern::get_repeat() { + return repeat; +} + +void Pattern::set_repeat(const Vector2 &val) { +repeat = val; +} + + + + //tool; + //export(Resource) ; + Ref image; + //export(int, "Multiply,Add,Max,Min,Xor,Pow") ; + int combiner_type = 0; + //export(int, "Sine,Triangle,Square,Sawtooth,Constant,Bounce") ; + int combiner_axis_type_x = 0; + //export(int, "Sine,Triangle,Square,Sawtooth,Constant,Bounce") ; + int combiner_axis_type_y = 0; + //export(Vector2) ; + Vector2 repeat = Vector2(4, 4); + + void Pattern::_init_properties() { + + if (!image) { + image = MMNodeUniversalProperty.new(); + image.default_type = MMNodeUniversalProperty.DEFAULT_TYPE_IMAGE; +} + + image.output_slot_type = MMNodeUniversalProperty.SLOT_TYPE_IMAGE; + register_output_property(image); +} + + + void Pattern::_register_methods(const Variant &mm_graph_node) { + mm_graph_node.add_slot_texture_universal(image); + mm_graph_node.add_slot_enum("get_combiner_type", "set_combiner_type", "Combiner Type", [ "Multiply", "Add" , "Max", "Min", "Xor", "Pow" ]); + mm_graph_node.add_slot_enum("get_combiner_axis_type_x", "set_combiner_axis_type_x", "Combiner Axis type", [ "Sine", "Triangle", "Square", "Sawtooth", "Constant", "Bounce" ]); + mm_graph_node.add_slot_enum("get_combiner_axis_type_y", "set_combiner_axis_type_y", "", [ "Sine", "Triangle", "Square", "Sawtooth", "Constant", "Bounce" ]); + //, Vector2(0, 32)); + mm_graph_node.add_slot_vector2("get_repeat", "set_repeat", "Repeat", 1); +} + + + void Pattern::_render(const Variant &material) { + Ref img = render_image(material); + image.set_value(img); +} + + + Color Pattern::_get_value_for(const Vector2 &uv, const int pseed) { + float f = MMAlgos.pattern(uv, repeat.x, repeat.y, combiner_type, combiner_axis_type_x, combiner_axis_type_y); + return Color(f, f, f, 1); +} + + //combiner_type; + + int Pattern::get_combiner_type() { + return combiner_type; +} + + + void Pattern::set_combiner_type(const int val) { + combiner_type = val; + set_dirty(true); +} + + //combiner_axis_type_x; + + int Pattern::get_combiner_axis_type_x() { + return combiner_axis_type_x; +} + + + void Pattern::set_combiner_axis_type_x(const int val) { + combiner_axis_type_x = val; + set_dirty(true); +} + + //combiner_axis_type_y; + + int Pattern::get_combiner_axis_type_y() { + return combiner_axis_type_y; +} + + + void Pattern::set_combiner_axis_type_y(const int val) { + combiner_axis_type_y = val; + set_dirty(true); +} + + //repeat; + + Vector2 Pattern::get_repeat() { + return repeat; +} + + + void Pattern::set_repeat(const Vector2 &val) { + repeat = val; + set_dirty(true); +} + +} + + Pattern::Pattern() { + image; + combiner_type = 0; + combiner_axis_type_x = 0; + combiner_axis_type_y = 0; + repeat = Vector2(4, 4); + } + + Pattern::~Pattern() { + } + + + static void Pattern::_bind_methods() { + ClassDB::bind_method(D_METHOD("get_image"), &Pattern::get_image); + ClassDB::bind_method(D_METHOD("set_image", "value"), &Pattern::set_image); + ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "image", PROPERTY_HINT_RESOURCE_TYPE, "Ref"), "set_image", "get_image"); + + + ClassDB::bind_method(D_METHOD("get_combiner_type"), &Pattern::get_combiner_type); + ClassDB::bind_method(D_METHOD("set_combiner_type", "value"), &Pattern::set_combiner_type); + ADD_PROPERTY(PropertyInfo(Variant::INT, "combiner_type"), "set_combiner_type", "get_combiner_type"); + + + ClassDB::bind_method(D_METHOD("get_combiner_axis_type_x"), &Pattern::get_combiner_axis_type_x); + ClassDB::bind_method(D_METHOD("set_combiner_axis_type_x", "value"), &Pattern::set_combiner_axis_type_x); + ADD_PROPERTY(PropertyInfo(Variant::INT, "combiner_axis_type_x"), "set_combiner_axis_type_x", "get_combiner_axis_type_x"); + + + ClassDB::bind_method(D_METHOD("get_combiner_axis_type_y"), &Pattern::get_combiner_axis_type_y); + ClassDB::bind_method(D_METHOD("set_combiner_axis_type_y", "value"), &Pattern::set_combiner_axis_type_y); + ADD_PROPERTY(PropertyInfo(Variant::INT, "combiner_axis_type_y"), "set_combiner_axis_type_y", "get_combiner_axis_type_y"); + + + ClassDB::bind_method(D_METHOD("get_repeat"), &Pattern::get_repeat); + ClassDB::bind_method(D_METHOD("set_repeat", "value"), &Pattern::set_repeat); + ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "repeat"), "set_repeat", "get_repeat"); + + + ClassDB::bind_method(D_METHOD("_init_properties"), &Pattern::_init_properties); + ClassDB::bind_method(D_METHOD("_register_methods", "mm_graph_node"), &Pattern::_register_methods); + ClassDB::bind_method(D_METHOD("_render", "material"), &Pattern::_render); + ClassDB::bind_method(D_METHOD("_get_value_for", "uv", "pseed"), &Pattern::_get_value_for); + ClassDB::bind_method(D_METHOD("get_combiner_type"), &Pattern::get_combiner_type); + ClassDB::bind_method(D_METHOD("set_combiner_type", "val"), &Pattern::set_combiner_type); + ClassDB::bind_method(D_METHOD("get_combiner_axis_type_x"), &Pattern::get_combiner_axis_type_x); + ClassDB::bind_method(D_METHOD("set_combiner_axis_type_x", "val"), &Pattern::set_combiner_axis_type_x); + ClassDB::bind_method(D_METHOD("get_combiner_axis_type_y"), &Pattern::get_combiner_axis_type_y); + ClassDB::bind_method(D_METHOD("set_combiner_axis_type_y", "val"), &Pattern::set_combiner_axis_type_y); + ClassDB::bind_method(D_METHOD("get_repeat"), &Pattern::get_repeat); + ClassDB::bind_method(D_METHOD("set_repeat", "val"), &Pattern::set_repeat); + + } + + + diff --git a/modules/material_maker/nodes/pattern/pattern.h b/modules/material_maker/nodes/pattern/pattern.h new file mode 100644 index 000000000..0d1838dba --- /dev/null +++ b/modules/material_maker/nodes/pattern/pattern.h @@ -0,0 +1,62 @@ +#ifndef PATTERN_H +#define PATTERN_H + + +class Pattern : public MMNode { + GDCLASS(Pattern, MMNode); + + public: + + Ref get_image(); + void set_image(const Ref &val); + + int get_combiner_type() const; + void set_combiner_type(const int val); + + int get_combiner_axis_type_x() const; + void set_combiner_axis_type_x(const int val); + + int get_combiner_axis_type_y() const; + void set_combiner_axis_type_y(const int val); + + Vector2 get_repeat(); + void set_repeat(const Vector2 &val); + + 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); + int get_combiner_type(); + void set_combiner_type(const int val); + int get_combiner_axis_type_x(); + void set_combiner_axis_type_x(const int val); + int get_combiner_axis_type_y(); + void set_combiner_axis_type_y(const int val); + Vector2 get_repeat(); + void set_repeat(const Vector2 &val); + + Pattern(); + ~Pattern(); + + protected: + static void _bind_methods(); + + //tool + //export(Resource) + Ref image; + //export(int, "Multiply,Add,Max,Min,Xor,Pow") + int combiner_type = 0; + //export(int, "Sine,Triangle,Square,Sawtooth,Constant,Bounce") + int combiner_axis_type_x = 0; + //export(int, "Sine,Triangle,Square,Sawtooth,Constant,Bounce") + int combiner_axis_type_y = 0; + //export(Vector2) + Vector2 repeat = Vector2(4, 4); + //combiner_type + //combiner_axis_type_x + //combiner_axis_type_y + //repeat +}; + + +#endif diff --git a/modules/material_maker/nodes/pattern/runes.cpp b/modules/material_maker/nodes/pattern/runes.cpp new file mode 100644 index 000000000..df4944049 --- /dev/null +++ b/modules/material_maker/nodes/pattern/runes.cpp @@ -0,0 +1,104 @@ + +#include "runes.h" + + +Ref Runes::get_image() { + return image; +} + +void Runes::set_image(const Ref &val) { +image = val; +} + + +Vector2 Runes::get_size() { + return size; +} + +void Runes::set_size(const Vector2 &val) { +size = val; +} + + + + //tool; + //export(Resource) ; + Ref image; + //export(Vector2) ; + Vector2 size = Vector2(4, 4); + + void Runes::_init_properties() { + + if (!image) { + image = MMNodeUniversalProperty.new(); + image.default_type = MMNodeUniversalProperty.DEFAULT_TYPE_IMAGE; +} + + image.output_slot_type = MMNodeUniversalProperty.SLOT_TYPE_IMAGE; + register_output_property(image); +} + + + void Runes::_register_methods(const Variant &mm_graph_node) { + mm_graph_node.add_slot_texture_universal(image); + mm_graph_node.add_slot_vector2("get_size", "set_size", "Size", 1); +} + + + void Runes::_render(const Variant &material) { + Ref img = render_image(material); + image.set_value(img); +} + + + Color Runes::_get_value_for(const Vector2 &uv, const int pseed) { + float ps = 1.0 / float(pseed); + //Rune(vec2($columns, $rows)*$uv, float($seed)); + return MMAlgos.runesc(uv, size, ps); +} + + //size; + + Vector2 Runes::get_size() { + return size; +} + + + void Runes::set_size(const Vector2 &val) { + size = val; + set_dirty(true); +} + +} + + Runes::Runes() { + image; + size = Vector2(4, 4); + } + + Runes::~Runes() { + } + + + static void Runes::_bind_methods() { + ClassDB::bind_method(D_METHOD("get_image"), &Runes::get_image); + ClassDB::bind_method(D_METHOD("set_image", "value"), &Runes::set_image); + ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "image", PROPERTY_HINT_RESOURCE_TYPE, "Ref"), "set_image", "get_image"); + + + ClassDB::bind_method(D_METHOD("get_size"), &Runes::get_size); + ClassDB::bind_method(D_METHOD("set_size", "value"), &Runes::set_size); + ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "size"), "set_size", "get_size"); + + + ClassDB::bind_method(D_METHOD("_init_properties"), &Runes::_init_properties); + ClassDB::bind_method(D_METHOD("_register_methods", "mm_graph_node"), &Runes::_register_methods); + ClassDB::bind_method(D_METHOD("_render", "material"), &Runes::_render); + ClassDB::bind_method(D_METHOD("_get_value_for", "uv", "pseed"), &Runes::_get_value_for); + ClassDB::bind_method(D_METHOD("get_size"), &Runes::get_size); + ClassDB::bind_method(D_METHOD("set_size", "val"), &Runes::set_size); + + } + + + diff --git a/modules/material_maker/nodes/pattern/runes.h b/modules/material_maker/nodes/pattern/runes.h new file mode 100644 index 000000000..7e7f570d0 --- /dev/null +++ b/modules/material_maker/nodes/pattern/runes.h @@ -0,0 +1,38 @@ +#ifndef RUNES_H +#define RUNES_H + + +class Runes : public MMNode { + GDCLASS(Runes, MMNode); + + public: + + Ref get_image(); + void set_image(const Ref &val); + + Vector2 get_size(); + void set_size(const Vector2 &val); + + 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_size(); + void set_size(const Vector2 &val); + + Runes(); + ~Runes(); + + protected: + static void _bind_methods(); + + //tool + //export(Resource) + Ref image; + //export(Vector2) + Vector2 size = Vector2(4, 4); + //size +}; + + +#endif diff --git a/modules/material_maker/nodes/pattern/scratches.cpp b/modules/material_maker/nodes/pattern/scratches.cpp new file mode 100644 index 000000000..32b39dc9d --- /dev/null +++ b/modules/material_maker/nodes/pattern/scratches.cpp @@ -0,0 +1,231 @@ + +#include "scratches.h" + + +Ref Scratches::get_image() { + return image; +} + +void Scratches::set_image(const Ref &val) { +image = val; +} + + +Vector2 Scratches::get_size() { + return size; +} + +void Scratches::set_size(const Vector2 &val) { +size = val; +} + + +int Scratches::get_layers() const { + return layers; +} + +void Scratches::set_layers(const int val) { +layers = val; +} + + +float Scratches::get_waviness() const { + return waviness; +} + +void Scratches::set_waviness(const float val) { +waviness = val; +} + + +int Scratches::get_angle() const { + return angle; +} + +void Scratches::set_angle(const int val) { +angle = val; +} + + +float Scratches::get_randomness() const { + return randomness; +} + +void Scratches::set_randomness(const float val) { +randomness = val; +} + + + + //tool; + //export(Resource) ; + Ref image; + //export(Vector2) ; + Vector2 size = Vector2(0.25, 0.4); + //export(int) ; + int layers = 4; + //export(float) ; + float waviness = 0.51; + //export(int) ; + int angle = 0; + //export(float) ; + float randomness = 0.44; + + void Scratches::_init_properties() { + + if (!image) { + image = MMNodeUniversalProperty.new(); + image.default_type = MMNodeUniversalProperty.DEFAULT_TYPE_IMAGE; +} + + image.output_slot_type = MMNodeUniversalProperty.SLOT_TYPE_IMAGE; + register_output_property(image); +} + + + void Scratches::_register_methods(const Variant &mm_graph_node) { + mm_graph_node.add_slot_texture_universal(image); + mm_graph_node.add_slot_vector2("get_size", "set_size", "Size", 0.01); + mm_graph_node.add_slot_int("get_layers", "set_layers", "Layers"); + mm_graph_node.add_slot_float("get_waviness", "set_waviness", "Waviness", 0.01); + mm_graph_node.add_slot_int("get_angle", "set_angle", "Angle"); + mm_graph_node.add_slot_float("get_randomness", "set_randomness", "Randomness", 0.01); +} + + + void Scratches::_render(const Variant &material) { + Ref img = render_image(material); + image.set_value(img); +} + + + Color Scratches::_get_value_for(const Vector2 &uv, const int pseed) { + //scratches($uv, int($layers), vec2($length, $width), $waviness, $angle, $randomness, vec2(float($seed), 0.0)); + return MMAlgos.scratchesc(uv, layers, size, waviness, angle, randomness, Vector2(pseed, 0.0)); +} + + //size; + + Vector2 Scratches::get_size() { + return size; +} + + + void Scratches::set_size(const Vector2 &val) { + size = val; + set_dirty(true); +} + + //layers; + + int Scratches::get_layers() { + return layers; +} + + + void Scratches::set_layers(const int val) { + layers = val; + set_dirty(true); +} + + //waviness; + + float Scratches::get_waviness() { + return waviness; +} + + + void Scratches::set_waviness(const float val) { + waviness = val; + set_dirty(true); +} + + //angle; + + int Scratches::get_angle() { + return angle; +} + + + void Scratches::set_angle(const int val) { + angle = val; + set_dirty(true); +} + + //randomness; + + float Scratches::get_randomness() { + return randomness; +} + + + void Scratches::set_randomness(const float val) { + randomness = val; + set_dirty(true); +} + +} + + Scratches::Scratches() { + image; + size = Vector2(0.25, 0.4); + layers = 4; + waviness = 0.51; + angle = 0; + randomness = 0.44; + } + + Scratches::~Scratches() { + } + + + static void Scratches::_bind_methods() { + ClassDB::bind_method(D_METHOD("get_image"), &Scratches::get_image); + ClassDB::bind_method(D_METHOD("set_image", "value"), &Scratches::set_image); + ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "image", PROPERTY_HINT_RESOURCE_TYPE, "Ref"), "set_image", "get_image"); + + + ClassDB::bind_method(D_METHOD("get_size"), &Scratches::get_size); + ClassDB::bind_method(D_METHOD("set_size", "value"), &Scratches::set_size); + ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "size"), "set_size", "get_size"); + + + ClassDB::bind_method(D_METHOD("get_layers"), &Scratches::get_layers); + ClassDB::bind_method(D_METHOD("set_layers", "value"), &Scratches::set_layers); + ADD_PROPERTY(PropertyInfo(Variant::INT, "layers"), "set_layers", "get_layers"); + + + ClassDB::bind_method(D_METHOD("get_waviness"), &Scratches::get_waviness); + ClassDB::bind_method(D_METHOD("set_waviness", "value"), &Scratches::set_waviness); + ADD_PROPERTY(PropertyInfo(Variant::REAL, "waviness"), "set_waviness", "get_waviness"); + + + ClassDB::bind_method(D_METHOD("get_angle"), &Scratches::get_angle); + ClassDB::bind_method(D_METHOD("set_angle", "value"), &Scratches::set_angle); + ADD_PROPERTY(PropertyInfo(Variant::INT, "angle"), "set_angle", "get_angle"); + + + ClassDB::bind_method(D_METHOD("get_randomness"), &Scratches::get_randomness); + ClassDB::bind_method(D_METHOD("set_randomness", "value"), &Scratches::set_randomness); + ADD_PROPERTY(PropertyInfo(Variant::REAL, "randomness"), "set_randomness", "get_randomness"); + + + ClassDB::bind_method(D_METHOD("_init_properties"), &Scratches::_init_properties); + ClassDB::bind_method(D_METHOD("_register_methods", "mm_graph_node"), &Scratches::_register_methods); + ClassDB::bind_method(D_METHOD("_render", "material"), &Scratches::_render); + ClassDB::bind_method(D_METHOD("_get_value_for", "uv", "pseed"), &Scratches::_get_value_for); + ClassDB::bind_method(D_METHOD("get_size"), &Scratches::get_size); + ClassDB::bind_method(D_METHOD("set_size", "val"), &Scratches::set_size); + ClassDB::bind_method(D_METHOD("get_layers"), &Scratches::get_layers); + ClassDB::bind_method(D_METHOD("set_layers", "val"), &Scratches::set_layers); + ClassDB::bind_method(D_METHOD("get_waviness"), &Scratches::get_waviness); + ClassDB::bind_method(D_METHOD("set_waviness", "val"), &Scratches::set_waviness); + ClassDB::bind_method(D_METHOD("get_angle"), &Scratches::get_angle); + ClassDB::bind_method(D_METHOD("set_angle", "val"), &Scratches::set_angle); + ClassDB::bind_method(D_METHOD("get_randomness"), &Scratches::get_randomness); + ClassDB::bind_method(D_METHOD("set_randomness", "val"), &Scratches::set_randomness); + + } + + + diff --git a/modules/material_maker/nodes/pattern/scratches.h b/modules/material_maker/nodes/pattern/scratches.h new file mode 100644 index 000000000..c66b182a9 --- /dev/null +++ b/modules/material_maker/nodes/pattern/scratches.h @@ -0,0 +1,70 @@ +#ifndef SCRATCHES_H +#define SCRATCHES_H + + +class Scratches : public MMNode { + GDCLASS(Scratches, MMNode); + + public: + + Ref get_image(); + void set_image(const Ref &val); + + Vector2 get_size(); + void set_size(const Vector2 &val); + + int get_layers() const; + void set_layers(const int val); + + float get_waviness() const; + void set_waviness(const float val); + + int get_angle() const; + void set_angle(const int val); + + float get_randomness() const; + void set_randomness(const float val); + + 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_size(); + void set_size(const Vector2 &val); + int get_layers(); + void set_layers(const int val); + float get_waviness(); + void set_waviness(const float val); + int get_angle(); + void set_angle(const int val); + float get_randomness(); + void set_randomness(const float val); + + Scratches(); + ~Scratches(); + + protected: + static void _bind_methods(); + + //tool + //export(Resource) + Ref image; + //export(Vector2) + Vector2 size = Vector2(0.25, 0.4); + //export(int) + int layers = 4; + //export(float) + float waviness = 0.51; + //export(int) + int angle = 0; + //export(float) + float randomness = 0.44; + //size + //layers + //waviness + //angle + //randomness +}; + + +#endif diff --git a/modules/material_maker/nodes/pattern/sine_wave.cpp b/modules/material_maker/nodes/pattern/sine_wave.cpp new file mode 100644 index 000000000..f85c6e7f2 --- /dev/null +++ b/modules/material_maker/nodes/pattern/sine_wave.cpp @@ -0,0 +1,167 @@ + +#include "sine_wave.h" + + +Ref SineWave::get_image() { + return image; +} + +void SineWave::set_image(const Ref &val) { +image = val; +} + + +float SineWave::get_amplitude() const { + return amplitude; +} + +void SineWave::set_amplitude(const float val) { +amplitude = val; +} + + +float SineWave::get_frequency() const { + return frequency; +} + +void SineWave::set_frequency(const float val) { +frequency = val; +} + + +float SineWave::get_phase() const { + return phase; +} + +void SineWave::set_phase(const float val) { +phase = val; +} + + + + //tool; + //export(Resource) ; + Ref image; + //export(float) ; + float amplitude = 0.5; + //export(float) ; + float frequency = 2; + //export(float) ; + float phase = 0; + + void SineWave::_init_properties() { + + if (!image) { + image = MMNodeUniversalProperty.new(); + image.default_type = MMNodeUniversalProperty.DEFAULT_TYPE_IMAGE; +} + + image.output_slot_type = MMNodeUniversalProperty.SLOT_TYPE_IMAGE; + register_output_property(image); +} + + + void SineWave::_register_methods(const Variant &mm_graph_node) { + mm_graph_node.add_slot_texture_universal(image); + mm_graph_node.add_slot_float("get_amplitude", "set_amplitude", "Amplitude", 0.01); + mm_graph_node.add_slot_float("get_frequency", "set_frequency", "Frequency", 0.1); + mm_graph_node.add_slot_float("get_phase", "set_phase", "Phase", 0.01); +} + + + void SineWave::_render(const Variant &material) { + Ref img = render_image(material); + image.set_value(img); +} + + + Color SineWave::_get_value_for(const Vector2 &uv, const int pseed) { + float f = 1.0 - abs(2.0 * (uv.y - 0.5) - amplitude *sin((frequency * uv.x + phase)*6.28318530718)); + return Color(f, f, f, 1); +} + + //amplitude; + + float SineWave::get_amplitude() { + return amplitude; +} + + + void SineWave::set_amplitude(const float val) { + amplitude = val; + set_dirty(true); +} + + //frequency; + + float SineWave::get_frequency() { + return frequency; +} + + + void SineWave::set_frequency(const float val) { + frequency = val; + set_dirty(true); +} + + //phase; + + float SineWave::get_phase() { + return phase; +} + + + void SineWave::set_phase(const float val) { + phase = val; + set_dirty(true); +} + +} + + SineWave::SineWave() { + image; + amplitude = 0.5; + frequency = 2; + phase = 0; + } + + SineWave::~SineWave() { + } + + + static void SineWave::_bind_methods() { + ClassDB::bind_method(D_METHOD("get_image"), &SineWave::get_image); + ClassDB::bind_method(D_METHOD("set_image", "value"), &SineWave::set_image); + ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "image", PROPERTY_HINT_RESOURCE_TYPE, "Ref"), "set_image", "get_image"); + + + ClassDB::bind_method(D_METHOD("get_amplitude"), &SineWave::get_amplitude); + ClassDB::bind_method(D_METHOD("set_amplitude", "value"), &SineWave::set_amplitude); + ADD_PROPERTY(PropertyInfo(Variant::REAL, "amplitude"), "set_amplitude", "get_amplitude"); + + + ClassDB::bind_method(D_METHOD("get_frequency"), &SineWave::get_frequency); + ClassDB::bind_method(D_METHOD("set_frequency", "value"), &SineWave::set_frequency); + ADD_PROPERTY(PropertyInfo(Variant::REAL, "frequency"), "set_frequency", "get_frequency"); + + + ClassDB::bind_method(D_METHOD("get_phase"), &SineWave::get_phase); + ClassDB::bind_method(D_METHOD("set_phase", "value"), &SineWave::set_phase); + ADD_PROPERTY(PropertyInfo(Variant::REAL, "phase"), "set_phase", "get_phase"); + + + ClassDB::bind_method(D_METHOD("_init_properties"), &SineWave::_init_properties); + ClassDB::bind_method(D_METHOD("_register_methods", "mm_graph_node"), &SineWave::_register_methods); + ClassDB::bind_method(D_METHOD("_render", "material"), &SineWave::_render); + ClassDB::bind_method(D_METHOD("_get_value_for", "uv", "pseed"), &SineWave::_get_value_for); + ClassDB::bind_method(D_METHOD("get_amplitude"), &SineWave::get_amplitude); + ClassDB::bind_method(D_METHOD("set_amplitude", "val"), &SineWave::set_amplitude); + ClassDB::bind_method(D_METHOD("get_frequency"), &SineWave::get_frequency); + ClassDB::bind_method(D_METHOD("set_frequency", "val"), &SineWave::set_frequency); + ClassDB::bind_method(D_METHOD("get_phase"), &SineWave::get_phase); + ClassDB::bind_method(D_METHOD("set_phase", "val"), &SineWave::set_phase); + + } + + + diff --git a/modules/material_maker/nodes/pattern/sine_wave.h b/modules/material_maker/nodes/pattern/sine_wave.h new file mode 100644 index 000000000..456197fd4 --- /dev/null +++ b/modules/material_maker/nodes/pattern/sine_wave.h @@ -0,0 +1,54 @@ +#ifndef SINE_WAVE_H +#define SINE_WAVE_H + + +class SineWave : public MMNode { + GDCLASS(SineWave, MMNode); + + public: + + Ref get_image(); + void set_image(const Ref &val); + + float get_amplitude() const; + void set_amplitude(const float val); + + float get_frequency() const; + void set_frequency(const float val); + + float get_phase() const; + void set_phase(const float val); + + 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); + float get_amplitude(); + void set_amplitude(const float val); + float get_frequency(); + void set_frequency(const float val); + float get_phase(); + void set_phase(const float val); + + SineWave(); + ~SineWave(); + + protected: + static void _bind_methods(); + + //tool + //export(Resource) + Ref image; + //export(float) + float amplitude = 0.5; + //export(float) + float frequency = 2; + //export(float) + float phase = 0; + //amplitude + //frequency + //phase +}; + + +#endif diff --git a/modules/material_maker/nodes/pattern/truchet.cpp b/modules/material_maker/nodes/pattern/truchet.cpp new file mode 100644 index 000000000..fd2608f5b --- /dev/null +++ b/modules/material_maker/nodes/pattern/truchet.cpp @@ -0,0 +1,144 @@ + +#include "truchet.h" + + +Ref Truchet::get_image() { + return image; +} + +void Truchet::set_image(const Ref &val) { +image = val; +} + + +int Truchet::get_shape() const { + return shape; +} + +void Truchet::set_shape(const int val) { +shape = val; +} + + +float Truchet::get_size() const { + return size; +} + +void Truchet::set_size(const float val) { +size = val; +} + + + + //tool; + //export(Resource) ; + Ref image; + //export(int, "Line,Circle") ; + int shape = 0; + //export(float) ; + float size = 4; + + void Truchet::_init_properties() { + + if (!image) { + image = MMNodeUniversalProperty.new(); + image.default_type = MMNodeUniversalProperty.DEFAULT_TYPE_IMAGE; +} + + image.output_slot_type = MMNodeUniversalProperty.SLOT_TYPE_IMAGE; + register_output_property(image); +} + + + void Truchet::_register_methods(const Variant &mm_graph_node) { + mm_graph_node.add_slot_texture_universal(image); + mm_graph_node.add_slot_enum("get_shape", "set_shape", "Shape", [ "Line", "Circle" ]); + mm_graph_node.add_slot_float("get_size", "set_size", "Size", 1); +} + + + void Truchet::_render(const Variant &material) { + Ref img = render_image(material); + image.set_value(img); +} + + + Color Truchet::_get_value_for(const Vector2 &uv, const int pseed) { + + if (shape == 0) { + return MMAlgos.truchet1c(uv, size, pseed); +} + + + else if (shape == 1) { + return MMAlgos.truchet2c(uv, size, pseed); +} + + return Color(); +} + + //shape; + + int Truchet::get_shape() { + return shape; +} + + + void Truchet::set_shape(const int val) { + shape = val; + set_dirty(true); +} + + //size; + + float Truchet::get_size() { + return size; +} + + + void Truchet::set_size(const float val) { + size = val; + set_dirty(true); +} + +} + + Truchet::Truchet() { + image; + shape = 0; + size = 4; + } + + Truchet::~Truchet() { + } + + + static void Truchet::_bind_methods() { + ClassDB::bind_method(D_METHOD("get_image"), &Truchet::get_image); + ClassDB::bind_method(D_METHOD("set_image", "value"), &Truchet::set_image); + ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "image", PROPERTY_HINT_RESOURCE_TYPE, "Ref"), "set_image", "get_image"); + + + ClassDB::bind_method(D_METHOD("get_shape"), &Truchet::get_shape); + ClassDB::bind_method(D_METHOD("set_shape", "value"), &Truchet::set_shape); + ADD_PROPERTY(PropertyInfo(Variant::INT, "shape"), "set_shape", "get_shape"); + + + ClassDB::bind_method(D_METHOD("get_size"), &Truchet::get_size); + ClassDB::bind_method(D_METHOD("set_size", "value"), &Truchet::set_size); + ADD_PROPERTY(PropertyInfo(Variant::REAL, "size"), "set_size", "get_size"); + + + ClassDB::bind_method(D_METHOD("_init_properties"), &Truchet::_init_properties); + ClassDB::bind_method(D_METHOD("_register_methods", "mm_graph_node"), &Truchet::_register_methods); + ClassDB::bind_method(D_METHOD("_render", "material"), &Truchet::_render); + ClassDB::bind_method(D_METHOD("_get_value_for", "uv", "pseed"), &Truchet::_get_value_for); + ClassDB::bind_method(D_METHOD("get_shape"), &Truchet::get_shape); + ClassDB::bind_method(D_METHOD("set_shape", "val"), &Truchet::set_shape); + ClassDB::bind_method(D_METHOD("get_size"), &Truchet::get_size); + ClassDB::bind_method(D_METHOD("set_size", "val"), &Truchet::set_size); + + } + + + diff --git a/modules/material_maker/nodes/pattern/truchet.h b/modules/material_maker/nodes/pattern/truchet.h new file mode 100644 index 000000000..0d079f3ab --- /dev/null +++ b/modules/material_maker/nodes/pattern/truchet.h @@ -0,0 +1,46 @@ +#ifndef TRUCHET_H +#define TRUCHET_H + + +class Truchet : public MMNode { + GDCLASS(Truchet, MMNode); + + public: + + Ref get_image(); + void set_image(const Ref &val); + + int get_shape() const; + void set_shape(const int val); + + float get_size() const; + void set_size(const float val); + + 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); + int get_shape(); + void set_shape(const int val); + float get_size(); + void set_size(const float val); + + Truchet(); + ~Truchet(); + + protected: + static void _bind_methods(); + + //tool + //export(Resource) + Ref image; + //export(int, "Line,Circle") + int shape = 0; + //export(float) + float size = 4; + //shape + //size +}; + + +#endif diff --git a/modules/material_maker/nodes/pattern/weave.cpp b/modules/material_maker/nodes/pattern/weave.cpp new file mode 100644 index 000000000..a3c22eea8 --- /dev/null +++ b/modules/material_maker/nodes/pattern/weave.cpp @@ -0,0 +1,258 @@ + +#include "weave.h" + + +Ref Weave::get_out_main() { + return out_main; +} + +void Weave::set_out_main(const Ref &val) { +out_main = val; +} + + +Ref Weave::get_out_horizontal_map() { + return out_horizontal_map; +} + +void Weave::set_out_horizontal_map(const Ref &val) { +out_horizontal_map = val; +} + + +Ref Weave::get_out_vertical_map() { + return out_vertical_map; +} + +void Weave::set_out_vertical_map(const Ref &val) { +out_vertical_map = val; +} + + +Vector2 Weave::get_size() { + return size; +} + +void Weave::set_size(const Vector2 &val) { +size = val; +} + + +Ref Weave::get_width() { + return width; +} + +void Weave::set_width(const Ref &val) { +width = val; +} + + +int Weave::get_stitch() const { + return stitch; +} + +void Weave::set_stitch(const int val) { +stitch = val; +} + + + + //tool; + //export(Resource) ; + Ref out_main; + //export(Resource) ; + Ref out_horizontal_map; + //export(Resource) ; + Ref out_vertical_map; + //export(Vector2) ; + Vector2 size = Vector2(4, 4); + //export(Resource) ; + Ref width; + //export(int) ; + int stitch = 1; + + void Weave::_init_properties() { + + if (!out_main) { + out_main = MMNodeUniversalProperty.new(); + out_main.default_type = MMNodeUniversalProperty.DEFAULT_TYPE_IMAGE; +} + + out_main.output_slot_type = MMNodeUniversalProperty.SLOT_TYPE_IMAGE; + + if (!out_horizontal_map) { + out_horizontal_map = MMNodeUniversalProperty.new(); + out_horizontal_map.default_type = MMNodeUniversalProperty.DEFAULT_TYPE_IMAGE; +} + + out_horizontal_map.output_slot_type = MMNodeUniversalProperty.SLOT_TYPE_IMAGE; + + if (!out_vertical_map) { + out_vertical_map = MMNodeUniversalProperty.new(); + out_vertical_map.default_type = MMNodeUniversalProperty.DEFAULT_TYPE_IMAGE; +} + + out_vertical_map.output_slot_type = MMNodeUniversalProperty.SLOT_TYPE_IMAGE; + + if (!width) { + width = MMNodeUniversalProperty.new(); + width.default_type = MMNodeUniversalProperty.DEFAULT_TYPE_VECTOR2; + width.set_default_value(Vector2(0.9, 0.9)); +} + + width.input_slot_type = MMNodeUniversalProperty.SLOT_TYPE_UNIVERSAL; + width.slot_name = "Width"; + width.value_step = 0.01; + width.value_range = Vector2(0, 1); + register_output_property(out_main); + register_output_property(out_horizontal_map); + register_output_property(out_vertical_map); + register_input_property(width); +} + + + void Weave::_register_methods(const Variant &mm_graph_node) { + mm_graph_node.add_slot_texture_universal(out_main); + mm_graph_node.add_slot_texture_universal(out_horizontal_map); + mm_graph_node.add_slot_texture_universal(out_vertical_map); + //, Vector2(1, 32))//, Vector2(0, 32)); + mm_graph_node.add_slot_vector2("get_size", "set_size", "Size"); + mm_graph_node.add_slot_vector2_universal(width); + mm_graph_node.add_slot_int("get_stitch", "set_stitch", "Stitch"); +} + + + void Weave::_render(const Variant &material) { + Ref main_pattern = Image.new(); + Ref horizontal_map = Image.new(); + Ref vertical_map = Image.new(); + main_pattern.create(material.image_size.x, material.image_size.y, false, Image.FORMAT_RGBA8); + horizontal_map.create(material.image_size.x, material.image_size.y, false, Image.FORMAT_RGBA8); + vertical_map.create(material.image_size.x, material.image_size.y, false, Image.FORMAT_RGBA8); + main_pattern.lock(); + horizontal_map.lock(); + vertical_map.lock(); + float w = material.image_size.x; + float h = material.image_size.y; + float pseed = randf() + randi(); + + 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); + Vector2 width_val = width.get_value(uv); + //vec3 $(name_uv) = weave2($uv, vec2($columns, $rows), $stitch, $width_x*$width_map($uv), $width_y*$width_map($uv)); + Vector3 weave = MMAlgos.weave2(uv, size, stitch, width_val.x, width_val.y); + //Outputs:; + //Output (float) - Shows the generated greyscale weave pattern.; + //$(name_uv).x; + Color main_pattern_col = Color(weave.x, weave.x, weave.x, 1); + //Horizontal mask (float) - Horizontal mask; + //$(name_uv).y; + Color horizontal_map_col = Color(weave.y, weave.y, weave.y, 1); + //Vertical mask (float) - Mask for vertical stripes; + //$(name_uv).z; + Color vertical_map_col = Color(weave.z, weave.z, weave.z, 1); + main_pattern.set_pixel(x, y, main_pattern_col); + horizontal_map.set_pixel(x, y, horizontal_map_col); + vertical_map.set_pixel(x, y, vertical_map_col); +} + +} + + main_pattern.unlock(); + horizontal_map.unlock(); + vertical_map.unlock(); + out_main.set_value(main_pattern); + out_horizontal_map.set_value(horizontal_map); + out_vertical_map.set_value(vertical_map); +} + + + Color Weave::_get_value_for(const Vector2 &uv, const int pseed) { + return Color(); +} + + //size; + + Vector2 Weave::get_size() { + return size; +} + + + void Weave::set_size(const Vector2 &val) { + size = val; + set_dirty(true); +} + + //stitch; + + int Weave::get_stitch() { + return stitch; +} + + + void Weave::set_stitch(const int val) { + stitch = val; + set_dirty(true); +} + +} + + Weave::Weave() { + out_main; + out_horizontal_map; + out_vertical_map; + size = Vector2(4, 4); + width; + stitch = 1; + } + + Weave::~Weave() { + } + + + static void Weave::_bind_methods() { + ClassDB::bind_method(D_METHOD("get_out_main"), &Weave::get_out_main); + ClassDB::bind_method(D_METHOD("set_out_main", "value"), &Weave::set_out_main); + ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "out_main", PROPERTY_HINT_RESOURCE_TYPE, "Ref"), "set_out_main", "get_out_main"); + + + ClassDB::bind_method(D_METHOD("get_out_horizontal_map"), &Weave::get_out_horizontal_map); + ClassDB::bind_method(D_METHOD("set_out_horizontal_map", "value"), &Weave::set_out_horizontal_map); + ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "out_horizontal_map", PROPERTY_HINT_RESOURCE_TYPE, "Ref"), "set_out_horizontal_map", "get_out_horizontal_map"); + + + ClassDB::bind_method(D_METHOD("get_out_vertical_map"), &Weave::get_out_vertical_map); + ClassDB::bind_method(D_METHOD("set_out_vertical_map", "value"), &Weave::set_out_vertical_map); + ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "out_vertical_map", PROPERTY_HINT_RESOURCE_TYPE, "Ref"), "set_out_vertical_map", "get_out_vertical_map"); + + + ClassDB::bind_method(D_METHOD("get_size"), &Weave::get_size); + ClassDB::bind_method(D_METHOD("set_size", "value"), &Weave::set_size); + ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "size"), "set_size", "get_size"); + + + ClassDB::bind_method(D_METHOD("get_width"), &Weave::get_width); + ClassDB::bind_method(D_METHOD("set_width", "value"), &Weave::set_width); + ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "width", PROPERTY_HINT_RESOURCE_TYPE, "Ref"), "set_width", "get_width"); + + + ClassDB::bind_method(D_METHOD("get_stitch"), &Weave::get_stitch); + ClassDB::bind_method(D_METHOD("set_stitch", "value"), &Weave::set_stitch); + ADD_PROPERTY(PropertyInfo(Variant::INT, "stitch"), "set_stitch", "get_stitch"); + + + ClassDB::bind_method(D_METHOD("_init_properties"), &Weave::_init_properties); + ClassDB::bind_method(D_METHOD("_register_methods", "mm_graph_node"), &Weave::_register_methods); + ClassDB::bind_method(D_METHOD("_render", "material"), &Weave::_render); + ClassDB::bind_method(D_METHOD("_get_value_for", "uv", "pseed"), &Weave::_get_value_for); + ClassDB::bind_method(D_METHOD("get_size"), &Weave::get_size); + ClassDB::bind_method(D_METHOD("set_size", "val"), &Weave::set_size); + ClassDB::bind_method(D_METHOD("get_stitch"), &Weave::get_stitch); + ClassDB::bind_method(D_METHOD("set_stitch", "val"), &Weave::set_stitch); + + } + + + diff --git a/modules/material_maker/nodes/pattern/weave.h b/modules/material_maker/nodes/pattern/weave.h new file mode 100644 index 000000000..eaf6fb0c0 --- /dev/null +++ b/modules/material_maker/nodes/pattern/weave.h @@ -0,0 +1,61 @@ +#ifndef WEAVE_H +#define WEAVE_H + + +class Weave : public MMNode { + GDCLASS(Weave, MMNode); + + public: + + Ref get_out_main(); + void set_out_main(const Ref &val); + + Ref get_out_horizontal_map(); + void set_out_horizontal_map(const Ref &val); + + Ref get_out_vertical_map(); + void set_out_vertical_map(const Ref &val); + + Vector2 get_size(); + void set_size(const Vector2 &val); + + Ref get_width(); + void set_width(const Ref &val); + + int get_stitch() const; + void set_stitch(const int val); + + 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_size(); + void set_size(const Vector2 &val); + int get_stitch(); + void set_stitch(const int val); + + Weave(); + ~Weave(); + + protected: + static void _bind_methods(); + + //tool + //export(Resource) + Ref out_main; + //export(Resource) + Ref out_horizontal_map; + //export(Resource) + Ref out_vertical_map; + //export(Vector2) + Vector2 size = Vector2(4, 4); + //export(Resource) + Ref width; + //export(int) + int stitch = 1; + //size + //stitch +}; + + +#endif diff --git a/modules/material_maker/nodes/sdf2d/sd_op_annular_shape.cpp b/modules/material_maker/nodes/sdf2d/sd_op_annular_shape.cpp new file mode 100644 index 000000000..83f49e0d1 --- /dev/null +++ b/modules/material_maker/nodes/sdf2d/sd_op_annular_shape.cpp @@ -0,0 +1,135 @@ + +#include "sd_op_annular_shape.h" + + +Ref SdOpAnnularShape::get_output() { + return output; +} + +void SdOpAnnularShape::set_output(const Ref &val) { +output = val; +} + + +float SdOpAnnularShape::get_width() const { + return width; +} + +void SdOpAnnularShape::set_width(const float val) { +width = val; +} + + +int SdOpAnnularShape::get_ripples() const { + return ripples; +} + +void SdOpAnnularShape::set_ripples(const int val) { +ripples = val; +} + + + + //tool; + //export(Resource) ; + Ref output; + //export(float) ; + float width = 0.1; + //export(int) ; + int ripples = 1; + + void SdOpAnnularShape::_init_properties() { + + if (!output) { + output = MMNodeUniversalProperty.new(); + output.default_type = MMNodeUniversalProperty.DEFAULT_TYPE_FLOAT; +} + + output.input_slot_type = MMNodeUniversalProperty.SLOT_TYPE_UNIVERSAL; + output.output_slot_type = MMNodeUniversalProperty.SLOT_TYPE_UNIVERSAL; + //output.output_slot_type = MMNodeUniversalProperty.SLOT_TYPE_FLOAT; + output.slot_name = ">>> Apply >>>"; + output.get_value_from_owner = true; + register_input_property(output); + register_output_property(output); +} + + + void SdOpAnnularShape::_register_methods(const Variant &mm_graph_node) { + mm_graph_node.add_slot_label_universal(output); + mm_graph_node.add_slot_float("get_width", "set_width", "Width", 0.01); + mm_graph_node.add_slot_int("get_ripples", "set_ripples", "Ripples"); +} + + + void SdOpAnnularShape::_get_property_value(const Vector2 &uv) { + float val = output.get_value(uv, true); + return MMAlgos.sdRipples(val, width, ripples); +} + + //width; + + float SdOpAnnularShape::get_width() { + return width; +} + + + void SdOpAnnularShape::set_width(const float val) { + width = val; + emit_changed(); + output.emit_changed(); +} + + //ripples; + + int SdOpAnnularShape::get_ripples() { + return ripples; +} + + + void SdOpAnnularShape::set_ripples(const int val) { + ripples = val; + emit_changed(); + output.emit_changed(); +} + +} + + SdOpAnnularShape::SdOpAnnularShape() { + output; + width = 0.1; + ripples = 1; + } + + SdOpAnnularShape::~SdOpAnnularShape() { + } + + + static void SdOpAnnularShape::_bind_methods() { + ClassDB::bind_method(D_METHOD("get_output"), &SdOpAnnularShape::get_output); + ClassDB::bind_method(D_METHOD("set_output", "value"), &SdOpAnnularShape::set_output); + ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "output", PROPERTY_HINT_RESOURCE_TYPE, "Ref"), "set_output", "get_output"); + + + ClassDB::bind_method(D_METHOD("get_width"), &SdOpAnnularShape::get_width); + ClassDB::bind_method(D_METHOD("set_width", "value"), &SdOpAnnularShape::set_width); + ADD_PROPERTY(PropertyInfo(Variant::REAL, "width"), "set_width", "get_width"); + + + ClassDB::bind_method(D_METHOD("get_ripples"), &SdOpAnnularShape::get_ripples); + ClassDB::bind_method(D_METHOD("set_ripples", "value"), &SdOpAnnularShape::set_ripples); + ADD_PROPERTY(PropertyInfo(Variant::INT, "ripples"), "set_ripples", "get_ripples"); + + + ClassDB::bind_method(D_METHOD("_init_properties"), &SdOpAnnularShape::_init_properties); + ClassDB::bind_method(D_METHOD("_register_methods", "mm_graph_node"), &SdOpAnnularShape::_register_methods); + ClassDB::bind_method(D_METHOD("_get_property_value", "uv"), &SdOpAnnularShape::_get_property_value); + ClassDB::bind_method(D_METHOD("get_width"), &SdOpAnnularShape::get_width); + ClassDB::bind_method(D_METHOD("set_width", "val"), &SdOpAnnularShape::set_width); + ClassDB::bind_method(D_METHOD("get_ripples"), &SdOpAnnularShape::get_ripples); + ClassDB::bind_method(D_METHOD("set_ripples", "val"), &SdOpAnnularShape::set_ripples); + + } + + + diff --git a/modules/material_maker/nodes/sdf2d/sd_op_annular_shape.h b/modules/material_maker/nodes/sdf2d/sd_op_annular_shape.h new file mode 100644 index 000000000..6a747fb59 --- /dev/null +++ b/modules/material_maker/nodes/sdf2d/sd_op_annular_shape.h @@ -0,0 +1,45 @@ +#ifndef SD_OP_ANNULAR_SHAPE_H +#define SD_OP_ANNULAR_SHAPE_H + + +class SdOpAnnularShape : public MMNode { + GDCLASS(SdOpAnnularShape, MMNode); + + public: + + Ref get_output(); + void set_output(const Ref &val); + + float get_width() const; + void set_width(const float val); + + int get_ripples() const; + void set_ripples(const int val); + + void _init_properties(); + void _register_methods(const Variant &mm_graph_node); + void _get_property_value(const Vector2 &uv); + float get_width(); + void set_width(const float val); + int get_ripples(); + void set_ripples(const int val); + + SdOpAnnularShape(); + ~SdOpAnnularShape(); + + protected: + static void _bind_methods(); + + //tool + //export(Resource) + Ref output; + //export(float) + float width = 0.1; + //export(int) + int ripples = 1; + //width + //ripples +}; + + +#endif diff --git a/modules/material_maker/nodes/sdf2d/sd_op_bool.cpp b/modules/material_maker/nodes/sdf2d/sd_op_bool.cpp new file mode 100644 index 000000000..0409ba5fd --- /dev/null +++ b/modules/material_maker/nodes/sdf2d/sd_op_bool.cpp @@ -0,0 +1,187 @@ + +#include "sd_op_bool.h" + + +Ref SdOpBool::get_input1() { + return input1; +} + +void SdOpBool::set_input1(const Ref &val) { +input1 = val; +} + + +Ref SdOpBool::get_input2() { + return input2; +} + +void SdOpBool::set_input2(const Ref &val) { +input2 = val; +} + + +Ref SdOpBool::get_output() { + return output; +} + +void SdOpBool::set_output(const Ref &val) { +output = val; +} + + +int SdOpBool::get_operation() const { + return operation; +} + +void SdOpBool::set_operation(const int val) { +operation = val; +} + + + + //tool; + //export(Resource) ; + Ref input1; + //export(Resource) ; + Ref input2; + //export(Resource) ; + Ref output; + //export(int, "Union,Substraction,Intersection") ; + int operation = 0; + + void SdOpBool::_init_properties() { + + if (!input1) { + input1 = MMNodeUniversalProperty.new(); + input1.default_type = MMNodeUniversalProperty.DEFAULT_TYPE_FLOAT; +} + + input1.input_slot_type = MMNodeUniversalProperty.SLOT_TYPE_UNIVERSAL; + // input1.input_slot_type = MMNodeUniversalProperty.SLOT_TYPE_FLOAT; + input1.slot_name = ">>> Input 1 "; + + if (!input1.is_connected("changed", self, "on_input_changed")) { + input1.connect("changed", self, "on_input_changed"); +} + + + if (!input2) { + input2 = MMNodeUniversalProperty.new(); + input2.default_type = MMNodeUniversalProperty.DEFAULT_TYPE_FLOAT; +} + + input2.input_slot_type = MMNodeUniversalProperty.SLOT_TYPE_UNIVERSAL; + // input2.input_slot_type = MMNodeUniversalProperty.SLOT_TYPE_FLOAT; + input2.slot_name = ">>> Input 2 "; + + if (!input2.is_connected("changed", self, "on_input_changed")) { + input2.connect("changed", self, "on_input_changed"); +} + + + if (!output) { + output = MMNodeUniversalProperty.new(); + output.default_type = MMNodeUniversalProperty.DEFAULT_TYPE_FLOAT; +} + + output.output_slot_type = MMNodeUniversalProperty.SLOT_TYPE_UNIVERSAL; + // output.output_slot_type = MMNodeUniversalProperty.SLOT_TYPE_FLOAT; + output.slot_name = " Output >>>"; + output.get_value_from_owner = true; + register_input_property(input1); + register_input_property(input2); + register_output_property(output); +} + + + void SdOpBool::_register_methods(const Variant &mm_graph_node) { + mm_graph_node.add_slot_label_universal(input1); + mm_graph_node.add_slot_label_universal(input2); + mm_graph_node.add_slot_label_universal(output); + mm_graph_node.add_slot_enum("get_operation", "set_operation", "Operation", [ "Union", "Substraction", "Intersection" ]); +} + + + float SdOpBool::_get_property_value(const Vector2 &uv) { + + if (operation == 0) { + return MMAlgos.sdf_boolean_union(input1.get_value(uv), input2.get_value(uv)); +} + + + else if (operation == 1) { + return MMAlgos.sdf_boolean_substraction(input1.get_value(uv), input2.get_value(uv)); +} + + + else if (operation == 2) { + return MMAlgos.sdf_boolean_intersection(input1.get_value(uv), input2.get_value(uv)); +} + + return 0.0; +} + + //operation; + + int SdOpBool::get_operation() { + return operation; +} + + + void SdOpBool::set_operation(const int val) { + operation = val; + emit_changed(); + output.emit_changed(); +} + + + void SdOpBool::on_input_changed() { + emit_changed(); + output.emit_changed(); +} + +} + + SdOpBool::SdOpBool() { + input1; + input2; + output; + operation = 0; + } + + SdOpBool::~SdOpBool() { + } + + + static void SdOpBool::_bind_methods() { + ClassDB::bind_method(D_METHOD("get_input1"), &SdOpBool::get_input1); + ClassDB::bind_method(D_METHOD("set_input1", "value"), &SdOpBool::set_input1); + ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "input1", PROPERTY_HINT_RESOURCE_TYPE, "Ref"), "set_input1", "get_input1"); + + + ClassDB::bind_method(D_METHOD("get_input2"), &SdOpBool::get_input2); + ClassDB::bind_method(D_METHOD("set_input2", "value"), &SdOpBool::set_input2); + ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "input2", PROPERTY_HINT_RESOURCE_TYPE, "Ref"), "set_input2", "get_input2"); + + + ClassDB::bind_method(D_METHOD("get_output"), &SdOpBool::get_output); + ClassDB::bind_method(D_METHOD("set_output", "value"), &SdOpBool::set_output); + ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "output", PROPERTY_HINT_RESOURCE_TYPE, "Ref"), "set_output", "get_output"); + + + ClassDB::bind_method(D_METHOD("get_operation"), &SdOpBool::get_operation); + ClassDB::bind_method(D_METHOD("set_operation", "value"), &SdOpBool::set_operation); + ADD_PROPERTY(PropertyInfo(Variant::INT, "operation"), "set_operation", "get_operation"); + + + ClassDB::bind_method(D_METHOD("_init_properties"), &SdOpBool::_init_properties); + ClassDB::bind_method(D_METHOD("_register_methods", "mm_graph_node"), &SdOpBool::_register_methods); + ClassDB::bind_method(D_METHOD("_get_property_value", "uv"), &SdOpBool::_get_property_value); + ClassDB::bind_method(D_METHOD("get_operation"), &SdOpBool::get_operation); + ClassDB::bind_method(D_METHOD("set_operation", "val"), &SdOpBool::set_operation); + ClassDB::bind_method(D_METHOD("on_input_changed"), &SdOpBool::on_input_changed); + + } + + + diff --git a/modules/material_maker/nodes/sdf2d/sd_op_bool.h b/modules/material_maker/nodes/sdf2d/sd_op_bool.h new file mode 100644 index 000000000..ff1800894 --- /dev/null +++ b/modules/material_maker/nodes/sdf2d/sd_op_bool.h @@ -0,0 +1,48 @@ +#ifndef SD_OP_BOOL_H +#define SD_OP_BOOL_H + + +class SdOpBool : public MMNode { + GDCLASS(SdOpBool, MMNode); + + public: + + Ref get_input1(); + void set_input1(const Ref &val); + + Ref get_input2(); + void set_input2(const Ref &val); + + Ref get_output(); + void set_output(const Ref &val); + + int get_operation() const; + void set_operation(const int val); + + void _init_properties(); + void _register_methods(const Variant &mm_graph_node); + float _get_property_value(const Vector2 &uv); + int get_operation(); + void set_operation(const int val); + void on_input_changed(); + + SdOpBool(); + ~SdOpBool(); + + protected: + static void _bind_methods(); + + //tool + //export(Resource) + Ref input1; + //export(Resource) + Ref input2; + //export(Resource) + Ref output; + //export(int, "Union,Substraction,Intersection") + int operation = 0; + //operation +}; + + +#endif diff --git a/modules/material_maker/nodes/sdf2d/sd_op_circle_repeat.cpp b/modules/material_maker/nodes/sdf2d/sd_op_circle_repeat.cpp new file mode 100644 index 000000000..80914fad4 --- /dev/null +++ b/modules/material_maker/nodes/sdf2d/sd_op_circle_repeat.cpp @@ -0,0 +1,103 @@ + +#include "sd_op_circle_repeat.h" + + +Ref SdOpCircleRepeat::get_output() { + return output; +} + +void SdOpCircleRepeat::set_output(const Ref &val) { +output = val; +} + + +int SdOpCircleRepeat::get_count() const { + return count; +} + +void SdOpCircleRepeat::set_count(const int val) { +count = val; +} + + + + //tool; + //export(Resource) ; + Ref output; + //export(int) ; + int count = 6; + + void SdOpCircleRepeat::_init_properties() { + + if (!output) { + output = MMNodeUniversalProperty.new(); + output.default_type = MMNodeUniversalProperty.DEFAULT_TYPE_FLOAT; +} + + output.input_slot_type = MMNodeUniversalProperty.SLOT_TYPE_UNIVERSAL; + output.output_slot_type = MMNodeUniversalProperty.SLOT_TYPE_UNIVERSAL; + //output.output_slot_type = MMNodeUniversalProperty.SLOT_TYPE_FLOAT; + output.slot_name = ">>> Apply >>>"; + output.get_value_from_owner = true; + register_input_property(output); + register_output_property(output); +} + + + void SdOpCircleRepeat::_register_methods(const Variant &mm_graph_node) { + mm_graph_node.add_slot_label_universal(output); + mm_graph_node.add_slot_int("get_count", "set_count", "Count"); +} + + + void SdOpCircleRepeat::_get_property_value(const Vector2 &uv) { + //$in(circle_repeat_transform_2d($uv-vec2(0.5), $c)+vec2(0.5)); + Vector2 new_uv = MMAlgos.circle_repeat_transform_2d(uv - Vector2(0.5, 0.5), count) + Vector2(0.5, 0.5); + return output.get_value(new_uv, true); +} + + //count; + + int SdOpCircleRepeat::get_count() { + return count; +} + + + void SdOpCircleRepeat::set_count(const int val) { + count = val; + emit_changed(); + output.emit_changed(); +} + +} + + SdOpCircleRepeat::SdOpCircleRepeat() { + output; + count = 6; + } + + SdOpCircleRepeat::~SdOpCircleRepeat() { + } + + + static void SdOpCircleRepeat::_bind_methods() { + ClassDB::bind_method(D_METHOD("get_output"), &SdOpCircleRepeat::get_output); + ClassDB::bind_method(D_METHOD("set_output", "value"), &SdOpCircleRepeat::set_output); + ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "output", PROPERTY_HINT_RESOURCE_TYPE, "Ref"), "set_output", "get_output"); + + + ClassDB::bind_method(D_METHOD("get_count"), &SdOpCircleRepeat::get_count); + ClassDB::bind_method(D_METHOD("set_count", "value"), &SdOpCircleRepeat::set_count); + ADD_PROPERTY(PropertyInfo(Variant::INT, "count"), "set_count", "get_count"); + + + ClassDB::bind_method(D_METHOD("_init_properties"), &SdOpCircleRepeat::_init_properties); + ClassDB::bind_method(D_METHOD("_register_methods", "mm_graph_node"), &SdOpCircleRepeat::_register_methods); + ClassDB::bind_method(D_METHOD("_get_property_value", "uv"), &SdOpCircleRepeat::_get_property_value); + ClassDB::bind_method(D_METHOD("get_count"), &SdOpCircleRepeat::get_count); + ClassDB::bind_method(D_METHOD("set_count", "val"), &SdOpCircleRepeat::set_count); + + } + + + diff --git a/modules/material_maker/nodes/sdf2d/sd_op_circle_repeat.h b/modules/material_maker/nodes/sdf2d/sd_op_circle_repeat.h new file mode 100644 index 000000000..89cb849da --- /dev/null +++ b/modules/material_maker/nodes/sdf2d/sd_op_circle_repeat.h @@ -0,0 +1,37 @@ +#ifndef SD_OP_CIRCLE_REPEAT_H +#define SD_OP_CIRCLE_REPEAT_H + + +class SdOpCircleRepeat : public MMNode { + GDCLASS(SdOpCircleRepeat, MMNode); + + public: + + Ref get_output(); + void set_output(const Ref &val); + + int get_count() const; + void set_count(const int val); + + void _init_properties(); + void _register_methods(const Variant &mm_graph_node); + void _get_property_value(const Vector2 &uv); + int get_count(); + void set_count(const int val); + + SdOpCircleRepeat(); + ~SdOpCircleRepeat(); + + protected: + static void _bind_methods(); + + //tool + //export(Resource) + Ref output; + //export(int) + int count = 6; + //count +}; + + +#endif diff --git a/modules/material_maker/nodes/sdf2d/sd_op_morph.cpp b/modules/material_maker/nodes/sdf2d/sd_op_morph.cpp new file mode 100644 index 000000000..f32614e21 --- /dev/null +++ b/modules/material_maker/nodes/sdf2d/sd_op_morph.cpp @@ -0,0 +1,172 @@ + +#include "sd_op_morph.h" + + +Ref SdOpMorph::get_input1() { + return input1; +} + +void SdOpMorph::set_input1(const Ref &val) { +input1 = val; +} + + +Ref SdOpMorph::get_input2() { + return input2; +} + +void SdOpMorph::set_input2(const Ref &val) { +input2 = val; +} + + +Ref SdOpMorph::get_output() { + return output; +} + +void SdOpMorph::set_output(const Ref &val) { +output = val; +} + + +float SdOpMorph::get_amount() const { + return amount; +} + +void SdOpMorph::set_amount(const float val) { +amount = val; +} + + + + //tool; + //export(Resource) ; + Ref input1; + //export(Resource) ; + Ref input2; + //export(Resource) ; + Ref output; + //export(float) ; + float amount = 0.5; + + void SdOpMorph::_init_properties() { + + if (!input1) { + input1 = MMNodeUniversalProperty.new(); + input1.default_type = MMNodeUniversalProperty.DEFAULT_TYPE_FLOAT; +} + + input1.input_slot_type = MMNodeUniversalProperty.SLOT_TYPE_UNIVERSAL; + // input1.input_slot_type = MMNodeUniversalProperty.SLOT_TYPE_FLOAT; + input1.slot_name = ">>> Input 1 "; + + if (!input1.is_connected("changed", self, "on_input_changed")) { + input1.connect("changed", self, "on_input_changed"); +} + + + if (!input2) { + input2 = MMNodeUniversalProperty.new(); + input2.default_type = MMNodeUniversalProperty.DEFAULT_TYPE_FLOAT; +} + + input2.input_slot_type = MMNodeUniversalProperty.SLOT_TYPE_UNIVERSAL; + // input2.input_slot_type = MMNodeUniversalProperty.SLOT_TYPE_FLOAT; + input2.slot_name = ">>> Input 2 "; + + if (!input2.is_connected("changed", self, "on_input_changed")) { + input2.connect("changed", self, "on_input_changed"); +} + + + if (!output) { + output = MMNodeUniversalProperty.new(); + output.default_type = MMNodeUniversalProperty.DEFAULT_TYPE_FLOAT; +} + + output.output_slot_type = MMNodeUniversalProperty.SLOT_TYPE_UNIVERSAL; + // output.output_slot_type = MMNodeUniversalProperty.SLOT_TYPE_FLOAT; + output.slot_name = " Output >>>"; + output.get_value_from_owner = true; + register_input_property(input1); + register_input_property(input2); + register_output_property(output); +} + + + void SdOpMorph::_register_methods(const Variant &mm_graph_node) { + mm_graph_node.add_slot_label_universal(input1); + mm_graph_node.add_slot_label_universal(input2); + mm_graph_node.add_slot_label_universal(output); + mm_graph_node.add_slot_float("get_amount", "set_amount", "Amount", 0.01); +} + + + float SdOpMorph::_get_property_value(const Vector2 &uv) { + return MMAlgos.sdf_morph(input1.get_value(uv), input2.get_value(uv), amount); +} + + //amount; + + float SdOpMorph::get_amount() { + return amount; +} + + + void SdOpMorph::set_amount(const float val) { + amount = val; + emit_changed(); + output.emit_changed(); +} + + + void SdOpMorph::on_input_changed() { + emit_changed(); + output.emit_changed(); +} + +} + + SdOpMorph::SdOpMorph() { + input1; + input2; + output; + amount = 0.5; + } + + SdOpMorph::~SdOpMorph() { + } + + + static void SdOpMorph::_bind_methods() { + ClassDB::bind_method(D_METHOD("get_input1"), &SdOpMorph::get_input1); + ClassDB::bind_method(D_METHOD("set_input1", "value"), &SdOpMorph::set_input1); + ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "input1", PROPERTY_HINT_RESOURCE_TYPE, "Ref"), "set_input1", "get_input1"); + + + ClassDB::bind_method(D_METHOD("get_input2"), &SdOpMorph::get_input2); + ClassDB::bind_method(D_METHOD("set_input2", "value"), &SdOpMorph::set_input2); + ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "input2", PROPERTY_HINT_RESOURCE_TYPE, "Ref"), "set_input2", "get_input2"); + + + ClassDB::bind_method(D_METHOD("get_output"), &SdOpMorph::get_output); + ClassDB::bind_method(D_METHOD("set_output", "value"), &SdOpMorph::set_output); + ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "output", PROPERTY_HINT_RESOURCE_TYPE, "Ref"), "set_output", "get_output"); + + + ClassDB::bind_method(D_METHOD("get_amount"), &SdOpMorph::get_amount); + ClassDB::bind_method(D_METHOD("set_amount", "value"), &SdOpMorph::set_amount); + ADD_PROPERTY(PropertyInfo(Variant::REAL, "amount"), "set_amount", "get_amount"); + + + ClassDB::bind_method(D_METHOD("_init_properties"), &SdOpMorph::_init_properties); + ClassDB::bind_method(D_METHOD("_register_methods", "mm_graph_node"), &SdOpMorph::_register_methods); + ClassDB::bind_method(D_METHOD("_get_property_value", "uv"), &SdOpMorph::_get_property_value); + ClassDB::bind_method(D_METHOD("get_amount"), &SdOpMorph::get_amount); + ClassDB::bind_method(D_METHOD("set_amount", "val"), &SdOpMorph::set_amount); + ClassDB::bind_method(D_METHOD("on_input_changed"), &SdOpMorph::on_input_changed); + + } + + + diff --git a/modules/material_maker/nodes/sdf2d/sd_op_morph.h b/modules/material_maker/nodes/sdf2d/sd_op_morph.h new file mode 100644 index 000000000..95008d019 --- /dev/null +++ b/modules/material_maker/nodes/sdf2d/sd_op_morph.h @@ -0,0 +1,48 @@ +#ifndef SD_OP_MORPH_H +#define SD_OP_MORPH_H + + +class SdOpMorph : public MMNode { + GDCLASS(SdOpMorph, MMNode); + + public: + + Ref get_input1(); + void set_input1(const Ref &val); + + Ref get_input2(); + void set_input2(const Ref &val); + + Ref get_output(); + void set_output(const Ref &val); + + float get_amount() const; + void set_amount(const float val); + + void _init_properties(); + void _register_methods(const Variant &mm_graph_node); + float _get_property_value(const Vector2 &uv); + float get_amount(); + void set_amount(const float val); + void on_input_changed(); + + SdOpMorph(); + ~SdOpMorph(); + + protected: + static void _bind_methods(); + + //tool + //export(Resource) + Ref input1; + //export(Resource) + Ref input2; + //export(Resource) + Ref output; + //export(float) + float amount = 0.5; + //amount +}; + + +#endif diff --git a/modules/material_maker/nodes/sdf2d/sd_op_repeat.cpp b/modules/material_maker/nodes/sdf2d/sd_op_repeat.cpp new file mode 100644 index 000000000..6d0eb8641 --- /dev/null +++ b/modules/material_maker/nodes/sdf2d/sd_op_repeat.cpp @@ -0,0 +1,171 @@ + +#include "sd_op_repeat.h" + + +Ref SdOpRepeat::get_output() { + return output; +} + +void SdOpRepeat::set_output(const Ref &val) { +output = val; +} + + +int SdOpRepeat::get_x() const { + return x; +} + +void SdOpRepeat::set_x(const int val) { +x = val; +} + + +int SdOpRepeat::get_y() const { + return y; +} + +void SdOpRepeat::set_y(const int val) { +y = val; +} + + +float SdOpRepeat::get_random_rotation() const { + return random_rotation; +} + +void SdOpRepeat::set_random_rotation(const float val) { +random_rotation = val; +} + + + + //tool; + //export(Resource) ; + Ref output; + //export(int) ; + int x = 3; + //export(int) ; + int y = 3; + //export(float) ; + float random_rotation = 0.5; + + void SdOpRepeat::_init_properties() { + + if (!output) { + output = MMNodeUniversalProperty.new(); + output.default_type = MMNodeUniversalProperty.DEFAULT_TYPE_FLOAT; +} + + output.input_slot_type = MMNodeUniversalProperty.SLOT_TYPE_UNIVERSAL; + output.output_slot_type = MMNodeUniversalProperty.SLOT_TYPE_UNIVERSAL; + //output.output_slot_type = MMNodeUniversalProperty.SLOT_TYPE_FLOAT; + output.slot_name = ">>> Apply >>>"; + output.get_value_from_owner = true; + register_input_property(output); + register_output_property(output); +} + + + void SdOpRepeat::_register_methods(const Variant &mm_graph_node) { + mm_graph_node.add_slot_label_universal(output); + mm_graph_node.add_slot_int("get_x", "set_x", "X"); + mm_graph_node.add_slot_int("get_y", "set_y", "Y"); + mm_graph_node.add_slot_float("get_random_rotation", "set_random_rotation", "Random rotation", 0.01); +} + + + void SdOpRepeat::_get_property_value(const Vector2 &uv) { + //todo add this as a parameter; + int pseed = 123123; + //$in(repeat_2d($uv, vec2(1.0/$rx, 1.0/$ry), float($seed), $r)); + Vector2 new_uv = MMAlgos.repeat_2d(uv, Vector2(1.0 / float(x), 1.0/ float(y)), 1.0/float(pseed), random_rotation); + return output.get_value(new_uv, true); +} + + //x; + + int SdOpRepeat::get_x() { + return x; +} + + + void SdOpRepeat::set_x(const int val) { + x = val; + emit_changed(); + output.emit_changed(); +} + + //y; + + int SdOpRepeat::get_y() { + return y; +} + + + void SdOpRepeat::set_y(const int val) { + y = val; + emit_changed(); + output.emit_changed(); +} + + //random_rotation; + + float SdOpRepeat::get_random_rotation() { + return random_rotation; +} + + + void SdOpRepeat::set_random_rotation(const float val) { + random_rotation = val; + emit_changed(); + output.emit_changed(); +} + +} + + SdOpRepeat::SdOpRepeat() { + output; + x = 3; + y = 3; + random_rotation = 0.5; + } + + SdOpRepeat::~SdOpRepeat() { + } + + + static void SdOpRepeat::_bind_methods() { + ClassDB::bind_method(D_METHOD("get_output"), &SdOpRepeat::get_output); + ClassDB::bind_method(D_METHOD("set_output", "value"), &SdOpRepeat::set_output); + ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "output", PROPERTY_HINT_RESOURCE_TYPE, "Ref"), "set_output", "get_output"); + + + ClassDB::bind_method(D_METHOD("get_x"), &SdOpRepeat::get_x); + ClassDB::bind_method(D_METHOD("set_x", "value"), &SdOpRepeat::set_x); + ADD_PROPERTY(PropertyInfo(Variant::INT, "x"), "set_x", "get_x"); + + + ClassDB::bind_method(D_METHOD("get_y"), &SdOpRepeat::get_y); + ClassDB::bind_method(D_METHOD("set_y", "value"), &SdOpRepeat::set_y); + ADD_PROPERTY(PropertyInfo(Variant::INT, "y"), "set_y", "get_y"); + + + ClassDB::bind_method(D_METHOD("get_random_rotation"), &SdOpRepeat::get_random_rotation); + ClassDB::bind_method(D_METHOD("set_random_rotation", "value"), &SdOpRepeat::set_random_rotation); + ADD_PROPERTY(PropertyInfo(Variant::REAL, "random_rotation"), "set_random_rotation", "get_random_rotation"); + + + ClassDB::bind_method(D_METHOD("_init_properties"), &SdOpRepeat::_init_properties); + ClassDB::bind_method(D_METHOD("_register_methods", "mm_graph_node"), &SdOpRepeat::_register_methods); + ClassDB::bind_method(D_METHOD("_get_property_value", "uv"), &SdOpRepeat::_get_property_value); + ClassDB::bind_method(D_METHOD("get_x"), &SdOpRepeat::get_x); + ClassDB::bind_method(D_METHOD("set_x", "val"), &SdOpRepeat::set_x); + ClassDB::bind_method(D_METHOD("get_y"), &SdOpRepeat::get_y); + ClassDB::bind_method(D_METHOD("set_y", "val"), &SdOpRepeat::set_y); + ClassDB::bind_method(D_METHOD("get_random_rotation"), &SdOpRepeat::get_random_rotation); + ClassDB::bind_method(D_METHOD("set_random_rotation", "val"), &SdOpRepeat::set_random_rotation); + + } + + + diff --git a/modules/material_maker/nodes/sdf2d/sd_op_repeat.h b/modules/material_maker/nodes/sdf2d/sd_op_repeat.h new file mode 100644 index 000000000..fd434e24f --- /dev/null +++ b/modules/material_maker/nodes/sdf2d/sd_op_repeat.h @@ -0,0 +1,53 @@ +#ifndef SD_OP_REPEAT_H +#define SD_OP_REPEAT_H + + +class SdOpRepeat : public MMNode { + GDCLASS(SdOpRepeat, MMNode); + + public: + + Ref get_output(); + void set_output(const Ref &val); + + int get_x() const; + void set_x(const int val); + + int get_y() const; + void set_y(const int val); + + float get_random_rotation() const; + void set_random_rotation(const float val); + + void _init_properties(); + void _register_methods(const Variant &mm_graph_node); + void _get_property_value(const Vector2 &uv); + int get_x(); + void set_x(const int val); + int get_y(); + void set_y(const int val); + float get_random_rotation(); + void set_random_rotation(const float val); + + SdOpRepeat(); + ~SdOpRepeat(); + + protected: + static void _bind_methods(); + + //tool + //export(Resource) + Ref output; + //export(int) + int x = 3; + //export(int) + int y = 3; + //export(float) + float random_rotation = 0.5; + //x + //y + //random_rotation +}; + + +#endif diff --git a/modules/material_maker/nodes/sdf2d/sd_op_rounded_shape.cpp b/modules/material_maker/nodes/sdf2d/sd_op_rounded_shape.cpp new file mode 100644 index 000000000..3ca06dc4a --- /dev/null +++ b/modules/material_maker/nodes/sdf2d/sd_op_rounded_shape.cpp @@ -0,0 +1,102 @@ + +#include "sd_op_rounded_shape.h" + + +Ref SdOpRoundedShape::get_output() { + return output; +} + +void SdOpRoundedShape::set_output(const Ref &val) { +output = val; +} + + +float SdOpRoundedShape::get_radius() const { + return radius; +} + +void SdOpRoundedShape::set_radius(const float val) { +radius = val; +} + + + + //tool; + //export(Resource) ; + Ref output; + //export(float) ; + float radius = 0; + + void SdOpRoundedShape::_init_properties() { + + if (!output) { + output = MMNodeUniversalProperty.new(); + output.default_type = MMNodeUniversalProperty.DEFAULT_TYPE_FLOAT; +} + + output.input_slot_type = MMNodeUniversalProperty.SLOT_TYPE_UNIVERSAL; + output.output_slot_type = MMNodeUniversalProperty.SLOT_TYPE_UNIVERSAL; + //output.output_slot_type = MMNodeUniversalProperty.SLOT_TYPE_FLOAT; + output.slot_name = ">>> Apply >>>"; + output.get_value_from_owner = true; + register_input_property(output); + register_output_property(output); +} + + + void SdOpRoundedShape::_register_methods(const Variant &mm_graph_node) { + mm_graph_node.add_slot_label_universal(output); + mm_graph_node.add_slot_float("get_radius", "set_radius", "Radius", 0.01); +} + + + void SdOpRoundedShape::_get_property_value(const Vector2 &uv) { + float val = output.get_value(uv, true); + return MMAlgos.sdf_rounded_shape(val, radius); +} + + //radius; + + float SdOpRoundedShape::get_radius() { + return radius; +} + + + void SdOpRoundedShape::set_radius(const float val) { + radius = val; + emit_changed(); + output.emit_changed(); +} + +} + + SdOpRoundedShape::SdOpRoundedShape() { + output; + radius = 0; + } + + SdOpRoundedShape::~SdOpRoundedShape() { + } + + + static void SdOpRoundedShape::_bind_methods() { + ClassDB::bind_method(D_METHOD("get_output"), &SdOpRoundedShape::get_output); + ClassDB::bind_method(D_METHOD("set_output", "value"), &SdOpRoundedShape::set_output); + ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "output", PROPERTY_HINT_RESOURCE_TYPE, "Ref"), "set_output", "get_output"); + + + ClassDB::bind_method(D_METHOD("get_radius"), &SdOpRoundedShape::get_radius); + ClassDB::bind_method(D_METHOD("set_radius", "value"), &SdOpRoundedShape::set_radius); + ADD_PROPERTY(PropertyInfo(Variant::REAL, "radius"), "set_radius", "get_radius"); + + + ClassDB::bind_method(D_METHOD("_init_properties"), &SdOpRoundedShape::_init_properties); + ClassDB::bind_method(D_METHOD("_register_methods", "mm_graph_node"), &SdOpRoundedShape::_register_methods); + ClassDB::bind_method(D_METHOD("_get_property_value", "uv"), &SdOpRoundedShape::_get_property_value); + ClassDB::bind_method(D_METHOD("get_radius"), &SdOpRoundedShape::get_radius); + ClassDB::bind_method(D_METHOD("set_radius", "val"), &SdOpRoundedShape::set_radius); + + } + + + diff --git a/modules/material_maker/nodes/sdf2d/sd_op_rounded_shape.h b/modules/material_maker/nodes/sdf2d/sd_op_rounded_shape.h new file mode 100644 index 000000000..3678737ac --- /dev/null +++ b/modules/material_maker/nodes/sdf2d/sd_op_rounded_shape.h @@ -0,0 +1,37 @@ +#ifndef SD_OP_ROUNDED_SHAPE_H +#define SD_OP_ROUNDED_SHAPE_H + + +class SdOpRoundedShape : public MMNode { + GDCLASS(SdOpRoundedShape, MMNode); + + public: + + Ref get_output(); + void set_output(const Ref &val); + + float get_radius() const; + void set_radius(const float val); + + void _init_properties(); + void _register_methods(const Variant &mm_graph_node); + void _get_property_value(const Vector2 &uv); + float get_radius(); + void set_radius(const float val); + + SdOpRoundedShape(); + ~SdOpRoundedShape(); + + protected: + static void _bind_methods(); + + //tool + //export(Resource) + Ref output; + //export(float) + float radius = 0; + //radius +}; + + +#endif diff --git a/modules/material_maker/nodes/sdf2d/sd_op_smooth_bool.cpp b/modules/material_maker/nodes/sdf2d/sd_op_smooth_bool.cpp new file mode 100644 index 000000000..f05f64e85 --- /dev/null +++ b/modules/material_maker/nodes/sdf2d/sd_op_smooth_bool.cpp @@ -0,0 +1,220 @@ + +#include "sd_op_smooth_bool.h" + + +Ref SdOpSmoothBool::get_input1() { + return input1; +} + +void SdOpSmoothBool::set_input1(const Ref &val) { +input1 = val; +} + + +Ref SdOpSmoothBool::get_input2() { + return input2; +} + +void SdOpSmoothBool::set_input2(const Ref &val) { +input2 = val; +} + + +Ref SdOpSmoothBool::get_output() { + return output; +} + +void SdOpSmoothBool::set_output(const Ref &val) { +output = val; +} + + +int SdOpSmoothBool::get_operation() const { + return operation; +} + +void SdOpSmoothBool::set_operation(const int val) { +operation = val; +} + + +float SdOpSmoothBool::get_smoothness() const { + return smoothness; +} + +void SdOpSmoothBool::set_smoothness(const float val) { +smoothness = val; +} + + + + //tool; + //export(Resource) ; + Ref input1; + //export(Resource) ; + Ref input2; + //export(Resource) ; + Ref output; + //export(int, "Union,Substraction,Intersection") ; + int operation = 0; + //export(float) ; + float smoothness = 0.15; + + void SdOpSmoothBool::_init_properties() { + + if (!input1) { + input1 = MMNodeUniversalProperty.new(); + input1.default_type = MMNodeUniversalProperty.DEFAULT_TYPE_FLOAT; +} + + input1.input_slot_type = MMNodeUniversalProperty.SLOT_TYPE_UNIVERSAL; + // input1.input_slot_type = MMNodeUniversalProperty.SLOT_TYPE_FLOAT; + input1.slot_name = ">>> Input 1 "; + + if (!input1.is_connected("changed", self, "on_input_changed")) { + input1.connect("changed", self, "on_input_changed"); +} + + + if (!input2) { + input2 = MMNodeUniversalProperty.new(); + input2.default_type = MMNodeUniversalProperty.DEFAULT_TYPE_FLOAT; +} + + input2.input_slot_type = MMNodeUniversalProperty.SLOT_TYPE_UNIVERSAL; + // input2.input_slot_type = MMNodeUniversalProperty.SLOT_TYPE_FLOAT; + input2.slot_name = ">>> Input 2 "; + + if (!input2.is_connected("changed", self, "on_input_changed")) { + input2.connect("changed", self, "on_input_changed"); +} + + + if (!output) { + output = MMNodeUniversalProperty.new(); + output.default_type = MMNodeUniversalProperty.DEFAULT_TYPE_FLOAT; +} + + output.output_slot_type = MMNodeUniversalProperty.SLOT_TYPE_UNIVERSAL; + // output.output_slot_type = MMNodeUniversalProperty.SLOT_TYPE_FLOAT; + output.slot_name = " Output >>>"; + output.get_value_from_owner = true; + register_input_property(input1); + register_input_property(input2); + register_output_property(output); +} + + + void SdOpSmoothBool::_register_methods(const Variant &mm_graph_node) { + mm_graph_node.add_slot_label_universal(input1); + mm_graph_node.add_slot_label_universal(input2); + mm_graph_node.add_slot_label_universal(output); + mm_graph_node.add_slot_enum("get_operation", "set_operation", "Operation", [ "Union", "Substraction", "Intersection" ]); + mm_graph_node.add_slot_float("get_smoothness", "set_smoothness", "Smoothness", 0.01); +} + + + float SdOpSmoothBool::_get_property_value(const Vector2 &uv) { + + if (operation == 0) { + return MMAlgos.sdf_smooth_boolean_union(input1.get_value(uv), input2.get_value(uv), smoothness); +} + + + else if (operation == 1) { + return MMAlgos.sdf_smooth_boolean_substraction(input1.get_value(uv), input2.get_value(uv), smoothness); +} + + + else if (operation == 2) { + return MMAlgos.sdf_smooth_boolean_intersection(input1.get_value(uv), input2.get_value(uv), smoothness); +} + + return 0.0; +} + + //operation; + + int SdOpSmoothBool::get_operation() { + return operation; +} + + + void SdOpSmoothBool::set_operation(const int val) { + operation = val; + emit_changed(); + output.emit_changed(); +} + + //smoothness; + + float SdOpSmoothBool::get_smoothness() { + return smoothness; +} + + + void SdOpSmoothBool::set_smoothness(const float val) { + smoothness = val; + emit_changed(); + output.emit_changed(); +} + + + void SdOpSmoothBool::on_input_changed() { + emit_changed(); + output.emit_changed(); +} + +} + + SdOpSmoothBool::SdOpSmoothBool() { + input1; + input2; + output; + operation = 0; + smoothness = 0.15; + } + + SdOpSmoothBool::~SdOpSmoothBool() { + } + + + static void SdOpSmoothBool::_bind_methods() { + ClassDB::bind_method(D_METHOD("get_input1"), &SdOpSmoothBool::get_input1); + ClassDB::bind_method(D_METHOD("set_input1", "value"), &SdOpSmoothBool::set_input1); + ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "input1", PROPERTY_HINT_RESOURCE_TYPE, "Ref"), "set_input1", "get_input1"); + + + ClassDB::bind_method(D_METHOD("get_input2"), &SdOpSmoothBool::get_input2); + ClassDB::bind_method(D_METHOD("set_input2", "value"), &SdOpSmoothBool::set_input2); + ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "input2", PROPERTY_HINT_RESOURCE_TYPE, "Ref"), "set_input2", "get_input2"); + + + ClassDB::bind_method(D_METHOD("get_output"), &SdOpSmoothBool::get_output); + ClassDB::bind_method(D_METHOD("set_output", "value"), &SdOpSmoothBool::set_output); + ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "output", PROPERTY_HINT_RESOURCE_TYPE, "Ref"), "set_output", "get_output"); + + + ClassDB::bind_method(D_METHOD("get_operation"), &SdOpSmoothBool::get_operation); + ClassDB::bind_method(D_METHOD("set_operation", "value"), &SdOpSmoothBool::set_operation); + ADD_PROPERTY(PropertyInfo(Variant::INT, "operation"), "set_operation", "get_operation"); + + + ClassDB::bind_method(D_METHOD("get_smoothness"), &SdOpSmoothBool::get_smoothness); + ClassDB::bind_method(D_METHOD("set_smoothness", "value"), &SdOpSmoothBool::set_smoothness); + ADD_PROPERTY(PropertyInfo(Variant::REAL, "smoothness"), "set_smoothness", "get_smoothness"); + + + ClassDB::bind_method(D_METHOD("_init_properties"), &SdOpSmoothBool::_init_properties); + ClassDB::bind_method(D_METHOD("_register_methods", "mm_graph_node"), &SdOpSmoothBool::_register_methods); + ClassDB::bind_method(D_METHOD("_get_property_value", "uv"), &SdOpSmoothBool::_get_property_value); + ClassDB::bind_method(D_METHOD("get_operation"), &SdOpSmoothBool::get_operation); + ClassDB::bind_method(D_METHOD("set_operation", "val"), &SdOpSmoothBool::set_operation); + ClassDB::bind_method(D_METHOD("get_smoothness"), &SdOpSmoothBool::get_smoothness); + ClassDB::bind_method(D_METHOD("set_smoothness", "val"), &SdOpSmoothBool::set_smoothness); + ClassDB::bind_method(D_METHOD("on_input_changed"), &SdOpSmoothBool::on_input_changed); + + } + + + diff --git a/modules/material_maker/nodes/sdf2d/sd_op_smooth_bool.h b/modules/material_maker/nodes/sdf2d/sd_op_smooth_bool.h new file mode 100644 index 000000000..034cd288f --- /dev/null +++ b/modules/material_maker/nodes/sdf2d/sd_op_smooth_bool.h @@ -0,0 +1,56 @@ +#ifndef SD_OP_SMOOTH_BOOL_H +#define SD_OP_SMOOTH_BOOL_H + + +class SdOpSmoothBool : public MMNode { + GDCLASS(SdOpSmoothBool, MMNode); + + public: + + Ref get_input1(); + void set_input1(const Ref &val); + + Ref get_input2(); + void set_input2(const Ref &val); + + Ref get_output(); + void set_output(const Ref &val); + + int get_operation() const; + void set_operation(const int val); + + float get_smoothness() const; + void set_smoothness(const float val); + + void _init_properties(); + void _register_methods(const Variant &mm_graph_node); + float _get_property_value(const Vector2 &uv); + int get_operation(); + void set_operation(const int val); + float get_smoothness(); + void set_smoothness(const float val); + void on_input_changed(); + + SdOpSmoothBool(); + ~SdOpSmoothBool(); + + protected: + static void _bind_methods(); + + //tool + //export(Resource) + Ref input1; + //export(Resource) + Ref input2; + //export(Resource) + Ref output; + //export(int, "Union,Substraction,Intersection") + int operation = 0; + //export(float) + float smoothness = 0.15; + //operation + //smoothness +}; + + +#endif diff --git a/modules/material_maker/nodes/sdf2d/sd_shape_arc.cpp b/modules/material_maker/nodes/sdf2d/sd_shape_arc.cpp new file mode 100644 index 000000000..21698da7f --- /dev/null +++ b/modules/material_maker/nodes/sdf2d/sd_shape_arc.cpp @@ -0,0 +1,164 @@ + +#include "sd_shape_arc.h" + + +Ref SdShapeArc::get_output() { + return output; +} + +void SdShapeArc::set_output(const Ref &val) { +output = val; +} + + +Vector2 SdShapeArc::get_angle() { + return angle; +} + +void SdShapeArc::set_angle(const Vector2 &val) { +angle = val; +} + + +float SdShapeArc::get_radius() const { + return radius; +} + +void SdShapeArc::set_radius(const float val) { +radius = val; +} + + +float SdShapeArc::get_width() const { + return width; +} + +void SdShapeArc::set_width(const float val) { +width = val; +} + + + + //tool; + //export(Resource) ; + Ref output; + //export(Vector2) ; + Vector2 angle = Vector2(30, 150); + //export(float) ; + float radius = 0.3; + //export(float) ; + float width = 0.1; + + void SdShapeArc::_init_properties() { + + if (!output) { + output = MMNodeUniversalProperty.new(); + output.default_type = MMNodeUniversalProperty.DEFAULT_TYPE_FLOAT; +} + + output.output_slot_type = MMNodeUniversalProperty.SLOT_TYPE_FLOAT; + output.slot_name = ">>> Output >>>"; + output.get_value_from_owner = true; + register_output_property(output); +} + + + void SdShapeArc::_register_methods(const Variant &mm_graph_node) { + mm_graph_node.add_slot_label_universal(output); + mm_graph_node.add_slot_vector2("get_angle", "set_angle", "Angle", 1); + mm_graph_node.add_slot_float("get_radius", "set_radius", "Radius", 0.01); + mm_graph_node.add_slot_float("get_width", "set_width", "Width", 0.01); +} + + + float SdShapeArc::_get_property_value(const Vector2 &uv) { + return MMAlgos.sdf_arc(uv, angle, Vector2(radius, width)); +} + + //angle; + + Vector2 SdShapeArc::get_angle() { + return angle; +} + + + void SdShapeArc::set_angle(const Vector2 &val) { + angle = val; + emit_changed(); + output.emit_changed(); +} + + //radius; + + float SdShapeArc::get_radius() { + return radius; +} + + + void SdShapeArc::set_radius(const float val) { + radius = val; + emit_changed(); + output.emit_changed(); +} + + //width; + + float SdShapeArc::get_width() { + return width; +} + + + void SdShapeArc::set_width(const float val) { + width = val; + emit_changed(); + output.emit_changed(); +} + +} + + SdShapeArc::SdShapeArc() { + output; + angle = Vector2(30, 150); + radius = 0.3; + width = 0.1; + } + + SdShapeArc::~SdShapeArc() { + } + + + static void SdShapeArc::_bind_methods() { + ClassDB::bind_method(D_METHOD("get_output"), &SdShapeArc::get_output); + ClassDB::bind_method(D_METHOD("set_output", "value"), &SdShapeArc::set_output); + ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "output", PROPERTY_HINT_RESOURCE_TYPE, "Ref"), "set_output", "get_output"); + + + ClassDB::bind_method(D_METHOD("get_angle"), &SdShapeArc::get_angle); + ClassDB::bind_method(D_METHOD("set_angle", "value"), &SdShapeArc::set_angle); + ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "angle"), "set_angle", "get_angle"); + + + ClassDB::bind_method(D_METHOD("get_radius"), &SdShapeArc::get_radius); + ClassDB::bind_method(D_METHOD("set_radius", "value"), &SdShapeArc::set_radius); + ADD_PROPERTY(PropertyInfo(Variant::REAL, "radius"), "set_radius", "get_radius"); + + + ClassDB::bind_method(D_METHOD("get_width"), &SdShapeArc::get_width); + ClassDB::bind_method(D_METHOD("set_width", "value"), &SdShapeArc::set_width); + ADD_PROPERTY(PropertyInfo(Variant::REAL, "width"), "set_width", "get_width"); + + + ClassDB::bind_method(D_METHOD("_init_properties"), &SdShapeArc::_init_properties); + ClassDB::bind_method(D_METHOD("_register_methods", "mm_graph_node"), &SdShapeArc::_register_methods); + ClassDB::bind_method(D_METHOD("_get_property_value", "uv"), &SdShapeArc::_get_property_value); + ClassDB::bind_method(D_METHOD("get_angle"), &SdShapeArc::get_angle); + ClassDB::bind_method(D_METHOD("set_angle", "val"), &SdShapeArc::set_angle); + ClassDB::bind_method(D_METHOD("get_radius"), &SdShapeArc::get_radius); + ClassDB::bind_method(D_METHOD("set_radius", "val"), &SdShapeArc::set_radius); + ClassDB::bind_method(D_METHOD("get_width"), &SdShapeArc::get_width); + ClassDB::bind_method(D_METHOD("set_width", "val"), &SdShapeArc::set_width); + + } + + + diff --git a/modules/material_maker/nodes/sdf2d/sd_shape_arc.h b/modules/material_maker/nodes/sdf2d/sd_shape_arc.h new file mode 100644 index 000000000..26381bd7b --- /dev/null +++ b/modules/material_maker/nodes/sdf2d/sd_shape_arc.h @@ -0,0 +1,53 @@ +#ifndef SD_SHAPE_ARC_H +#define SD_SHAPE_ARC_H + + +class SdShapeArc : public MMNode { + GDCLASS(SdShapeArc, MMNode); + + public: + + Ref get_output(); + void set_output(const Ref &val); + + Vector2 get_angle(); + void set_angle(const Vector2 &val); + + float get_radius() const; + void set_radius(const float val); + + float get_width() const; + void set_width(const float val); + + void _init_properties(); + void _register_methods(const Variant &mm_graph_node); + float _get_property_value(const Vector2 &uv); + Vector2 get_angle(); + void set_angle(const Vector2 &val); + float get_radius(); + void set_radius(const float val); + float get_width(); + void set_width(const float val); + + SdShapeArc(); + ~SdShapeArc(); + + protected: + static void _bind_methods(); + + //tool + //export(Resource) + Ref output; + //export(Vector2) + Vector2 angle = Vector2(30, 150); + //export(float) + float radius = 0.3; + //export(float) + float width = 0.1; + //angle + //radius + //width +}; + + +#endif diff --git a/modules/material_maker/nodes/sdf2d/sd_shape_box.cpp b/modules/material_maker/nodes/sdf2d/sd_shape_box.cpp new file mode 100644 index 000000000..f48601830 --- /dev/null +++ b/modules/material_maker/nodes/sdf2d/sd_shape_box.cpp @@ -0,0 +1,131 @@ + +#include "sd_shape_box.h" + + +Ref SdShapeBox::get_output() { + return output; +} + +void SdShapeBox::set_output(const Ref &val) { +output = val; +} + + +Vector2 SdShapeBox::get_center() { + return center; +} + +void SdShapeBox::set_center(const Vector2 &val) { +center = val; +} + + +Vector2 SdShapeBox::get_size() { + return size; +} + +void SdShapeBox::set_size(const Vector2 &val) { +size = val; +} + + + + //tool; + //export(Resource) ; + Ref output; + //export(Vector2) ; + Vector2 center = Vector2(0, 0); + //export(Vector2) ; + Vector2 size = Vector2(0.3, 0.2); + + void SdShapeBox::_init_properties() { + + if (!output) { + output = MMNodeUniversalProperty.new(); + output.default_type = MMNodeUniversalProperty.DEFAULT_TYPE_FLOAT; +} + + output.output_slot_type = MMNodeUniversalProperty.SLOT_TYPE_FLOAT; + output.slot_name = ">>> Output >>>"; + output.get_value_from_owner = true; + register_output_property(output); +} + + + void SdShapeBox::_register_methods(const Variant &mm_graph_node) { + mm_graph_node.add_slot_label_universal(output); + mm_graph_node.add_slot_vector2("get_center", "set_center", "Center", 0.01); + mm_graph_node.add_slot_vector2("get_size", "set_size", "Size", 0.01); +} + + + float SdShapeBox::_get_property_value(const Vector2 &uv) { + return MMAlgos.sdf_box(uv, center, size); +} + + //center; + + Vector2 SdShapeBox::get_center() { + return center; +} + + + void SdShapeBox::set_center(const Vector2 &val) { + center = val; + emit_changed(); + output.emit_changed(); +} + + //size; + + Vector2 SdShapeBox::get_size() { + return size; +} + + + void SdShapeBox::set_size(const Vector2 &val) { + size = val; + emit_changed(); + output.emit_changed(); +} + +} + + SdShapeBox::SdShapeBox() { + output; + center = Vector2(0, 0); + size = Vector2(0.3, 0.2); + } + + SdShapeBox::~SdShapeBox() { + } + + + static void SdShapeBox::_bind_methods() { + ClassDB::bind_method(D_METHOD("get_output"), &SdShapeBox::get_output); + ClassDB::bind_method(D_METHOD("set_output", "value"), &SdShapeBox::set_output); + ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "output", PROPERTY_HINT_RESOURCE_TYPE, "Ref"), "set_output", "get_output"); + + + ClassDB::bind_method(D_METHOD("get_center"), &SdShapeBox::get_center); + ClassDB::bind_method(D_METHOD("set_center", "value"), &SdShapeBox::set_center); + ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "center"), "set_center", "get_center"); + + + ClassDB::bind_method(D_METHOD("get_size"), &SdShapeBox::get_size); + ClassDB::bind_method(D_METHOD("set_size", "value"), &SdShapeBox::set_size); + ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "size"), "set_size", "get_size"); + + + ClassDB::bind_method(D_METHOD("_init_properties"), &SdShapeBox::_init_properties); + ClassDB::bind_method(D_METHOD("_register_methods", "mm_graph_node"), &SdShapeBox::_register_methods); + ClassDB::bind_method(D_METHOD("_get_property_value", "uv"), &SdShapeBox::_get_property_value); + ClassDB::bind_method(D_METHOD("get_center"), &SdShapeBox::get_center); + ClassDB::bind_method(D_METHOD("set_center", "val"), &SdShapeBox::set_center); + ClassDB::bind_method(D_METHOD("get_size"), &SdShapeBox::get_size); + ClassDB::bind_method(D_METHOD("set_size", "val"), &SdShapeBox::set_size); + + } + + + diff --git a/modules/material_maker/nodes/sdf2d/sd_shape_box.h b/modules/material_maker/nodes/sdf2d/sd_shape_box.h new file mode 100644 index 000000000..f55cd9d2a --- /dev/null +++ b/modules/material_maker/nodes/sdf2d/sd_shape_box.h @@ -0,0 +1,45 @@ +#ifndef SD_SHAPE_BOX_H +#define SD_SHAPE_BOX_H + + +class SdShapeBox : public MMNode { + GDCLASS(SdShapeBox, MMNode); + + public: + + Ref get_output(); + void set_output(const Ref &val); + + Vector2 get_center(); + void set_center(const Vector2 &val); + + Vector2 get_size(); + void set_size(const Vector2 &val); + + void _init_properties(); + void _register_methods(const Variant &mm_graph_node); + float _get_property_value(const Vector2 &uv); + Vector2 get_center(); + void set_center(const Vector2 &val); + Vector2 get_size(); + void set_size(const Vector2 &val); + + SdShapeBox(); + ~SdShapeBox(); + + protected: + static void _bind_methods(); + + //tool + //export(Resource) + Ref output; + //export(Vector2) + Vector2 center = Vector2(0, 0); + //export(Vector2) + Vector2 size = Vector2(0.3, 0.2); + //center + //size +}; + + +#endif diff --git a/modules/material_maker/nodes/sdf2d/sd_shape_circle.cpp b/modules/material_maker/nodes/sdf2d/sd_shape_circle.cpp new file mode 100644 index 000000000..a74d5058e --- /dev/null +++ b/modules/material_maker/nodes/sdf2d/sd_shape_circle.cpp @@ -0,0 +1,131 @@ + +#include "sd_shape_circle.h" + + +Ref SdShapeCircle::get_output() { + return output; +} + +void SdShapeCircle::set_output(const Ref &val) { +output = val; +} + + +Vector2 SdShapeCircle::get_center() { + return center; +} + +void SdShapeCircle::set_center(const Vector2 &val) { +center = val; +} + + +float SdShapeCircle::get_radius() const { + return radius; +} + +void SdShapeCircle::set_radius(const float val) { +radius = val; +} + + + + //tool; + //export(Resource) ; + Ref output; + //export(Vector2) ; + Vector2 center = Vector2(0, 0); + //export(float) ; + float radius = 0.4; + + void SdShapeCircle::_init_properties() { + + if (!output) { + output = MMNodeUniversalProperty.new(); + output.default_type = MMNodeUniversalProperty.DEFAULT_TYPE_FLOAT; +} + + output.output_slot_type = MMNodeUniversalProperty.SLOT_TYPE_FLOAT; + output.slot_name = ">>> Output >>>"; + output.get_value_from_owner = true; + register_output_property(output); +} + + + void SdShapeCircle::_register_methods(const Variant &mm_graph_node) { + mm_graph_node.add_slot_label_universal(output); + mm_graph_node.add_slot_vector2("get_center", "set_center", "Center", 0.01); + mm_graph_node.add_slot_float("get_radius", "set_radius", "Radius", 0.01); +} + + + float SdShapeCircle::_get_property_value(const Vector2 &uv) { + return MMAlgos.sdf_circle(uv, center, radius); +} + + //center; + + Vector2 SdShapeCircle::get_center() { + return center; +} + + + void SdShapeCircle::set_center(const Vector2 &val) { + center = val; + emit_changed(); + output.emit_changed(); +} + + //radius; + + float SdShapeCircle::get_radius() { + return radius; +} + + + void SdShapeCircle::set_radius(const float val) { + radius = val; + emit_changed(); + output.emit_changed(); +} + +} + + SdShapeCircle::SdShapeCircle() { + output; + center = Vector2(0, 0); + radius = 0.4; + } + + SdShapeCircle::~SdShapeCircle() { + } + + + static void SdShapeCircle::_bind_methods() { + ClassDB::bind_method(D_METHOD("get_output"), &SdShapeCircle::get_output); + ClassDB::bind_method(D_METHOD("set_output", "value"), &SdShapeCircle::set_output); + ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "output", PROPERTY_HINT_RESOURCE_TYPE, "Ref"), "set_output", "get_output"); + + + ClassDB::bind_method(D_METHOD("get_center"), &SdShapeCircle::get_center); + ClassDB::bind_method(D_METHOD("set_center", "value"), &SdShapeCircle::set_center); + ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "center"), "set_center", "get_center"); + + + ClassDB::bind_method(D_METHOD("get_radius"), &SdShapeCircle::get_radius); + ClassDB::bind_method(D_METHOD("set_radius", "value"), &SdShapeCircle::set_radius); + ADD_PROPERTY(PropertyInfo(Variant::REAL, "radius"), "set_radius", "get_radius"); + + + ClassDB::bind_method(D_METHOD("_init_properties"), &SdShapeCircle::_init_properties); + ClassDB::bind_method(D_METHOD("_register_methods", "mm_graph_node"), &SdShapeCircle::_register_methods); + ClassDB::bind_method(D_METHOD("_get_property_value", "uv"), &SdShapeCircle::_get_property_value); + ClassDB::bind_method(D_METHOD("get_center"), &SdShapeCircle::get_center); + ClassDB::bind_method(D_METHOD("set_center", "val"), &SdShapeCircle::set_center); + ClassDB::bind_method(D_METHOD("get_radius"), &SdShapeCircle::get_radius); + ClassDB::bind_method(D_METHOD("set_radius", "val"), &SdShapeCircle::set_radius); + + } + + + diff --git a/modules/material_maker/nodes/sdf2d/sd_shape_circle.h b/modules/material_maker/nodes/sdf2d/sd_shape_circle.h new file mode 100644 index 000000000..42237a9e2 --- /dev/null +++ b/modules/material_maker/nodes/sdf2d/sd_shape_circle.h @@ -0,0 +1,45 @@ +#ifndef SD_SHAPE_CIRCLE_H +#define SD_SHAPE_CIRCLE_H + + +class SdShapeCircle : public MMNode { + GDCLASS(SdShapeCircle, MMNode); + + public: + + Ref get_output(); + void set_output(const Ref &val); + + Vector2 get_center(); + void set_center(const Vector2 &val); + + float get_radius() const; + void set_radius(const float val); + + void _init_properties(); + void _register_methods(const Variant &mm_graph_node); + float _get_property_value(const Vector2 &uv); + Vector2 get_center(); + void set_center(const Vector2 &val); + float get_radius(); + void set_radius(const float val); + + SdShapeCircle(); + ~SdShapeCircle(); + + protected: + static void _bind_methods(); + + //tool + //export(Resource) + Ref output; + //export(Vector2) + Vector2 center = Vector2(0, 0); + //export(float) + float radius = 0.4; + //center + //radius +}; + + +#endif diff --git a/modules/material_maker/nodes/sdf2d/sd_shape_line.cpp b/modules/material_maker/nodes/sdf2d/sd_shape_line.cpp new file mode 100644 index 000000000..c107e8c30 --- /dev/null +++ b/modules/material_maker/nodes/sdf2d/sd_shape_line.cpp @@ -0,0 +1,180 @@ + +#include "sd_shape_line.h" + + +Ref SdShapeLine::get_output() { + return output; +} + +void SdShapeLine::set_output(const Ref &val) { +output = val; +} + + +Vector2 SdShapeLine::get_A() { + return A; +} + +void SdShapeLine::set_A(const Vector2 &val) { +A = val; +} + + +Vector2 SdShapeLine::get_B() { + return B; +} + +void SdShapeLine::set_B(const Vector2 &val) { +B = val; +} + + +float SdShapeLine::get_width() const { + return width; +} + +void SdShapeLine::set_width(const float val) { +width = val; +} + + + + //tool; + //export(Resource) ; + Ref output; + //export(Vector2) ; + Vector2 A = Vector2(-0.3, -0.3); + //export(Vector2) ; + Vector2 B = Vector2(0.3, 0.3); + //export(float) ; + float width = 0.1; + + void SdShapeLine::_init() { + init_points_11(); +} + + + void SdShapeLine::_init_properties() { + + if (!output) { + output = MMNodeUniversalProperty.new(); + output.default_type = MMNodeUniversalProperty.DEFAULT_TYPE_FLOAT; +} + + output.output_slot_type = MMNodeUniversalProperty.SLOT_TYPE_FLOAT; + output.slot_name = ">>> Output >>>"; + output.get_value_from_owner = true; + register_output_property(output); +} + + + void SdShapeLine::_register_methods(const Variant &mm_graph_node) { + mm_graph_node.add_slot_label_universal(output); + mm_graph_node.add_slot_vector2("get_a", "set_a", "A", 0.01); + mm_graph_node.add_slot_vector2("get_b", "set_b", "B", 0.01); + mm_graph_node.add_slot_float("get_width", "set_width", "Width", 0.01); + mm_graph_node.add_slot_curve(); +} + + + float SdShapeLine::_get_property_value(const Vector2 &uv) { + Vector2 line = MMAlgos.sdf_line(uv, A, B, width); + //$(name_uv)_sdl.x - $r * $profile($(name_uv)_sdl.y); + return line.x - width * MMAlgos.curve(line.y, points_array); +} + + //a; + + Vector2 SdShapeLine::get_a() { + return A; +} + + + void SdShapeLine::set_a(const Vector2 &val) { + A = val; + emit_changed(); + output.emit_changed(); +} + + //b; + + Vector2 SdShapeLine::get_b() { + return B; +} + + + void SdShapeLine::set_b(const Vector2 &val) { + B = val; + emit_changed(); + output.emit_changed(); +} + + //width; + + float SdShapeLine::get_width() { + return width; +} + + + void SdShapeLine::set_width(const float val) { + width = val; + emit_changed(); + output.emit_changed(); +} + + + void SdShapeLine::_curve_changed() { + emit_changed(); + output.emit_changed(); +} + +} + + SdShapeLine::SdShapeLine() { + output; + A = Vector2(-0.3, -0.3); + B = Vector2(0.3, 0.3); + width = 0.1; + } + + SdShapeLine::~SdShapeLine() { + } + + + static void SdShapeLine::_bind_methods() { + ClassDB::bind_method(D_METHOD("get_output"), &SdShapeLine::get_output); + ClassDB::bind_method(D_METHOD("set_output", "value"), &SdShapeLine::set_output); + ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "output", PROPERTY_HINT_RESOURCE_TYPE, "Ref"), "set_output", "get_output"); + + + ClassDB::bind_method(D_METHOD("get_A"), &SdShapeLine::get_A); + ClassDB::bind_method(D_METHOD("set_A", "value"), &SdShapeLine::set_A); + ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "A"), "set_A", "get_A"); + + + ClassDB::bind_method(D_METHOD("get_B"), &SdShapeLine::get_B); + ClassDB::bind_method(D_METHOD("set_B", "value"), &SdShapeLine::set_B); + ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "B"), "set_B", "get_B"); + + + ClassDB::bind_method(D_METHOD("get_width"), &SdShapeLine::get_width); + ClassDB::bind_method(D_METHOD("set_width", "value"), &SdShapeLine::set_width); + ADD_PROPERTY(PropertyInfo(Variant::REAL, "width"), "set_width", "get_width"); + + + ClassDB::bind_method(D_METHOD("_init"), &SdShapeLine::_init); + ClassDB::bind_method(D_METHOD("_init_properties"), &SdShapeLine::_init_properties); + ClassDB::bind_method(D_METHOD("_register_methods", "mm_graph_node"), &SdShapeLine::_register_methods); + ClassDB::bind_method(D_METHOD("_get_property_value", "uv"), &SdShapeLine::_get_property_value); + ClassDB::bind_method(D_METHOD("get_a"), &SdShapeLine::get_a); + ClassDB::bind_method(D_METHOD("set_a", "val"), &SdShapeLine::set_a); + ClassDB::bind_method(D_METHOD("get_b"), &SdShapeLine::get_b); + ClassDB::bind_method(D_METHOD("set_b", "val"), &SdShapeLine::set_b); + ClassDB::bind_method(D_METHOD("get_width"), &SdShapeLine::get_width); + ClassDB::bind_method(D_METHOD("set_width", "val"), &SdShapeLine::set_width); + ClassDB::bind_method(D_METHOD("_curve_changed"), &SdShapeLine::_curve_changed); + + } + + + diff --git a/modules/material_maker/nodes/sdf2d/sd_shape_line.h b/modules/material_maker/nodes/sdf2d/sd_shape_line.h new file mode 100644 index 000000000..0ed16d474 --- /dev/null +++ b/modules/material_maker/nodes/sdf2d/sd_shape_line.h @@ -0,0 +1,55 @@ +#ifndef SD_SHAPE_LINE_H +#define SD_SHAPE_LINE_H + + +class SdShapeLine : public CurveBase { + GDCLASS(SdShapeLine, CurveBase); + + public: + + Ref get_output(); + void set_output(const Ref &val); + + Vector2 get_A(); + void set_A(const Vector2 &val); + + Vector2 get_B(); + void set_B(const Vector2 &val); + + float get_width() const; + void set_width(const float val); + + void _init(); + void _init_properties(); + void _register_methods(const Variant &mm_graph_node); + float _get_property_value(const Vector2 &uv); + Vector2 get_a(); + void set_a(const Vector2 &val); + Vector2 get_b(); + void set_b(const Vector2 &val); + float get_width(); + void set_width(const float val); + void _curve_changed(); + + SdShapeLine(); + ~SdShapeLine(); + + protected: + static void _bind_methods(); + + //tool + //export(Resource) + Ref output; + //export(Vector2) + Vector2 A = Vector2(-0.3, -0.3); + //export(Vector2) + Vector2 B = Vector2(0.3, 0.3); + //export(float) + float width = 0.1; + //a + //b + //width +}; + + +#endif diff --git a/modules/material_maker/nodes/sdf2d/sd_shape_polygon.cpp b/modules/material_maker/nodes/sdf2d/sd_shape_polygon.cpp new file mode 100644 index 000000000..024b88d51 --- /dev/null +++ b/modules/material_maker/nodes/sdf2d/sd_shape_polygon.cpp @@ -0,0 +1,73 @@ + +#include "sd_shape_polygon.h" + + +Ref SdShapePolygon::get_output() { + return output; +} + +void SdShapePolygon::set_output(const Ref &val) { +output = val; +} + + + + //tool; + //export(Resource) ; + Ref output; + + void SdShapePolygon::_init_properties() { + + if (!output) { + output = MMNodeUniversalProperty.new(); + output.default_type = MMNodeUniversalProperty.DEFAULT_TYPE_FLOAT; +} + + output.output_slot_type = MMNodeUniversalProperty.SLOT_TYPE_FLOAT; + output.slot_name = ">>> Output >>>"; + output.get_value_from_owner = true; + register_output_property(output); +} + + + void SdShapePolygon::_register_methods(const Variant &mm_graph_node) { + mm_graph_node.add_slot_label_universal(output); + mm_graph_node.add_slot_polygon(); +} + + + float SdShapePolygon::_get_property_value(const Vector2 &uv) { + return MMAlgos.sdPolygon(uv, points); +} + + + void SdShapePolygon::_polygon_changed() { + emit_changed(); + output.emit_changed(); +} + +} + + SdShapePolygon::SdShapePolygon() { + output; + } + + SdShapePolygon::~SdShapePolygon() { + } + + + static void SdShapePolygon::_bind_methods() { + ClassDB::bind_method(D_METHOD("get_output"), &SdShapePolygon::get_output); + ClassDB::bind_method(D_METHOD("set_output", "value"), &SdShapePolygon::set_output); + ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "output", PROPERTY_HINT_RESOURCE_TYPE, "Ref"), "set_output", "get_output"); + + + ClassDB::bind_method(D_METHOD("_init_properties"), &SdShapePolygon::_init_properties); + ClassDB::bind_method(D_METHOD("_register_methods", "mm_graph_node"), &SdShapePolygon::_register_methods); + ClassDB::bind_method(D_METHOD("_get_property_value", "uv"), &SdShapePolygon::_get_property_value); + ClassDB::bind_method(D_METHOD("_polygon_changed"), &SdShapePolygon::_polygon_changed); + + } + + + diff --git a/modules/material_maker/nodes/sdf2d/sd_shape_polygon.h b/modules/material_maker/nodes/sdf2d/sd_shape_polygon.h new file mode 100644 index 000000000..75fa95a61 --- /dev/null +++ b/modules/material_maker/nodes/sdf2d/sd_shape_polygon.h @@ -0,0 +1,30 @@ +#ifndef SD_SHAPE_POLYGON_H +#define SD_SHAPE_POLYGON_H + + +class SdShapePolygon : public PolygonBase { + GDCLASS(SdShapePolygon, PolygonBase); + + public: + + Ref get_output(); + void set_output(const Ref &val); + + void _init_properties(); + void _register_methods(const Variant &mm_graph_node); + float _get_property_value(const Vector2 &uv); + void _polygon_changed(); + + SdShapePolygon(); + ~SdShapePolygon(); + + protected: + static void _bind_methods(); + + //tool + //export(Resource) + Ref output; +}; + + +#endif diff --git a/modules/material_maker/nodes/sdf2d/sd_shape_rhombus.cpp b/modules/material_maker/nodes/sdf2d/sd_shape_rhombus.cpp new file mode 100644 index 000000000..c02951dec --- /dev/null +++ b/modules/material_maker/nodes/sdf2d/sd_shape_rhombus.cpp @@ -0,0 +1,131 @@ + +#include "sd_shape_rhombus.h" + + +Ref SdShapeRhombus::get_output() { + return output; +} + +void SdShapeRhombus::set_output(const Ref &val) { +output = val; +} + + +Vector2 SdShapeRhombus::get_center() { + return center; +} + +void SdShapeRhombus::set_center(const Vector2 &val) { +center = val; +} + + +Vector2 SdShapeRhombus::get_size() { + return size; +} + +void SdShapeRhombus::set_size(const Vector2 &val) { +size = val; +} + + + + //tool; + //export(Resource) ; + Ref output; + //export(Vector2) ; + Vector2 center = Vector2(0, 0); + //export(Vector2) ; + Vector2 size = Vector2(0.3, 0.2); + + void SdShapeRhombus::_init_properties() { + + if (!output) { + output = MMNodeUniversalProperty.new(); + output.default_type = MMNodeUniversalProperty.DEFAULT_TYPE_FLOAT; +} + + output.output_slot_type = MMNodeUniversalProperty.SLOT_TYPE_FLOAT; + output.slot_name = ">>> Output >>>"; + output.get_value_from_owner = true; + register_output_property(output); +} + + + void SdShapeRhombus::_register_methods(const Variant &mm_graph_node) { + mm_graph_node.add_slot_label_universal(output); + mm_graph_node.add_slot_vector2("get_center", "set_center", "Center", 0.01); + mm_graph_node.add_slot_vector2("get_size", "set_size", "Size", 0.01); +} + + + float SdShapeRhombus::_get_property_value(const Vector2 &uv) { + return MMAlgos.sdf_rhombus(uv, center, size); +} + + //center; + + Vector2 SdShapeRhombus::get_center() { + return center; +} + + + void SdShapeRhombus::set_center(const Vector2 &val) { + center = val; + emit_changed(); + output.emit_changed(); +} + + //size; + + Vector2 SdShapeRhombus::get_size() { + return size; +} + + + void SdShapeRhombus::set_size(const Vector2 &val) { + size = val; + emit_changed(); + output.emit_changed(); +} + +} + + SdShapeRhombus::SdShapeRhombus() { + output; + center = Vector2(0, 0); + size = Vector2(0.3, 0.2); + } + + SdShapeRhombus::~SdShapeRhombus() { + } + + + static void SdShapeRhombus::_bind_methods() { + ClassDB::bind_method(D_METHOD("get_output"), &SdShapeRhombus::get_output); + ClassDB::bind_method(D_METHOD("set_output", "value"), &SdShapeRhombus::set_output); + ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "output", PROPERTY_HINT_RESOURCE_TYPE, "Ref"), "set_output", "get_output"); + + + ClassDB::bind_method(D_METHOD("get_center"), &SdShapeRhombus::get_center); + ClassDB::bind_method(D_METHOD("set_center", "value"), &SdShapeRhombus::set_center); + ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "center"), "set_center", "get_center"); + + + ClassDB::bind_method(D_METHOD("get_size"), &SdShapeRhombus::get_size); + ClassDB::bind_method(D_METHOD("set_size", "value"), &SdShapeRhombus::set_size); + ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "size"), "set_size", "get_size"); + + + ClassDB::bind_method(D_METHOD("_init_properties"), &SdShapeRhombus::_init_properties); + ClassDB::bind_method(D_METHOD("_register_methods", "mm_graph_node"), &SdShapeRhombus::_register_methods); + ClassDB::bind_method(D_METHOD("_get_property_value", "uv"), &SdShapeRhombus::_get_property_value); + ClassDB::bind_method(D_METHOD("get_center"), &SdShapeRhombus::get_center); + ClassDB::bind_method(D_METHOD("set_center", "val"), &SdShapeRhombus::set_center); + ClassDB::bind_method(D_METHOD("get_size"), &SdShapeRhombus::get_size); + ClassDB::bind_method(D_METHOD("set_size", "val"), &SdShapeRhombus::set_size); + + } + + + diff --git a/modules/material_maker/nodes/sdf2d/sd_shape_rhombus.h b/modules/material_maker/nodes/sdf2d/sd_shape_rhombus.h new file mode 100644 index 000000000..bbf709aff --- /dev/null +++ b/modules/material_maker/nodes/sdf2d/sd_shape_rhombus.h @@ -0,0 +1,45 @@ +#ifndef SD_SHAPE_RHOMBUS_H +#define SD_SHAPE_RHOMBUS_H + + +class SdShapeRhombus : public MMNode { + GDCLASS(SdShapeRhombus, MMNode); + + public: + + Ref get_output(); + void set_output(const Ref &val); + + Vector2 get_center(); + void set_center(const Vector2 &val); + + Vector2 get_size(); + void set_size(const Vector2 &val); + + void _init_properties(); + void _register_methods(const Variant &mm_graph_node); + float _get_property_value(const Vector2 &uv); + Vector2 get_center(); + void set_center(const Vector2 &val); + Vector2 get_size(); + void set_size(const Vector2 &val); + + SdShapeRhombus(); + ~SdShapeRhombus(); + + protected: + static void _bind_methods(); + + //tool + //export(Resource) + Ref output; + //export(Vector2) + Vector2 center = Vector2(0, 0); + //export(Vector2) + Vector2 size = Vector2(0.3, 0.2); + //center + //size +}; + + +#endif diff --git a/modules/material_maker/nodes/sdf2d/sd_show.cpp b/modules/material_maker/nodes/sdf2d/sd_show.cpp new file mode 100644 index 000000000..24c87954c --- /dev/null +++ b/modules/material_maker/nodes/sdf2d/sd_show.cpp @@ -0,0 +1,166 @@ + +#include "sd_show.h" + + +Ref SdShow::get_image() { + return image; +} + +void SdShow::set_image(const Ref &val) { +image = val; +} + + +Ref SdShow::get_input() { + return input; +} + +void SdShow::set_input(const Ref &val) { +input = val; +} + + +float SdShow::get_bevel() const { + return bevel; +} + +void SdShow::set_bevel(const float val) { +bevel = val; +} + + +float SdShow::get_base() const { + return base; +} + +void SdShow::set_base(const float val) { +base = val; +} + + + + //tool; + //export(Resource) ; + Ref image; + //export(Resource) ; + Ref input; + //export(float) ; + float bevel = 0; + //export(float) ; + float base = 0; + + void SdShow::_init_properties() { + + if (!image) { + image = MMNodeUniversalProperty.new(); + image.default_type = MMNodeUniversalProperty.DEFAULT_TYPE_IMAGE; +} + + image.output_slot_type = MMNodeUniversalProperty.SLOT_TYPE_IMAGE; + + if (!input) { + input = MMNodeUniversalProperty.new(); + input.default_type = MMNodeUniversalProperty.DEFAULT_TYPE_FLOAT; +} + + //for some reason this doesn't work, todo check; + // input.input_slot_type = MMNodeUniversalProperty.SLOT_TYPE_FLOAT; + input.input_slot_type = MMNodeUniversalProperty.SLOT_TYPE_UNIVERSAL; + input.slot_name = "Input"; + register_output_property(image); + register_input_property(input); +} + + + void SdShow::_register_methods(const Variant &mm_graph_node) { + mm_graph_node.add_slot_texture_universal(image); + mm_graph_node.add_slot_label_universal(input); + mm_graph_node.add_slot_float("get_bevel", "set_bevel", "Bevel", 0.01); + mm_graph_node.add_slot_float("get_base", "set_base", "Base", 0.01); +} + + + void SdShow::_render(const Variant &material) { + Ref img = render_image(material); + image.set_value(img); +} + + + Color SdShow::_get_value_for(const Vector2 &uv, const int pseed) { + float f = input.get_value(uv); + //clamp($base-$in($uv)/max($bevel, 0.00001), 0.0, 1.0); + float cf = clamp(base - f / max(bevel, 0.00001), 0.0, 1.0); + return Color(cf, cf, cf, 1); +} + + //bevel; + + float SdShow::get_bevel() { + return bevel; +} + + + void SdShow::set_bevel(const float val) { + bevel = val; + set_dirty(true); +} + + //base; + + float SdShow::get_base() { + return base; +} + + + void SdShow::set_base(const float val) { + base = val; + set_dirty(true); +} + +} + + SdShow::SdShow() { + image; + input; + bevel = 0; + base = 0; + } + + SdShow::~SdShow() { + } + + + static void SdShow::_bind_methods() { + ClassDB::bind_method(D_METHOD("get_image"), &SdShow::get_image); + ClassDB::bind_method(D_METHOD("set_image", "value"), &SdShow::set_image); + ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "image", PROPERTY_HINT_RESOURCE_TYPE, "Ref"), "set_image", "get_image"); + + + ClassDB::bind_method(D_METHOD("get_input"), &SdShow::get_input); + ClassDB::bind_method(D_METHOD("set_input", "value"), &SdShow::set_input); + ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "input", PROPERTY_HINT_RESOURCE_TYPE, "Ref"), "set_input", "get_input"); + + + ClassDB::bind_method(D_METHOD("get_bevel"), &SdShow::get_bevel); + ClassDB::bind_method(D_METHOD("set_bevel", "value"), &SdShow::set_bevel); + ADD_PROPERTY(PropertyInfo(Variant::REAL, "bevel"), "set_bevel", "get_bevel"); + + + ClassDB::bind_method(D_METHOD("get_base"), &SdShow::get_base); + ClassDB::bind_method(D_METHOD("set_base", "value"), &SdShow::set_base); + ADD_PROPERTY(PropertyInfo(Variant::REAL, "base"), "set_base", "get_base"); + + + ClassDB::bind_method(D_METHOD("_init_properties"), &SdShow::_init_properties); + ClassDB::bind_method(D_METHOD("_register_methods", "mm_graph_node"), &SdShow::_register_methods); + ClassDB::bind_method(D_METHOD("_render", "material"), &SdShow::_render); + ClassDB::bind_method(D_METHOD("_get_value_for", "uv", "pseed"), &SdShow::_get_value_for); + ClassDB::bind_method(D_METHOD("get_bevel"), &SdShow::get_bevel); + ClassDB::bind_method(D_METHOD("set_bevel", "val"), &SdShow::set_bevel); + ClassDB::bind_method(D_METHOD("get_base"), &SdShow::get_base); + ClassDB::bind_method(D_METHOD("set_base", "val"), &SdShow::set_base); + + } + + + diff --git a/modules/material_maker/nodes/sdf2d/sd_show.h b/modules/material_maker/nodes/sdf2d/sd_show.h new file mode 100644 index 000000000..7f9427b2d --- /dev/null +++ b/modules/material_maker/nodes/sdf2d/sd_show.h @@ -0,0 +1,51 @@ +#ifndef SD_SHOW_H +#define SD_SHOW_H + + +class SdShow : public MMNode { + GDCLASS(SdShow, MMNode); + + public: + + Ref get_image(); + void set_image(const Ref &val); + + Ref get_input(); + void set_input(const Ref &val); + + float get_bevel() const; + void set_bevel(const float val); + + float get_base() const; + void set_base(const float val); + + 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); + float get_bevel(); + void set_bevel(const float val); + float get_base(); + void set_base(const float val); + + SdShow(); + ~SdShow(); + + protected: + static void _bind_methods(); + + //tool + //export(Resource) + Ref image; + //export(Resource) + Ref input; + //export(float) + float bevel = 0; + //export(float) + float base = 0; + //bevel + //base +}; + + +#endif diff --git a/modules/material_maker/nodes/sdf2d/sd_tf_rotate.cpp b/modules/material_maker/nodes/sdf2d/sd_tf_rotate.cpp new file mode 100644 index 000000000..ce6ae84d9 --- /dev/null +++ b/modules/material_maker/nodes/sdf2d/sd_tf_rotate.cpp @@ -0,0 +1,102 @@ + +#include "sd_tf_rotate.h" + + +Ref SdTfRotate::get_output() { + return output; +} + +void SdTfRotate::set_output(const Ref &val) { +output = val; +} + + +float SdTfRotate::get_angle() const { + return angle; +} + +void SdTfRotate::set_angle(const float val) { +angle = val; +} + + + + //tool; + //export(Resource) ; + Ref output; + //export(float) ; + float angle = 0; + + void SdTfRotate::_init_properties() { + + if (!output) { + output = MMNodeUniversalProperty.new(); + output.default_type = MMNodeUniversalProperty.DEFAULT_TYPE_FLOAT; +} + + output.input_slot_type = MMNodeUniversalProperty.SLOT_TYPE_UNIVERSAL; + output.output_slot_type = MMNodeUniversalProperty.SLOT_TYPE_UNIVERSAL; + //output.output_slot_type = MMNodeUniversalProperty.SLOT_TYPE_FLOAT; + output.slot_name = ">>> Apply >>>"; + output.get_value_from_owner = true; + register_input_property(output); + register_output_property(output); +} + + + void SdTfRotate::_register_methods(const Variant &mm_graph_node) { + mm_graph_node.add_slot_label_universal(output); + mm_graph_node.add_slot_float("get_angle", "set_angle", "Angle", 1); +} + + + void SdTfRotate::_get_property_value(const Vector2 &uv) { + //$in(sdf2d_rotate($uv, $a*0.01745329251))",; + return output.get_value(MMAlgos.sdf2d_rotate(uv, angle * 0.01745329251), true); +} + + //angle; + + float SdTfRotate::get_angle() { + return angle; +} + + + void SdTfRotate::set_angle(const float val) { + angle = val; + emit_changed(); + output.emit_changed(); +} + +} + + SdTfRotate::SdTfRotate() { + output; + angle = 0; + } + + SdTfRotate::~SdTfRotate() { + } + + + static void SdTfRotate::_bind_methods() { + ClassDB::bind_method(D_METHOD("get_output"), &SdTfRotate::get_output); + ClassDB::bind_method(D_METHOD("set_output", "value"), &SdTfRotate::set_output); + ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "output", PROPERTY_HINT_RESOURCE_TYPE, "Ref"), "set_output", "get_output"); + + + ClassDB::bind_method(D_METHOD("get_angle"), &SdTfRotate::get_angle); + ClassDB::bind_method(D_METHOD("set_angle", "value"), &SdTfRotate::set_angle); + ADD_PROPERTY(PropertyInfo(Variant::REAL, "angle"), "set_angle", "get_angle"); + + + ClassDB::bind_method(D_METHOD("_init_properties"), &SdTfRotate::_init_properties); + ClassDB::bind_method(D_METHOD("_register_methods", "mm_graph_node"), &SdTfRotate::_register_methods); + ClassDB::bind_method(D_METHOD("_get_property_value", "uv"), &SdTfRotate::_get_property_value); + ClassDB::bind_method(D_METHOD("get_angle"), &SdTfRotate::get_angle); + ClassDB::bind_method(D_METHOD("set_angle", "val"), &SdTfRotate::set_angle); + + } + + + diff --git a/modules/material_maker/nodes/sdf2d/sd_tf_rotate.h b/modules/material_maker/nodes/sdf2d/sd_tf_rotate.h new file mode 100644 index 000000000..c05d21ae7 --- /dev/null +++ b/modules/material_maker/nodes/sdf2d/sd_tf_rotate.h @@ -0,0 +1,37 @@ +#ifndef SD_TF_ROTATE_H +#define SD_TF_ROTATE_H + + +class SdTfRotate : public MMNode { + GDCLASS(SdTfRotate, MMNode); + + public: + + Ref get_output(); + void set_output(const Ref &val); + + float get_angle() const; + void set_angle(const float val); + + void _init_properties(); + void _register_methods(const Variant &mm_graph_node); + void _get_property_value(const Vector2 &uv); + float get_angle(); + void set_angle(const float val); + + SdTfRotate(); + ~SdTfRotate(); + + protected: + static void _bind_methods(); + + //tool + //export(Resource) + Ref output; + //export(float) + float angle = 0; + //angle +}; + + +#endif diff --git a/modules/material_maker/nodes/sdf2d/sd_tf_scale.cpp b/modules/material_maker/nodes/sdf2d/sd_tf_scale.cpp new file mode 100644 index 000000000..dce9a0240 --- /dev/null +++ b/modules/material_maker/nodes/sdf2d/sd_tf_scale.cpp @@ -0,0 +1,102 @@ + +#include "sd_tf_scale.h" + + +Ref SdTfScale::get_output() { + return output; +} + +void SdTfScale::set_output(const Ref &val) { +output = val; +} + + +float SdTfScale::get_scale() const { + return scale; +} + +void SdTfScale::set_scale(const float val) { +scale = val; +} + + + + //tool; + //export(Resource) ; + Ref output; + //export(float) ; + float scale = 1; + + void SdTfScale::_init_properties() { + + if (!output) { + output = MMNodeUniversalProperty.new(); + output.default_type = MMNodeUniversalProperty.DEFAULT_TYPE_FLOAT; +} + + output.input_slot_type = MMNodeUniversalProperty.SLOT_TYPE_UNIVERSAL; + output.output_slot_type = MMNodeUniversalProperty.SLOT_TYPE_UNIVERSAL; + //output.output_slot_type = MMNodeUniversalProperty.SLOT_TYPE_FLOAT; + output.slot_name = ">>> Apply >>>"; + output.get_value_from_owner = true; + register_input_property(output); + register_output_property(output); +} + + + void SdTfScale::_register_methods(const Variant &mm_graph_node) { + mm_graph_node.add_slot_label_universal(output); + mm_graph_node.add_slot_float("get_scale", "set_scale", "Scale", 0.01); +} + + + void SdTfScale::_get_property_value(const Vector2 &uv) { + //$in(($uv-vec2(0.5))/$s+vec2(0.5))*$s; + return output.get_value(((uv - Vector2(0.5, 0.5)) / scale + Vector2(0.5, 0.5)), true); +} + + //scale; + + float SdTfScale::get_scale() { + return scale; +} + + + void SdTfScale::set_scale(const float val) { + scale = val; + emit_changed(); + output.emit_changed(); +} + +} + + SdTfScale::SdTfScale() { + output; + scale = 1; + } + + SdTfScale::~SdTfScale() { + } + + + static void SdTfScale::_bind_methods() { + ClassDB::bind_method(D_METHOD("get_output"), &SdTfScale::get_output); + ClassDB::bind_method(D_METHOD("set_output", "value"), &SdTfScale::set_output); + ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "output", PROPERTY_HINT_RESOURCE_TYPE, "Ref"), "set_output", "get_output"); + + + ClassDB::bind_method(D_METHOD("get_scale"), &SdTfScale::get_scale); + ClassDB::bind_method(D_METHOD("set_scale", "value"), &SdTfScale::set_scale); + ADD_PROPERTY(PropertyInfo(Variant::REAL, "scale"), "set_scale", "get_scale"); + + + ClassDB::bind_method(D_METHOD("_init_properties"), &SdTfScale::_init_properties); + ClassDB::bind_method(D_METHOD("_register_methods", "mm_graph_node"), &SdTfScale::_register_methods); + ClassDB::bind_method(D_METHOD("_get_property_value", "uv"), &SdTfScale::_get_property_value); + ClassDB::bind_method(D_METHOD("get_scale"), &SdTfScale::get_scale); + ClassDB::bind_method(D_METHOD("set_scale", "val"), &SdTfScale::set_scale); + + } + + + diff --git a/modules/material_maker/nodes/sdf2d/sd_tf_scale.h b/modules/material_maker/nodes/sdf2d/sd_tf_scale.h new file mode 100644 index 000000000..d49c45d75 --- /dev/null +++ b/modules/material_maker/nodes/sdf2d/sd_tf_scale.h @@ -0,0 +1,37 @@ +#ifndef SD_TF_SCALE_H +#define SD_TF_SCALE_H + + +class SdTfScale : public MMNode { + GDCLASS(SdTfScale, MMNode); + + public: + + Ref get_output(); + void set_output(const Ref &val); + + float get_scale() const; + void set_scale(const float val); + + void _init_properties(); + void _register_methods(const Variant &mm_graph_node); + void _get_property_value(const Vector2 &uv); + float get_scale(); + void set_scale(const float val); + + SdTfScale(); + ~SdTfScale(); + + protected: + static void _bind_methods(); + + //tool + //export(Resource) + Ref output; + //export(float) + float scale = 1; + //scale +}; + + +#endif diff --git a/modules/material_maker/nodes/sdf2d/sd_tf_translate.cpp b/modules/material_maker/nodes/sdf2d/sd_tf_translate.cpp new file mode 100644 index 000000000..f57feab14 --- /dev/null +++ b/modules/material_maker/nodes/sdf2d/sd_tf_translate.cpp @@ -0,0 +1,101 @@ + +#include "sd_tf_translate.h" + + +Ref SdTfTranslate::get_output() { + return output; +} + +void SdTfTranslate::set_output(const Ref &val) { +output = val; +} + + +Vector2 SdTfTranslate::get_translation() { + return translation; +} + +void SdTfTranslate::set_translation(const Vector2 &val) { +translation = val; +} + + + + //tool; + //export(Resource) ; + Ref output; + //export(Vector2) ; + Vector2 translation = Vector2(0, 0); + + void SdTfTranslate::_init_properties() { + + if (!output) { + output = MMNodeUniversalProperty.new(); + output.default_type = MMNodeUniversalProperty.DEFAULT_TYPE_FLOAT; +} + + output.input_slot_type = MMNodeUniversalProperty.SLOT_TYPE_UNIVERSAL; + output.output_slot_type = MMNodeUniversalProperty.SLOT_TYPE_UNIVERSAL; + //output.output_slot_type = MMNodeUniversalProperty.SLOT_TYPE_FLOAT; + output.slot_name = ">>> Apply >>>"; + output.get_value_from_owner = true; + register_input_property(output); + register_output_property(output); +} + + + void SdTfTranslate::_register_methods(const Variant &mm_graph_node) { + mm_graph_node.add_slot_label_universal(output); + mm_graph_node.add_slot_vector2("get_translation", "set_translation", "Translation", 0.01); +} + + + void SdTfTranslate::_get_property_value(const Vector2 &uv) { + return output.get_value(uv - translation, true); +} + + //a; + + Vector2 SdTfTranslate::get_translation() { + return translation; +} + + + void SdTfTranslate::set_translation(const Vector2 &val) { + translation = val; + emit_changed(); + output.emit_changed(); +} + +} + + SdTfTranslate::SdTfTranslate() { + output; + translation = Vector2(0, 0); + } + + SdTfTranslate::~SdTfTranslate() { + } + + + static void SdTfTranslate::_bind_methods() { + ClassDB::bind_method(D_METHOD("get_output"), &SdTfTranslate::get_output); + ClassDB::bind_method(D_METHOD("set_output", "value"), &SdTfTranslate::set_output); + ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "output", PROPERTY_HINT_RESOURCE_TYPE, "Ref"), "set_output", "get_output"); + + + ClassDB::bind_method(D_METHOD("get_translation"), &SdTfTranslate::get_translation); + ClassDB::bind_method(D_METHOD("set_translation", "value"), &SdTfTranslate::set_translation); + ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "translation"), "set_translation", "get_translation"); + + + ClassDB::bind_method(D_METHOD("_init_properties"), &SdTfTranslate::_init_properties); + ClassDB::bind_method(D_METHOD("_register_methods", "mm_graph_node"), &SdTfTranslate::_register_methods); + ClassDB::bind_method(D_METHOD("_get_property_value", "uv"), &SdTfTranslate::_get_property_value); + ClassDB::bind_method(D_METHOD("get_translation"), &SdTfTranslate::get_translation); + ClassDB::bind_method(D_METHOD("set_translation", "val"), &SdTfTranslate::set_translation); + + } + + + diff --git a/modules/material_maker/nodes/sdf2d/sd_tf_translate.h b/modules/material_maker/nodes/sdf2d/sd_tf_translate.h new file mode 100644 index 000000000..8df50192e --- /dev/null +++ b/modules/material_maker/nodes/sdf2d/sd_tf_translate.h @@ -0,0 +1,37 @@ +#ifndef SD_TF_TRANSLATE_H +#define SD_TF_TRANSLATE_H + + +class SdTfTranslate : public MMNode { + GDCLASS(SdTfTranslate, MMNode); + + public: + + Ref get_output(); + void set_output(const Ref &val); + + Vector2 get_translation(); + void set_translation(const Vector2 &val); + + void _init_properties(); + void _register_methods(const Variant &mm_graph_node); + void _get_property_value(const Vector2 &uv); + Vector2 get_translation(); + void set_translation(const Vector2 &val); + + SdTfTranslate(); + ~SdTfTranslate(); + + protected: + static void _bind_methods(); + + //tool + //export(Resource) + Ref output; + //export(Vector2) + Vector2 translation = Vector2(0, 0); + //a +}; + + +#endif diff --git a/modules/material_maker/nodes/sdf3d/sdf3d_color.cpp b/modules/material_maker/nodes/sdf3d/sdf3d_color.cpp new file mode 100644 index 000000000..5cd2cebc5 --- /dev/null +++ b/modules/material_maker/nodes/sdf3d/sdf3d_color.cpp @@ -0,0 +1,140 @@ + +#include "sdf3d_color.h" + + +Ref Sdf3dColor::get_input() { + return input; +} + +void Sdf3dColor::set_input(const Ref &val) { +input = val; +} + + +Ref Sdf3dColor::get_output() { + return output; +} + +void Sdf3dColor::set_output(const Ref &val) { +output = val; +} + + +float Sdf3dColor::get_color() const { + return color; +} + +void Sdf3dColor::set_color(const float val) { +color = val; +} + + + + //tool; + //export(Resource) ; + Ref input; + //export(Resource) ; + Ref output; + //export(float) ; + float color = 0.5; + + void Sdf3dColor::_init_properties() { + + if (!input) { + input = MMNodeUniversalProperty.new(); + input.default_type = MMNodeUniversalProperty.DEFAULT_TYPE_VECTOR2; +} + + input.input_slot_type = MMNodeUniversalProperty.SLOT_TYPE_UNIVERSAL; + // input.input_slot_type = MMNodeUniversalProperty.SLOT_TYPE_VECTOR2; + input.slot_name = ">>> Input "; + + if (!input.is_connected("changed", self, "on_input_changed")) { + input.connect("changed", self, "on_input_changed"); +} + + + if (!output) { + output = MMNodeUniversalProperty.new(); + output.default_type = MMNodeUniversalProperty.DEFAULT_TYPE_VECTOR2; +} + + output.output_slot_type = MMNodeUniversalProperty.SLOT_TYPE_FLOAT; + output.slot_name = ">>> Output >>>"; + output.get_value_from_owner = true; + register_input_property(input); + register_output_property(output); +} + + + void Sdf3dColor::_register_methods(const Variant &mm_graph_node) { + mm_graph_node.add_slot_label_universal(input); + mm_graph_node.add_slot_label_universal(output); + mm_graph_node.add_slot_float("get_color", "set_color", "Color", 0.01); +} + + + Vector2 Sdf3dColor::_get_property_value_sdf3d(const Vector3 &uv3) { + Vector2 v = input.get_value_sdf3d(uv3); + v.y = color; + return v; +} + + //color; + + float Sdf3dColor::get_color() { + return color; +} + + + void Sdf3dColor::set_color(const float val) { + color = val; + emit_changed(); + output.emit_changed(); +} + + + void Sdf3dColor::on_input_changed() { + emit_changed(); + output.emit_changed(); +} + +} + + Sdf3dColor::Sdf3dColor() { + input; + output; + color = 0.5; + } + + Sdf3dColor::~Sdf3dColor() { + } + + + static void Sdf3dColor::_bind_methods() { + ClassDB::bind_method(D_METHOD("get_input"), &Sdf3dColor::get_input); + ClassDB::bind_method(D_METHOD("set_input", "value"), &Sdf3dColor::set_input); + ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "input", PROPERTY_HINT_RESOURCE_TYPE, "Ref"), "set_input", "get_input"); + + + ClassDB::bind_method(D_METHOD("get_output"), &Sdf3dColor::get_output); + ClassDB::bind_method(D_METHOD("set_output", "value"), &Sdf3dColor::set_output); + ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "output", PROPERTY_HINT_RESOURCE_TYPE, "Ref"), "set_output", "get_output"); + + + ClassDB::bind_method(D_METHOD("get_color"), &Sdf3dColor::get_color); + ClassDB::bind_method(D_METHOD("set_color", "value"), &Sdf3dColor::set_color); + ADD_PROPERTY(PropertyInfo(Variant::REAL, "color"), "set_color", "get_color"); + + + ClassDB::bind_method(D_METHOD("_init_properties"), &Sdf3dColor::_init_properties); + ClassDB::bind_method(D_METHOD("_register_methods", "mm_graph_node"), &Sdf3dColor::_register_methods); + ClassDB::bind_method(D_METHOD("_get_property_value_sdf3d", "uv3"), &Sdf3dColor::_get_property_value_sdf3d); + ClassDB::bind_method(D_METHOD("get_color"), &Sdf3dColor::get_color); + ClassDB::bind_method(D_METHOD("set_color", "val"), &Sdf3dColor::set_color); + ClassDB::bind_method(D_METHOD("on_input_changed"), &Sdf3dColor::on_input_changed); + + } + + + diff --git a/modules/material_maker/nodes/sdf3d/sdf3d_color.h b/modules/material_maker/nodes/sdf3d/sdf3d_color.h new file mode 100644 index 000000000..df81e3f4d --- /dev/null +++ b/modules/material_maker/nodes/sdf3d/sdf3d_color.h @@ -0,0 +1,43 @@ +#ifndef SDF3D_COLOR_H +#define SDF3D_COLOR_H + + +class Sdf3dColor : public MMNode { + GDCLASS(Sdf3dColor, MMNode); + + public: + + Ref get_input(); + void set_input(const Ref &val); + + Ref get_output(); + void set_output(const Ref &val); + + float get_color() const; + void set_color(const float val); + + void _init_properties(); + void _register_methods(const Variant &mm_graph_node); + Vector2 _get_property_value_sdf3d(const Vector3 &uv3); + float get_color(); + void set_color(const float val); + void on_input_changed(); + + Sdf3dColor(); + ~Sdf3dColor(); + + protected: + static void _bind_methods(); + + //tool + //export(Resource) + Ref input; + //export(Resource) + Ref output; + //export(float) + float color = 0.5; + //color +}; + + +#endif diff --git a/modules/material_maker/nodes/sdf3d/sdf3d_op_bool.cpp b/modules/material_maker/nodes/sdf3d/sdf3d_op_bool.cpp new file mode 100644 index 000000000..d11049fc7 --- /dev/null +++ b/modules/material_maker/nodes/sdf3d/sdf3d_op_bool.cpp @@ -0,0 +1,188 @@ + +#include "sdf3d_op_bool.h" + + +Ref Sdf3dOpBool::get_input1() { + return input1; +} + +void Sdf3dOpBool::set_input1(const Ref &val) { +input1 = val; +} + + +Ref Sdf3dOpBool::get_input2() { + return input2; +} + +void Sdf3dOpBool::set_input2(const Ref &val) { +input2 = val; +} + + +Ref Sdf3dOpBool::get_output() { + return output; +} + +void Sdf3dOpBool::set_output(const Ref &val) { +output = val; +} + + +int Sdf3dOpBool::get_operation() const { + return operation; +} + +void Sdf3dOpBool::set_operation(const int val) { +operation = val; +} + + + + //tool; + //export(Resource) ; + Ref input1; + //export(Resource) ; + Ref input2; + //export(Resource) ; + Ref output; + //export(int, "Union,Substraction,Intersection") ; + int operation = 0; + + void Sdf3dOpBool::_init_properties() { + + if (!input1) { + input1 = MMNodeUniversalProperty.new(); + input1.default_type = MMNodeUniversalProperty.DEFAULT_TYPE_VECTOR2; +} + + input1.input_slot_type = MMNodeUniversalProperty.SLOT_TYPE_UNIVERSAL; + // input1.input_slot_type = MMNodeUniversalProperty.SLOT_TYPE_VECTOR2; + input1.slot_name = ">>> Input 1 "; + + if (!input1.is_connected("changed", self, "on_input_changed")) { + input1.connect("changed", self, "on_input_changed"); +} + + + if (!input2) { + input2 = MMNodeUniversalProperty.new(); + input2.default_type = MMNodeUniversalProperty.DEFAULT_TYPE_VECTOR2; +} + + input2.input_slot_type = MMNodeUniversalProperty.SLOT_TYPE_UNIVERSAL; + // input2.input_slot_type = MMNodeUniversalProperty.SLOT_TYPE_VECTOR2; + input2.slot_name = ">>> Input 2 "; + + if (!input2.is_connected("changed", self, "on_input_changed")) { + input2.connect("changed", self, "on_input_changed"); +} + + + if (!output) { + output = MMNodeUniversalProperty.new(); + output.default_type = MMNodeUniversalProperty.DEFAULT_TYPE_VECTOR2; +} + + output.output_slot_type = MMNodeUniversalProperty.SLOT_TYPE_FLOAT; + output.slot_name = ">>> Output >>>"; + output.get_value_from_owner = true; + register_input_property(input1); + register_input_property(input2); + register_output_property(output); +} + + + void Sdf3dOpBool::_register_methods(const Variant &mm_graph_node) { + mm_graph_node.add_slot_label_universal(input1); + mm_graph_node.add_slot_label_universal(input2); + mm_graph_node.add_slot_label_universal(output); + mm_graph_node.add_slot_enum("get_operation", "set_operation", "Operation", [ "Union", "Substraction", "Intersection" ]); +} + + + Vector2 Sdf3dOpBool::_get_property_value_sdf3d(const Vector3 &uv3) { + Vector2 s1 = input1.get_value_sdf3d(uv3); + Vector2 s2 = input2.get_value_sdf3d(uv3); + + if (operation == 0) { + return MMAlgos.sdf3dc_union(s1, s2); +} + + + else if (operation == 1) { + return MMAlgos.sdf3dc_sub(s1, s2); +} + + + else if (operation == 2) { + return MMAlgos.sdf3dc_inter(s1, s2); +} + + return Vector2(); +} + + //operation; + + int Sdf3dOpBool::get_operation() { + return operation; +} + + + void Sdf3dOpBool::set_operation(const int val) { + operation = val; + emit_changed(); + output.emit_changed(); +} + + + void Sdf3dOpBool::on_input_changed() { + emit_changed(); + output.emit_changed(); +} + +} + + Sdf3dOpBool::Sdf3dOpBool() { + input1; + input2; + output; + operation = 0; + } + + Sdf3dOpBool::~Sdf3dOpBool() { + } + + + static void Sdf3dOpBool::_bind_methods() { + ClassDB::bind_method(D_METHOD("get_input1"), &Sdf3dOpBool::get_input1); + ClassDB::bind_method(D_METHOD("set_input1", "value"), &Sdf3dOpBool::set_input1); + ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "input1", PROPERTY_HINT_RESOURCE_TYPE, "Ref"), "set_input1", "get_input1"); + + + ClassDB::bind_method(D_METHOD("get_input2"), &Sdf3dOpBool::get_input2); + ClassDB::bind_method(D_METHOD("set_input2", "value"), &Sdf3dOpBool::set_input2); + ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "input2", PROPERTY_HINT_RESOURCE_TYPE, "Ref"), "set_input2", "get_input2"); + + + ClassDB::bind_method(D_METHOD("get_output"), &Sdf3dOpBool::get_output); + ClassDB::bind_method(D_METHOD("set_output", "value"), &Sdf3dOpBool::set_output); + ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "output", PROPERTY_HINT_RESOURCE_TYPE, "Ref"), "set_output", "get_output"); + + + ClassDB::bind_method(D_METHOD("get_operation"), &Sdf3dOpBool::get_operation); + ClassDB::bind_method(D_METHOD("set_operation", "value"), &Sdf3dOpBool::set_operation); + ADD_PROPERTY(PropertyInfo(Variant::INT, "operation"), "set_operation", "get_operation"); + + + ClassDB::bind_method(D_METHOD("_init_properties"), &Sdf3dOpBool::_init_properties); + ClassDB::bind_method(D_METHOD("_register_methods", "mm_graph_node"), &Sdf3dOpBool::_register_methods); + ClassDB::bind_method(D_METHOD("_get_property_value_sdf3d", "uv3"), &Sdf3dOpBool::_get_property_value_sdf3d); + ClassDB::bind_method(D_METHOD("get_operation"), &Sdf3dOpBool::get_operation); + ClassDB::bind_method(D_METHOD("set_operation", "val"), &Sdf3dOpBool::set_operation); + ClassDB::bind_method(D_METHOD("on_input_changed"), &Sdf3dOpBool::on_input_changed); + + } + + + diff --git a/modules/material_maker/nodes/sdf3d/sdf3d_op_bool.h b/modules/material_maker/nodes/sdf3d/sdf3d_op_bool.h new file mode 100644 index 000000000..b4b3f22a6 --- /dev/null +++ b/modules/material_maker/nodes/sdf3d/sdf3d_op_bool.h @@ -0,0 +1,48 @@ +#ifndef SDF3D_OP_BOOL_H +#define SDF3D_OP_BOOL_H + + +class Sdf3dOpBool : public MMNode { + GDCLASS(Sdf3dOpBool, MMNode); + + public: + + Ref get_input1(); + void set_input1(const Ref &val); + + Ref get_input2(); + void set_input2(const Ref &val); + + Ref get_output(); + void set_output(const Ref &val); + + int get_operation() const; + void set_operation(const int val); + + void _init_properties(); + void _register_methods(const Variant &mm_graph_node); + Vector2 _get_property_value_sdf3d(const Vector3 &uv3); + int get_operation(); + void set_operation(const int val); + void on_input_changed(); + + Sdf3dOpBool(); + ~Sdf3dOpBool(); + + protected: + static void _bind_methods(); + + //tool + //export(Resource) + Ref input1; + //export(Resource) + Ref input2; + //export(Resource) + Ref output; + //export(int, "Union,Substraction,Intersection") + int operation = 0; + //operation +}; + + +#endif diff --git a/modules/material_maker/nodes/sdf3d/sdf3d_op_circle_repeat.cpp b/modules/material_maker/nodes/sdf3d/sdf3d_op_circle_repeat.cpp new file mode 100644 index 000000000..bfe92a041 --- /dev/null +++ b/modules/material_maker/nodes/sdf3d/sdf3d_op_circle_repeat.cpp @@ -0,0 +1,140 @@ + +#include "sdf3d_op_circle_repeat.h" + + +Ref Sdf3dOpCircleRepeat::get_input() { + return input; +} + +void Sdf3dOpCircleRepeat::set_input(const Ref &val) { +input = val; +} + + +Ref Sdf3dOpCircleRepeat::get_output() { + return output; +} + +void Sdf3dOpCircleRepeat::set_output(const Ref &val) { +output = val; +} + + +int Sdf3dOpCircleRepeat::get_count() const { + return count; +} + +void Sdf3dOpCircleRepeat::set_count(const int val) { +count = val; +} + + + + //tool; + //export(Resource) ; + Ref input; + //export(Resource) ; + Ref output; + //export(int) ; + int count = 5; + + void Sdf3dOpCircleRepeat::_init_properties() { + + if (!input) { + input = MMNodeUniversalProperty.new(); + input.default_type = MMNodeUniversalProperty.DEFAULT_TYPE_VECTOR2; +} + + input.input_slot_type = MMNodeUniversalProperty.SLOT_TYPE_UNIVERSAL; + // input.input_slot_type = MMNodeUniversalProperty.SLOT_TYPE_VECTOR2; + input.slot_name = ">>> Input "; + + if (!input.is_connected("changed", self, "on_input_changed")) { + input.connect("changed", self, "on_input_changed"); +} + + + if (!output) { + output = MMNodeUniversalProperty.new(); + output.default_type = MMNodeUniversalProperty.DEFAULT_TYPE_VECTOR2; +} + + output.output_slot_type = MMNodeUniversalProperty.SLOT_TYPE_FLOAT; + output.slot_name = ">>> Output >>>"; + output.get_value_from_owner = true; + register_input_property(input); + register_output_property(output); +} + + + void Sdf3dOpCircleRepeat::_register_methods(const Variant &mm_graph_node) { + mm_graph_node.add_slot_label_universal(input); + mm_graph_node.add_slot_label_universal(output); + mm_graph_node.add_slot_int("get_count", "set_count", "Count"); +} + + + Vector2 Sdf3dOpCircleRepeat::_get_property_value_sdf3d(const Vector3 &uv3) { + //todo make seed a class variable probably into MMNode; + Vector3 new_uv = MMAlgos.circle_repeat_transform(uv3, count); + return input.get_value_sdf3d(new_uv); +} + + //count; + + int Sdf3dOpCircleRepeat::get_count() { + return count; +} + + + void Sdf3dOpCircleRepeat::set_count(const int val) { + count = val; + emit_changed(); + output.emit_changed(); +} + + + void Sdf3dOpCircleRepeat::on_input_changed() { + emit_changed(); + output.emit_changed(); +} + +} + + Sdf3dOpCircleRepeat::Sdf3dOpCircleRepeat() { + input; + output; + count = 5; + } + + Sdf3dOpCircleRepeat::~Sdf3dOpCircleRepeat() { + } + + + static void Sdf3dOpCircleRepeat::_bind_methods() { + ClassDB::bind_method(D_METHOD("get_input"), &Sdf3dOpCircleRepeat::get_input); + ClassDB::bind_method(D_METHOD("set_input", "value"), &Sdf3dOpCircleRepeat::set_input); + ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "input", PROPERTY_HINT_RESOURCE_TYPE, "Ref"), "set_input", "get_input"); + + + ClassDB::bind_method(D_METHOD("get_output"), &Sdf3dOpCircleRepeat::get_output); + ClassDB::bind_method(D_METHOD("set_output", "value"), &Sdf3dOpCircleRepeat::set_output); + ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "output", PROPERTY_HINT_RESOURCE_TYPE, "Ref"), "set_output", "get_output"); + + + ClassDB::bind_method(D_METHOD("get_count"), &Sdf3dOpCircleRepeat::get_count); + ClassDB::bind_method(D_METHOD("set_count", "value"), &Sdf3dOpCircleRepeat::set_count); + ADD_PROPERTY(PropertyInfo(Variant::INT, "count"), "set_count", "get_count"); + + + ClassDB::bind_method(D_METHOD("_init_properties"), &Sdf3dOpCircleRepeat::_init_properties); + ClassDB::bind_method(D_METHOD("_register_methods", "mm_graph_node"), &Sdf3dOpCircleRepeat::_register_methods); + ClassDB::bind_method(D_METHOD("_get_property_value_sdf3d", "uv3"), &Sdf3dOpCircleRepeat::_get_property_value_sdf3d); + ClassDB::bind_method(D_METHOD("get_count"), &Sdf3dOpCircleRepeat::get_count); + ClassDB::bind_method(D_METHOD("set_count", "val"), &Sdf3dOpCircleRepeat::set_count); + ClassDB::bind_method(D_METHOD("on_input_changed"), &Sdf3dOpCircleRepeat::on_input_changed); + + } + + + diff --git a/modules/material_maker/nodes/sdf3d/sdf3d_op_circle_repeat.h b/modules/material_maker/nodes/sdf3d/sdf3d_op_circle_repeat.h new file mode 100644 index 000000000..08e712d6a --- /dev/null +++ b/modules/material_maker/nodes/sdf3d/sdf3d_op_circle_repeat.h @@ -0,0 +1,43 @@ +#ifndef SDF3D_OP_CIRCLE_REPEAT_H +#define SDF3D_OP_CIRCLE_REPEAT_H + + +class Sdf3dOpCircleRepeat : public MMNode { + GDCLASS(Sdf3dOpCircleRepeat, MMNode); + + public: + + Ref get_input(); + void set_input(const Ref &val); + + Ref get_output(); + void set_output(const Ref &val); + + int get_count() const; + void set_count(const int val); + + void _init_properties(); + void _register_methods(const Variant &mm_graph_node); + Vector2 _get_property_value_sdf3d(const Vector3 &uv3); + int get_count(); + void set_count(const int val); + void on_input_changed(); + + Sdf3dOpCircleRepeat(); + ~Sdf3dOpCircleRepeat(); + + protected: + static void _bind_methods(); + + //tool + //export(Resource) + Ref input; + //export(Resource) + Ref output; + //export(int) + int count = 5; + //count +}; + + +#endif diff --git a/modules/material_maker/nodes/sdf3d/sdf3d_op_elongation.cpp b/modules/material_maker/nodes/sdf3d/sdf3d_op_elongation.cpp new file mode 100644 index 000000000..37f34384f --- /dev/null +++ b/modules/material_maker/nodes/sdf3d/sdf3d_op_elongation.cpp @@ -0,0 +1,140 @@ + +#include "sdf3d_op_elongation.h" + + +Ref Sdf3dOpElongation::get_input() { + return input; +} + +void Sdf3dOpElongation::set_input(const Ref &val) { +input = val; +} + + +Ref Sdf3dOpElongation::get_output() { + return output; +} + +void Sdf3dOpElongation::set_output(const Ref &val) { +output = val; +} + + +Vector3 Sdf3dOpElongation::get_length() { + return length; +} + +void Sdf3dOpElongation::set_length(const Vector3 &val) { +length = val; +} + + + + //tool; + //export(Resource) ; + Ref input; + //export(Resource) ; + Ref output; + //export(Vector3) ; + Vector3 length = Vector3(0.2, 0, 0); + + void Sdf3dOpElongation::_init_properties() { + + if (!input) { + input = MMNodeUniversalProperty.new(); + input.default_type = MMNodeUniversalProperty.DEFAULT_TYPE_VECTOR2; +} + + input.input_slot_type = MMNodeUniversalProperty.SLOT_TYPE_UNIVERSAL; + // input.input_slot_type = MMNodeUniversalProperty.SLOT_TYPE_VECTOR2; + input.slot_name = ">>> Input "; + + if (!input.is_connected("changed", self, "on_input_changed")) { + input.connect("changed", self, "on_input_changed"); +} + + + if (!output) { + output = MMNodeUniversalProperty.new(); + output.default_type = MMNodeUniversalProperty.DEFAULT_TYPE_VECTOR2; +} + + output.output_slot_type = MMNodeUniversalProperty.SLOT_TYPE_FLOAT; + output.slot_name = ">>> Output >>>"; + output.get_value_from_owner = true; + register_input_property(input); + register_output_property(output); +} + + + void Sdf3dOpElongation::_register_methods(const Variant &mm_graph_node) { + mm_graph_node.add_slot_label_universal(input); + mm_graph_node.add_slot_label_universal(output); + mm_graph_node.add_slot_vector3("get_length", "set_length", "Length", 0.01); +} + + + Vector2 Sdf3dOpElongation::_get_property_value_sdf3d(const Vector3 &uv3) { + //$in($uv - clamp($uv, -abs(vec3($x, $y, $z)), abs(vec3($x, $y, $z)))); + Vector3 new_uv = uv3 - MMAlgos.clampv3(uv3, -MMAlgos.absv3(length), MMAlgos.absv3(length)); + return input.get_value_sdf3d(new_uv); +} + + //length; + + Vector3 Sdf3dOpElongation::get_length() { + return length; +} + + + void Sdf3dOpElongation::set_length(const Vector3 &val) { + length = val; + emit_changed(); + output.emit_changed(); +} + + + void Sdf3dOpElongation::on_input_changed() { + emit_changed(); + output.emit_changed(); +} + +} + + Sdf3dOpElongation::Sdf3dOpElongation() { + input; + output; + length = Vector3(0.2, 0, 0); + } + + Sdf3dOpElongation::~Sdf3dOpElongation() { + } + + + static void Sdf3dOpElongation::_bind_methods() { + ClassDB::bind_method(D_METHOD("get_input"), &Sdf3dOpElongation::get_input); + ClassDB::bind_method(D_METHOD("set_input", "value"), &Sdf3dOpElongation::set_input); + ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "input", PROPERTY_HINT_RESOURCE_TYPE, "Ref"), "set_input", "get_input"); + + + ClassDB::bind_method(D_METHOD("get_output"), &Sdf3dOpElongation::get_output); + ClassDB::bind_method(D_METHOD("set_output", "value"), &Sdf3dOpElongation::set_output); + ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "output", PROPERTY_HINT_RESOURCE_TYPE, "Ref"), "set_output", "get_output"); + + + ClassDB::bind_method(D_METHOD("get_length"), &Sdf3dOpElongation::get_length); + ClassDB::bind_method(D_METHOD("set_length", "value"), &Sdf3dOpElongation::set_length); + ADD_PROPERTY(PropertyInfo(Variant::VECTOR3, "length"), "set_length", "get_length"); + + + ClassDB::bind_method(D_METHOD("_init_properties"), &Sdf3dOpElongation::_init_properties); + ClassDB::bind_method(D_METHOD("_register_methods", "mm_graph_node"), &Sdf3dOpElongation::_register_methods); + ClassDB::bind_method(D_METHOD("_get_property_value_sdf3d", "uv3"), &Sdf3dOpElongation::_get_property_value_sdf3d); + ClassDB::bind_method(D_METHOD("get_length"), &Sdf3dOpElongation::get_length); + ClassDB::bind_method(D_METHOD("set_length", "val"), &Sdf3dOpElongation::set_length); + ClassDB::bind_method(D_METHOD("on_input_changed"), &Sdf3dOpElongation::on_input_changed); + + } + + + diff --git a/modules/material_maker/nodes/sdf3d/sdf3d_op_elongation.h b/modules/material_maker/nodes/sdf3d/sdf3d_op_elongation.h new file mode 100644 index 000000000..aa011cbef --- /dev/null +++ b/modules/material_maker/nodes/sdf3d/sdf3d_op_elongation.h @@ -0,0 +1,43 @@ +#ifndef SDF3D_OP_ELONGATION_H +#define SDF3D_OP_ELONGATION_H + + +class Sdf3dOpElongation : public MMNode { + GDCLASS(Sdf3dOpElongation, MMNode); + + public: + + Ref get_input(); + void set_input(const Ref &val); + + Ref get_output(); + void set_output(const Ref &val); + + Vector3 get_length(); + void set_length(const Vector3 &val); + + void _init_properties(); + void _register_methods(const Variant &mm_graph_node); + Vector2 _get_property_value_sdf3d(const Vector3 &uv3); + Vector3 get_length(); + void set_length(const Vector3 &val); + void on_input_changed(); + + Sdf3dOpElongation(); + ~Sdf3dOpElongation(); + + protected: + static void _bind_methods(); + + //tool + //export(Resource) + Ref input; + //export(Resource) + Ref output; + //export(Vector3) + Vector3 length = Vector3(0.2, 0, 0); + //length +}; + + +#endif diff --git a/modules/material_maker/nodes/sdf3d/sdf3d_op_extrusion.cpp b/modules/material_maker/nodes/sdf3d/sdf3d_op_extrusion.cpp new file mode 100644 index 000000000..b618c2f4f --- /dev/null +++ b/modules/material_maker/nodes/sdf3d/sdf3d_op_extrusion.cpp @@ -0,0 +1,143 @@ + +#include "sdf3d_op_extrusion.h" + + +Ref Sdf3dOpExtrusion::get_input() { + return input; +} + +void Sdf3dOpExtrusion::set_input(const Ref &val) { +input = val; +} + + +Ref Sdf3dOpExtrusion::get_output() { + return output; +} + +void Sdf3dOpExtrusion::set_output(const Ref &val) { +output = val; +} + + +float Sdf3dOpExtrusion::get_length() const { + return length; +} + +void Sdf3dOpExtrusion::set_length(const float val) { +length = val; +} + + + + //tool; + //export(Resource) ; + Ref input; + //export(Resource) ; + Ref output; + //export(float) ; + float length = 0.25; + + void Sdf3dOpExtrusion::_init_properties() { + + if (!input) { + input = MMNodeUniversalProperty.new(); + input.default_type = MMNodeUniversalProperty.DEFAULT_TYPE_FLOAT; +} + + input.input_slot_type = MMNodeUniversalProperty.SLOT_TYPE_UNIVERSAL; + // input.input_slot_type = MMNodeUniversalProperty.SLOT_TYPE_FLOAT; + input.slot_name = ">>> Input "; + + if (!input.is_connected("changed", self, "on_input_changed")) { + input.connect("changed", self, "on_input_changed"); +} + + + if (!output) { + output = MMNodeUniversalProperty.new(); + output.default_type = MMNodeUniversalProperty.DEFAULT_TYPE_VECTOR2; +} + + output.output_slot_type = MMNodeUniversalProperty.SLOT_TYPE_FLOAT; + output.slot_name = ">>> Output >>>"; + output.get_value_from_owner = true; + register_input_property(input); + register_output_property(output); +} + + + void Sdf3dOpExtrusion::_register_methods(const Variant &mm_graph_node) { + mm_graph_node.add_slot_label_universal(input); + mm_graph_node.add_slot_label_universal(output); + mm_graph_node.add_slot_float("get_length", "set_length", "Length", 0.01); +} + + + Vector2 Sdf3dOpExtrusion::_get_property_value_sdf3d(const Vector3 &uv3) { + //vec2 $(name_uv)_w = vec2($in($uv.xz+vec2(0.5)),abs($uv.y)-$d); + //ret min(max($(name_uv)_w.x,$(name_uv)_w.y),0.0)+length(max($(name_uv)_w,0.0)); + float f = input.get_value(Vector2(uv3.x, uv3.z) + Vector2(0.5, 0.5)); + Vector2 w = Vector2(f, abs(uv3.y) - length); + float ff = min(max(w.x,w.y),0.0) + MMAlgos.maxv2(w, Vector2()).length(); + return Vector2(ff, 0); +} + + //length; + + float Sdf3dOpExtrusion::get_length() { + return length; +} + + + void Sdf3dOpExtrusion::set_length(const float val) { + length = val; + emit_changed(); + output.emit_changed(); +} + + + void Sdf3dOpExtrusion::on_input_changed() { + emit_changed(); + output.emit_changed(); +} + +} + + Sdf3dOpExtrusion::Sdf3dOpExtrusion() { + input; + output; + length = 0.25; + } + + Sdf3dOpExtrusion::~Sdf3dOpExtrusion() { + } + + + static void Sdf3dOpExtrusion::_bind_methods() { + ClassDB::bind_method(D_METHOD("get_input"), &Sdf3dOpExtrusion::get_input); + ClassDB::bind_method(D_METHOD("set_input", "value"), &Sdf3dOpExtrusion::set_input); + ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "input", PROPERTY_HINT_RESOURCE_TYPE, "Ref"), "set_input", "get_input"); + + + ClassDB::bind_method(D_METHOD("get_output"), &Sdf3dOpExtrusion::get_output); + ClassDB::bind_method(D_METHOD("set_output", "value"), &Sdf3dOpExtrusion::set_output); + ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "output", PROPERTY_HINT_RESOURCE_TYPE, "Ref"), "set_output", "get_output"); + + + ClassDB::bind_method(D_METHOD("get_length"), &Sdf3dOpExtrusion::get_length); + ClassDB::bind_method(D_METHOD("set_length", "value"), &Sdf3dOpExtrusion::set_length); + ADD_PROPERTY(PropertyInfo(Variant::REAL, "length"), "set_length", "get_length"); + + + ClassDB::bind_method(D_METHOD("_init_properties"), &Sdf3dOpExtrusion::_init_properties); + ClassDB::bind_method(D_METHOD("_register_methods", "mm_graph_node"), &Sdf3dOpExtrusion::_register_methods); + ClassDB::bind_method(D_METHOD("_get_property_value_sdf3d", "uv3"), &Sdf3dOpExtrusion::_get_property_value_sdf3d); + ClassDB::bind_method(D_METHOD("get_length"), &Sdf3dOpExtrusion::get_length); + ClassDB::bind_method(D_METHOD("set_length", "val"), &Sdf3dOpExtrusion::set_length); + ClassDB::bind_method(D_METHOD("on_input_changed"), &Sdf3dOpExtrusion::on_input_changed); + + } + + + diff --git a/modules/material_maker/nodes/sdf3d/sdf3d_op_extrusion.h b/modules/material_maker/nodes/sdf3d/sdf3d_op_extrusion.h new file mode 100644 index 000000000..157392d8d --- /dev/null +++ b/modules/material_maker/nodes/sdf3d/sdf3d_op_extrusion.h @@ -0,0 +1,43 @@ +#ifndef SDF3D_OP_EXTRUSION_H +#define SDF3D_OP_EXTRUSION_H + + +class Sdf3dOpExtrusion : public MMNode { + GDCLASS(Sdf3dOpExtrusion, MMNode); + + public: + + Ref get_input(); + void set_input(const Ref &val); + + Ref get_output(); + void set_output(const Ref &val); + + float get_length() const; + void set_length(const float val); + + void _init_properties(); + void _register_methods(const Variant &mm_graph_node); + Vector2 _get_property_value_sdf3d(const Vector3 &uv3); + float get_length(); + void set_length(const float val); + void on_input_changed(); + + Sdf3dOpExtrusion(); + ~Sdf3dOpExtrusion(); + + protected: + static void _bind_methods(); + + //tool + //export(Resource) + Ref input; + //export(Resource) + Ref output; + //export(float) + float length = 0.25; + //length +}; + + +#endif diff --git a/modules/material_maker/nodes/sdf3d/sdf3d_op_morph.cpp b/modules/material_maker/nodes/sdf3d/sdf3d_op_morph.cpp new file mode 100644 index 000000000..d61bbfcaa --- /dev/null +++ b/modules/material_maker/nodes/sdf3d/sdf3d_op_morph.cpp @@ -0,0 +1,174 @@ + +#include "sdf3d_op_morph.h" + + +Ref Sdf3dOpMorph::get_input1() { + return input1; +} + +void Sdf3dOpMorph::set_input1(const Ref &val) { +input1 = val; +} + + +Ref Sdf3dOpMorph::get_input2() { + return input2; +} + +void Sdf3dOpMorph::set_input2(const Ref &val) { +input2 = val; +} + + +Ref Sdf3dOpMorph::get_output() { + return output; +} + +void Sdf3dOpMorph::set_output(const Ref &val) { +output = val; +} + + +float Sdf3dOpMorph::get_amount() const { + return amount; +} + +void Sdf3dOpMorph::set_amount(const float val) { +amount = val; +} + + + + //tool; + //export(Resource) ; + Ref input1; + //export(Resource) ; + Ref input2; + //export(Resource) ; + Ref output; + //export(float) ; + float amount = 0.5; + + void Sdf3dOpMorph::_init_properties() { + + if (!input1) { + input1 = MMNodeUniversalProperty.new(); + input1.default_type = MMNodeUniversalProperty.DEFAULT_TYPE_VECTOR2; +} + + input1.input_slot_type = MMNodeUniversalProperty.SLOT_TYPE_UNIVERSAL; + // input1.input_slot_type = MMNodeUniversalProperty.SLOT_TYPE_VECTOR2; + input1.slot_name = ">>> Input 1 "; + + if (!input1.is_connected("changed", self, "on_input_changed")) { + input1.connect("changed", self, "on_input_changed"); +} + + + if (!input2) { + input2 = MMNodeUniversalProperty.new(); + input2.default_type = MMNodeUniversalProperty.DEFAULT_TYPE_VECTOR2; +} + + input2.input_slot_type = MMNodeUniversalProperty.SLOT_TYPE_UNIVERSAL; + // input2.input_slot_type = MMNodeUniversalProperty.SLOT_TYPE_VECTOR2; + input2.slot_name = ">>> Input 2 "; + + if (!input2.is_connected("changed", self, "on_input_changed")) { + input2.connect("changed", self, "on_input_changed"); +} + + + if (!output) { + output = MMNodeUniversalProperty.new(); + output.default_type = MMNodeUniversalProperty.DEFAULT_TYPE_VECTOR2; +} + + output.output_slot_type = MMNodeUniversalProperty.SLOT_TYPE_FLOAT; + output.slot_name = ">>> Output >>>"; + output.get_value_from_owner = true; + register_input_property(input1); + register_input_property(input2); + register_output_property(output); +} + + + void Sdf3dOpMorph::_register_methods(const Variant &mm_graph_node) { + mm_graph_node.add_slot_label_universal(input1); + mm_graph_node.add_slot_label_universal(input2); + mm_graph_node.add_slot_label_universal(output); + mm_graph_node.add_slot_float("get_amount", "set_amount", "Amount", 0.01); +} + + + Vector2 Sdf3dOpMorph::_get_property_value_sdf3d(const Vector3 &uv3) { + Vector2 s1 = input1.get_value_sdf3d(uv3); + Vector2 s2 = input2.get_value_sdf3d(uv3); + //mix($in1($uv), $in2($uv), $amount); + return lerp(s1, s2, amount); +} + + //amount; + + float Sdf3dOpMorph::get_amount() { + return amount; +} + + + void Sdf3dOpMorph::set_amount(const float val) { + amount = val; + emit_changed(); + output.emit_changed(); +} + + + void Sdf3dOpMorph::on_input_changed() { + emit_changed(); + output.emit_changed(); +} + +} + + Sdf3dOpMorph::Sdf3dOpMorph() { + input1; + input2; + output; + amount = 0.5; + } + + Sdf3dOpMorph::~Sdf3dOpMorph() { + } + + + static void Sdf3dOpMorph::_bind_methods() { + ClassDB::bind_method(D_METHOD("get_input1"), &Sdf3dOpMorph::get_input1); + ClassDB::bind_method(D_METHOD("set_input1", "value"), &Sdf3dOpMorph::set_input1); + ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "input1", PROPERTY_HINT_RESOURCE_TYPE, "Ref"), "set_input1", "get_input1"); + + + ClassDB::bind_method(D_METHOD("get_input2"), &Sdf3dOpMorph::get_input2); + ClassDB::bind_method(D_METHOD("set_input2", "value"), &Sdf3dOpMorph::set_input2); + ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "input2", PROPERTY_HINT_RESOURCE_TYPE, "Ref"), "set_input2", "get_input2"); + + + ClassDB::bind_method(D_METHOD("get_output"), &Sdf3dOpMorph::get_output); + ClassDB::bind_method(D_METHOD("set_output", "value"), &Sdf3dOpMorph::set_output); + ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "output", PROPERTY_HINT_RESOURCE_TYPE, "Ref"), "set_output", "get_output"); + + + ClassDB::bind_method(D_METHOD("get_amount"), &Sdf3dOpMorph::get_amount); + ClassDB::bind_method(D_METHOD("set_amount", "value"), &Sdf3dOpMorph::set_amount); + ADD_PROPERTY(PropertyInfo(Variant::REAL, "amount"), "set_amount", "get_amount"); + + + ClassDB::bind_method(D_METHOD("_init_properties"), &Sdf3dOpMorph::_init_properties); + ClassDB::bind_method(D_METHOD("_register_methods", "mm_graph_node"), &Sdf3dOpMorph::_register_methods); + ClassDB::bind_method(D_METHOD("_get_property_value_sdf3d", "uv3"), &Sdf3dOpMorph::_get_property_value_sdf3d); + ClassDB::bind_method(D_METHOD("get_amount"), &Sdf3dOpMorph::get_amount); + ClassDB::bind_method(D_METHOD("set_amount", "val"), &Sdf3dOpMorph::set_amount); + ClassDB::bind_method(D_METHOD("on_input_changed"), &Sdf3dOpMorph::on_input_changed); + + } + + + diff --git a/modules/material_maker/nodes/sdf3d/sdf3d_op_morph.h b/modules/material_maker/nodes/sdf3d/sdf3d_op_morph.h new file mode 100644 index 000000000..7d79a5ffc --- /dev/null +++ b/modules/material_maker/nodes/sdf3d/sdf3d_op_morph.h @@ -0,0 +1,48 @@ +#ifndef SDF3D_OP_MORPH_H +#define SDF3D_OP_MORPH_H + + +class Sdf3dOpMorph : public MMNode { + GDCLASS(Sdf3dOpMorph, MMNode); + + public: + + Ref get_input1(); + void set_input1(const Ref &val); + + Ref get_input2(); + void set_input2(const Ref &val); + + Ref get_output(); + void set_output(const Ref &val); + + float get_amount() const; + void set_amount(const float val); + + void _init_properties(); + void _register_methods(const Variant &mm_graph_node); + Vector2 _get_property_value_sdf3d(const Vector3 &uv3); + float get_amount(); + void set_amount(const float val); + void on_input_changed(); + + Sdf3dOpMorph(); + ~Sdf3dOpMorph(); + + protected: + static void _bind_methods(); + + //tool + //export(Resource) + Ref input1; + //export(Resource) + Ref input2; + //export(Resource) + Ref output; + //export(float) + float amount = 0.5; + //amount +}; + + +#endif diff --git a/modules/material_maker/nodes/sdf3d/sdf3d_op_repeat.cpp b/modules/material_maker/nodes/sdf3d/sdf3d_op_repeat.cpp new file mode 100644 index 000000000..195e972fe --- /dev/null +++ b/modules/material_maker/nodes/sdf3d/sdf3d_op_repeat.cpp @@ -0,0 +1,173 @@ + +#include "sdf3d_op_repeat.h" + + +Ref Sdf3dOpRepeat::get_input() { + return input; +} + +void Sdf3dOpRepeat::set_input(const Ref &val) { +input = val; +} + + +Ref Sdf3dOpRepeat::get_output() { + return output; +} + +void Sdf3dOpRepeat::set_output(const Ref &val) { +output = val; +} + + +Vector2 Sdf3dOpRepeat::get_col_row() { + return col_row; +} + +void Sdf3dOpRepeat::set_col_row(const Vector2 &val) { +col_row = val; +} + + +float Sdf3dOpRepeat::get_rotation() const { + return rotation; +} + +void Sdf3dOpRepeat::set_rotation(const float val) { +rotation = val; +} + + + + //tool; + //export(Resource) ; + Ref input; + //export(Resource) ; + Ref output; + //export(Vector2) ; + Vector2 col_row = Vector2(3, 3); + //export(float) ; + float rotation = 0.3; + + void Sdf3dOpRepeat::_init_properties() { + + if (!input) { + input = MMNodeUniversalProperty.new(); + input.default_type = MMNodeUniversalProperty.DEFAULT_TYPE_VECTOR2; +} + + input.input_slot_type = MMNodeUniversalProperty.SLOT_TYPE_UNIVERSAL; + // input.input_slot_type = MMNodeUniversalProperty.SLOT_TYPE_VECTOR2; + input.slot_name = ">>> Input "; + + if (!input.is_connected("changed", self, "on_input_changed")) { + input.connect("changed", self, "on_input_changed"); +} + + + if (!output) { + output = MMNodeUniversalProperty.new(); + output.default_type = MMNodeUniversalProperty.DEFAULT_TYPE_VECTOR2; +} + + output.output_slot_type = MMNodeUniversalProperty.SLOT_TYPE_FLOAT; + output.slot_name = ">>> Output >>>"; + output.get_value_from_owner = true; + register_input_property(input); + register_output_property(output); +} + + + void Sdf3dOpRepeat::_register_methods(const Variant &mm_graph_node) { + mm_graph_node.add_slot_label_universal(input); + mm_graph_node.add_slot_label_universal(output); + mm_graph_node.add_slot_vector2("get_col_row", "set_col_row", "Col,Row", 1); + mm_graph_node.add_slot_float("get_rotation", "set_rotation", "Rotation", 0.01); +} + + + Vector2 Sdf3dOpRepeat::_get_property_value_sdf3d(const Vector3 &uv3) { + //todo make seed a class variable probably into MMNode; + Vector3 new_uv = MMAlgos.sdf3d_repeat(uv3, col_row, rotation, 1); + return input.get_value_sdf3d(new_uv); +} + + //col_row; + + Vector2 Sdf3dOpRepeat::get_col_row() { + return col_row; +} + + + void Sdf3dOpRepeat::set_col_row(const Vector2 &val) { + col_row = val; + emit_changed(); + output.emit_changed(); +} + + //rotation; + + float Sdf3dOpRepeat::get_rotation() { + return rotation; +} + + + void Sdf3dOpRepeat::set_rotation(const float val) { + rotation = val; + emit_changed(); + output.emit_changed(); +} + + + void Sdf3dOpRepeat::on_input_changed() { + emit_changed(); + output.emit_changed(); +} + +} + + Sdf3dOpRepeat::Sdf3dOpRepeat() { + input; + output; + col_row = Vector2(3, 3); + rotation = 0.3; + } + + Sdf3dOpRepeat::~Sdf3dOpRepeat() { + } + + + static void Sdf3dOpRepeat::_bind_methods() { + ClassDB::bind_method(D_METHOD("get_input"), &Sdf3dOpRepeat::get_input); + ClassDB::bind_method(D_METHOD("set_input", "value"), &Sdf3dOpRepeat::set_input); + ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "input", PROPERTY_HINT_RESOURCE_TYPE, "Ref"), "set_input", "get_input"); + + + ClassDB::bind_method(D_METHOD("get_output"), &Sdf3dOpRepeat::get_output); + ClassDB::bind_method(D_METHOD("set_output", "value"), &Sdf3dOpRepeat::set_output); + ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "output", PROPERTY_HINT_RESOURCE_TYPE, "Ref"), "set_output", "get_output"); + + + ClassDB::bind_method(D_METHOD("get_col_row"), &Sdf3dOpRepeat::get_col_row); + ClassDB::bind_method(D_METHOD("set_col_row", "value"), &Sdf3dOpRepeat::set_col_row); + ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "col_row"), "set_col_row", "get_col_row"); + + + ClassDB::bind_method(D_METHOD("get_rotation"), &Sdf3dOpRepeat::get_rotation); + ClassDB::bind_method(D_METHOD("set_rotation", "value"), &Sdf3dOpRepeat::set_rotation); + ADD_PROPERTY(PropertyInfo(Variant::REAL, "rotation"), "set_rotation", "get_rotation"); + + + ClassDB::bind_method(D_METHOD("_init_properties"), &Sdf3dOpRepeat::_init_properties); + ClassDB::bind_method(D_METHOD("_register_methods", "mm_graph_node"), &Sdf3dOpRepeat::_register_methods); + ClassDB::bind_method(D_METHOD("_get_property_value_sdf3d", "uv3"), &Sdf3dOpRepeat::_get_property_value_sdf3d); + ClassDB::bind_method(D_METHOD("get_col_row"), &Sdf3dOpRepeat::get_col_row); + ClassDB::bind_method(D_METHOD("set_col_row", "val"), &Sdf3dOpRepeat::set_col_row); + ClassDB::bind_method(D_METHOD("get_rotation"), &Sdf3dOpRepeat::get_rotation); + ClassDB::bind_method(D_METHOD("set_rotation", "val"), &Sdf3dOpRepeat::set_rotation); + ClassDB::bind_method(D_METHOD("on_input_changed"), &Sdf3dOpRepeat::on_input_changed); + + } + + + diff --git a/modules/material_maker/nodes/sdf3d/sdf3d_op_repeat.h b/modules/material_maker/nodes/sdf3d/sdf3d_op_repeat.h new file mode 100644 index 000000000..15dee14e7 --- /dev/null +++ b/modules/material_maker/nodes/sdf3d/sdf3d_op_repeat.h @@ -0,0 +1,51 @@ +#ifndef SDF3D_OP_REPEAT_H +#define SDF3D_OP_REPEAT_H + + +class Sdf3dOpRepeat : public MMNode { + GDCLASS(Sdf3dOpRepeat, MMNode); + + public: + + Ref get_input(); + void set_input(const Ref &val); + + Ref get_output(); + void set_output(const Ref &val); + + Vector2 get_col_row(); + void set_col_row(const Vector2 &val); + + float get_rotation() const; + void set_rotation(const float val); + + void _init_properties(); + void _register_methods(const Variant &mm_graph_node); + Vector2 _get_property_value_sdf3d(const Vector3 &uv3); + Vector2 get_col_row(); + void set_col_row(const Vector2 &val); + float get_rotation(); + void set_rotation(const float val); + void on_input_changed(); + + Sdf3dOpRepeat(); + ~Sdf3dOpRepeat(); + + protected: + static void _bind_methods(); + + //tool + //export(Resource) + Ref input; + //export(Resource) + Ref output; + //export(Vector2) + Vector2 col_row = Vector2(3, 3); + //export(float) + float rotation = 0.3; + //col_row + //rotation +}; + + +#endif diff --git a/modules/material_maker/nodes/sdf3d/sdf3d_op_revolution.cpp b/modules/material_maker/nodes/sdf3d/sdf3d_op_revolution.cpp new file mode 100644 index 000000000..bf341151b --- /dev/null +++ b/modules/material_maker/nodes/sdf3d/sdf3d_op_revolution.cpp @@ -0,0 +1,141 @@ + +#include "sdf3d_op_revolution.h" + + +Ref Sdf3dOpRevolution::get_input() { + return input; +} + +void Sdf3dOpRevolution::set_input(const Ref &val) { +input = val; +} + + +Ref Sdf3dOpRevolution::get_output() { + return output; +} + +void Sdf3dOpRevolution::set_output(const Ref &val) { +output = val; +} + + +float Sdf3dOpRevolution::get_offset() const { + return offset; +} + +void Sdf3dOpRevolution::set_offset(const float val) { +offset = val; +} + + + + //tool; + //export(Resource) ; + Ref input; + //export(Resource) ; + Ref output; + //export(float) ; + float offset = 0.25; + + void Sdf3dOpRevolution::_init_properties() { + + if (!input) { + input = MMNodeUniversalProperty.new(); + input.default_type = MMNodeUniversalProperty.DEFAULT_TYPE_FLOAT; +} + + input.input_slot_type = MMNodeUniversalProperty.SLOT_TYPE_UNIVERSAL; + // input.input_slot_type = MMNodeUniversalProperty.SLOT_TYPE_FLOAT; + input.slot_name = ">>> Input "; + + if (!input.is_connected("changed", self, "on_input_changed")) { + input.connect("changed", self, "on_input_changed"); +} + + + if (!output) { + output = MMNodeUniversalProperty.new(); + output.default_type = MMNodeUniversalProperty.DEFAULT_TYPE_VECTOR2; +} + + output.output_slot_type = MMNodeUniversalProperty.SLOT_TYPE_FLOAT; + output.slot_name = ">>> Output >>>"; + output.get_value_from_owner = true; + register_input_property(input); + register_output_property(output); +} + + + void Sdf3dOpRevolution::_register_methods(const Variant &mm_graph_node) { + mm_graph_node.add_slot_label_universal(input); + mm_graph_node.add_slot_label_universal(output); + mm_graph_node.add_slot_float("get_offset", "set_offset", "Offset", 0.01); +} + + + Vector2 Sdf3dOpRevolution::_get_property_value_sdf3d(const Vector3 &uv3) { + //vec2 $(name_uv)_q = vec2(length($uv.xy) - $d + 0.5, $uv.z + 0.5); + Vector2 uv = Vector2(Vector2(uv3.x, uv3.y).length() - offset + 0.5, uv3.z + 0.5); + float f = input.get_value(uv); + return Vector2(f, 0); +} + + //offset; + + float Sdf3dOpRevolution::get_offset() { + return offset; +} + + + void Sdf3dOpRevolution::set_offset(const float val) { + offset = val; + emit_changed(); + output.emit_changed(); +} + + + void Sdf3dOpRevolution::on_input_changed() { + emit_changed(); + output.emit_changed(); +} + +} + + Sdf3dOpRevolution::Sdf3dOpRevolution() { + input; + output; + offset = 0.25; + } + + Sdf3dOpRevolution::~Sdf3dOpRevolution() { + } + + + static void Sdf3dOpRevolution::_bind_methods() { + ClassDB::bind_method(D_METHOD("get_input"), &Sdf3dOpRevolution::get_input); + ClassDB::bind_method(D_METHOD("set_input", "value"), &Sdf3dOpRevolution::set_input); + ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "input", PROPERTY_HINT_RESOURCE_TYPE, "Ref"), "set_input", "get_input"); + + + ClassDB::bind_method(D_METHOD("get_output"), &Sdf3dOpRevolution::get_output); + ClassDB::bind_method(D_METHOD("set_output", "value"), &Sdf3dOpRevolution::set_output); + ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "output", PROPERTY_HINT_RESOURCE_TYPE, "Ref"), "set_output", "get_output"); + + + ClassDB::bind_method(D_METHOD("get_offset"), &Sdf3dOpRevolution::get_offset); + ClassDB::bind_method(D_METHOD("set_offset", "value"), &Sdf3dOpRevolution::set_offset); + ADD_PROPERTY(PropertyInfo(Variant::REAL, "offset"), "set_offset", "get_offset"); + + + ClassDB::bind_method(D_METHOD("_init_properties"), &Sdf3dOpRevolution::_init_properties); + ClassDB::bind_method(D_METHOD("_register_methods", "mm_graph_node"), &Sdf3dOpRevolution::_register_methods); + ClassDB::bind_method(D_METHOD("_get_property_value_sdf3d", "uv3"), &Sdf3dOpRevolution::_get_property_value_sdf3d); + ClassDB::bind_method(D_METHOD("get_offset"), &Sdf3dOpRevolution::get_offset); + ClassDB::bind_method(D_METHOD("set_offset", "val"), &Sdf3dOpRevolution::set_offset); + ClassDB::bind_method(D_METHOD("on_input_changed"), &Sdf3dOpRevolution::on_input_changed); + + } + + + diff --git a/modules/material_maker/nodes/sdf3d/sdf3d_op_revolution.h b/modules/material_maker/nodes/sdf3d/sdf3d_op_revolution.h new file mode 100644 index 000000000..dd6db4a7f --- /dev/null +++ b/modules/material_maker/nodes/sdf3d/sdf3d_op_revolution.h @@ -0,0 +1,43 @@ +#ifndef SDF3D_OP_REVOLUTION_H +#define SDF3D_OP_REVOLUTION_H + + +class Sdf3dOpRevolution : public MMNode { + GDCLASS(Sdf3dOpRevolution, MMNode); + + public: + + Ref get_input(); + void set_input(const Ref &val); + + Ref get_output(); + void set_output(const Ref &val); + + float get_offset() const; + void set_offset(const float val); + + void _init_properties(); + void _register_methods(const Variant &mm_graph_node); + Vector2 _get_property_value_sdf3d(const Vector3 &uv3); + float get_offset(); + void set_offset(const float val); + void on_input_changed(); + + Sdf3dOpRevolution(); + ~Sdf3dOpRevolution(); + + protected: + static void _bind_methods(); + + //tool + //export(Resource) + Ref input; + //export(Resource) + Ref output; + //export(float) + float offset = 0.25; + //offset +}; + + +#endif diff --git a/modules/material_maker/nodes/sdf3d/sdf3d_op_rounded.cpp b/modules/material_maker/nodes/sdf3d/sdf3d_op_rounded.cpp new file mode 100644 index 000000000..c24f7e9db --- /dev/null +++ b/modules/material_maker/nodes/sdf3d/sdf3d_op_rounded.cpp @@ -0,0 +1,141 @@ + +#include "sdf3d_op_rounded.h" + + +Ref Sdf3dOpRounded::get_input() { + return input; +} + +void Sdf3dOpRounded::set_input(const Ref &val) { +input = val; +} + + +Ref Sdf3dOpRounded::get_output() { + return output; +} + +void Sdf3dOpRounded::set_output(const Ref &val) { +output = val; +} + + +float Sdf3dOpRounded::get_radius() const { + return radius; +} + +void Sdf3dOpRounded::set_radius(const float val) { +radius = val; +} + + + + //tool; + //export(Resource) ; + Ref input; + //export(Resource) ; + Ref output; + //export(float) ; + float radius = 0.15; + + void Sdf3dOpRounded::_init_properties() { + + if (!input) { + input = MMNodeUniversalProperty.new(); + input.default_type = MMNodeUniversalProperty.DEFAULT_TYPE_VECTOR2; +} + + input.input_slot_type = MMNodeUniversalProperty.SLOT_TYPE_UNIVERSAL; + // input.input_slot_type = MMNodeUniversalProperty.SLOT_TYPE_VECTOR2; + input.slot_name = ">>> Input "; + + if (!input.is_connected("changed", self, "on_input_changed")) { + input.connect("changed", self, "on_input_changed"); +} + + + if (!output) { + output = MMNodeUniversalProperty.new(); + output.default_type = MMNodeUniversalProperty.DEFAULT_TYPE_VECTOR2; +} + + output.output_slot_type = MMNodeUniversalProperty.SLOT_TYPE_FLOAT; + output.slot_name = ">>> Output >>>"; + output.get_value_from_owner = true; + register_input_property(input); + register_output_property(output); +} + + + void Sdf3dOpRounded::_register_methods(const Variant &mm_graph_node) { + mm_graph_node.add_slot_label_universal(input); + mm_graph_node.add_slot_label_universal(output); + mm_graph_node.add_slot_float("get_radius", "set_radius", "Radius", 0.01); +} + + + Vector2 Sdf3dOpRounded::_get_property_value_sdf3d(const Vector3 &uv3) { + Vector2 v = input.get_value_sdf3d(uv3); + //vec2($(name_uv)_v.x-$r, $(name_uv)_v.y); + v.x -= radius; + return v; +} + + //radius; + + float Sdf3dOpRounded::get_radius() { + return radius; +} + + + void Sdf3dOpRounded::set_radius(const float val) { + radius = val; + emit_changed(); + output.emit_changed(); +} + + + void Sdf3dOpRounded::on_input_changed() { + emit_changed(); + output.emit_changed(); +} + +} + + Sdf3dOpRounded::Sdf3dOpRounded() { + input; + output; + radius = 0.15; + } + + Sdf3dOpRounded::~Sdf3dOpRounded() { + } + + + static void Sdf3dOpRounded::_bind_methods() { + ClassDB::bind_method(D_METHOD("get_input"), &Sdf3dOpRounded::get_input); + ClassDB::bind_method(D_METHOD("set_input", "value"), &Sdf3dOpRounded::set_input); + ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "input", PROPERTY_HINT_RESOURCE_TYPE, "Ref"), "set_input", "get_input"); + + + ClassDB::bind_method(D_METHOD("get_output"), &Sdf3dOpRounded::get_output); + ClassDB::bind_method(D_METHOD("set_output", "value"), &Sdf3dOpRounded::set_output); + ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "output", PROPERTY_HINT_RESOURCE_TYPE, "Ref"), "set_output", "get_output"); + + + ClassDB::bind_method(D_METHOD("get_radius"), &Sdf3dOpRounded::get_radius); + ClassDB::bind_method(D_METHOD("set_radius", "value"), &Sdf3dOpRounded::set_radius); + ADD_PROPERTY(PropertyInfo(Variant::REAL, "radius"), "set_radius", "get_radius"); + + + ClassDB::bind_method(D_METHOD("_init_properties"), &Sdf3dOpRounded::_init_properties); + ClassDB::bind_method(D_METHOD("_register_methods", "mm_graph_node"), &Sdf3dOpRounded::_register_methods); + ClassDB::bind_method(D_METHOD("_get_property_value_sdf3d", "uv3"), &Sdf3dOpRounded::_get_property_value_sdf3d); + ClassDB::bind_method(D_METHOD("get_radius"), &Sdf3dOpRounded::get_radius); + ClassDB::bind_method(D_METHOD("set_radius", "val"), &Sdf3dOpRounded::set_radius); + ClassDB::bind_method(D_METHOD("on_input_changed"), &Sdf3dOpRounded::on_input_changed); + + } + + + diff --git a/modules/material_maker/nodes/sdf3d/sdf3d_op_rounded.h b/modules/material_maker/nodes/sdf3d/sdf3d_op_rounded.h new file mode 100644 index 000000000..5c8930db3 --- /dev/null +++ b/modules/material_maker/nodes/sdf3d/sdf3d_op_rounded.h @@ -0,0 +1,43 @@ +#ifndef SDF3D_OP_ROUNDED_H +#define SDF3D_OP_ROUNDED_H + + +class Sdf3dOpRounded : public MMNode { + GDCLASS(Sdf3dOpRounded, MMNode); + + public: + + Ref get_input(); + void set_input(const Ref &val); + + Ref get_output(); + void set_output(const Ref &val); + + float get_radius() const; + void set_radius(const float val); + + void _init_properties(); + void _register_methods(const Variant &mm_graph_node); + Vector2 _get_property_value_sdf3d(const Vector3 &uv3); + float get_radius(); + void set_radius(const float val); + void on_input_changed(); + + Sdf3dOpRounded(); + ~Sdf3dOpRounded(); + + protected: + static void _bind_methods(); + + //tool + //export(Resource) + Ref input; + //export(Resource) + Ref output; + //export(float) + float radius = 0.15; + //radius +}; + + +#endif diff --git a/modules/material_maker/nodes/sdf3d/sdf3d_op_smooth_bool.cpp b/modules/material_maker/nodes/sdf3d/sdf3d_op_smooth_bool.cpp new file mode 100644 index 000000000..0d7a26078 --- /dev/null +++ b/modules/material_maker/nodes/sdf3d/sdf3d_op_smooth_bool.cpp @@ -0,0 +1,221 @@ + +#include "sdf3d_op_smooth_bool.h" + + +Ref Sdf3dOpSmoothBool::get_input1() { + return input1; +} + +void Sdf3dOpSmoothBool::set_input1(const Ref &val) { +input1 = val; +} + + +Ref Sdf3dOpSmoothBool::get_input2() { + return input2; +} + +void Sdf3dOpSmoothBool::set_input2(const Ref &val) { +input2 = val; +} + + +Ref Sdf3dOpSmoothBool::get_output() { + return output; +} + +void Sdf3dOpSmoothBool::set_output(const Ref &val) { +output = val; +} + + +int Sdf3dOpSmoothBool::get_operation() const { + return operation; +} + +void Sdf3dOpSmoothBool::set_operation(const int val) { +operation = val; +} + + +float Sdf3dOpSmoothBool::get_smoothness() const { + return smoothness; +} + +void Sdf3dOpSmoothBool::set_smoothness(const float val) { +smoothness = val; +} + + + + //tool; + //export(Resource) ; + Ref input1; + //export(Resource) ; + Ref input2; + //export(Resource) ; + Ref output; + //export(int, "Union,Substraction,Intersection") ; + int operation = 0; + //export(float) ; + float smoothness = 0.15; + + void Sdf3dOpSmoothBool::_init_properties() { + + if (!input1) { + input1 = MMNodeUniversalProperty.new(); + input1.default_type = MMNodeUniversalProperty.DEFAULT_TYPE_VECTOR2; +} + + input1.input_slot_type = MMNodeUniversalProperty.SLOT_TYPE_UNIVERSAL; + // input1.input_slot_type = MMNodeUniversalProperty.SLOT_TYPE_VECTOR2; + input1.slot_name = ">>> Input 1 "; + + if (!input1.is_connected("changed", self, "on_input_changed")) { + input1.connect("changed", self, "on_input_changed"); +} + + + if (!input2) { + input2 = MMNodeUniversalProperty.new(); + input2.default_type = MMNodeUniversalProperty.DEFAULT_TYPE_VECTOR2; +} + + input2.input_slot_type = MMNodeUniversalProperty.SLOT_TYPE_UNIVERSAL; + // input2.input_slot_type = MMNodeUniversalProperty.SLOT_TYPE_VECTOR2; + input2.slot_name = ">>> Input 2 "; + + if (!input2.is_connected("changed", self, "on_input_changed")) { + input2.connect("changed", self, "on_input_changed"); +} + + + if (!output) { + output = MMNodeUniversalProperty.new(); + output.default_type = MMNodeUniversalProperty.DEFAULT_TYPE_VECTOR2; +} + + output.output_slot_type = MMNodeUniversalProperty.SLOT_TYPE_FLOAT; + output.slot_name = ">>> Output >>>"; + output.get_value_from_owner = true; + register_input_property(input1); + register_input_property(input2); + register_output_property(output); +} + + + void Sdf3dOpSmoothBool::_register_methods(const Variant &mm_graph_node) { + mm_graph_node.add_slot_label_universal(input1); + mm_graph_node.add_slot_label_universal(input2); + mm_graph_node.add_slot_label_universal(output); + mm_graph_node.add_slot_enum("get_operation", "set_operation", "Operation", [ "Union", "Substraction", "Intersection" ]); + mm_graph_node.add_slot_float("get_smoothness", "set_smoothness", "Smoothness", 0.01); +} + + + Vector2 Sdf3dOpSmoothBool::_get_property_value_sdf3d(const Vector3 &uv3) { + Vector2 s1 = input1.get_value_sdf3d(uv3); + Vector2 s2 = input2.get_value_sdf3d(uv3); + + if (operation == 0) { + return MMAlgos.sdf3d_smooth_union(s1, s2, smoothness); +} + + + else if (operation == 1) { + return MMAlgos.sdf3d_smooth_subtraction(s1, s2, smoothness); +} + + + else if (operation == 2) { + return MMAlgos.sdf3d_smooth_intersection(s1, s2, smoothness); +} + + return Vector2(); +} + + //operation; + + int Sdf3dOpSmoothBool::get_operation() { + return operation; +} + + + void Sdf3dOpSmoothBool::set_operation(const int val) { + operation = val; + emit_changed(); + output.emit_changed(); +} + + //smoothness; + + float Sdf3dOpSmoothBool::get_smoothness() { + return smoothness; +} + + + void Sdf3dOpSmoothBool::set_smoothness(const float val) { + smoothness = val; + emit_changed(); + output.emit_changed(); +} + + + void Sdf3dOpSmoothBool::on_input_changed() { + emit_changed(); + output.emit_changed(); +} + +} + + Sdf3dOpSmoothBool::Sdf3dOpSmoothBool() { + input1; + input2; + output; + operation = 0; + smoothness = 0.15; + } + + Sdf3dOpSmoothBool::~Sdf3dOpSmoothBool() { + } + + + static void Sdf3dOpSmoothBool::_bind_methods() { + ClassDB::bind_method(D_METHOD("get_input1"), &Sdf3dOpSmoothBool::get_input1); + ClassDB::bind_method(D_METHOD("set_input1", "value"), &Sdf3dOpSmoothBool::set_input1); + ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "input1", PROPERTY_HINT_RESOURCE_TYPE, "Ref"), "set_input1", "get_input1"); + + + ClassDB::bind_method(D_METHOD("get_input2"), &Sdf3dOpSmoothBool::get_input2); + ClassDB::bind_method(D_METHOD("set_input2", "value"), &Sdf3dOpSmoothBool::set_input2); + ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "input2", PROPERTY_HINT_RESOURCE_TYPE, "Ref"), "set_input2", "get_input2"); + + + ClassDB::bind_method(D_METHOD("get_output"), &Sdf3dOpSmoothBool::get_output); + ClassDB::bind_method(D_METHOD("set_output", "value"), &Sdf3dOpSmoothBool::set_output); + ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "output", PROPERTY_HINT_RESOURCE_TYPE, "Ref"), "set_output", "get_output"); + + + ClassDB::bind_method(D_METHOD("get_operation"), &Sdf3dOpSmoothBool::get_operation); + ClassDB::bind_method(D_METHOD("set_operation", "value"), &Sdf3dOpSmoothBool::set_operation); + ADD_PROPERTY(PropertyInfo(Variant::INT, "operation"), "set_operation", "get_operation"); + + + ClassDB::bind_method(D_METHOD("get_smoothness"), &Sdf3dOpSmoothBool::get_smoothness); + ClassDB::bind_method(D_METHOD("set_smoothness", "value"), &Sdf3dOpSmoothBool::set_smoothness); + ADD_PROPERTY(PropertyInfo(Variant::REAL, "smoothness"), "set_smoothness", "get_smoothness"); + + + ClassDB::bind_method(D_METHOD("_init_properties"), &Sdf3dOpSmoothBool::_init_properties); + ClassDB::bind_method(D_METHOD("_register_methods", "mm_graph_node"), &Sdf3dOpSmoothBool::_register_methods); + ClassDB::bind_method(D_METHOD("_get_property_value_sdf3d", "uv3"), &Sdf3dOpSmoothBool::_get_property_value_sdf3d); + ClassDB::bind_method(D_METHOD("get_operation"), &Sdf3dOpSmoothBool::get_operation); + ClassDB::bind_method(D_METHOD("set_operation", "val"), &Sdf3dOpSmoothBool::set_operation); + ClassDB::bind_method(D_METHOD("get_smoothness"), &Sdf3dOpSmoothBool::get_smoothness); + ClassDB::bind_method(D_METHOD("set_smoothness", "val"), &Sdf3dOpSmoothBool::set_smoothness); + ClassDB::bind_method(D_METHOD("on_input_changed"), &Sdf3dOpSmoothBool::on_input_changed); + + } + + + diff --git a/modules/material_maker/nodes/sdf3d/sdf3d_op_smooth_bool.h b/modules/material_maker/nodes/sdf3d/sdf3d_op_smooth_bool.h new file mode 100644 index 000000000..54aa6ac8e --- /dev/null +++ b/modules/material_maker/nodes/sdf3d/sdf3d_op_smooth_bool.h @@ -0,0 +1,56 @@ +#ifndef SDF3D_OP_SMOOTH_BOOL_H +#define SDF3D_OP_SMOOTH_BOOL_H + + +class Sdf3dOpSmoothBool : public MMNode { + GDCLASS(Sdf3dOpSmoothBool, MMNode); + + public: + + Ref get_input1(); + void set_input1(const Ref &val); + + Ref get_input2(); + void set_input2(const Ref &val); + + Ref get_output(); + void set_output(const Ref &val); + + int get_operation() const; + void set_operation(const int val); + + float get_smoothness() const; + void set_smoothness(const float val); + + void _init_properties(); + void _register_methods(const Variant &mm_graph_node); + Vector2 _get_property_value_sdf3d(const Vector3 &uv3); + int get_operation(); + void set_operation(const int val); + float get_smoothness(); + void set_smoothness(const float val); + void on_input_changed(); + + Sdf3dOpSmoothBool(); + ~Sdf3dOpSmoothBool(); + + protected: + static void _bind_methods(); + + //tool + //export(Resource) + Ref input1; + //export(Resource) + Ref input2; + //export(Resource) + Ref output; + //export(int, "Union,Substraction,Intersection") + int operation = 0; + //export(float) + float smoothness = 0.15; + //operation + //smoothness +}; + + +#endif diff --git a/modules/material_maker/nodes/sdf3d/sdf3d_render.cpp b/modules/material_maker/nodes/sdf3d/sdf3d_render.cpp new file mode 100644 index 000000000..05f389c98 --- /dev/null +++ b/modules/material_maker/nodes/sdf3d/sdf3d_render.cpp @@ -0,0 +1,273 @@ + +#include "sdf3d_render.h" + + +Ref Sdf3dRender::get_input() { + return input; +} + +void Sdf3dRender::set_input(const Ref &val) { +input = val; +} + + +Ref Sdf3dRender::get_out_height_map() { + return out_height_map; +} + +void Sdf3dRender::set_out_height_map(const Ref &val) { +out_height_map = val; +} + + +Ref Sdf3dRender::get_out_normal_map() { + return out_normal_map; +} + +void Sdf3dRender::set_out_normal_map(const Ref &val) { +out_normal_map = val; +} + + +Ref Sdf3dRender::get_out_color_map() { + return out_color_map; +} + +void Sdf3dRender::set_out_color_map(const Ref &val) { +out_color_map = val; +} + + + + //tool; + //export(Resource) ; + Ref input; + //export(Resource) ; + Ref out_height_map; + //export(Resource) ; + Ref out_normal_map; + //export(Resource) ; + Ref out_color_map; + + void Sdf3dRender::_init_properties() { + + if (!input) { + input = MMNodeUniversalProperty.new(); + input.default_type = MMNodeUniversalProperty.DEFAULT_TYPE_VECTOR2; +} + + //for some reason this doesn't work, todo check; + // input.input_slot_type = MMNodeUniversalProperty.SLOT_TYPE_FLOAT; + input.input_slot_type = MMNodeUniversalProperty.SLOT_TYPE_UNIVERSAL; + input.slot_name = "Input"; + + if (!out_height_map) { + out_height_map = MMNodeUniversalProperty.new(); + out_height_map.default_type = MMNodeUniversalProperty.DEFAULT_TYPE_IMAGE; +} + + out_height_map.output_slot_type = MMNodeUniversalProperty.SLOT_TYPE_IMAGE; + + if (!out_normal_map) { + out_normal_map = MMNodeUniversalProperty.new(); + out_normal_map.default_type = MMNodeUniversalProperty.DEFAULT_TYPE_IMAGE; +} + + out_normal_map.output_slot_type = MMNodeUniversalProperty.SLOT_TYPE_IMAGE; + + if (!out_color_map) { + out_color_map = MMNodeUniversalProperty.new(); + out_color_map.default_type = MMNodeUniversalProperty.DEFAULT_TYPE_IMAGE; +} + + out_color_map.output_slot_type = MMNodeUniversalProperty.SLOT_TYPE_IMAGE; + register_output_property(out_height_map); + register_output_property(out_normal_map); + register_output_property(out_color_map); + register_input_property(input); +} + + + void Sdf3dRender::_register_methods(const Variant &mm_graph_node) { + mm_graph_node.add_slot_label_universal(input); + mm_graph_node.add_slot_texture_universal(out_height_map); + mm_graph_node.add_slot_texture_universal(out_normal_map); + mm_graph_node.add_slot_texture_universal(out_color_map); +} + + + void Sdf3dRender::_render(const Variant &material) { + Ref height_map = Image.new(); + Ref normal_map = Image.new(); + Ref color_map = Image.new(); + height_map.create(material.image_size.x, material.image_size.y, false, Image.FORMAT_RGBA8); + normal_map.create(material.image_size.x, material.image_size.y, false, Image.FORMAT_RGBA8); + color_map.create(material.image_size.x, material.image_size.y, false, Image.FORMAT_RGBA8); + height_map.lock(); + normal_map.lock(); + color_map.lock(); + float w = material.image_size.x; + float h = material.image_size.y; + float pseed = randf() + randi(); + + 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); + Vector2 raymarch = sdf3d_raymarch(uv); + //HeightMap - float - The generated height map; + //1.0-$(name_uv)_d.x; + float hmf = 1.0 - raymarch.x; + Color height_map_col = Color(hmf, hmf, hmf, 1); + //NormalMap - rgb - The generated normal map; + //vec3(0.5) + 0.5* normal_$name(vec3($uv-vec2(0.5), 1.0-$(name_uv)_d.x)); + Vector2 nuv = uv - Vector2(0.5, 0.5); + Vector3 n = sdf3d_normal(Vector3(nuv.x, nuv.y, 1.0 - raymarch.x)); + Vector3 nn = Vector3(0.5, 0.5, 0.5) + 0.5 * n; + Color normal_map_col = Color(nn.x, nn.y, nn.z, 1); + //ColorMap - float - The generated color index map; + //$(name_uv)_d.y; + Color color_map_col = Color(raymarch.y, raymarch.y, raymarch.y, 1); + height_map.set_pixel(x, y, height_map_col); + normal_map.set_pixel(x, y, normal_map_col); + color_map.set_pixel(x, y, color_map_col); +} + +} + + height_map.unlock(); + normal_map.unlock(); + color_map.unlock(); + out_height_map.set_value(height_map); + out_normal_map.set_value(normal_map); + out_color_map.set_value(color_map); +} + + + Color Sdf3dRender::_get_value_for(const Vector2 &uv, const int pseed) { + return Color(); +} + + //vec2 raymarch_$name(vec2 uv) {; + // vec3 ro = vec3(uv-vec2(0.5), 1.0); + // vec3 rd = vec3(0.0, 0.0, -1.0); + // float dO = 0.0; + // float c = 0.0; + //; + // for (int i=0; i < 100; i++) {; + // vec3 p = ro + rd*dO; + // vec2 dS = $sdf(p); + // dO += dS.x; + //; + // if (dO >= 1.0) {; + // break; + // } else if (dS.x < 0.0001) {; + // c = dS.y; + // break; + // }; + // }; + //; + // return vec2(dO, c); + //}; + + Vector2 Sdf3dRender::sdf3d_raymarch(const Vector2 &uv) { + Vector3 ro = Vector3(uv.x - 0.5, uv.y - 0.5, 1.0); + Vector3 rd = Vector3(0.0, 0.0, -1.0); + float dO = 0.0; + float c = 0.0; + + for (int i = 0; i < 100; ++i) { //i in range(100) + Vector3 p = ro + rd * dO; + Vector2 dS = input.get_value_sdf3d(p); + dO += dS.x; + + if ((dO >= 1.0)) { + break; +} + + + else if ((dS.x < 0.0001)) { + c = dS.y; + break; +} + +} + + return Vector2(dO, c); +} + + //vec3 normal_$name(vec3 p) {; + // if (p.z <= 0.0) {; + // return vec3(0.0, 0.0, 1.0); + // }; + //; + // float d = $sdf(p).x; + // float e = .001; + // vec3 n = d - vec3(; + // $sdf(p-vec3(e, 0.0, 0.0)).x,; + // $sdf(p-vec3(0.0, e, 0.0)).x,; + // $sdf(p-vec3(0.0, 0.0, e)).x); + //; + // return vec3(-1.0, -1.0, -1.0)*normalize(n); + //}; + + Vector3 Sdf3dRender::sdf3d_normal(const Vector3 &p) { + + if ((p.z <= 0.0)) { + return Vector3(0.0, 0.0, 1.0); +} + + float d = input.get_value_sdf3d(p).x; + float e = .001; + Vector3 n = Vector3(; + d - input.get_value_sdf3d(p - Vector3(e, 0.0, 0.0)).x,; + d - input.get_value_sdf3d(p - Vector3(0.0, e, 0.0)).x,; + d - input.get_value_sdf3d(p - Vector3(0.0, 0.0, e)).x); + return Vector3(-1.0, -1.0, -1.0) * n.normalized(); +} + +} + + Sdf3dRender::Sdf3dRender() { + input; + out_height_map; + out_normal_map; + out_color_map; + } + + Sdf3dRender::~Sdf3dRender() { + } + + + static void Sdf3dRender::_bind_methods() { + ClassDB::bind_method(D_METHOD("get_input"), &Sdf3dRender::get_input); + ClassDB::bind_method(D_METHOD("set_input", "value"), &Sdf3dRender::set_input); + ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "input", PROPERTY_HINT_RESOURCE_TYPE, "Ref"), "set_input", "get_input"); + + + ClassDB::bind_method(D_METHOD("get_out_height_map"), &Sdf3dRender::get_out_height_map); + ClassDB::bind_method(D_METHOD("set_out_height_map", "value"), &Sdf3dRender::set_out_height_map); + ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "out_height_map", PROPERTY_HINT_RESOURCE_TYPE, "Ref"), "set_out_height_map", "get_out_height_map"); + + + ClassDB::bind_method(D_METHOD("get_out_normal_map"), &Sdf3dRender::get_out_normal_map); + ClassDB::bind_method(D_METHOD("set_out_normal_map", "value"), &Sdf3dRender::set_out_normal_map); + ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "out_normal_map", PROPERTY_HINT_RESOURCE_TYPE, "Ref"), "set_out_normal_map", "get_out_normal_map"); + + + ClassDB::bind_method(D_METHOD("get_out_color_map"), &Sdf3dRender::get_out_color_map); + ClassDB::bind_method(D_METHOD("set_out_color_map", "value"), &Sdf3dRender::set_out_color_map); + ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "out_color_map", PROPERTY_HINT_RESOURCE_TYPE, "Ref"), "set_out_color_map", "get_out_color_map"); + + + ClassDB::bind_method(D_METHOD("_init_properties"), &Sdf3dRender::_init_properties); + ClassDB::bind_method(D_METHOD("_register_methods", "mm_graph_node"), &Sdf3dRender::_register_methods); + ClassDB::bind_method(D_METHOD("_render", "material"), &Sdf3dRender::_render); + ClassDB::bind_method(D_METHOD("_get_value_for", "uv", "pseed"), &Sdf3dRender::_get_value_for); + ClassDB::bind_method(D_METHOD("sdf3d_raymarch", "uv"), &Sdf3dRender::sdf3d_raymarch); + ClassDB::bind_method(D_METHOD("sdf3d_normal", "p"), &Sdf3dRender::sdf3d_normal); + + } + + + diff --git a/modules/material_maker/nodes/sdf3d/sdf3d_render.h b/modules/material_maker/nodes/sdf3d/sdf3d_render.h new file mode 100644 index 000000000..8c2b57018 --- /dev/null +++ b/modules/material_maker/nodes/sdf3d/sdf3d_render.h @@ -0,0 +1,82 @@ +#ifndef SDF3D_RENDER_H +#define SDF3D_RENDER_H + + +class Sdf3dRender : public MMNode { + GDCLASS(Sdf3dRender, MMNode); + + public: + + Ref get_input(); + void set_input(const Ref &val); + + Ref get_out_height_map(); + void set_out_height_map(const Ref &val); + + Ref get_out_normal_map(); + void set_out_normal_map(const Ref &val); + + Ref get_out_color_map(); + void set_out_color_map(const Ref &val); + + 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 sdf3d_raymarch(const Vector2 &uv); + Vector3 sdf3d_normal(const Vector3 &p); + + Sdf3dRender(); + ~Sdf3dRender(); + + protected: + static void _bind_methods(); + + //tool + //export(Resource) + Ref input; + //export(Resource) + Ref out_height_map; + //export(Resource) + Ref out_normal_map; + //export(Resource) + Ref out_color_map; + //vec2 raymarch_$name(vec2 uv) { + // vec3 ro = vec3(uv-vec2(0.5), 1.0); + // vec3 rd = vec3(0.0, 0.0, -1.0); + // float dO = 0.0; + // float c = 0.0; + // + // for (int i=0; i < 100; i++) { + // vec3 p = ro + rd*dO; + // vec2 dS = $sdf(p); + // dO += dS.x; + // + // if (dO >= 1.0) { + // break; + // } else if (dS.x < 0.0001) { + // c = dS.y; + // break; + // } + // } + // + // return vec2(dO, c); + //} + //vec3 normal_$name(vec3 p) { + // if (p.z <= 0.0) { + // return vec3(0.0, 0.0, 1.0); + // } + // + // float d = $sdf(p).x; + // float e = .001; + // vec3 n = d - vec3( + // $sdf(p-vec3(e, 0.0, 0.0)).x, + // $sdf(p-vec3(0.0, e, 0.0)).x, + // $sdf(p-vec3(0.0, 0.0, e)).x); + // + // return vec3(-1.0, -1.0, -1.0)*normalize(n); + //} +}; + + +#endif diff --git a/modules/material_maker/nodes/sdf3d/sdf3d_shape_box.cpp b/modules/material_maker/nodes/sdf3d/sdf3d_shape_box.cpp new file mode 100644 index 000000000..ba1cc14b4 --- /dev/null +++ b/modules/material_maker/nodes/sdf3d/sdf3d_shape_box.cpp @@ -0,0 +1,131 @@ + +#include "sdf3d_shape_box.h" + + +Ref Sdf3dShapeBox::get_output() { + return output; +} + +void Sdf3dShapeBox::set_output(const Ref &val) { +output = val; +} + + +Vector3 Sdf3dShapeBox::get_size() { + return size; +} + +void Sdf3dShapeBox::set_size(const Vector3 &val) { +size = val; +} + + +float Sdf3dShapeBox::get_radius() const { + return radius; +} + +void Sdf3dShapeBox::set_radius(const float val) { +radius = val; +} + + + + //tool; + //export(Resource) ; + Ref output; + //export(Vector3) ; + Vector3 size = Vector3(0.3, 0.25, 0.25); + //export(float) ; + float radius = 0.01; + + void Sdf3dShapeBox::_init_properties() { + + if (!output) { + output = MMNodeUniversalProperty.new(); + output.default_type = MMNodeUniversalProperty.DEFAULT_TYPE_VECTOR2; +} + + output.output_slot_type = MMNodeUniversalProperty.SLOT_TYPE_FLOAT; + output.slot_name = ">>> Output >>>"; + output.get_value_from_owner = true; + register_output_property(output); +} + + + void Sdf3dShapeBox::_register_methods(const Variant &mm_graph_node) { + mm_graph_node.add_slot_label_universal(output); + mm_graph_node.add_slot_vector3("get_size", "set_size", "Size", 0.01); + mm_graph_node.add_slot_float("get_radius", "set_radius", "Radius", 0.01); +} + + + Vector2 Sdf3dShapeBox::_get_property_value_sdf3d(const Vector3 &uv3) { + return MMAlgos.sdf3d_box(uv3, size.x, size.y, size.z, radius); +} + + //size; + + Vector3 Sdf3dShapeBox::get_size() { + return size; +} + + + void Sdf3dShapeBox::set_size(const Vector3 &val) { + size = val; + emit_changed(); + output.emit_changed(); +} + + //radius; + + float Sdf3dShapeBox::get_radius() { + return radius; +} + + + void Sdf3dShapeBox::set_radius(const float val) { + radius = val; + emit_changed(); + output.emit_changed(); +} + +} + + Sdf3dShapeBox::Sdf3dShapeBox() { + output; + size = Vector3(0.3, 0.25, 0.25); + radius = 0.01; + } + + Sdf3dShapeBox::~Sdf3dShapeBox() { + } + + + static void Sdf3dShapeBox::_bind_methods() { + ClassDB::bind_method(D_METHOD("get_output"), &Sdf3dShapeBox::get_output); + ClassDB::bind_method(D_METHOD("set_output", "value"), &Sdf3dShapeBox::set_output); + ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "output", PROPERTY_HINT_RESOURCE_TYPE, "Ref"), "set_output", "get_output"); + + + ClassDB::bind_method(D_METHOD("get_size"), &Sdf3dShapeBox::get_size); + ClassDB::bind_method(D_METHOD("set_size", "value"), &Sdf3dShapeBox::set_size); + ADD_PROPERTY(PropertyInfo(Variant::VECTOR3, "size"), "set_size", "get_size"); + + + ClassDB::bind_method(D_METHOD("get_radius"), &Sdf3dShapeBox::get_radius); + ClassDB::bind_method(D_METHOD("set_radius", "value"), &Sdf3dShapeBox::set_radius); + ADD_PROPERTY(PropertyInfo(Variant::REAL, "radius"), "set_radius", "get_radius"); + + + ClassDB::bind_method(D_METHOD("_init_properties"), &Sdf3dShapeBox::_init_properties); + ClassDB::bind_method(D_METHOD("_register_methods", "mm_graph_node"), &Sdf3dShapeBox::_register_methods); + ClassDB::bind_method(D_METHOD("_get_property_value_sdf3d", "uv3"), &Sdf3dShapeBox::_get_property_value_sdf3d); + ClassDB::bind_method(D_METHOD("get_size"), &Sdf3dShapeBox::get_size); + ClassDB::bind_method(D_METHOD("set_size", "val"), &Sdf3dShapeBox::set_size); + ClassDB::bind_method(D_METHOD("get_radius"), &Sdf3dShapeBox::get_radius); + ClassDB::bind_method(D_METHOD("set_radius", "val"), &Sdf3dShapeBox::set_radius); + + } + + + diff --git a/modules/material_maker/nodes/sdf3d/sdf3d_shape_box.h b/modules/material_maker/nodes/sdf3d/sdf3d_shape_box.h new file mode 100644 index 000000000..a34f89b9f --- /dev/null +++ b/modules/material_maker/nodes/sdf3d/sdf3d_shape_box.h @@ -0,0 +1,45 @@ +#ifndef SDF3D_SHAPE_BOX_H +#define SDF3D_SHAPE_BOX_H + + +class Sdf3dShapeBox : public MMNode { + GDCLASS(Sdf3dShapeBox, MMNode); + + public: + + Ref get_output(); + void set_output(const Ref &val); + + Vector3 get_size(); + void set_size(const Vector3 &val); + + float get_radius() const; + void set_radius(const float val); + + void _init_properties(); + void _register_methods(const Variant &mm_graph_node); + Vector2 _get_property_value_sdf3d(const Vector3 &uv3); + Vector3 get_size(); + void set_size(const Vector3 &val); + float get_radius(); + void set_radius(const float val); + + Sdf3dShapeBox(); + ~Sdf3dShapeBox(); + + protected: + static void _bind_methods(); + + //tool + //export(Resource) + Ref output; + //export(Vector3) + Vector3 size = Vector3(0.3, 0.25, 0.25); + //export(float) + float radius = 0.01; + //size + //radius +}; + + +#endif diff --git a/modules/material_maker/nodes/sdf3d/sdf3d_shape_capsule.cpp b/modules/material_maker/nodes/sdf3d/sdf3d_shape_capsule.cpp new file mode 100644 index 000000000..b8edbe263 --- /dev/null +++ b/modules/material_maker/nodes/sdf3d/sdf3d_shape_capsule.cpp @@ -0,0 +1,229 @@ + +#include "sdf3d_shape_capsule.h" + + +Ref Sdf3dShapeCapsule::get_output() { + return output; +} + +void Sdf3dShapeCapsule::set_output(const Ref &val) { +output = val; +} + + +int Sdf3dShapeCapsule::get_axis() const { + return axis; +} + +void Sdf3dShapeCapsule::set_axis(const int val) { +axis = val; +} + + +float Sdf3dShapeCapsule::get_length() const { + return length; +} + +void Sdf3dShapeCapsule::set_length(const float val) { +length = val; +} + + +float Sdf3dShapeCapsule::get_radius() const { + return radius; +} + +void Sdf3dShapeCapsule::set_radius(const float val) { +radius = val; +} + + + + //tool; + //export(Resource) ; + Ref output; + //export(int, "X,Y,Z") ; + int axis = 1; + //export(float) ; + float length = 0.3; + //export(float) ; + float radius = 0.2; + + void Sdf3dShapeCapsule::_init() { + init_points_11(); +} + + + void Sdf3dShapeCapsule::_init_properties() { + + if (!output) { + output = MMNodeUniversalProperty.new(); + output.default_type = MMNodeUniversalProperty.DEFAULT_TYPE_VECTOR2; +} + + output.output_slot_type = MMNodeUniversalProperty.SLOT_TYPE_FLOAT; + output.slot_name = ">>> Output >>>"; + output.get_value_from_owner = true; + register_output_property(output); +} + + + void Sdf3dShapeCapsule::_register_methods(const Variant &mm_graph_node) { + mm_graph_node.add_slot_label_universal(output); + mm_graph_node.add_slot_enum("get_axis", "set_axis", "Axis", [ "X", "Y", "Z" ]); + mm_graph_node.add_slot_float("get_length", "set_length", "Length", 0.01); + mm_graph_node.add_slot_float("get_radius", "set_radius", "Radius", 0.01); + mm_graph_node.add_slot_curve(); +} + + + Vector2 Sdf3dShapeCapsule::_get_property_value_sdf3d(const Vector3 &uv3) { + + if (axis == 0) { + return sdf3d_capsule_x(uv3, radius, length); +} + + + else if (axis == 1) { + return sdf3d_capsule_y(uv3, radius, length); +} + + + else if (axis == 2) { + return sdf3d_capsule_z(uv3, radius, length); +} + + return Vector2(); +} + + //vec3 $(name_uv)_p = $uv; + //$(name_uv)_p.$axis -= clamp($(name_uv)_p.$axis, -$l, $l); + //return length($(name_uv)_p) - $r * $profile(clamp(0.5+0.5*($uv).$axis/$l, 0.0, 1.0)); + + Vector2 Sdf3dShapeCapsule::sdf3d_capsule_y(const Vector3 &p, const float r, const float l) { + Vector3 v = p; + v.y -= clamp(v.y, -l, l); + float cx = clamp(0.5 + 0.5 * p.y / l, 0.0, 1.0); + float cp = MMAlgos.curve(cx, points_array); + float f = v.length() - r * cp; + return Vector2(f, 0.0); +} + + + Vector2 Sdf3dShapeCapsule::sdf3d_capsule_x(const Vector3 &p, const float r, const float l) { + Vector3 v = p; + v.x -= clamp(v.x, -l, l); + float cx = clamp(0.5 + 0.5 * p.x / l, 0.0, 1.0); + float cp = MMAlgos.curve(cx, points_array); + float f = v.length() - r * cp; + return Vector2(f, 0.0); +} + + + Vector2 Sdf3dShapeCapsule::sdf3d_capsule_z(const Vector3 &p, const float r, const float l) { + Vector3 v = p; + v.z -= clamp(v.z, -l, l); + float cx = clamp(0.5 + 0.5 * p.z / l, 0.0, 1.0); + float cp = MMAlgos.curve(cx, points_array); + float f = v.length() - r * cp; + return Vector2(f, 0.0); +} + + //axis; + + int Sdf3dShapeCapsule::get_axis() { + return axis; +} + + + void Sdf3dShapeCapsule::set_axis(const int val) { + axis = val; + emit_changed(); + output.emit_changed(); +} + + //length; + + float Sdf3dShapeCapsule::get_length() { + return length; +} + + + void Sdf3dShapeCapsule::set_length(const float val) { + length = val; + emit_changed(); + output.emit_changed(); +} + + //radius; + + float Sdf3dShapeCapsule::get_radius() { + return radius; +} + + + void Sdf3dShapeCapsule::set_radius(const float val) { + radius = val; + emit_changed(); + output.emit_changed(); +} + + + void Sdf3dShapeCapsule::_curve_changed() { + emit_changed(); + output.emit_changed(); +} + +} + + Sdf3dShapeCapsule::Sdf3dShapeCapsule() { + output; + axis = 1; + length = 0.3; + radius = 0.2; + } + + Sdf3dShapeCapsule::~Sdf3dShapeCapsule() { + } + + + static void Sdf3dShapeCapsule::_bind_methods() { + ClassDB::bind_method(D_METHOD("get_output"), &Sdf3dShapeCapsule::get_output); + ClassDB::bind_method(D_METHOD("set_output", "value"), &Sdf3dShapeCapsule::set_output); + ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "output", PROPERTY_HINT_RESOURCE_TYPE, "Ref"), "set_output", "get_output"); + + + ClassDB::bind_method(D_METHOD("get_axis"), &Sdf3dShapeCapsule::get_axis); + ClassDB::bind_method(D_METHOD("set_axis", "value"), &Sdf3dShapeCapsule::set_axis); + ADD_PROPERTY(PropertyInfo(Variant::INT, "axis"), "set_axis", "get_axis"); + + + ClassDB::bind_method(D_METHOD("get_length"), &Sdf3dShapeCapsule::get_length); + ClassDB::bind_method(D_METHOD("set_length", "value"), &Sdf3dShapeCapsule::set_length); + ADD_PROPERTY(PropertyInfo(Variant::REAL, "length"), "set_length", "get_length"); + + + ClassDB::bind_method(D_METHOD("get_radius"), &Sdf3dShapeCapsule::get_radius); + ClassDB::bind_method(D_METHOD("set_radius", "value"), &Sdf3dShapeCapsule::set_radius); + ADD_PROPERTY(PropertyInfo(Variant::REAL, "radius"), "set_radius", "get_radius"); + + + ClassDB::bind_method(D_METHOD("_init"), &Sdf3dShapeCapsule::_init); + ClassDB::bind_method(D_METHOD("_init_properties"), &Sdf3dShapeCapsule::_init_properties); + ClassDB::bind_method(D_METHOD("_register_methods", "mm_graph_node"), &Sdf3dShapeCapsule::_register_methods); + ClassDB::bind_method(D_METHOD("_get_property_value_sdf3d", "uv3"), &Sdf3dShapeCapsule::_get_property_value_sdf3d); + ClassDB::bind_method(D_METHOD("sdf3d_capsule_y", "p", "r", "l"), &Sdf3dShapeCapsule::sdf3d_capsule_y); + ClassDB::bind_method(D_METHOD("sdf3d_capsule_x", "p", "r", "l"), &Sdf3dShapeCapsule::sdf3d_capsule_x); + ClassDB::bind_method(D_METHOD("sdf3d_capsule_z", "p", "r", "l"), &Sdf3dShapeCapsule::sdf3d_capsule_z); + ClassDB::bind_method(D_METHOD("get_axis"), &Sdf3dShapeCapsule::get_axis); + ClassDB::bind_method(D_METHOD("set_axis", "val"), &Sdf3dShapeCapsule::set_axis); + ClassDB::bind_method(D_METHOD("get_length"), &Sdf3dShapeCapsule::get_length); + ClassDB::bind_method(D_METHOD("set_length", "val"), &Sdf3dShapeCapsule::set_length); + ClassDB::bind_method(D_METHOD("get_radius"), &Sdf3dShapeCapsule::get_radius); + ClassDB::bind_method(D_METHOD("set_radius", "val"), &Sdf3dShapeCapsule::set_radius); + ClassDB::bind_method(D_METHOD("_curve_changed"), &Sdf3dShapeCapsule::_curve_changed); + + } + + + diff --git a/modules/material_maker/nodes/sdf3d/sdf3d_shape_capsule.h b/modules/material_maker/nodes/sdf3d/sdf3d_shape_capsule.h new file mode 100644 index 000000000..4eec5e890 --- /dev/null +++ b/modules/material_maker/nodes/sdf3d/sdf3d_shape_capsule.h @@ -0,0 +1,61 @@ +#ifndef SDF3D_SHAPE_CAPSULE_H +#define SDF3D_SHAPE_CAPSULE_H + + +class Sdf3dShapeCapsule : public CurveBase { + GDCLASS(Sdf3dShapeCapsule, CurveBase); + + public: + + Ref get_output(); + void set_output(const Ref &val); + + int get_axis() const; + void set_axis(const int val); + + float get_length() const; + void set_length(const float val); + + float get_radius() const; + void set_radius(const float val); + + void _init(); + void _init_properties(); + void _register_methods(const Variant &mm_graph_node); + Vector2 _get_property_value_sdf3d(const Vector3 &uv3); + Vector2 sdf3d_capsule_y(const Vector3 &p, const float r, const float l); + Vector2 sdf3d_capsule_x(const Vector3 &p, const float r, const float l); + Vector2 sdf3d_capsule_z(const Vector3 &p, const float r, const float l); + int get_axis(); + void set_axis(const int val); + float get_length(); + void set_length(const float val); + float get_radius(); + void set_radius(const float val); + void _curve_changed(); + + Sdf3dShapeCapsule(); + ~Sdf3dShapeCapsule(); + + protected: + static void _bind_methods(); + + //tool + //export(Resource) + Ref output; + //export(int, "X,Y,Z") + int axis = 1; + //export(float) + float length = 0.3; + //export(float) + float radius = 0.2; + //vec3 $(name_uv)_p = $uv; + //$(name_uv)_p.$axis -= clamp($(name_uv)_p.$axis, -$l, $l); + //return length($(name_uv)_p) - $r * $profile(clamp(0.5+0.5*($uv).$axis/$l, 0.0, 1.0)) + //axis + //length + //radius +}; + + +#endif diff --git a/modules/material_maker/nodes/sdf3d/sdf3d_shape_cone.cpp b/modules/material_maker/nodes/sdf3d/sdf3d_shape_cone.cpp new file mode 100644 index 000000000..9978da4ad --- /dev/null +++ b/modules/material_maker/nodes/sdf3d/sdf3d_shape_cone.cpp @@ -0,0 +1,161 @@ + +#include "sdf3d_shape_cone.h" + + +Ref Sdf3dShapeCone::get_output() { + return output; +} + +void Sdf3dShapeCone::set_output(const Ref &val) { +output = val; +} + + +int Sdf3dShapeCone::get_axis() const { + return axis; +} + +void Sdf3dShapeCone::set_axis(const int val) { +axis = val; +} + + +float Sdf3dShapeCone::get_angle() const { + return angle; +} + +void Sdf3dShapeCone::set_angle(const float val) { +angle = val; +} + + + + //tool; + //export(Resource) ; + Ref output; + //export(int, "+X,-X,+Y,-Y,+Z,-Z") ; + int axis = 2; + //export(float) ; + float angle = 30; + + void Sdf3dShapeCone::_init_properties() { + + if (!output) { + output = MMNodeUniversalProperty.new(); + output.default_type = MMNodeUniversalProperty.DEFAULT_TYPE_VECTOR2; +} + + output.output_slot_type = MMNodeUniversalProperty.SLOT_TYPE_FLOAT; + output.slot_name = ">>> Output >>>"; + output.get_value_from_owner = true; + register_output_property(output); +} + + + void Sdf3dShapeCone::_register_methods(const Variant &mm_graph_node) { + mm_graph_node.add_slot_label_universal(output); + mm_graph_node.add_slot_enum("get_axis", "set_axis", "Axis", [ "+X", "-X", "+Y", "-Y", "+Z", "-Z" ]); + mm_graph_node.add_slot_float("get_angle", "set_angle", "Angle", 1); +} + + + Vector2 Sdf3dShapeCone::_get_property_value_sdf3d(const Vector3 &uv3) { + + if (axis == 0) { + return MMAlgos.sdf3d_cone_px(uv3, angle); +} + + + else if (axis == 1) { + return MMAlgos.sdf3d_cone_nx(uv3, angle); +} + + + else if (axis == 2) { + return MMAlgos.sdf3d_cone_py(uv3, angle); +} + + + else if (axis == 3) { + return MMAlgos.sdf3d_cone_ny(uv3, angle); +} + + + else if (axis == 4) { + return MMAlgos.sdf3d_cone_pz(uv3, angle); +} + + + else if (axis == 5) { + return MMAlgos.sdf3d_cone_nz(uv3, angle); +} + + return Vector2(); +} + + //axis; + + int Sdf3dShapeCone::get_axis() { + return axis; +} + + + void Sdf3dShapeCone::set_axis(const int val) { + axis = val; + emit_changed(); + output.emit_changed(); +} + + //angle; + + float Sdf3dShapeCone::get_angle() { + return angle; +} + + + void Sdf3dShapeCone::set_angle(const float val) { + angle = val; + emit_changed(); + output.emit_changed(); +} + +} + + Sdf3dShapeCone::Sdf3dShapeCone() { + output; + axis = 2; + angle = 30; + } + + Sdf3dShapeCone::~Sdf3dShapeCone() { + } + + + static void Sdf3dShapeCone::_bind_methods() { + ClassDB::bind_method(D_METHOD("get_output"), &Sdf3dShapeCone::get_output); + ClassDB::bind_method(D_METHOD("set_output", "value"), &Sdf3dShapeCone::set_output); + ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "output", PROPERTY_HINT_RESOURCE_TYPE, "Ref"), "set_output", "get_output"); + + + ClassDB::bind_method(D_METHOD("get_axis"), &Sdf3dShapeCone::get_axis); + ClassDB::bind_method(D_METHOD("set_axis", "value"), &Sdf3dShapeCone::set_axis); + ADD_PROPERTY(PropertyInfo(Variant::INT, "axis"), "set_axis", "get_axis"); + + + ClassDB::bind_method(D_METHOD("get_angle"), &Sdf3dShapeCone::get_angle); + ClassDB::bind_method(D_METHOD("set_angle", "value"), &Sdf3dShapeCone::set_angle); + ADD_PROPERTY(PropertyInfo(Variant::REAL, "angle"), "set_angle", "get_angle"); + + + ClassDB::bind_method(D_METHOD("_init_properties"), &Sdf3dShapeCone::_init_properties); + ClassDB::bind_method(D_METHOD("_register_methods", "mm_graph_node"), &Sdf3dShapeCone::_register_methods); + ClassDB::bind_method(D_METHOD("_get_property_value_sdf3d", "uv3"), &Sdf3dShapeCone::_get_property_value_sdf3d); + ClassDB::bind_method(D_METHOD("get_axis"), &Sdf3dShapeCone::get_axis); + ClassDB::bind_method(D_METHOD("set_axis", "val"), &Sdf3dShapeCone::set_axis); + ClassDB::bind_method(D_METHOD("get_angle"), &Sdf3dShapeCone::get_angle); + ClassDB::bind_method(D_METHOD("set_angle", "val"), &Sdf3dShapeCone::set_angle); + + } + + + diff --git a/modules/material_maker/nodes/sdf3d/sdf3d_shape_cone.h b/modules/material_maker/nodes/sdf3d/sdf3d_shape_cone.h new file mode 100644 index 000000000..f71f7aaf8 --- /dev/null +++ b/modules/material_maker/nodes/sdf3d/sdf3d_shape_cone.h @@ -0,0 +1,45 @@ +#ifndef SDF3D_SHAPE_CONE_H +#define SDF3D_SHAPE_CONE_H + + +class Sdf3dShapeCone : public MMNode { + GDCLASS(Sdf3dShapeCone, MMNode); + + public: + + Ref get_output(); + void set_output(const Ref &val); + + int get_axis() const; + void set_axis(const int val); + + float get_angle() const; + void set_angle(const float val); + + void _init_properties(); + void _register_methods(const Variant &mm_graph_node); + Vector2 _get_property_value_sdf3d(const Vector3 &uv3); + int get_axis(); + void set_axis(const int val); + float get_angle(); + void set_angle(const float val); + + Sdf3dShapeCone(); + ~Sdf3dShapeCone(); + + protected: + static void _bind_methods(); + + //tool + //export(Resource) + Ref output; + //export(int, "+X,-X,+Y,-Y,+Z,-Z") + int axis = 2; + //export(float) + float angle = 30; + //axis + //angle +}; + + +#endif diff --git a/modules/material_maker/nodes/sdf3d/sdf3d_shape_cylinder.cpp b/modules/material_maker/nodes/sdf3d/sdf3d_shape_cylinder.cpp new file mode 100644 index 000000000..6e6555e2f --- /dev/null +++ b/modules/material_maker/nodes/sdf3d/sdf3d_shape_cylinder.cpp @@ -0,0 +1,179 @@ + +#include "sdf3d_shape_cylinder.h" + + +Ref Sdf3dShapeCylinder::get_output() { + return output; +} + +void Sdf3dShapeCylinder::set_output(const Ref &val) { +output = val; +} + + +int Sdf3dShapeCylinder::get_axis() const { + return axis; +} + +void Sdf3dShapeCylinder::set_axis(const int val) { +axis = val; +} + + +float Sdf3dShapeCylinder::get_length() const { + return length; +} + +void Sdf3dShapeCylinder::set_length(const float val) { +length = val; +} + + +float Sdf3dShapeCylinder::get_radius() const { + return radius; +} + +void Sdf3dShapeCylinder::set_radius(const float val) { +radius = val; +} + + + + //tool; + //export(Resource) ; + Ref output; + //export(int, "X,Y,Z") ; + int axis = 1; + //export(float) ; + float length = 0.25; + //export(float) ; + float radius = 0.25; + + void Sdf3dShapeCylinder::_init_properties() { + + if (!output) { + output = MMNodeUniversalProperty.new(); + output.default_type = MMNodeUniversalProperty.DEFAULT_TYPE_VECTOR2; +} + + output.output_slot_type = MMNodeUniversalProperty.SLOT_TYPE_FLOAT; + output.slot_name = ">>> Output >>>"; + output.get_value_from_owner = true; + register_output_property(output); +} + + + void Sdf3dShapeCylinder::_register_methods(const Variant &mm_graph_node) { + mm_graph_node.add_slot_label_universal(output); + mm_graph_node.add_slot_enum("get_axis", "set_axis", "Axis", [ "X", "Y", "Z" ]); + mm_graph_node.add_slot_float("get_length", "set_length", "Length", 0.01); + mm_graph_node.add_slot_float("get_radius", "set_radius", "Radius", 0.01); +} + + + Vector2 Sdf3dShapeCylinder::_get_property_value_sdf3d(const Vector3 &uv3) { + + if (axis == 0) { + return MMAlgos.sdf3d_cylinder_x(uv3, radius, length); +} + + + else if (axis == 1) { + return MMAlgos.sdf3d_cylinder_y(uv3, radius, length); +} + + + else if (axis == 2) { + return MMAlgos.sdf3d_cylinder_z(uv3, radius, length); +} + + return Vector2(); +} + + //axis; + + int Sdf3dShapeCylinder::get_axis() { + return axis; +} + + + void Sdf3dShapeCylinder::set_axis(const int val) { + axis = val; + emit_changed(); + output.emit_changed(); +} + + //length; + + float Sdf3dShapeCylinder::get_length() { + return length; +} + + + void Sdf3dShapeCylinder::set_length(const float val) { + length = val; + emit_changed(); + output.emit_changed(); +} + + //radius; + + float Sdf3dShapeCylinder::get_radius() { + return radius; +} + + + void Sdf3dShapeCylinder::set_radius(const float val) { + radius = val; + emit_changed(); + output.emit_changed(); +} + +} + + Sdf3dShapeCylinder::Sdf3dShapeCylinder() { + output; + axis = 1; + length = 0.25; + radius = 0.25; + } + + Sdf3dShapeCylinder::~Sdf3dShapeCylinder() { + } + + + static void Sdf3dShapeCylinder::_bind_methods() { + ClassDB::bind_method(D_METHOD("get_output"), &Sdf3dShapeCylinder::get_output); + ClassDB::bind_method(D_METHOD("set_output", "value"), &Sdf3dShapeCylinder::set_output); + ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "output", PROPERTY_HINT_RESOURCE_TYPE, "Ref"), "set_output", "get_output"); + + + ClassDB::bind_method(D_METHOD("get_axis"), &Sdf3dShapeCylinder::get_axis); + ClassDB::bind_method(D_METHOD("set_axis", "value"), &Sdf3dShapeCylinder::set_axis); + ADD_PROPERTY(PropertyInfo(Variant::INT, "axis"), "set_axis", "get_axis"); + + + ClassDB::bind_method(D_METHOD("get_length"), &Sdf3dShapeCylinder::get_length); + ClassDB::bind_method(D_METHOD("set_length", "value"), &Sdf3dShapeCylinder::set_length); + ADD_PROPERTY(PropertyInfo(Variant::REAL, "length"), "set_length", "get_length"); + + + ClassDB::bind_method(D_METHOD("get_radius"), &Sdf3dShapeCylinder::get_radius); + ClassDB::bind_method(D_METHOD("set_radius", "value"), &Sdf3dShapeCylinder::set_radius); + ADD_PROPERTY(PropertyInfo(Variant::REAL, "radius"), "set_radius", "get_radius"); + + + ClassDB::bind_method(D_METHOD("_init_properties"), &Sdf3dShapeCylinder::_init_properties); + ClassDB::bind_method(D_METHOD("_register_methods", "mm_graph_node"), &Sdf3dShapeCylinder::_register_methods); + ClassDB::bind_method(D_METHOD("_get_property_value_sdf3d", "uv3"), &Sdf3dShapeCylinder::_get_property_value_sdf3d); + ClassDB::bind_method(D_METHOD("get_axis"), &Sdf3dShapeCylinder::get_axis); + ClassDB::bind_method(D_METHOD("set_axis", "val"), &Sdf3dShapeCylinder::set_axis); + ClassDB::bind_method(D_METHOD("get_length"), &Sdf3dShapeCylinder::get_length); + ClassDB::bind_method(D_METHOD("set_length", "val"), &Sdf3dShapeCylinder::set_length); + ClassDB::bind_method(D_METHOD("get_radius"), &Sdf3dShapeCylinder::get_radius); + ClassDB::bind_method(D_METHOD("set_radius", "val"), &Sdf3dShapeCylinder::set_radius); + + } + + + diff --git a/modules/material_maker/nodes/sdf3d/sdf3d_shape_cylinder.h b/modules/material_maker/nodes/sdf3d/sdf3d_shape_cylinder.h new file mode 100644 index 000000000..ca15f38b9 --- /dev/null +++ b/modules/material_maker/nodes/sdf3d/sdf3d_shape_cylinder.h @@ -0,0 +1,53 @@ +#ifndef SDF3D_SHAPE_CYLINDER_H +#define SDF3D_SHAPE_CYLINDER_H + + +class Sdf3dShapeCylinder : public MMNode { + GDCLASS(Sdf3dShapeCylinder, MMNode); + + public: + + Ref get_output(); + void set_output(const Ref &val); + + int get_axis() const; + void set_axis(const int val); + + float get_length() const; + void set_length(const float val); + + float get_radius() const; + void set_radius(const float val); + + void _init_properties(); + void _register_methods(const Variant &mm_graph_node); + Vector2 _get_property_value_sdf3d(const Vector3 &uv3); + int get_axis(); + void set_axis(const int val); + float get_length(); + void set_length(const float val); + float get_radius(); + void set_radius(const float val); + + Sdf3dShapeCylinder(); + ~Sdf3dShapeCylinder(); + + protected: + static void _bind_methods(); + + //tool + //export(Resource) + Ref output; + //export(int, "X,Y,Z") + int axis = 1; + //export(float) + float length = 0.25; + //export(float) + float radius = 0.25; + //axis + //length + //radius +}; + + +#endif diff --git a/modules/material_maker/nodes/sdf3d/sdf3d_shape_sphere.cpp b/modules/material_maker/nodes/sdf3d/sdf3d_shape_sphere.cpp new file mode 100644 index 000000000..4fd6f5905 --- /dev/null +++ b/modules/material_maker/nodes/sdf3d/sdf3d_shape_sphere.cpp @@ -0,0 +1,98 @@ + +#include "sdf3d_shape_sphere.h" + + +Ref Sdf3dShapeSphere::get_output() { + return output; +} + +void Sdf3dShapeSphere::set_output(const Ref &val) { +output = val; +} + + +float Sdf3dShapeSphere::get_radius() const { + return radius; +} + +void Sdf3dShapeSphere::set_radius(const float val) { +radius = val; +} + + + + //tool; + //export(Resource) ; + Ref output; + //export(float) ; + float radius = 0.5; + + void Sdf3dShapeSphere::_init_properties() { + + if (!output) { + output = MMNodeUniversalProperty.new(); + output.default_type = MMNodeUniversalProperty.DEFAULT_TYPE_VECTOR2; +} + + output.output_slot_type = MMNodeUniversalProperty.SLOT_TYPE_FLOAT; + output.slot_name = ">>> Output >>>"; + output.get_value_from_owner = true; + register_output_property(output); +} + + + void Sdf3dShapeSphere::_register_methods(const Variant &mm_graph_node) { + mm_graph_node.add_slot_label_universal(output); + mm_graph_node.add_slot_float("get_radius", "set_radius", "Radius", 0.01); +} + + + Vector2 Sdf3dShapeSphere::_get_property_value_sdf3d(const Vector3 &uv3) { + return MMAlgos.sdf3d_sphere(uv3, radius); +} + + //radius; + + float Sdf3dShapeSphere::get_radius() { + return radius; +} + + + void Sdf3dShapeSphere::set_radius(const float val) { + radius = val; + emit_changed(); + output.emit_changed(); +} + +} + + Sdf3dShapeSphere::Sdf3dShapeSphere() { + output; + radius = 0.5; + } + + Sdf3dShapeSphere::~Sdf3dShapeSphere() { + } + + + static void Sdf3dShapeSphere::_bind_methods() { + ClassDB::bind_method(D_METHOD("get_output"), &Sdf3dShapeSphere::get_output); + ClassDB::bind_method(D_METHOD("set_output", "value"), &Sdf3dShapeSphere::set_output); + ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "output", PROPERTY_HINT_RESOURCE_TYPE, "Ref"), "set_output", "get_output"); + + + ClassDB::bind_method(D_METHOD("get_radius"), &Sdf3dShapeSphere::get_radius); + ClassDB::bind_method(D_METHOD("set_radius", "value"), &Sdf3dShapeSphere::set_radius); + ADD_PROPERTY(PropertyInfo(Variant::REAL, "radius"), "set_radius", "get_radius"); + + + ClassDB::bind_method(D_METHOD("_init_properties"), &Sdf3dShapeSphere::_init_properties); + ClassDB::bind_method(D_METHOD("_register_methods", "mm_graph_node"), &Sdf3dShapeSphere::_register_methods); + ClassDB::bind_method(D_METHOD("_get_property_value_sdf3d", "uv3"), &Sdf3dShapeSphere::_get_property_value_sdf3d); + ClassDB::bind_method(D_METHOD("get_radius"), &Sdf3dShapeSphere::get_radius); + ClassDB::bind_method(D_METHOD("set_radius", "val"), &Sdf3dShapeSphere::set_radius); + + } + + + diff --git a/modules/material_maker/nodes/sdf3d/sdf3d_shape_sphere.h b/modules/material_maker/nodes/sdf3d/sdf3d_shape_sphere.h new file mode 100644 index 000000000..8991b0721 --- /dev/null +++ b/modules/material_maker/nodes/sdf3d/sdf3d_shape_sphere.h @@ -0,0 +1,37 @@ +#ifndef SDF3D_SHAPE_SPHERE_H +#define SDF3D_SHAPE_SPHERE_H + + +class Sdf3dShapeSphere : public MMNode { + GDCLASS(Sdf3dShapeSphere, MMNode); + + public: + + Ref get_output(); + void set_output(const Ref &val); + + float get_radius() const; + void set_radius(const float val); + + void _init_properties(); + void _register_methods(const Variant &mm_graph_node); + Vector2 _get_property_value_sdf3d(const Vector3 &uv3); + float get_radius(); + void set_radius(const float val); + + Sdf3dShapeSphere(); + ~Sdf3dShapeSphere(); + + protected: + static void _bind_methods(); + + //tool + //export(Resource) + Ref output; + //export(float) + float radius = 0.5; + //radius +}; + + +#endif diff --git a/modules/material_maker/nodes/sdf3d/sdf3d_shape_torus.cpp b/modules/material_maker/nodes/sdf3d/sdf3d_shape_torus.cpp new file mode 100644 index 000000000..f9da769ee --- /dev/null +++ b/modules/material_maker/nodes/sdf3d/sdf3d_shape_torus.cpp @@ -0,0 +1,179 @@ + +#include "sdf3d_shape_torus.h" + + +Ref Sdf3dShapeTorus::get_output() { + return output; +} + +void Sdf3dShapeTorus::set_output(const Ref &val) { +output = val; +} + + +int Sdf3dShapeTorus::get_axis() const { + return axis; +} + +void Sdf3dShapeTorus::set_axis(const int val) { +axis = val; +} + + +float Sdf3dShapeTorus::get_major_radius() const { + return major_radius; +} + +void Sdf3dShapeTorus::set_major_radius(const float val) { +major_radius = val; +} + + +float Sdf3dShapeTorus::get_minor_radius() const { + return minor_radius; +} + +void Sdf3dShapeTorus::set_minor_radius(const float val) { +minor_radius = val; +} + + + + //tool; + //export(Resource) ; + Ref output; + //export(int, "X,Y,Z") ; + int axis = 2; + //export(float) ; + float major_radius = 0.3; + //export(float) ; + float minor_radius = 0.15; + + void Sdf3dShapeTorus::_init_properties() { + + if (!output) { + output = MMNodeUniversalProperty.new(); + output.default_type = MMNodeUniversalProperty.DEFAULT_TYPE_VECTOR2; +} + + output.output_slot_type = MMNodeUniversalProperty.SLOT_TYPE_FLOAT; + output.slot_name = ">>> Output >>>"; + output.get_value_from_owner = true; + register_output_property(output); +} + + + void Sdf3dShapeTorus::_register_methods(const Variant &mm_graph_node) { + mm_graph_node.add_slot_label_universal(output); + mm_graph_node.add_slot_enum("get_axis", "set_axis", "Axis", [ "X", "Y", "Z" ]); + mm_graph_node.add_slot_float("get_major_radius", "set_major_radius", "Major_radius", 0.01); + mm_graph_node.add_slot_float("get_minor_radius", "set_minor_radius", "Minor_radius", 0.01); +} + + + Vector2 Sdf3dShapeTorus::_get_property_value_sdf3d(const Vector3 &uv3) { + + if (axis == 0) { + return MMAlgos.sdf3d_torus_x(uv3, major_radius, minor_radius); +} + + + else if (axis == 1) { + return MMAlgos.sdf3d_torus_y(uv3, major_radius, minor_radius); +} + + + else if (axis == 2) { + return MMAlgos.sdf3d_torus_z(uv3, major_radius, minor_radius); +} + + return Vector2(); +} + + //axis; + + int Sdf3dShapeTorus::get_axis() { + return axis; +} + + + void Sdf3dShapeTorus::set_axis(const int val) { + axis = val; + emit_changed(); + output.emit_changed(); +} + + //major_radius; + + float Sdf3dShapeTorus::get_major_radius() { + return major_radius; +} + + + void Sdf3dShapeTorus::set_major_radius(const float val) { + major_radius = val; + emit_changed(); + output.emit_changed(); +} + + //minor_radius; + + float Sdf3dShapeTorus::get_minor_radius() { + return minor_radius; +} + + + void Sdf3dShapeTorus::set_minor_radius(const float val) { + minor_radius = val; + emit_changed(); + output.emit_changed(); +} + +} + + Sdf3dShapeTorus::Sdf3dShapeTorus() { + output; + axis = 2; + major_radius = 0.3; + minor_radius = 0.15; + } + + Sdf3dShapeTorus::~Sdf3dShapeTorus() { + } + + + static void Sdf3dShapeTorus::_bind_methods() { + ClassDB::bind_method(D_METHOD("get_output"), &Sdf3dShapeTorus::get_output); + ClassDB::bind_method(D_METHOD("set_output", "value"), &Sdf3dShapeTorus::set_output); + ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "output", PROPERTY_HINT_RESOURCE_TYPE, "Ref"), "set_output", "get_output"); + + + ClassDB::bind_method(D_METHOD("get_axis"), &Sdf3dShapeTorus::get_axis); + ClassDB::bind_method(D_METHOD("set_axis", "value"), &Sdf3dShapeTorus::set_axis); + ADD_PROPERTY(PropertyInfo(Variant::INT, "axis"), "set_axis", "get_axis"); + + + ClassDB::bind_method(D_METHOD("get_major_radius"), &Sdf3dShapeTorus::get_major_radius); + ClassDB::bind_method(D_METHOD("set_major_radius", "value"), &Sdf3dShapeTorus::set_major_radius); + ADD_PROPERTY(PropertyInfo(Variant::REAL, "major_radius"), "set_major_radius", "get_major_radius"); + + + ClassDB::bind_method(D_METHOD("get_minor_radius"), &Sdf3dShapeTorus::get_minor_radius); + ClassDB::bind_method(D_METHOD("set_minor_radius", "value"), &Sdf3dShapeTorus::set_minor_radius); + ADD_PROPERTY(PropertyInfo(Variant::REAL, "minor_radius"), "set_minor_radius", "get_minor_radius"); + + + ClassDB::bind_method(D_METHOD("_init_properties"), &Sdf3dShapeTorus::_init_properties); + ClassDB::bind_method(D_METHOD("_register_methods", "mm_graph_node"), &Sdf3dShapeTorus::_register_methods); + ClassDB::bind_method(D_METHOD("_get_property_value_sdf3d", "uv3"), &Sdf3dShapeTorus::_get_property_value_sdf3d); + ClassDB::bind_method(D_METHOD("get_axis"), &Sdf3dShapeTorus::get_axis); + ClassDB::bind_method(D_METHOD("set_axis", "val"), &Sdf3dShapeTorus::set_axis); + ClassDB::bind_method(D_METHOD("get_major_radius"), &Sdf3dShapeTorus::get_major_radius); + ClassDB::bind_method(D_METHOD("set_major_radius", "val"), &Sdf3dShapeTorus::set_major_radius); + ClassDB::bind_method(D_METHOD("get_minor_radius"), &Sdf3dShapeTorus::get_minor_radius); + ClassDB::bind_method(D_METHOD("set_minor_radius", "val"), &Sdf3dShapeTorus::set_minor_radius); + + } + + + diff --git a/modules/material_maker/nodes/sdf3d/sdf3d_shape_torus.h b/modules/material_maker/nodes/sdf3d/sdf3d_shape_torus.h new file mode 100644 index 000000000..cbbd86f3c --- /dev/null +++ b/modules/material_maker/nodes/sdf3d/sdf3d_shape_torus.h @@ -0,0 +1,53 @@ +#ifndef SDF3D_SHAPE_TORUS_H +#define SDF3D_SHAPE_TORUS_H + + +class Sdf3dShapeTorus : public MMNode { + GDCLASS(Sdf3dShapeTorus, MMNode); + + public: + + Ref get_output(); + void set_output(const Ref &val); + + int get_axis() const; + void set_axis(const int val); + + float get_major_radius() const; + void set_major_radius(const float val); + + float get_minor_radius() const; + void set_minor_radius(const float val); + + void _init_properties(); + void _register_methods(const Variant &mm_graph_node); + Vector2 _get_property_value_sdf3d(const Vector3 &uv3); + int get_axis(); + void set_axis(const int val); + float get_major_radius(); + void set_major_radius(const float val); + float get_minor_radius(); + void set_minor_radius(const float val); + + Sdf3dShapeTorus(); + ~Sdf3dShapeTorus(); + + protected: + static void _bind_methods(); + + //tool + //export(Resource) + Ref output; + //export(int, "X,Y,Z") + int axis = 2; + //export(float) + float major_radius = 0.3; + //export(float) + float minor_radius = 0.15; + //axis + //major_radius + //minor_radius +}; + + +#endif diff --git a/modules/material_maker/nodes/sdf3d/sdf3d_tf_rotate.cpp b/modules/material_maker/nodes/sdf3d/sdf3d_tf_rotate.cpp new file mode 100644 index 000000000..45b3aa4a5 --- /dev/null +++ b/modules/material_maker/nodes/sdf3d/sdf3d_tf_rotate.cpp @@ -0,0 +1,139 @@ + +#include "sdf3d_tf_rotate.h" + + +Ref Sdf3dTfRotate::get_input() { + return input; +} + +void Sdf3dTfRotate::set_input(const Ref &val) { +input = val; +} + + +Ref Sdf3dTfRotate::get_output() { + return output; +} + +void Sdf3dTfRotate::set_output(const Ref &val) { +output = val; +} + + +Vector3 Sdf3dTfRotate::get_rotation() { + return rotation; +} + +void Sdf3dTfRotate::set_rotation(const Vector3 &val) { +rotation = val; +} + + + + //tool; + //export(Resource) ; + Ref input; + //export(Resource) ; + Ref output; + //export(Vector3) ; + Vector3 rotation = Vector3(); + + void Sdf3dTfRotate::_init_properties() { + + if (!input) { + input = MMNodeUniversalProperty.new(); + input.default_type = MMNodeUniversalProperty.DEFAULT_TYPE_VECTOR2; +} + + input.input_slot_type = MMNodeUniversalProperty.SLOT_TYPE_UNIVERSAL; + // input.input_slot_type = MMNodeUniversalProperty.SLOT_TYPE_VECTOR2; + input.slot_name = ">>> Input "; + + if (!input.is_connected("changed", self, "on_input_changed")) { + input.connect("changed", self, "on_input_changed"); +} + + + if (!output) { + output = MMNodeUniversalProperty.new(); + output.default_type = MMNodeUniversalProperty.DEFAULT_TYPE_VECTOR2; +} + + output.output_slot_type = MMNodeUniversalProperty.SLOT_TYPE_FLOAT; + output.slot_name = ">>> Output >>>"; + output.get_value_from_owner = true; + register_input_property(input); + register_output_property(output); +} + + + void Sdf3dTfRotate::_register_methods(const Variant &mm_graph_node) { + mm_graph_node.add_slot_label_universal(input); + mm_graph_node.add_slot_label_universal(output); + mm_graph_node.add_slot_vector3("get_rotation", "set_rotation", "Rotation", 0.01); +} + + + Vector2 Sdf3dTfRotate::_get_property_value_sdf3d(const Vector3 &uv3) { + //$in(rotate3d($uv, -vec3($ax, $ay, $az)*0.01745329251)); + return input.get_value_sdf3d(MMAlgos.rotate3d(uv3, -rotation * 0.01745329251)); +} + + //rotation; + + Vector3 Sdf3dTfRotate::get_rotation() { + return rotation; +} + + + void Sdf3dTfRotate::set_rotation(const Vector3 &val) { + rotation = val; + emit_changed(); + output.emit_changed(); +} + + + void Sdf3dTfRotate::on_input_changed() { + emit_changed(); + output.emit_changed(); +} + +} + + Sdf3dTfRotate::Sdf3dTfRotate() { + input; + output; + rotation = Vector3(); + } + + Sdf3dTfRotate::~Sdf3dTfRotate() { + } + + + static void Sdf3dTfRotate::_bind_methods() { + ClassDB::bind_method(D_METHOD("get_input"), &Sdf3dTfRotate::get_input); + ClassDB::bind_method(D_METHOD("set_input", "value"), &Sdf3dTfRotate::set_input); + ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "input", PROPERTY_HINT_RESOURCE_TYPE, "Ref"), "set_input", "get_input"); + + + ClassDB::bind_method(D_METHOD("get_output"), &Sdf3dTfRotate::get_output); + ClassDB::bind_method(D_METHOD("set_output", "value"), &Sdf3dTfRotate::set_output); + ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "output", PROPERTY_HINT_RESOURCE_TYPE, "Ref"), "set_output", "get_output"); + + + ClassDB::bind_method(D_METHOD("get_rotation"), &Sdf3dTfRotate::get_rotation); + ClassDB::bind_method(D_METHOD("set_rotation", "value"), &Sdf3dTfRotate::set_rotation); + ADD_PROPERTY(PropertyInfo(Variant::VECTOR3, "rotation"), "set_rotation", "get_rotation"); + + + ClassDB::bind_method(D_METHOD("_init_properties"), &Sdf3dTfRotate::_init_properties); + ClassDB::bind_method(D_METHOD("_register_methods", "mm_graph_node"), &Sdf3dTfRotate::_register_methods); + ClassDB::bind_method(D_METHOD("_get_property_value_sdf3d", "uv3"), &Sdf3dTfRotate::_get_property_value_sdf3d); + ClassDB::bind_method(D_METHOD("get_rotation"), &Sdf3dTfRotate::get_rotation); + ClassDB::bind_method(D_METHOD("set_rotation", "val"), &Sdf3dTfRotate::set_rotation); + ClassDB::bind_method(D_METHOD("on_input_changed"), &Sdf3dTfRotate::on_input_changed); + + } + + + diff --git a/modules/material_maker/nodes/sdf3d/sdf3d_tf_rotate.h b/modules/material_maker/nodes/sdf3d/sdf3d_tf_rotate.h new file mode 100644 index 000000000..0a401c57d --- /dev/null +++ b/modules/material_maker/nodes/sdf3d/sdf3d_tf_rotate.h @@ -0,0 +1,43 @@ +#ifndef SDF3D_TF_ROTATE_H +#define SDF3D_TF_ROTATE_H + + +class Sdf3dTfRotate : public MMNode { + GDCLASS(Sdf3dTfRotate, MMNode); + + public: + + Ref get_input(); + void set_input(const Ref &val); + + Ref get_output(); + void set_output(const Ref &val); + + Vector3 get_rotation(); + void set_rotation(const Vector3 &val); + + void _init_properties(); + void _register_methods(const Variant &mm_graph_node); + Vector2 _get_property_value_sdf3d(const Vector3 &uv3); + Vector3 get_rotation(); + void set_rotation(const Vector3 &val); + void on_input_changed(); + + Sdf3dTfRotate(); + ~Sdf3dTfRotate(); + + protected: + static void _bind_methods(); + + //tool + //export(Resource) + Ref input; + //export(Resource) + Ref output; + //export(Vector3) + Vector3 rotation = Vector3(); + //rotation +}; + + +#endif diff --git a/modules/material_maker/nodes/sdf3d/sdf3d_tf_scale.cpp b/modules/material_maker/nodes/sdf3d/sdf3d_tf_scale.cpp new file mode 100644 index 000000000..f151729ab --- /dev/null +++ b/modules/material_maker/nodes/sdf3d/sdf3d_tf_scale.cpp @@ -0,0 +1,139 @@ + +#include "sdf3d_tf_scale.h" + + +Ref Sdf3dTfScale::get_input() { + return input; +} + +void Sdf3dTfScale::set_input(const Ref &val) { +input = val; +} + + +Ref Sdf3dTfScale::get_output() { + return output; +} + +void Sdf3dTfScale::set_output(const Ref &val) { +output = val; +} + + +float Sdf3dTfScale::get_scale() const { + return scale; +} + +void Sdf3dTfScale::set_scale(const float val) { +scale = val; +} + + + + //tool; + //export(Resource) ; + Ref input; + //export(Resource) ; + Ref output; + //export(float) ; + float scale = 1; + + void Sdf3dTfScale::_init_properties() { + + if (!input) { + input = MMNodeUniversalProperty.new(); + input.default_type = MMNodeUniversalProperty.DEFAULT_TYPE_VECTOR2; +} + + input.input_slot_type = MMNodeUniversalProperty.SLOT_TYPE_UNIVERSAL; + // input.input_slot_type = MMNodeUniversalProperty.SLOT_TYPE_VECTOR2; + input.slot_name = ">>> Input "; + + if (!input.is_connected("changed", self, "on_input_changed")) { + input.connect("changed", self, "on_input_changed"); +} + + + if (!output) { + output = MMNodeUniversalProperty.new(); + output.default_type = MMNodeUniversalProperty.DEFAULT_TYPE_VECTOR2; +} + + output.output_slot_type = MMNodeUniversalProperty.SLOT_TYPE_FLOAT; + output.slot_name = ">>> Output >>>"; + output.get_value_from_owner = true; + register_input_property(input); + register_output_property(output); +} + + + void Sdf3dTfScale::_register_methods(const Variant &mm_graph_node) { + mm_graph_node.add_slot_label_universal(input); + mm_graph_node.add_slot_label_universal(output); + mm_graph_node.add_slot_float("get_scale", "set_scale", "Scale", 0.01); +} + + + Vector2 Sdf3dTfScale::_get_property_value_sdf3d(const Vector3 &uv3) { + //vec2 $(name_uv)_in = $in(($uv)/$s); + return input.get_value_sdf3d(uv3 / scale); +} + + //scale; + + float Sdf3dTfScale::get_scale() { + return scale; +} + + + void Sdf3dTfScale::set_scale(const float val) { + scale = val; + emit_changed(); + output.emit_changed(); +} + + + void Sdf3dTfScale::on_input_changed() { + emit_changed(); + output.emit_changed(); +} + +} + + Sdf3dTfScale::Sdf3dTfScale() { + input; + output; + scale = 1; + } + + Sdf3dTfScale::~Sdf3dTfScale() { + } + + + static void Sdf3dTfScale::_bind_methods() { + ClassDB::bind_method(D_METHOD("get_input"), &Sdf3dTfScale::get_input); + ClassDB::bind_method(D_METHOD("set_input", "value"), &Sdf3dTfScale::set_input); + ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "input", PROPERTY_HINT_RESOURCE_TYPE, "Ref"), "set_input", "get_input"); + + + ClassDB::bind_method(D_METHOD("get_output"), &Sdf3dTfScale::get_output); + ClassDB::bind_method(D_METHOD("set_output", "value"), &Sdf3dTfScale::set_output); + ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "output", PROPERTY_HINT_RESOURCE_TYPE, "Ref"), "set_output", "get_output"); + + + ClassDB::bind_method(D_METHOD("get_scale"), &Sdf3dTfScale::get_scale); + ClassDB::bind_method(D_METHOD("set_scale", "value"), &Sdf3dTfScale::set_scale); + ADD_PROPERTY(PropertyInfo(Variant::REAL, "scale"), "set_scale", "get_scale"); + + + ClassDB::bind_method(D_METHOD("_init_properties"), &Sdf3dTfScale::_init_properties); + ClassDB::bind_method(D_METHOD("_register_methods", "mm_graph_node"), &Sdf3dTfScale::_register_methods); + ClassDB::bind_method(D_METHOD("_get_property_value_sdf3d", "uv3"), &Sdf3dTfScale::_get_property_value_sdf3d); + ClassDB::bind_method(D_METHOD("get_scale"), &Sdf3dTfScale::get_scale); + ClassDB::bind_method(D_METHOD("set_scale", "val"), &Sdf3dTfScale::set_scale); + ClassDB::bind_method(D_METHOD("on_input_changed"), &Sdf3dTfScale::on_input_changed); + + } + + + diff --git a/modules/material_maker/nodes/sdf3d/sdf3d_tf_scale.h b/modules/material_maker/nodes/sdf3d/sdf3d_tf_scale.h new file mode 100644 index 000000000..cc9828600 --- /dev/null +++ b/modules/material_maker/nodes/sdf3d/sdf3d_tf_scale.h @@ -0,0 +1,43 @@ +#ifndef SDF3D_TF_SCALE_H +#define SDF3D_TF_SCALE_H + + +class Sdf3dTfScale : public MMNode { + GDCLASS(Sdf3dTfScale, MMNode); + + public: + + Ref get_input(); + void set_input(const Ref &val); + + Ref get_output(); + void set_output(const Ref &val); + + float get_scale() const; + void set_scale(const float val); + + void _init_properties(); + void _register_methods(const Variant &mm_graph_node); + Vector2 _get_property_value_sdf3d(const Vector3 &uv3); + float get_scale(); + void set_scale(const float val); + void on_input_changed(); + + Sdf3dTfScale(); + ~Sdf3dTfScale(); + + protected: + static void _bind_methods(); + + //tool + //export(Resource) + Ref input; + //export(Resource) + Ref output; + //export(float) + float scale = 1; + //scale +}; + + +#endif diff --git a/modules/material_maker/nodes/sdf3d/sdf3d_tf_translate.cpp b/modules/material_maker/nodes/sdf3d/sdf3d_tf_translate.cpp new file mode 100644 index 000000000..353a4847f --- /dev/null +++ b/modules/material_maker/nodes/sdf3d/sdf3d_tf_translate.cpp @@ -0,0 +1,139 @@ + +#include "sdf3d_tf_translate.h" + + +Ref Sdf3dTfTranslate::get_input() { + return input; +} + +void Sdf3dTfTranslate::set_input(const Ref &val) { +input = val; +} + + +Ref Sdf3dTfTranslate::get_output() { + return output; +} + +void Sdf3dTfTranslate::set_output(const Ref &val) { +output = val; +} + + +Vector3 Sdf3dTfTranslate::get_translation() { + return translation; +} + +void Sdf3dTfTranslate::set_translation(const Vector3 &val) { +translation = val; +} + + + + //tool; + //export(Resource) ; + Ref input; + //export(Resource) ; + Ref output; + //export(Vector3) ; + Vector3 translation = Vector3(); + + void Sdf3dTfTranslate::_init_properties() { + + if (!input) { + input = MMNodeUniversalProperty.new(); + input.default_type = MMNodeUniversalProperty.DEFAULT_TYPE_VECTOR2; +} + + input.input_slot_type = MMNodeUniversalProperty.SLOT_TYPE_UNIVERSAL; + // input.input_slot_type = MMNodeUniversalProperty.SLOT_TYPE_VECTOR2; + input.slot_name = ">>> Input "; + + if (!input.is_connected("changed", self, "on_input_changed")) { + input.connect("changed", self, "on_input_changed"); +} + + + if (!output) { + output = MMNodeUniversalProperty.new(); + output.default_type = MMNodeUniversalProperty.DEFAULT_TYPE_VECTOR2; +} + + output.output_slot_type = MMNodeUniversalProperty.SLOT_TYPE_FLOAT; + output.slot_name = ">>> Output >>>"; + output.get_value_from_owner = true; + register_input_property(input); + register_output_property(output); +} + + + void Sdf3dTfTranslate::_register_methods(const Variant &mm_graph_node) { + mm_graph_node.add_slot_label_universal(input); + mm_graph_node.add_slot_label_universal(output); + mm_graph_node.add_slot_vector3("get_translation", "set_translation", "Translation", 0.01); +} + + + Vector2 Sdf3dTfTranslate::_get_property_value_sdf3d(const Vector3 &uv3) { + //$in($uv-vec3($x, $y, $z)); + return input.get_value_sdf3d(uv3 - translation); +} + + //translation; + + Vector3 Sdf3dTfTranslate::get_translation() { + return translation; +} + + + void Sdf3dTfTranslate::set_translation(const Vector3 &val) { + translation = val; + emit_changed(); + output.emit_changed(); +} + + + void Sdf3dTfTranslate::on_input_changed() { + emit_changed(); + output.emit_changed(); +} + +} + + Sdf3dTfTranslate::Sdf3dTfTranslate() { + input; + output; + translation = Vector3(); + } + + Sdf3dTfTranslate::~Sdf3dTfTranslate() { + } + + + static void Sdf3dTfTranslate::_bind_methods() { + ClassDB::bind_method(D_METHOD("get_input"), &Sdf3dTfTranslate::get_input); + ClassDB::bind_method(D_METHOD("set_input", "value"), &Sdf3dTfTranslate::set_input); + ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "input", PROPERTY_HINT_RESOURCE_TYPE, "Ref"), "set_input", "get_input"); + + + ClassDB::bind_method(D_METHOD("get_output"), &Sdf3dTfTranslate::get_output); + ClassDB::bind_method(D_METHOD("set_output", "value"), &Sdf3dTfTranslate::set_output); + ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "output", PROPERTY_HINT_RESOURCE_TYPE, "Ref"), "set_output", "get_output"); + + + ClassDB::bind_method(D_METHOD("get_translation"), &Sdf3dTfTranslate::get_translation); + ClassDB::bind_method(D_METHOD("set_translation", "value"), &Sdf3dTfTranslate::set_translation); + ADD_PROPERTY(PropertyInfo(Variant::VECTOR3, "translation"), "set_translation", "get_translation"); + + + ClassDB::bind_method(D_METHOD("_init_properties"), &Sdf3dTfTranslate::_init_properties); + ClassDB::bind_method(D_METHOD("_register_methods", "mm_graph_node"), &Sdf3dTfTranslate::_register_methods); + ClassDB::bind_method(D_METHOD("_get_property_value_sdf3d", "uv3"), &Sdf3dTfTranslate::_get_property_value_sdf3d); + ClassDB::bind_method(D_METHOD("get_translation"), &Sdf3dTfTranslate::get_translation); + ClassDB::bind_method(D_METHOD("set_translation", "val"), &Sdf3dTfTranslate::set_translation); + ClassDB::bind_method(D_METHOD("on_input_changed"), &Sdf3dTfTranslate::on_input_changed); + + } + + + diff --git a/modules/material_maker/nodes/sdf3d/sdf3d_tf_translate.h b/modules/material_maker/nodes/sdf3d/sdf3d_tf_translate.h new file mode 100644 index 000000000..aee82c598 --- /dev/null +++ b/modules/material_maker/nodes/sdf3d/sdf3d_tf_translate.h @@ -0,0 +1,43 @@ +#ifndef SDF3D_TF_TRANSLATE_H +#define SDF3D_TF_TRANSLATE_H + + +class Sdf3dTfTranslate : public MMNode { + GDCLASS(Sdf3dTfTranslate, MMNode); + + public: + + Ref get_input(); + void set_input(const Ref &val); + + Ref get_output(); + void set_output(const Ref &val); + + Vector3 get_translation(); + void set_translation(const Vector3 &val); + + void _init_properties(); + void _register_methods(const Variant &mm_graph_node); + Vector2 _get_property_value_sdf3d(const Vector3 &uv3); + Vector3 get_translation(); + void set_translation(const Vector3 &val); + void on_input_changed(); + + Sdf3dTfTranslate(); + ~Sdf3dTfTranslate(); + + protected: + static void _bind_methods(); + + //tool + //export(Resource) + Ref input; + //export(Resource) + Ref output; + //export(Vector3) + Vector3 translation = Vector3(); + //translation +}; + + +#endif diff --git a/modules/material_maker/nodes/simple/curve.cpp b/modules/material_maker/nodes/simple/curve.cpp new file mode 100644 index 000000000..5a50446fa --- /dev/null +++ b/modules/material_maker/nodes/simple/curve.cpp @@ -0,0 +1,279 @@ + +#include "curve.h" + + +Ref Curve::get_image() { + return image; +} + +void Curve::set_image(const Ref &val) { +image = val; +} + + +Ref Curve::get_input() { + return input; +} + +void Curve::set_input(const Ref &val) { +input = val; +} + + +Vector2 Curve::get_a() { + return a; +} + +void Curve::set_a(const Vector2 &val) { +a = val; +} + + +Vector2 Curve::get_b() { + return b; +} + +void Curve::set_b(const Vector2 &val) { +b = val; +} + + +Vector2 Curve::get_c() { + return c; +} + +void Curve::set_c(const Vector2 &val) { +c = val; +} + + +float Curve::get_width() const { + return width; +} + +void Curve::set_width(const float val) { +width = val; +} + + +int Curve::get_repeat() const { + return repeat; +} + +void Curve::set_repeat(const int val) { +repeat = val; +} + + + + //tool; + //export(Resource) ; + Ref image; + //export(Resource) ; + Ref input; + //export(Vector2) ; + Vector2 a = Vector2(-0.35, -0.2); + //export(Vector2) ; + Vector2 b = Vector2(0, 0.5); + //export(Vector2) ; + Vector2 c = Vector2(0.35, -0.2); + //export(float) ; + float width = 0.05; + //export(int) ; + int repeat = 1; + + void Curve::_init_properties() { + + if (!image) { + image = MMNodeUniversalProperty.new(); + image.default_type = MMNodeUniversalProperty.DEFAULT_TYPE_IMAGE; +} + + image.output_slot_type = MMNodeUniversalProperty.SLOT_TYPE_IMAGE; + + if (!input) { + input = MMNodeUniversalProperty.new(); + input.default_type = MMNodeUniversalProperty.DEFAULT_TYPE_FLOAT; + input.set_default_value(1.0); +} + + input.input_slot_type = MMNodeUniversalProperty.SLOT_TYPE_UNIVERSAL; + input.slot_name = ">>> Input "; + register_input_property(input); + register_output_property(image); +} + + + void Curve::_register_methods(const Variant &mm_graph_node) { + mm_graph_node.add_slot_texture_universal(image); + mm_graph_node.add_slot_label_universal(input); + mm_graph_node.add_slot_vector2("get_a", "set_a", "A", 0.01); + mm_graph_node.add_slot_vector2("get_b", "set_b", "B", 0.01); + mm_graph_node.add_slot_vector2("get_c", "set_c", "C", 0.01); + mm_graph_node.add_slot_float("get_width", "set_width", "Width", 0.01); + mm_graph_node.add_slot_int("get_repeat", "set_repeat", "Repeat"); +} + + + Color Curve::_get_value_for(const Vector2 &uv, const int pseed) { + Vector2 nuv = transform_uv(uv); + float f = 0; + + if (nuv.x != 0 && nuv.y != 0) { + f = input.get_value(nuv); +} + + return Color(f, f, f, 1); +} + + + void Curve::_render(const Variant &material) { + Ref img = render_image(material); + image.set_value(img); +} + + + Vector2 Curve::transform_uv(const Vector2 &uv) { + //vec2 $(name_uv)_bezier = sdBezier($uv, vec2($ax+0.5, $ay+0.5), vec2($bx+0.5, $by+0.5), vec2($cx+0.5, $cy+0.5)); + Vector2 bezier = MMAlgos.sdBezier(uv, Vector2(a.x + 0.5, a.y + 0.5), Vector2(b.x + 0.5, b.y + 0.5), Vector2(c.x + 0.5, c.y + 0.5)); + //vec2 $(name_uv)_uv = vec2($(name_uv)_bezier.x, $(name_uv)_bezier.y / $width+0.5); + Vector2 new_uv = Vector2(bezier.x, bezier.y / width + 0.5); + //vec2 $(name_uv)_uvtest = step(vec2(0.5), abs($(name_uv)_uv-vec2(0.5))); + Vector2 uv_test = MMAlgos.stepv2(Vector2(0.5, 0.5), MMAlgos.absv2(new_uv - Vector2(0.5, 0.5))); + //$(name_uv)_uv = mix(vec2(fract($repeat*$(name_uv)_uv.x), $(name_uv)_uv.y), vec2(0.0), max($(name_uv)_uvtest.x, $(name_uv)_uvtest.y)); + Vector2 final_uv = lerp(Vector2(MMAlgos.fract(repeat * new_uv.x), new_uv.y), Vector2(), max(uv_test.x, uv_test.y)); + return final_uv; +} + + //b; + + Vector2 Curve::get_a() { + return a; +} + + + void Curve::set_a(const Vector2 &val) { + a = val; + set_dirty(true); +} + + //b; + + Vector2 Curve::get_b() { + return b; +} + + + void Curve::set_b(const Vector2 &val) { + b = val; + set_dirty(true); +} + + //c; + + Vector2 Curve::get_c() { + return c; +} + + + void Curve::set_c(const Vector2 &val) { + c = val; + set_dirty(true); +} + + //width; + + float Curve::get_width() { + return width; +} + + + void Curve::set_width(const float val) { + width = val; + set_dirty(true); +} + + //repeat; + + int Curve::get_repeat() { + return repeat; +} + + + void Curve::set_repeat(const int val) { + repeat = val; + set_dirty(true); +} + +} + + Curve::Curve() { + image; + input; + a = Vector2(-0.35, -0.2); + b = Vector2(0, 0.5); + c = Vector2(0.35, -0.2); + width = 0.05; + repeat = 1; + } + + Curve::~Curve() { + } + + + static void Curve::_bind_methods() { + ClassDB::bind_method(D_METHOD("get_image"), &Curve::get_image); + ClassDB::bind_method(D_METHOD("set_image", "value"), &Curve::set_image); + ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "image", PROPERTY_HINT_RESOURCE_TYPE, "Ref"), "set_image", "get_image"); + + + ClassDB::bind_method(D_METHOD("get_input"), &Curve::get_input); + ClassDB::bind_method(D_METHOD("set_input", "value"), &Curve::set_input); + ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "input", PROPERTY_HINT_RESOURCE_TYPE, "Ref"), "set_input", "get_input"); + + + ClassDB::bind_method(D_METHOD("get_a"), &Curve::get_a); + ClassDB::bind_method(D_METHOD("set_a", "value"), &Curve::set_a); + ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "a"), "set_a", "get_a"); + + + ClassDB::bind_method(D_METHOD("get_b"), &Curve::get_b); + ClassDB::bind_method(D_METHOD("set_b", "value"), &Curve::set_b); + ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "b"), "set_b", "get_b"); + + + ClassDB::bind_method(D_METHOD("get_c"), &Curve::get_c); + ClassDB::bind_method(D_METHOD("set_c", "value"), &Curve::set_c); + ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "c"), "set_c", "get_c"); + + + ClassDB::bind_method(D_METHOD("get_width"), &Curve::get_width); + ClassDB::bind_method(D_METHOD("set_width", "value"), &Curve::set_width); + ADD_PROPERTY(PropertyInfo(Variant::REAL, "width"), "set_width", "get_width"); + + + ClassDB::bind_method(D_METHOD("get_repeat"), &Curve::get_repeat); + ClassDB::bind_method(D_METHOD("set_repeat", "value"), &Curve::set_repeat); + ADD_PROPERTY(PropertyInfo(Variant::INT, "repeat"), "set_repeat", "get_repeat"); + + + ClassDB::bind_method(D_METHOD("_init_properties"), &Curve::_init_properties); + ClassDB::bind_method(D_METHOD("_register_methods", "mm_graph_node"), &Curve::_register_methods); + ClassDB::bind_method(D_METHOD("_get_value_for", "uv", "pseed"), &Curve::_get_value_for); + ClassDB::bind_method(D_METHOD("_render", "material"), &Curve::_render); + ClassDB::bind_method(D_METHOD("transform_uv", "uv"), &Curve::transform_uv); + ClassDB::bind_method(D_METHOD("get_a"), &Curve::get_a); + ClassDB::bind_method(D_METHOD("set_a", "val"), &Curve::set_a); + ClassDB::bind_method(D_METHOD("get_b"), &Curve::get_b); + ClassDB::bind_method(D_METHOD("set_b", "val"), &Curve::set_b); + ClassDB::bind_method(D_METHOD("get_c"), &Curve::get_c); + ClassDB::bind_method(D_METHOD("set_c", "val"), &Curve::set_c); + ClassDB::bind_method(D_METHOD("get_width"), &Curve::get_width); + ClassDB::bind_method(D_METHOD("set_width", "val"), &Curve::set_width); + ClassDB::bind_method(D_METHOD("get_repeat"), &Curve::get_repeat); + ClassDB::bind_method(D_METHOD("set_repeat", "val"), &Curve::set_repeat); + + } + + + diff --git a/modules/material_maker/nodes/simple/curve.h b/modules/material_maker/nodes/simple/curve.h new file mode 100644 index 000000000..6905615b8 --- /dev/null +++ b/modules/material_maker/nodes/simple/curve.h @@ -0,0 +1,76 @@ +#ifndef CURVE_H +#define CURVE_H + + +class Curve : public MMNode { + GDCLASS(Curve, MMNode); + + public: + + Ref get_image(); + void set_image(const Ref &val); + + Ref get_input(); + void set_input(const Ref &val); + + Vector2 get_a(); + void set_a(const Vector2 &val); + + Vector2 get_b(); + void set_b(const Vector2 &val); + + Vector2 get_c(); + void set_c(const Vector2 &val); + + float get_width() const; + void set_width(const float val); + + int get_repeat() const; + void set_repeat(const int val); + + 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 transform_uv(const Vector2 &uv); + Vector2 get_a(); + void set_a(const Vector2 &val); + Vector2 get_b(); + void set_b(const Vector2 &val); + Vector2 get_c(); + void set_c(const Vector2 &val); + float get_width(); + void set_width(const float val); + int get_repeat(); + void set_repeat(const int val); + + Curve(); + ~Curve(); + + protected: + static void _bind_methods(); + + //tool + //export(Resource) + Ref image; + //export(Resource) + Ref input; + //export(Vector2) + Vector2 a = Vector2(-0.35, -0.2); + //export(Vector2) + Vector2 b = Vector2(0, 0.5); + //export(Vector2) + Vector2 c = Vector2(0.35, -0.2); + //export(float) + float width = 0.05; + //export(int) + int repeat = 1; + //b + //b + //c + //width + //repeat +}; + + +#endif diff --git a/modules/material_maker/nodes/simple/image.cpp b/modules/material_maker/nodes/simple/image.cpp new file mode 100644 index 000000000..98cfa6944 --- /dev/null +++ b/modules/material_maker/nodes/simple/image.cpp @@ -0,0 +1,104 @@ + +#include "image.h" + + +Ref Image::get_image() { + return image; +} + +void Image::set_image(const Ref &val) { +image = val; +} + + +String Image::get_image_path() { + return image_path; +} + +void Image::set_image_path(const String &val) { +image_path = val; +} + + + + //tool; + //export(Resource) ; + Ref image; + //export(String) ; + String image_path = ; + + void Image::_init_properties() { + + if (!image) { + image = MMNodeUniversalProperty.new(); + image.default_type = MMNodeUniversalProperty.DEFAULT_TYPE_IMAGE; +} + + image.output_slot_type = MMNodeUniversalProperty.SLOT_TYPE_IMAGE; + register_output_property(image); +} + + + void Image::_register_methods(const Variant &mm_graph_node) { + mm_graph_node.add_slot_image_path_universal(image, "get_image_path", "set_image_path"); +} + + //func _render(material) -> void:; + // var img : Image = render_image(material); + //; + // image.set_value(img); + + Color Image::_get_value_for(const Vector2 &uv, const int pseed) { + return image.get_value(uv); +} + + + String Image::get_image_path() { + return image_path; +} + + + void Image::set_image_path(const String &val) { + image_path = val; + Ref img = Image.new(); + + if (image_path && image_path != "") { + img.load(image_path); +} + + image.set_value(img); + set_dirty(true); +} + +} + + Image::Image() { + image; + image_path = ; + } + + Image::~Image() { + } + + + static void Image::_bind_methods() { + ClassDB::bind_method(D_METHOD("get_image"), &Image::get_image); + ClassDB::bind_method(D_METHOD("set_image", "value"), &Image::set_image); + ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "image", PROPERTY_HINT_RESOURCE_TYPE, "Ref"), "set_image", "get_image"); + + + ClassDB::bind_method(D_METHOD("get_image_path"), &Image::get_image_path); + ClassDB::bind_method(D_METHOD("set_image_path", "value"), &Image::set_image_path); + ADD_PROPERTY(PropertyInfo(Variant::STRING, "image_path"), "set_image_path", "get_image_path"); + + + ClassDB::bind_method(D_METHOD("_init_properties"), &Image::_init_properties); + ClassDB::bind_method(D_METHOD("_register_methods", "mm_graph_node"), &Image::_register_methods); + ClassDB::bind_method(D_METHOD("_get_value_for", "uv", "pseed"), &Image::_get_value_for); + ClassDB::bind_method(D_METHOD("get_image_path"), &Image::get_image_path); + ClassDB::bind_method(D_METHOD("set_image_path", "val"), &Image::set_image_path); + + } + + + diff --git a/modules/material_maker/nodes/simple/image.h b/modules/material_maker/nodes/simple/image.h new file mode 100644 index 000000000..1af951871 --- /dev/null +++ b/modules/material_maker/nodes/simple/image.h @@ -0,0 +1,40 @@ +#ifndef IMAGE_H +#define IMAGE_H + + +class Image : public MMNode { + GDCLASS(Image, MMNode); + + public: + + Ref get_image(); + void set_image(const Ref &val); + + String get_image_path(); + void set_image_path(const String &val); + + void _init_properties(); + void _register_methods(const Variant &mm_graph_node); + Color _get_value_for(const Vector2 &uv, const int pseed); + String get_image_path(); + void set_image_path(const String &val); + + Image(); + ~Image(); + + protected: + static void _bind_methods(); + + //tool + //export(Resource) + Ref image; + //export(String) + String image_path = ; + //func _render(material) -> void: + // var img : Image = render_image(material) + // + // image.set_value(img) +}; + + +#endif diff --git a/modules/material_maker/nodes/simple/shape.cpp b/modules/material_maker/nodes/simple/shape.cpp new file mode 100644 index 000000000..793a46490 --- /dev/null +++ b/modules/material_maker/nodes/simple/shape.cpp @@ -0,0 +1,230 @@ + +#include "shape.h" + + +Ref Shape::get_image() { + return image; +} + +void Shape::set_image(const Ref &val) { +image = val; +} + + +int Shape::get_shape_type() const { + return shape_type; +} + +void Shape::set_shape_type(const int val) { +shape_type = val; +} + + +int Shape::get_sides() const { + return sides; +} + +void Shape::set_sides(const int val) { +sides = val; +} + + +Ref Shape::get_radius() { + return radius; +} + +void Shape::set_radius(const Ref &val) { +radius = val; +} + + +Ref Shape::get_edge() { + return edge; +} + +void Shape::set_edge(const Ref &val) { +edge = val; +} + + + + //tool; + }; + //export(Resource) ; + Ref image; + //export(int, "Circle,Polygon,Star,Curved Star,Rays") ; + int shape_type = 0; + //export(int) ; + int sides = 6; + //export(Resource) ; + Ref radius; + //export(Resource) ; + Ref edge; + + void Shape::_init_properties() { + + if (!image) { + image = MMNodeUniversalProperty.new(); + image.default_type = MMNodeUniversalProperty.DEFAULT_TYPE_IMAGE; +} + + image.output_slot_type = MMNodeUniversalProperty.SLOT_TYPE_IMAGE; + + if (!radius) { + radius = MMNodeUniversalProperty.new(); + radius.default_type = MMNodeUniversalProperty.DEFAULT_TYPE_FLOAT; + radius.set_default_value(0.34375); +} + + radius.input_slot_type = MMNodeUniversalProperty.SLOT_TYPE_UNIVERSAL; + radius.slot_name = "radius"; + radius.value_step = 0.05; + + if (!edge) { + edge = MMNodeUniversalProperty.new(); + edge.default_type = MMNodeUniversalProperty.DEFAULT_TYPE_FLOAT; + edge.set_default_value(0.2); +} + + edge.input_slot_type = MMNodeUniversalProperty.SLOT_TYPE_UNIVERSAL; + edge.slot_name = "edge"; + edge.value_step = 0.05; + register_input_property(radius); + register_input_property(edge); + register_output_property(image); +} + + + void Shape::_register_methods(const Variant &mm_graph_node) { + mm_graph_node.add_slot_texture_universal(image); + mm_graph_node.add_slot_enum("get_shape_typoe", "set_shape_typoe", "shape_type", [ "Circle", "Polygon", "Star", "Curved Star", "Rays" ]); + //, Vector2(1, 10)); + mm_graph_node.add_slot_int("get_sides", "set_sides", "sides"); + mm_graph_node.add_slot_float_universal(radius); + mm_graph_node.add_slot_float_universal(edge); +} + + + void Shape::_render(const Variant &material) { + Ref img = render_image(material); + image.set_value(img); +} + + + Color Shape::_get_value_for(const Vector2 &uv, const int pseed) { + float c = 0; + float rad = radius.get_value(uv); + float edg = edge.get_value(uv); + + if (rad == 0) { + rad = 0.0000001; +} + + + if (edg == 0) { + edg = 0.0000001; +} + + + if (shape_type == ShapeType.SHAPE_TYPE_CIRCLE) { + c = MMAlgos.shape_circle(uv, sides, rad, edg); +} + + + else if (shape_type == ShapeType.SHAPE_TYPE_POLYGON) { + c = MMAlgos.shape_polygon(uv, sides, rad, edg); +} + + + else if (shape_type == ShapeType.SHAPE_TYPE_STAR) { + c = MMAlgos.shape_star(uv, sides, rad, edg); +} + + + else if (shape_type == ShapeType.SHAPE_TYPE_CURVED_STAR) { + c = MMAlgos.shape_curved_star(uv, sides, rad, edg); +} + + + else if (shape_type == ShapeType.SHAPE_TYPE_RAYS) { + c = MMAlgos.shape_rays(uv, sides, rad, edg); +} + + return Color(c, c, c, 1); +} + + + int Shape::get_shape_typoe() { + return shape_type; +} + + + void Shape::set_shape_typoe(const int val) { + shape_type = val; + set_dirty(true); +} + + + int Shape::get_sides() { + return sides; +} + + + void Shape::set_sides(const int val) { + sides = val; + set_dirty(true); +} + +} + + Shape::Shape() { + image; + shape_type = 0; + sides = 6; + radius; + edge; + } + + Shape::~Shape() { + } + + + static void Shape::_bind_methods() { + ClassDB::bind_method(D_METHOD("get_image"), &Shape::get_image); + ClassDB::bind_method(D_METHOD("set_image", "value"), &Shape::set_image); + ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "image", PROPERTY_HINT_RESOURCE_TYPE, "Ref"), "set_image", "get_image"); + + + ClassDB::bind_method(D_METHOD("get_shape_type"), &Shape::get_shape_type); + ClassDB::bind_method(D_METHOD("set_shape_type", "value"), &Shape::set_shape_type); + ADD_PROPERTY(PropertyInfo(Variant::INT, "shape_type"), "set_shape_type", "get_shape_type"); + + + ClassDB::bind_method(D_METHOD("get_sides"), &Shape::get_sides); + ClassDB::bind_method(D_METHOD("set_sides", "value"), &Shape::set_sides); + ADD_PROPERTY(PropertyInfo(Variant::INT, "sides"), "set_sides", "get_sides"); + + + ClassDB::bind_method(D_METHOD("get_radius"), &Shape::get_radius); + ClassDB::bind_method(D_METHOD("set_radius", "value"), &Shape::set_radius); + ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "radius", PROPERTY_HINT_RESOURCE_TYPE, "Ref"), "set_radius", "get_radius"); + + + ClassDB::bind_method(D_METHOD("get_edge"), &Shape::get_edge); + ClassDB::bind_method(D_METHOD("set_edge", "value"), &Shape::set_edge); + ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "edge", PROPERTY_HINT_RESOURCE_TYPE, "Ref"), "set_edge", "get_edge"); + + + ClassDB::bind_method(D_METHOD("_init_properties"), &Shape::_init_properties); + ClassDB::bind_method(D_METHOD("_register_methods", "mm_graph_node"), &Shape::_register_methods); + ClassDB::bind_method(D_METHOD("_render", "material"), &Shape::_render); + ClassDB::bind_method(D_METHOD("_get_value_for", "uv", "pseed"), &Shape::_get_value_for); + ClassDB::bind_method(D_METHOD("get_shape_typoe"), &Shape::get_shape_typoe); + ClassDB::bind_method(D_METHOD("set_shape_typoe", "val"), &Shape::set_shape_typoe); + ClassDB::bind_method(D_METHOD("get_sides"), &Shape::get_sides); + ClassDB::bind_method(D_METHOD("set_sides", "val"), &Shape::set_sides); + + } + + + diff --git a/modules/material_maker/nodes/simple/shape.h b/modules/material_maker/nodes/simple/shape.h new file mode 100644 index 000000000..da26cdf2b --- /dev/null +++ b/modules/material_maker/nodes/simple/shape.h @@ -0,0 +1,64 @@ +#ifndef SHAPE_H +#define SHAPE_H + + +class Shape : public MMNode { + GDCLASS(Shape, MMNode); + + public: + + Ref get_image(); + void set_image(const Ref &val); + + int get_shape_type() const; + void set_shape_type(const int val); + + int get_sides() const; + void set_sides(const int val); + + Ref get_radius(); + void set_radius(const Ref &val); + + Ref get_edge(); + void set_edge(const Ref &val); + + enum ShapeType { + + SHAPE_TYPE_CIRCLE = 0, + SHAPE_TYPE_POLYGON = 1, + SHAPE_TYPE_STAR = 2, + SHAPE_TYPE_CURVED_STAR = 3, + SHAPE_TYPE_RAYS = 4, +}; + + 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); + int get_shape_typoe(); + void set_shape_typoe(const int val); + int get_sides(); + void set_sides(const int val); + + Shape(); + ~Shape(); + + protected: + static void _bind_methods(); + + //tool + }; + //export(Resource) + Ref image; + //export(int, "Circle,Polygon,Star,Curved Star,Rays") + int shape_type = 0; + //export(int) + int sides = 6; + //export(Resource) + Ref radius; + //export(Resource) + Ref edge; +}; + + +#endif diff --git a/modules/material_maker/nodes/transform/circle_map.cpp b/modules/material_maker/nodes/transform/circle_map.cpp new file mode 100644 index 000000000..5ecbb03db --- /dev/null +++ b/modules/material_maker/nodes/transform/circle_map.cpp @@ -0,0 +1,171 @@ + +#include "circle_map.h" + + +Ref CircleMap::get_image() { + return image; +} + +void CircleMap::set_image(const Ref &val) { +image = val; +} + + +Ref CircleMap::get_input() { + return input; +} + +void CircleMap::set_input(const Ref &val) { +input = val; +} + + +float CircleMap::get_radius() const { + return radius; +} + +void CircleMap::set_radius(const float val) { +radius = val; +} + + +int CircleMap::get_repeat() const { + return repeat; +} + +void CircleMap::set_repeat(const int val) { +repeat = val; +} + + + + //tool; + //export(Resource) ; + Ref image; + //export(Resource) ; + Ref input; + //export(float) ; + float radius = 1; + //export(int) ; + int repeat = 1; + + void CircleMap::_init_properties() { + + if (!input) { + input = MMNodeUniversalProperty.new(); + input.default_type = MMNodeUniversalProperty.DEFAULT_TYPE_COLOR; + input.set_default_value(Color(0, 0, 0, 1)); +} + + input.input_slot_type = MMNodeUniversalProperty.SLOT_TYPE_UNIVERSAL; + input.slot_name = ">>> Input "; + + if (!image) { + image = MMNodeUniversalProperty.new(); + image.default_type = MMNodeUniversalProperty.DEFAULT_TYPE_IMAGE; +} + + //image.input_slot_type = MMNodeUniversalProperty.SLOT_TYPE_FLOAT; + image.output_slot_type = MMNodeUniversalProperty.SLOT_TYPE_IMAGE; + //image.force_override = true; + register_input_property(input); + register_output_property(image); +} + + + void CircleMap::_register_methods(const Variant &mm_graph_node) { + mm_graph_node.add_slot_label_universal(input); + mm_graph_node.add_slot_texture_universal(image); + mm_graph_node.add_slot_float("get_radius", "set_radius", "Radius", 0.01); + mm_graph_node.add_slot_int("get_repeat", "set_repeat", "Repeat"); +} + + + void CircleMap::_render(const Variant &material) { + Ref img = render_image(material); + image.set_value(img); +} + + + Color CircleMap::_get_value_for(const Vector2 &uv, const int pseed) { + //$in(vec2(fract($repeat*atan($uv.y-0.5, $uv.x-0.5)*0.15915494309), min(0.99999, 2.0/$radius*length($uv-vec2(0.5)))))",; + Vector2 nuv = Vector2(MMAlgos.fractf(repeat*atan2(uv.y - 0.5, uv.x - 0.5) * 0.15915494309), min(0.99999, 2.0 / radius * (uv - Vector2(0.5, 0.5)).length())); + return input.get_value(nuv); +} + + //radius; + + float CircleMap::get_radius() { + return radius; +} + + + void CircleMap::set_radius(const float val) { + radius = val; + + if (radius == 0) { + radius = 0.000000001; +} + + set_dirty(true); +} + + //repeat; + + int CircleMap::get_repeat() { + return repeat; +} + + + void CircleMap::set_repeat(const int val) { + repeat = val; + set_dirty(true); +} + +} + + CircleMap::CircleMap() { + image; + input; + radius = 1; + repeat = 1; + } + + CircleMap::~CircleMap() { + } + + + static void CircleMap::_bind_methods() { + ClassDB::bind_method(D_METHOD("get_image"), &CircleMap::get_image); + ClassDB::bind_method(D_METHOD("set_image", "value"), &CircleMap::set_image); + ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "image", PROPERTY_HINT_RESOURCE_TYPE, "Ref"), "set_image", "get_image"); + + + ClassDB::bind_method(D_METHOD("get_input"), &CircleMap::get_input); + ClassDB::bind_method(D_METHOD("set_input", "value"), &CircleMap::set_input); + ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "input", PROPERTY_HINT_RESOURCE_TYPE, "Ref"), "set_input", "get_input"); + + + ClassDB::bind_method(D_METHOD("get_radius"), &CircleMap::get_radius); + ClassDB::bind_method(D_METHOD("set_radius", "value"), &CircleMap::set_radius); + ADD_PROPERTY(PropertyInfo(Variant::REAL, "radius"), "set_radius", "get_radius"); + + + ClassDB::bind_method(D_METHOD("get_repeat"), &CircleMap::get_repeat); + ClassDB::bind_method(D_METHOD("set_repeat", "value"), &CircleMap::set_repeat); + ADD_PROPERTY(PropertyInfo(Variant::INT, "repeat"), "set_repeat", "get_repeat"); + + + ClassDB::bind_method(D_METHOD("_init_properties"), &CircleMap::_init_properties); + ClassDB::bind_method(D_METHOD("_register_methods", "mm_graph_node"), &CircleMap::_register_methods); + ClassDB::bind_method(D_METHOD("_render", "material"), &CircleMap::_render); + ClassDB::bind_method(D_METHOD("_get_value_for", "uv", "pseed"), &CircleMap::_get_value_for); + ClassDB::bind_method(D_METHOD("get_radius"), &CircleMap::get_radius); + ClassDB::bind_method(D_METHOD("set_radius", "val"), &CircleMap::set_radius); + ClassDB::bind_method(D_METHOD("get_repeat"), &CircleMap::get_repeat); + ClassDB::bind_method(D_METHOD("set_repeat", "val"), &CircleMap::set_repeat); + + } + + + diff --git a/modules/material_maker/nodes/transform/circle_map.h b/modules/material_maker/nodes/transform/circle_map.h new file mode 100644 index 000000000..69bbe2c77 --- /dev/null +++ b/modules/material_maker/nodes/transform/circle_map.h @@ -0,0 +1,51 @@ +#ifndef CIRCLE_MAP_H +#define CIRCLE_MAP_H + + +class CircleMap : public MMNode { + GDCLASS(CircleMap, MMNode); + + public: + + Ref get_image(); + void set_image(const Ref &val); + + Ref get_input(); + void set_input(const Ref &val); + + float get_radius() const; + void set_radius(const float val); + + int get_repeat() const; + void set_repeat(const int val); + + 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); + float get_radius(); + void set_radius(const float val); + int get_repeat(); + void set_repeat(const int val); + + CircleMap(); + ~CircleMap(); + + protected: + static void _bind_methods(); + + //tool + //export(Resource) + Ref image; + //export(Resource) + Ref input; + //export(float) + float radius = 1; + //export(int) + int repeat = 1; + //radius + //repeat +}; + + +#endif diff --git a/modules/material_maker/nodes/transform/color_tiler.cpp b/modules/material_maker/nodes/transform/color_tiler.cpp new file mode 100644 index 000000000..fd7e1e095 --- /dev/null +++ b/modules/material_maker/nodes/transform/color_tiler.cpp @@ -0,0 +1,609 @@ + +#include "color_tiler.h" + + +Ref ColorTiler::get_input() { + return input; +} + +void ColorTiler::set_input(const Ref &val) { +input = val; +} + + +Ref ColorTiler::get_in_mask() { + return in_mask; +} + +void ColorTiler::set_in_mask(const Ref &val) { +in_mask = val; +} + + +Ref ColorTiler::get_output() { + return output; +} + +void ColorTiler::set_output(const Ref &val) { +output = val; +} + + +Ref ColorTiler::get_instance_map() { + return instance_map; +} + +void ColorTiler::set_instance_map(const Ref &val) { +instance_map = val; +} + + +Vector2 ColorTiler::get_tile() { + return tile; +} + +void ColorTiler::set_tile(const Vector2 &val) { +tile = val; +} + + +float ColorTiler::get_overlap() const { + return overlap; +} + +void ColorTiler::set_overlap(const float val) { +overlap = val; +} + + +int ColorTiler::get_select_inputs() const { + return select_inputs; +} + +void ColorTiler::set_select_inputs(const int val) { +select_inputs = val; +} + + +Vector2 ColorTiler::get_scale() { + return scale; +} + +void ColorTiler::set_scale(const Vector2 &val) { +scale = val; +} + + +float ColorTiler::get_fixed_offset() const { + return fixed_offset; +} + +void ColorTiler::set_fixed_offset(const float val) { +fixed_offset = val; +} + + +float ColorTiler::get_rnd_offset() const { + return rnd_offset; +} + +void ColorTiler::set_rnd_offset(const float val) { +rnd_offset = val; +} + + +float ColorTiler::get_rnd_rotate() const { + return rnd_rotate; +} + +void ColorTiler::set_rnd_rotate(const float val) { +rnd_rotate = val; +} + + +float ColorTiler::get_rnd_scale() const { + return rnd_scale; +} + +void ColorTiler::set_rnd_scale(const float val) { +rnd_scale = val; +} + + +float ColorTiler::get_rnd_opacity() const { + return rnd_opacity; +} + +void ColorTiler::set_rnd_opacity(const float val) { +rnd_opacity = val; +} + + +bool ColorTiler::get_variations() const { + return variations; +} + +void ColorTiler::set_variations(const bool val) { +variations = val; +} + + + + //tool; + //export(Resource) ; + Ref input; + //export(Resource) ; + Ref in_mask; + //export(Resource) ; + Ref output; + //export(Resource) ; + Ref instance_map; + //export(Vector2) ; + Vector2 tile = Vector2(4, 4); + //export(float) ; + float overlap = 1; + //export(int, "1,4,16") ; + int select_inputs = 0; + //export(Vector2) ; + Vector2 scale = Vector2(0.5, 0.5); + //export(float) ; + float fixed_offset = 0; + //export(float) ; + float rnd_offset = 0.25; + //export(float) ; + float rnd_rotate = 45; + //export(float) ; + float rnd_scale = 0.2; + //export(float) ; + float rnd_opacity = 0; + //export(bool) ; + bool variations = false; + + void ColorTiler::_init_properties() { + + if (!input) { + input = MMNodeUniversalProperty.new(); + input.default_type = MMNodeUniversalProperty.DEFAULT_TYPE_COLOR; + input.set_default_value(Color(0, 0, 0, 1)); +} + + input.input_slot_type = MMNodeUniversalProperty.SLOT_TYPE_UNIVERSAL; + input.slot_name = ">>> Input "; + + if (!in_mask) { + in_mask = MMNodeUniversalProperty.new(); + in_mask.default_type = MMNodeUniversalProperty.DEFAULT_TYPE_FLOAT; + in_mask.set_default_value(1); +} + + in_mask.input_slot_type = MMNodeUniversalProperty.SLOT_TYPE_UNIVERSAL; + in_mask.slot_name = ">>> Mask "; + + if (!output) { + output = MMNodeUniversalProperty.new(); + output.default_type = MMNodeUniversalProperty.DEFAULT_TYPE_IMAGE; +} + + output.output_slot_type = MMNodeUniversalProperty.SLOT_TYPE_IMAGE; + + if (!instance_map) { + instance_map = MMNodeUniversalProperty.new(); + instance_map.default_type = MMNodeUniversalProperty.DEFAULT_TYPE_IMAGE; +} + + instance_map.output_slot_type = MMNodeUniversalProperty.SLOT_TYPE_IMAGE; + register_input_property(input); + register_input_property(in_mask); + register_output_property(output); + register_output_property(instance_map); +} + + + void ColorTiler::_register_methods(const Variant &mm_graph_node) { + mm_graph_node.add_slot_label_universal(input); + mm_graph_node.add_slot_label_universal(in_mask); + mm_graph_node.add_slot_texture_universal(output); + mm_graph_node.add_slot_texture_universal(instance_map); + mm_graph_node.add_slot_vector2("get_tile", "set_tile", "Tile", 1); + mm_graph_node.add_slot_float("get_overlap", "set_overlap", "Overlap", 1); + mm_graph_node.add_slot_enum("get_select_inputs", "set_select_inputs", "Select inputs", [ "1", "4", "16" ]); + mm_graph_node.add_slot_vector2("get_scale", "set_scale", "Scale", 0.01); + mm_graph_node.add_slot_float("get_fixed_offset", "set_fixed_offset", "Fixed Offset", 0.01); + mm_graph_node.add_slot_float("get_rnd_offset", "set_rnd_offset", "Rnd Offset", 0.01); + mm_graph_node.add_slot_float("get_rnd_rotate", "set_rnd_rotate", "Rnd Rotate", 0.1); + mm_graph_node.add_slot_float("get_rnd_scale", "set_rnd_scale", "Rnd Scale", 0.01); + mm_graph_node.add_slot_float("get_rnd_opacity", "set_rnd_opacity", "Rnd Opacity", 0.01); +} + + //mm_graph_node.add_slot_bool("get_variations", "set_variations", "Variations"); + + void ColorTiler::_render(const Variant &material) { + Ref output_img = Image.new(); + Ref instance_map_img = Image.new(); + output_img.create(material.image_size.x, material.image_size.y, false, Image.FORMAT_RGBA8); + instance_map_img.create(material.image_size.x, material.image_size.y, false, Image.FORMAT_RGBA8); + output_img.lock(); + instance_map_img.lock(); + float w = material.image_size.x; + float h = material.image_size.y; + float pseed = randf() + randi(); + float ps = 1.0 / float(pseed); + int ix = int(material.image_size.x); + int iy = int(material.image_size.y); + + for (int x = 0; x < ix; ++x) { //x in range(ix) + + for (int y = 0; y < iy; ++y) { //y in range(iy) + Vector2 uv = Vector2(x / w, y / h); + //vec3 $(name_uv)_random_color; + //vec4 $(name_uv)_tiled_output = tiler_$(name)($uv, vec2($tx, $ty), int($overlap), vec2(float($seed)), $(name_uv)_random_color); + PoolColorArray rch = tiler_calc(uv, tile, overlap, Vector2(ps, ps)); + output_img.set_pixel(x, y, rch[1]); + instance_map_img.set_pixel(x, y, rch[0]); +} + +} + + output_img.unlock(); + instance_map_img.unlock(); + output.set_value(output_img); + instance_map.set_value(instance_map_img); +} + + + Color ColorTiler::_get_value_for(const Vector2 &uv, const int pseed) { + return Color(); +} + + //tile; + + Vector2 ColorTiler::get_tile() { + return tile; +} + + + void ColorTiler::set_tile(const Vector2 &val) { + tile = val; + set_dirty(true); +} + + //overlap; + + float ColorTiler::get_overlap() { + return overlap; +} + + + void ColorTiler::set_overlap(const float val) { + overlap = val; + set_dirty(true); +} + + //select_inputs; + + int ColorTiler::get_select_inputs() { + return select_inputs; +} + + + void ColorTiler::set_select_inputs(const int val) { + select_inputs = val; + set_dirty(true); +} + + //scale; + + Vector2 ColorTiler::get_scale() { + return scale; +} + + + void ColorTiler::set_scale(const Vector2 &val) { + scale = val; + set_dirty(true); +} + + //fixed_offset; + + float ColorTiler::get_fixed_offset() { + return fixed_offset; +} + + + void ColorTiler::set_fixed_offset(const float val) { + fixed_offset = val; + set_dirty(true); +} + + //rnd_offset; + + float ColorTiler::get_rnd_offset() { + return rnd_offset; +} + + + void ColorTiler::set_rnd_offset(const float val) { + rnd_offset = val; + set_dirty(true); +} + + //rnd_rotate; + + float ColorTiler::get_rnd_rotate() { + return rnd_rotate; +} + + + void ColorTiler::set_rnd_rotate(const float val) { + rnd_rotate = val; + set_dirty(true); +} + + //rnd_scale; + + float ColorTiler::get_rnd_scale() { + return rnd_scale; +} + + + void ColorTiler::set_rnd_scale(const float val) { + rnd_scale = val; + set_dirty(true); +} + + //rnd_opacity; + + float ColorTiler::get_rnd_opacity() { + return rnd_opacity; +} + + + void ColorTiler::set_rnd_opacity(const float val) { + rnd_opacity = val; + set_dirty(true); +} + + //variations; + + bool ColorTiler::get_variations() { + return variations; +} + + + void ColorTiler::set_variations(const bool val) { + variations = val; + set_dirty(true); +} + + //----------------------; + //color_tiler.mmg; + //Tiles several occurences of an input image while adding randomness.; + //vec4 tiler_$(name)(vec2 uv, vec2 tile, int overlap, vec2 _seed, out vec3 random_color) {; + // vec4 c = vec4(0.0); + // vec3 rc = vec3(0.0); + // vec3 rc1; + //; + // for (int dx = -overlap; dx <= overlap; ++dx) {; + // for (int dy = -overlap; dy <= overlap; ++dy) {; + // vec2 pos = fract((floor(uv*tile)+vec2(float(dx), float(dy))+vec2(0.5))/tile-vec2(0.5)); + // vec2 seed = rand2(pos+_seed); + // rc1 = rand3(seed); + // pos = fract(pos+vec2($fixed_offset/tile.x, 0.0)*floor(mod(pos.y*tile.y, 2.0))+$offset*seed/tile); + // float mask = $mask(fract(pos+vec2(0.5))); + // if (mask > 0.01) {; + // vec2 pv = fract(uv - pos)-vec2(0.5); + // seed = rand2(seed); + // float angle = (seed.x * 2.0 - 1.0) * $rotate * 0.01745329251; + // float ca = cos(angle); + // float sa = sin(angle); + // pv = vec2(ca*pv.x+sa*pv.y, -sa*pv.x+ca*pv.y); + // pv *= (seed.y-0.5)*2.0*$scale+1.0; + // pv /= vec2($scale_x, $scale_y); + // pv += vec2(0.5); + // pv = clamp(pv, vec2(0.0), vec2(1.0)); + //; + // $select_inputs; + //; + // vec4 n = $in.variation(pv, $variations ? seed.x : 0.0); + //; + // seed = rand2(seed); + // float na = n.a*mask*(1.0-$opacity*seed.x); + // float a = (1.0-c.a)*(1.0*na); + //; + // c = mix(c, n, na); + // rc = mix(rc, rc1, n.a); + // }; + // }; + // }; + //; + // random_color = rc; + // return c; + //}; + //select_inputs enum; + //1, " "; + //4, "pv = clamp(0.5*(pv+floor(rand2(seed)*2.0)), vec2(0.0), vec2(1.0));"; + //16, "pv = clamp(0.25*(pv+floor(rand2(seed)*4.0)), vec2(0.0), vec2(1.0));"; + + PoolColorArray ColorTiler::tiler_calc(const Vector2 &uv, const Vector2 &tile, const int overlap, const Vector2 &_seed) { + Color c = Color(); + Vector3 rc = Vector3(); + Vector3 rc1 = Vector3(); + //for (int dx = -overlap; dx <= overlap; ++dx) {; + + for (int dx = -overlap; dx < overlap; ++dx) { //dx in range(-overlap, overlap) + //for (int dy = -overlap; dy <= overlap; ++dy) {; + + for (int dy = -overlap; dy < overlap; ++dy) { //dy in range(-overlap, overlap) + Vector2 pos = MMAlgos.fractv2((MMAlgos.floorv2(uv * tile) + Vector2(dx, dy) + Vector2(0.5, 0.5)) / tile - Vector2(0.5, 0.5)); + Vector2 vseed = MMAlgos.rand2(pos + _seed); + rc1 = MMAlgos.rand3(vseed); + pos = MMAlgos.fractv2(pos + Vector2(fixed_offset / tile.x, 0.0) * floor(MMAlgos.modf(pos.y * tile.y, 2.0)) + rnd_offset * vseed / tile); + float mask = in_mask.get_value(MMAlgos.fractv2(pos + Vector2(0.5, 0.5))); + + if ((mask > 0.01)) { + Vector2 pv = MMAlgos.fractv2(uv - pos) - Vector2(0.5, 0.5); + vseed = MMAlgos.rand2(vseed); + float angle = (vseed.x * 2.0 - 1.0) * rnd_rotate * 0.01745329251; + float ca = cos(angle); + float sa = sin(angle); + pv = Vector2(ca * pv.x + sa * pv.y, -sa * pv.x + ca * pv.y); + pv *= (vseed.y-0.5) * 2.0 * rnd_scale + 1.0; + pv /= scale; + pv += Vector2(0.5, 0.5); + pv = MMAlgos.clampv2(pv, Vector2(), Vector2(1, 1)); + //1, " "; + //4, "pv = clamp(0.5*(pv+floor(rand2(seed)*2.0)), vec2(0.0), vec2(1.0));"; + //16, "pv = clamp(0.25*(pv+floor(rand2(seed)*4.0)), vec2(0.0), vec2(1.0));"; + + if (select_inputs == 1) { + pv = MMAlgos.clampv2(0.5*(pv + MMAlgos.floorv2(MMAlgos.rand2(vseed)*2.0)), Vector2(), Vector2(1, 1)); +} + + + else if (select_inputs == 2) { + pv = MMAlgos.clampv2(0.25*(pv + MMAlgos.floorv2(MMAlgos.rand2(vseed)*4.0)), Vector2(), Vector2(1, 1)); +} + + // vec4 n = $in.variation(pv, $variations ? seed.x : 0.0); + Color n = input.get_value(pv) * mask * (1.0 - rnd_opacity * vseed.x); + vseed = MMAlgos.rand2(vseed); + float na = n.a * mask * (1.0 - rnd_opacity * vseed.x); + float a = (1.0 - c.a) * (1.0 * na); + c = lerp(c, n, na); + rc = lerp(rc, rc1, n.a); +} + +} + +} + + PoolColorArray pc = PoolColorArray(); + pc.append(Color(rc.x, rc.y, rc.z, 1)); + pc.append(c); + return pc; +} + +} + + ColorTiler::ColorTiler() { + input; + in_mask; + output; + instance_map; + tile = Vector2(4, 4); + overlap = 1; + select_inputs = 0; + scale = Vector2(0.5, 0.5); + fixed_offset = 0; + rnd_offset = 0.25; + rnd_rotate = 45; + rnd_scale = 0.2; + rnd_opacity = 0; + variations = false; + } + + ColorTiler::~ColorTiler() { + } + + + static void ColorTiler::_bind_methods() { + ClassDB::bind_method(D_METHOD("get_input"), &ColorTiler::get_input); + ClassDB::bind_method(D_METHOD("set_input", "value"), &ColorTiler::set_input); + ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "input", PROPERTY_HINT_RESOURCE_TYPE, "Ref"), "set_input", "get_input"); + + + ClassDB::bind_method(D_METHOD("get_in_mask"), &ColorTiler::get_in_mask); + ClassDB::bind_method(D_METHOD("set_in_mask", "value"), &ColorTiler::set_in_mask); + ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "in_mask", PROPERTY_HINT_RESOURCE_TYPE, "Ref"), "set_in_mask", "get_in_mask"); + + + ClassDB::bind_method(D_METHOD("get_output"), &ColorTiler::get_output); + ClassDB::bind_method(D_METHOD("set_output", "value"), &ColorTiler::set_output); + ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "output", PROPERTY_HINT_RESOURCE_TYPE, "Ref"), "set_output", "get_output"); + + + ClassDB::bind_method(D_METHOD("get_instance_map"), &ColorTiler::get_instance_map); + ClassDB::bind_method(D_METHOD("set_instance_map", "value"), &ColorTiler::set_instance_map); + ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "instance_map", PROPERTY_HINT_RESOURCE_TYPE, "Ref"), "set_instance_map", "get_instance_map"); + + + ClassDB::bind_method(D_METHOD("get_tile"), &ColorTiler::get_tile); + ClassDB::bind_method(D_METHOD("set_tile", "value"), &ColorTiler::set_tile); + ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "tile"), "set_tile", "get_tile"); + + + ClassDB::bind_method(D_METHOD("get_overlap"), &ColorTiler::get_overlap); + ClassDB::bind_method(D_METHOD("set_overlap", "value"), &ColorTiler::set_overlap); + ADD_PROPERTY(PropertyInfo(Variant::REAL, "overlap"), "set_overlap", "get_overlap"); + + + ClassDB::bind_method(D_METHOD("get_select_inputs"), &ColorTiler::get_select_inputs); + ClassDB::bind_method(D_METHOD("set_select_inputs", "value"), &ColorTiler::set_select_inputs); + ADD_PROPERTY(PropertyInfo(Variant::INT, "select_inputs"), "set_select_inputs", "get_select_inputs"); + + + ClassDB::bind_method(D_METHOD("get_scale"), &ColorTiler::get_scale); + ClassDB::bind_method(D_METHOD("set_scale", "value"), &ColorTiler::set_scale); + ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "scale"), "set_scale", "get_scale"); + + + ClassDB::bind_method(D_METHOD("get_fixed_offset"), &ColorTiler::get_fixed_offset); + ClassDB::bind_method(D_METHOD("set_fixed_offset", "value"), &ColorTiler::set_fixed_offset); + ADD_PROPERTY(PropertyInfo(Variant::REAL, "fixed_offset"), "set_fixed_offset", "get_fixed_offset"); + + + ClassDB::bind_method(D_METHOD("get_rnd_offset"), &ColorTiler::get_rnd_offset); + ClassDB::bind_method(D_METHOD("set_rnd_offset", "value"), &ColorTiler::set_rnd_offset); + ADD_PROPERTY(PropertyInfo(Variant::REAL, "rnd_offset"), "set_rnd_offset", "get_rnd_offset"); + + + ClassDB::bind_method(D_METHOD("get_rnd_rotate"), &ColorTiler::get_rnd_rotate); + ClassDB::bind_method(D_METHOD("set_rnd_rotate", "value"), &ColorTiler::set_rnd_rotate); + ADD_PROPERTY(PropertyInfo(Variant::REAL, "rnd_rotate"), "set_rnd_rotate", "get_rnd_rotate"); + + + ClassDB::bind_method(D_METHOD("get_rnd_scale"), &ColorTiler::get_rnd_scale); + ClassDB::bind_method(D_METHOD("set_rnd_scale", "value"), &ColorTiler::set_rnd_scale); + ADD_PROPERTY(PropertyInfo(Variant::REAL, "rnd_scale"), "set_rnd_scale", "get_rnd_scale"); + + + ClassDB::bind_method(D_METHOD("get_rnd_opacity"), &ColorTiler::get_rnd_opacity); + ClassDB::bind_method(D_METHOD("set_rnd_opacity", "value"), &ColorTiler::set_rnd_opacity); + ADD_PROPERTY(PropertyInfo(Variant::REAL, "rnd_opacity"), "set_rnd_opacity", "get_rnd_opacity"); + + + ClassDB::bind_method(D_METHOD("get_variations"), &ColorTiler::get_variations); + ClassDB::bind_method(D_METHOD("set_variations", "value"), &ColorTiler::set_variations); + ADD_PROPERTY(PropertyInfo(Variant::BOOL, "variations"), "set_variations", "get_variations"); + + + ClassDB::bind_method(D_METHOD("_init_properties"), &ColorTiler::_init_properties); + ClassDB::bind_method(D_METHOD("_register_methods", "mm_graph_node"), &ColorTiler::_register_methods); + ClassDB::bind_method(D_METHOD("_render", "material"), &ColorTiler::_render); + ClassDB::bind_method(D_METHOD("_get_value_for", "uv", "pseed"), &ColorTiler::_get_value_for); + ClassDB::bind_method(D_METHOD("get_tile"), &ColorTiler::get_tile); + ClassDB::bind_method(D_METHOD("set_tile", "val"), &ColorTiler::set_tile); + ClassDB::bind_method(D_METHOD("get_overlap"), &ColorTiler::get_overlap); + ClassDB::bind_method(D_METHOD("set_overlap", "val"), &ColorTiler::set_overlap); + ClassDB::bind_method(D_METHOD("get_select_inputs"), &ColorTiler::get_select_inputs); + ClassDB::bind_method(D_METHOD("set_select_inputs", "val"), &ColorTiler::set_select_inputs); + ClassDB::bind_method(D_METHOD("get_scale"), &ColorTiler::get_scale); + ClassDB::bind_method(D_METHOD("set_scale", "val"), &ColorTiler::set_scale); + ClassDB::bind_method(D_METHOD("get_fixed_offset"), &ColorTiler::get_fixed_offset); + ClassDB::bind_method(D_METHOD("set_fixed_offset", "val"), &ColorTiler::set_fixed_offset); + ClassDB::bind_method(D_METHOD("get_rnd_offset"), &ColorTiler::get_rnd_offset); + ClassDB::bind_method(D_METHOD("set_rnd_offset", "val"), &ColorTiler::set_rnd_offset); + ClassDB::bind_method(D_METHOD("get_rnd_rotate"), &ColorTiler::get_rnd_rotate); + ClassDB::bind_method(D_METHOD("set_rnd_rotate", "val"), &ColorTiler::set_rnd_rotate); + ClassDB::bind_method(D_METHOD("get_rnd_scale"), &ColorTiler::get_rnd_scale); + ClassDB::bind_method(D_METHOD("set_rnd_scale", "val"), &ColorTiler::set_rnd_scale); + ClassDB::bind_method(D_METHOD("get_rnd_opacity"), &ColorTiler::get_rnd_opacity); + ClassDB::bind_method(D_METHOD("set_rnd_opacity", "val"), &ColorTiler::set_rnd_opacity); + ClassDB::bind_method(D_METHOD("get_variations"), &ColorTiler::get_variations); + ClassDB::bind_method(D_METHOD("set_variations", "val"), &ColorTiler::set_variations); + ClassDB::bind_method(D_METHOD("tiler_calc", "uv", "tile", "overlap", "_seed"), &ColorTiler::tiler_calc); + + } + + + diff --git a/modules/material_maker/nodes/transform/color_tiler.h b/modules/material_maker/nodes/transform/color_tiler.h new file mode 100644 index 000000000..bfb65a08c --- /dev/null +++ b/modules/material_maker/nodes/transform/color_tiler.h @@ -0,0 +1,175 @@ +#ifndef COLOR_TILER_H +#define COLOR_TILER_H + + +class ColorTiler : public MMNode { + GDCLASS(ColorTiler, MMNode); + + public: + + Ref get_input(); + void set_input(const Ref &val); + + Ref get_in_mask(); + void set_in_mask(const Ref &val); + + Ref get_output(); + void set_output(const Ref &val); + + Ref get_instance_map(); + void set_instance_map(const Ref &val); + + Vector2 get_tile(); + void set_tile(const Vector2 &val); + + float get_overlap() const; + void set_overlap(const float val); + + int get_select_inputs() const; + void set_select_inputs(const int val); + + Vector2 get_scale(); + void set_scale(const Vector2 &val); + + float get_fixed_offset() const; + void set_fixed_offset(const float val); + + float get_rnd_offset() const; + void set_rnd_offset(const float val); + + float get_rnd_rotate() const; + void set_rnd_rotate(const float val); + + float get_rnd_scale() const; + void set_rnd_scale(const float val); + + float get_rnd_opacity() const; + void set_rnd_opacity(const float val); + + bool get_variations() const; + void set_variations(const bool val); + + 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_tile(); + void set_tile(const Vector2 &val); + float get_overlap(); + void set_overlap(const float val); + int get_select_inputs(); + void set_select_inputs(const int val); + Vector2 get_scale(); + void set_scale(const Vector2 &val); + float get_fixed_offset(); + void set_fixed_offset(const float val); + float get_rnd_offset(); + void set_rnd_offset(const float val); + float get_rnd_rotate(); + void set_rnd_rotate(const float val); + float get_rnd_scale(); + void set_rnd_scale(const float val); + float get_rnd_opacity(); + void set_rnd_opacity(const float val); + bool get_variations(); + void set_variations(const bool val); + PoolColorArray tiler_calc(const Vector2 &uv, const Vector2 &tile, const int overlap, const Vector2 &_seed); + + ColorTiler(); + ~ColorTiler(); + + protected: + static void _bind_methods(); + + //tool + //export(Resource) + Ref input; + //export(Resource) + Ref in_mask; + //export(Resource) + Ref output; + //export(Resource) + Ref instance_map; + //export(Vector2) + Vector2 tile = Vector2(4, 4); + //export(float) + float overlap = 1; + //export(int, "1,4,16") + int select_inputs = 0; + //export(Vector2) + Vector2 scale = Vector2(0.5, 0.5); + //export(float) + float fixed_offset = 0; + //export(float) + float rnd_offset = 0.25; + //export(float) + float rnd_rotate = 45; + //export(float) + float rnd_scale = 0.2; + //export(float) + float rnd_opacity = 0; + //export(bool) + bool variations = false; + //mm_graph_node.add_slot_bool("get_variations", "set_variations", "Variations") + //tile + //overlap + //select_inputs + //scale + //fixed_offset + //rnd_offset + //rnd_rotate + //rnd_scale + //rnd_opacity + //variations + //---------------------- + //color_tiler.mmg + //Tiles several occurences of an input image while adding randomness. + //vec4 tiler_$(name)(vec2 uv, vec2 tile, int overlap, vec2 _seed, out vec3 random_color) { + // vec4 c = vec4(0.0); + // vec3 rc = vec3(0.0); + // vec3 rc1; + // + // for (int dx = -overlap; dx <= overlap; ++dx) { + // for (int dy = -overlap; dy <= overlap; ++dy) { + // vec2 pos = fract((floor(uv*tile)+vec2(float(dx), float(dy))+vec2(0.5))/tile-vec2(0.5)); + // vec2 seed = rand2(pos+_seed); + // rc1 = rand3(seed); + // pos = fract(pos+vec2($fixed_offset/tile.x, 0.0)*floor(mod(pos.y*tile.y, 2.0))+$offset*seed/tile); + // float mask = $mask(fract(pos+vec2(0.5))); + // if (mask > 0.01) { + // vec2 pv = fract(uv - pos)-vec2(0.5); + // seed = rand2(seed); + // float angle = (seed.x * 2.0 - 1.0) * $rotate * 0.01745329251; + // float ca = cos(angle); + // float sa = sin(angle); + // pv = vec2(ca*pv.x+sa*pv.y, -sa*pv.x+ca*pv.y); + // pv *= (seed.y-0.5)*2.0*$scale+1.0; + // pv /= vec2($scale_x, $scale_y); + // pv += vec2(0.5); + // pv = clamp(pv, vec2(0.0), vec2(1.0)); + // + // $select_inputs + // + // vec4 n = $in.variation(pv, $variations ? seed.x : 0.0); + // + // seed = rand2(seed); + // float na = n.a*mask*(1.0-$opacity*seed.x); + // float a = (1.0-c.a)*(1.0*na); + // + // c = mix(c, n, na); + // rc = mix(rc, rc1, n.a); + // } + // } + // } + // + // random_color = rc; + // return c; + //} + //select_inputs enum + //1, " " + //4, "pv = clamp(0.5*(pv+floor(rand2(seed)*2.0)), vec2(0.0), vec2(1.0));" + //16, "pv = clamp(0.25*(pv+floor(rand2(seed)*4.0)), vec2(0.0), vec2(1.0));" +}; + + +#endif diff --git a/modules/material_maker/nodes/transform/kaleidoscope.cpp b/modules/material_maker/nodes/transform/kaleidoscope.cpp new file mode 100644 index 000000000..b48308b56 --- /dev/null +++ b/modules/material_maker/nodes/transform/kaleidoscope.cpp @@ -0,0 +1,165 @@ + +#include "kaleidoscope.h" + + +Ref Kaleidoscope::get_image() { + return image; +} + +void Kaleidoscope::set_image(const Ref &val) { +image = val; +} + + +Ref Kaleidoscope::get_input() { + return input; +} + +void Kaleidoscope::set_input(const Ref &val) { +input = val; +} + + +int Kaleidoscope::get_count() const { + return count; +} + +void Kaleidoscope::set_count(const int val) { +count = val; +} + + +float Kaleidoscope::get_offset() const { + return offset; +} + +void Kaleidoscope::set_offset(const float val) { +offset = val; +} + + + + //tool; + //export(Resource) ; + Ref image; + //export(Resource) ; + Ref input; + //export(int) ; + int count = 5; + //export(float) ; + float offset = 0; + + void Kaleidoscope::_init_properties() { + + if (!input) { + input = MMNodeUniversalProperty.new(); + input.default_type = MMNodeUniversalProperty.DEFAULT_TYPE_COLOR; + input.set_default_value(Color(0, 0, 0, 1)); +} + + input.input_slot_type = MMNodeUniversalProperty.SLOT_TYPE_UNIVERSAL; + input.slot_name = ">>> Input "; + + if (!image) { + image = MMNodeUniversalProperty.new(); + image.default_type = MMNodeUniversalProperty.DEFAULT_TYPE_IMAGE; +} + + //image.input_slot_type = MMNodeUniversalProperty.SLOT_TYPE_FLOAT; + image.output_slot_type = MMNodeUniversalProperty.SLOT_TYPE_IMAGE; + //image.force_override = true; + register_input_property(input); + register_output_property(image); +} + + + void Kaleidoscope::_register_methods(const Variant &mm_graph_node) { + mm_graph_node.add_slot_label_universal(input); + mm_graph_node.add_slot_texture_universal(image); + mm_graph_node.add_slot_int("get_count", "set_count", "Count"); + mm_graph_node.add_slot_float("get_offset", "set_offset", "Offset", 0.5); +} + + + void Kaleidoscope::_render(const Variant &material) { + Ref img = render_image(material); + image.set_value(img); +} + + + Color Kaleidoscope::_get_value_for(const Vector2 &uv, const int pseed) { + //$i(kal_rotate($uv, $count, $offset)); + return input.get_value(MMAlgos.kal_rotate(uv, count, offset)); +} + + //count; + + int Kaleidoscope::get_count() { + return count; +} + + + void Kaleidoscope::set_count(const int val) { + count = val; + set_dirty(true); +} + + //offset; + + float Kaleidoscope::get_offset() { + return offset; +} + + + void Kaleidoscope::set_offset(const float val) { + offset = val; + set_dirty(true); +} + +} + + Kaleidoscope::Kaleidoscope() { + image; + input; + count = 5; + offset = 0; + } + + Kaleidoscope::~Kaleidoscope() { + } + + + static void Kaleidoscope::_bind_methods() { + ClassDB::bind_method(D_METHOD("get_image"), &Kaleidoscope::get_image); + ClassDB::bind_method(D_METHOD("set_image", "value"), &Kaleidoscope::set_image); + ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "image", PROPERTY_HINT_RESOURCE_TYPE, "Ref"), "set_image", "get_image"); + + + ClassDB::bind_method(D_METHOD("get_input"), &Kaleidoscope::get_input); + ClassDB::bind_method(D_METHOD("set_input", "value"), &Kaleidoscope::set_input); + ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "input", PROPERTY_HINT_RESOURCE_TYPE, "Ref"), "set_input", "get_input"); + + + ClassDB::bind_method(D_METHOD("get_count"), &Kaleidoscope::get_count); + ClassDB::bind_method(D_METHOD("set_count", "value"), &Kaleidoscope::set_count); + ADD_PROPERTY(PropertyInfo(Variant::INT, "count"), "set_count", "get_count"); + + + ClassDB::bind_method(D_METHOD("get_offset"), &Kaleidoscope::get_offset); + ClassDB::bind_method(D_METHOD("set_offset", "value"), &Kaleidoscope::set_offset); + ADD_PROPERTY(PropertyInfo(Variant::REAL, "offset"), "set_offset", "get_offset"); + + + ClassDB::bind_method(D_METHOD("_init_properties"), &Kaleidoscope::_init_properties); + ClassDB::bind_method(D_METHOD("_register_methods", "mm_graph_node"), &Kaleidoscope::_register_methods); + ClassDB::bind_method(D_METHOD("_render", "material"), &Kaleidoscope::_render); + ClassDB::bind_method(D_METHOD("_get_value_for", "uv", "pseed"), &Kaleidoscope::_get_value_for); + ClassDB::bind_method(D_METHOD("get_count"), &Kaleidoscope::get_count); + ClassDB::bind_method(D_METHOD("set_count", "val"), &Kaleidoscope::set_count); + ClassDB::bind_method(D_METHOD("get_offset"), &Kaleidoscope::get_offset); + ClassDB::bind_method(D_METHOD("set_offset", "val"), &Kaleidoscope::set_offset); + + } + + + diff --git a/modules/material_maker/nodes/transform/kaleidoscope.h b/modules/material_maker/nodes/transform/kaleidoscope.h new file mode 100644 index 000000000..7fe0ed2ba --- /dev/null +++ b/modules/material_maker/nodes/transform/kaleidoscope.h @@ -0,0 +1,51 @@ +#ifndef KALEIDOSCOPE_H +#define KALEIDOSCOPE_H + + +class Kaleidoscope : public MMNode { + GDCLASS(Kaleidoscope, MMNode); + + public: + + Ref get_image(); + void set_image(const Ref &val); + + Ref get_input(); + void set_input(const Ref &val); + + int get_count() const; + void set_count(const int val); + + float get_offset() const; + void set_offset(const float val); + + 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); + int get_count(); + void set_count(const int val); + float get_offset(); + void set_offset(const float val); + + Kaleidoscope(); + ~Kaleidoscope(); + + protected: + static void _bind_methods(); + + //tool + //export(Resource) + Ref image; + //export(Resource) + Ref input; + //export(int) + int count = 5; + //export(float) + float offset = 0; + //count + //offset +}; + + +#endif diff --git a/modules/material_maker/nodes/transform/mirror.cpp b/modules/material_maker/nodes/transform/mirror.cpp new file mode 100644 index 000000000..92da19759 --- /dev/null +++ b/modules/material_maker/nodes/transform/mirror.cpp @@ -0,0 +1,175 @@ + +#include "mirror.h" + + +Ref Mirror::get_image() { + return image; +} + +void Mirror::set_image(const Ref &val) { +image = val; +} + + +Ref Mirror::get_input() { + return input; +} + +void Mirror::set_input(const Ref &val) { +input = val; +} + + +int Mirror::get_direction() const { + return direction; +} + +void Mirror::set_direction(const int val) { +direction = val; +} + + +float Mirror::get_offset() const { + return offset; +} + +void Mirror::set_offset(const float val) { +offset = val; +} + + + + //tool; + //export(Resource) ; + Ref image; + //export(Resource) ; + Ref input; + //export(int, "Horizontal,Vertical") ; + int direction = 0; + //export(float) ; + float offset = 0; + + void Mirror::_init_properties() { + + if (!input) { + input = MMNodeUniversalProperty.new(); + input.default_type = MMNodeUniversalProperty.DEFAULT_TYPE_COLOR; + input.set_default_value(Color(0, 0, 0, 1)); +} + + input.input_slot_type = MMNodeUniversalProperty.SLOT_TYPE_UNIVERSAL; + input.slot_name = ">>> Input "; + + if (!image) { + image = MMNodeUniversalProperty.new(); + image.default_type = MMNodeUniversalProperty.DEFAULT_TYPE_IMAGE; +} + + //image.input_slot_type = MMNodeUniversalProperty.SLOT_TYPE_FLOAT; + image.output_slot_type = MMNodeUniversalProperty.SLOT_TYPE_IMAGE; + //image.force_override = true; + register_input_property(input); + register_output_property(image); +} + + + void Mirror::_register_methods(const Variant &mm_graph_node) { + mm_graph_node.add_slot_label_universal(input); + mm_graph_node.add_slot_texture_universal(image); + mm_graph_node.add_slot_enum("get_direction", "set_direction", "Direction", [ "Horizontal", "Vertical" ]); + mm_graph_node.add_slot_float("get_offset", "set_offset", "offset", 0.01); +} + + + void Mirror::_render(const Variant &material) { + Ref img = render_image(material); + image.set_value(img); +} + + + Color Mirror::_get_value_for(const Vector2 &uv, const int pseed) { + //$i(uvmirror_$direction($uv, $offset)); + + if (direction == 0) { + return input.get_value(MMAlgos.uvmirror_h(uv, offset)); +} + + + else if (direction == 1) { + return input.get_value(MMAlgos.uvmirror_v(uv, offset)); +} + + return Color(0, 0, 0, 1); +} + + //direction; + + int Mirror::get_direction() { + return direction; +} + + + void Mirror::set_direction(const int val) { + direction = val; + set_dirty(true); +} + + //offset; + + float Mirror::get_offset() { + return offset; +} + + + void Mirror::set_offset(const float val) { + offset = val; + set_dirty(true); +} + +} + + Mirror::Mirror() { + image; + input; + direction = 0; + offset = 0; + } + + Mirror::~Mirror() { + } + + + static void Mirror::_bind_methods() { + ClassDB::bind_method(D_METHOD("get_image"), &Mirror::get_image); + ClassDB::bind_method(D_METHOD("set_image", "value"), &Mirror::set_image); + ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "image", PROPERTY_HINT_RESOURCE_TYPE, "Ref"), "set_image", "get_image"); + + + ClassDB::bind_method(D_METHOD("get_input"), &Mirror::get_input); + ClassDB::bind_method(D_METHOD("set_input", "value"), &Mirror::set_input); + ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "input", PROPERTY_HINT_RESOURCE_TYPE, "Ref"), "set_input", "get_input"); + + + ClassDB::bind_method(D_METHOD("get_direction"), &Mirror::get_direction); + ClassDB::bind_method(D_METHOD("set_direction", "value"), &Mirror::set_direction); + ADD_PROPERTY(PropertyInfo(Variant::INT, "direction"), "set_direction", "get_direction"); + + + ClassDB::bind_method(D_METHOD("get_offset"), &Mirror::get_offset); + ClassDB::bind_method(D_METHOD("set_offset", "value"), &Mirror::set_offset); + ADD_PROPERTY(PropertyInfo(Variant::REAL, "offset"), "set_offset", "get_offset"); + + + ClassDB::bind_method(D_METHOD("_init_properties"), &Mirror::_init_properties); + ClassDB::bind_method(D_METHOD("_register_methods", "mm_graph_node"), &Mirror::_register_methods); + ClassDB::bind_method(D_METHOD("_render", "material"), &Mirror::_render); + ClassDB::bind_method(D_METHOD("_get_value_for", "uv", "pseed"), &Mirror::_get_value_for); + ClassDB::bind_method(D_METHOD("get_direction"), &Mirror::get_direction); + ClassDB::bind_method(D_METHOD("set_direction", "val"), &Mirror::set_direction); + ClassDB::bind_method(D_METHOD("get_offset"), &Mirror::get_offset); + ClassDB::bind_method(D_METHOD("set_offset", "val"), &Mirror::set_offset); + + } + + + diff --git a/modules/material_maker/nodes/transform/mirror.h b/modules/material_maker/nodes/transform/mirror.h new file mode 100644 index 000000000..324095496 --- /dev/null +++ b/modules/material_maker/nodes/transform/mirror.h @@ -0,0 +1,51 @@ +#ifndef MIRROR_H +#define MIRROR_H + + +class Mirror : public MMNode { + GDCLASS(Mirror, MMNode); + + public: + + Ref get_image(); + void set_image(const Ref &val); + + Ref get_input(); + void set_input(const Ref &val); + + int get_direction() const; + void set_direction(const int val); + + float get_offset() const; + void set_offset(const float val); + + 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); + int get_direction(); + void set_direction(const int val); + float get_offset(); + void set_offset(const float val); + + Mirror(); + ~Mirror(); + + protected: + static void _bind_methods(); + + //tool + //export(Resource) + Ref image; + //export(Resource) + Ref input; + //export(int, "Horizontal,Vertical") + int direction = 0; + //export(float) + float offset = 0; + //direction + //offset +}; + + +#endif diff --git a/modules/material_maker/nodes/transform/repeat.cpp b/modules/material_maker/nodes/transform/repeat.cpp new file mode 100644 index 000000000..f679c7fa7 --- /dev/null +++ b/modules/material_maker/nodes/transform/repeat.cpp @@ -0,0 +1,69 @@ + +#include "repeat.h" + + +Ref Repeat::get_input() { + return input; +} + +void Repeat::set_input(const Ref &val) { +input = val; +} + + + + //tool; + //export(Resource) ; + Ref input; + + void Repeat::_init_properties() { + + if (!input) { + input = MMNodeUniversalProperty.new(); + input.default_type = MMNodeUniversalProperty.DEFAULT_TYPE_COLOR; + input.set_default_value(Color(0, 0, 0, 1)); +} + + input.input_slot_type = MMNodeUniversalProperty.SLOT_TYPE_UNIVERSAL; + input.slot_name = ">>> Apply >>>"; + //input.input_slot_type = MMNodeUniversalProperty.SLOT_TYPE_COLOR; + input.output_slot_type = MMNodeUniversalProperty.SLOT_TYPE_UNIVERSAL; + input.get_value_from_owner = true; + register_input_property(input); + register_output_property(input); +} + + + void Repeat::_register_methods(const Variant &mm_graph_node) { + mm_graph_node.add_slot_label_universal(input); +} + + + void Repeat::_get_property_value(const Vector2 &uv) { + return input.get_value(MMAlgos.fractv2(uv), true); +} + +} + + Repeat::Repeat() { + input; + } + + Repeat::~Repeat() { + } + + + static void Repeat::_bind_methods() { + ClassDB::bind_method(D_METHOD("get_input"), &Repeat::get_input); + ClassDB::bind_method(D_METHOD("set_input", "value"), &Repeat::set_input); + ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "input", PROPERTY_HINT_RESOURCE_TYPE, "Ref"), "set_input", "get_input"); + + + ClassDB::bind_method(D_METHOD("_init_properties"), &Repeat::_init_properties); + ClassDB::bind_method(D_METHOD("_register_methods", "mm_graph_node"), &Repeat::_register_methods); + ClassDB::bind_method(D_METHOD("_get_property_value", "uv"), &Repeat::_get_property_value); + + } + + + diff --git a/modules/material_maker/nodes/transform/repeat.h b/modules/material_maker/nodes/transform/repeat.h new file mode 100644 index 000000000..4ca66c961 --- /dev/null +++ b/modules/material_maker/nodes/transform/repeat.h @@ -0,0 +1,29 @@ +#ifndef REPEAT_H +#define REPEAT_H + + +class Repeat : public MMNode { + GDCLASS(Repeat, MMNode); + + public: + + Ref get_input(); + void set_input(const Ref &val); + + void _init_properties(); + void _register_methods(const Variant &mm_graph_node); + void _get_property_value(const Vector2 &uv); + + Repeat(); + ~Repeat(); + + protected: + static void _bind_methods(); + + //tool + //export(Resource) + Ref input; +}; + + +#endif diff --git a/modules/material_maker/nodes/transform/rotate.cpp b/modules/material_maker/nodes/transform/rotate.cpp new file mode 100644 index 000000000..d349205e9 --- /dev/null +++ b/modules/material_maker/nodes/transform/rotate.cpp @@ -0,0 +1,165 @@ + +#include "rotate.h" + + +Ref Rotate::get_image() { + return image; +} + +void Rotate::set_image(const Ref &val) { +image = val; +} + + +Ref Rotate::get_input() { + return input; +} + +void Rotate::set_input(const Ref &val) { +input = val; +} + + +Vector2 Rotate::get_center() { + return center; +} + +void Rotate::set_center(const Vector2 &val) { +center = val; +} + + +float Rotate::get_rotate() const { + return rotate; +} + +void Rotate::set_rotate(const float val) { +rotate = val; +} + + + + //tool; + //export(Resource) ; + Ref image; + //export(Resource) ; + Ref input; + //export(Vector2) ; + Vector2 center = Vector2(); + //export(float) ; + float rotate = 0; + + void Rotate::_init_properties() { + + if (!input) { + input = MMNodeUniversalProperty.new(); + input.default_type = MMNodeUniversalProperty.DEFAULT_TYPE_COLOR; + input.set_default_value(Color(0, 0, 0, 1)); +} + + input.input_slot_type = MMNodeUniversalProperty.SLOT_TYPE_UNIVERSAL; + input.slot_name = ">>> Input1 "; + + if (!image) { + image = MMNodeUniversalProperty.new(); + image.default_type = MMNodeUniversalProperty.DEFAULT_TYPE_IMAGE; +} + + //image.input_slot_type = MMNodeUniversalProperty.SLOT_TYPE_FLOAT; + image.output_slot_type = MMNodeUniversalProperty.SLOT_TYPE_IMAGE; + //image.force_override = true; + register_input_property(input); + register_output_property(image); +} + + + void Rotate::_register_methods(const Variant &mm_graph_node) { + mm_graph_node.add_slot_label_universal(input); + mm_graph_node.add_slot_texture_universal(image); + mm_graph_node.add_slot_vector2("get_center", "set_center", "Center", 0.01); + mm_graph_node.add_slot_float("get_rotate", "set_rotate", "Rotate", 0.1); +} + + + void Rotate::_render(const Variant &material) { + Ref img = render_image(material); + image.set_value(img); +} + + + Color Rotate::_get_value_for(const Vector2 &uv, const int pseed) { + //$i(rotate($uv, vec2(0.5+$cx, 0.5+$cy), $rotate*0.01745329251)); + return input.get_value(MMAlgos.rotate(uv, center + Vector2(0.5, 0.5), rotate*0.01745329251)); +} + + //center; + + Vector2 Rotate::get_center() { + return center; +} + + + void Rotate::set_center(const Vector2 &val) { + center = val; + set_dirty(true); +} + + //rotate; + + float Rotate::get_rotate() { + return rotate; +} + + + void Rotate::set_rotate(const float val) { + rotate = val; + set_dirty(true); +} + +} + + Rotate::Rotate() { + image; + input; + center = Vector2(); + rotate = 0; + } + + Rotate::~Rotate() { + } + + + static void Rotate::_bind_methods() { + ClassDB::bind_method(D_METHOD("get_image"), &Rotate::get_image); + ClassDB::bind_method(D_METHOD("set_image", "value"), &Rotate::set_image); + ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "image", PROPERTY_HINT_RESOURCE_TYPE, "Ref"), "set_image", "get_image"); + + + ClassDB::bind_method(D_METHOD("get_input"), &Rotate::get_input); + ClassDB::bind_method(D_METHOD("set_input", "value"), &Rotate::set_input); + ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "input", PROPERTY_HINT_RESOURCE_TYPE, "Ref"), "set_input", "get_input"); + + + ClassDB::bind_method(D_METHOD("get_center"), &Rotate::get_center); + ClassDB::bind_method(D_METHOD("set_center", "value"), &Rotate::set_center); + ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "center"), "set_center", "get_center"); + + + ClassDB::bind_method(D_METHOD("get_rotate"), &Rotate::get_rotate); + ClassDB::bind_method(D_METHOD("set_rotate", "value"), &Rotate::set_rotate); + ADD_PROPERTY(PropertyInfo(Variant::REAL, "rotate"), "set_rotate", "get_rotate"); + + + ClassDB::bind_method(D_METHOD("_init_properties"), &Rotate::_init_properties); + ClassDB::bind_method(D_METHOD("_register_methods", "mm_graph_node"), &Rotate::_register_methods); + ClassDB::bind_method(D_METHOD("_render", "material"), &Rotate::_render); + ClassDB::bind_method(D_METHOD("_get_value_for", "uv", "pseed"), &Rotate::_get_value_for); + ClassDB::bind_method(D_METHOD("get_center"), &Rotate::get_center); + ClassDB::bind_method(D_METHOD("set_center", "val"), &Rotate::set_center); + ClassDB::bind_method(D_METHOD("get_rotate"), &Rotate::get_rotate); + ClassDB::bind_method(D_METHOD("set_rotate", "val"), &Rotate::set_rotate); + + } + + + diff --git a/modules/material_maker/nodes/transform/rotate.h b/modules/material_maker/nodes/transform/rotate.h new file mode 100644 index 000000000..3941c86db --- /dev/null +++ b/modules/material_maker/nodes/transform/rotate.h @@ -0,0 +1,51 @@ +#ifndef ROTATE_H +#define ROTATE_H + + +class Rotate : public MMNode { + GDCLASS(Rotate, MMNode); + + public: + + Ref get_image(); + void set_image(const Ref &val); + + Ref get_input(); + void set_input(const Ref &val); + + Vector2 get_center(); + void set_center(const Vector2 &val); + + float get_rotate() const; + void set_rotate(const float val); + + 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_center(); + void set_center(const Vector2 &val); + float get_rotate(); + void set_rotate(const float val); + + Rotate(); + ~Rotate(); + + protected: + static void _bind_methods(); + + //tool + //export(Resource) + Ref image; + //export(Resource) + Ref input; + //export(Vector2) + Vector2 center = Vector2(); + //export(float) + float rotate = 0; + //center + //rotate +}; + + +#endif diff --git a/modules/material_maker/nodes/transform/scale.cpp b/modules/material_maker/nodes/transform/scale.cpp new file mode 100644 index 000000000..3a9b4ce96 --- /dev/null +++ b/modules/material_maker/nodes/transform/scale.cpp @@ -0,0 +1,165 @@ + +#include "scale.h" + + +Ref Scale::get_image() { + return image; +} + +void Scale::set_image(const Ref &val) { +image = val; +} + + +Ref Scale::get_input() { + return input; +} + +void Scale::set_input(const Ref &val) { +input = val; +} + + +Vector2 Scale::get_center() { + return center; +} + +void Scale::set_center(const Vector2 &val) { +center = val; +} + + +Vector2 Scale::get_scale() { + return scale; +} + +void Scale::set_scale(const Vector2 &val) { +scale = val; +} + + + + //tool; + //export(Resource) ; + Ref image; + //export(Resource) ; + Ref input; + //export(Vector2) ; + Vector2 center = Vector2(); + //export(Vector2) ; + Vector2 scale = Vector2(1, 1); + + void Scale::_init_properties() { + + if (!input) { + input = MMNodeUniversalProperty.new(); + input.default_type = MMNodeUniversalProperty.DEFAULT_TYPE_COLOR; + input.set_default_value(Color(0, 0, 0, 1)); +} + + input.input_slot_type = MMNodeUniversalProperty.SLOT_TYPE_UNIVERSAL; + input.slot_name = ">>> Input1 "; + + if (!image) { + image = MMNodeUniversalProperty.new(); + image.default_type = MMNodeUniversalProperty.DEFAULT_TYPE_IMAGE; +} + + //image.input_slot_type = MMNodeUniversalProperty.SLOT_TYPE_FLOAT; + image.output_slot_type = MMNodeUniversalProperty.SLOT_TYPE_IMAGE; + //image.force_override = true; + register_input_property(input); + register_output_property(image); +} + + + void Scale::_register_methods(const Variant &mm_graph_node) { + mm_graph_node.add_slot_label_universal(input); + mm_graph_node.add_slot_texture_universal(image); + mm_graph_node.add_slot_vector2("get_center", "set_center", "Center", 0.01); + mm_graph_node.add_slot_vector2("get_scale", "set_scale", "Scale", 0.01); +} + + + void Scale::_render(const Variant &material) { + Ref img = render_image(material); + image.set_value(img); +} + + + Color Scale::_get_value_for(const Vector2 &uv, const int pseed) { + //$i(scale($uv, vec2(0.5+$cx, 0.5+$cy), vec2($scale_x, $scale_y))); + return input.get_value(MMAlgos.scale(uv, center + Vector2(0.5, 0.5), scale)); +} + + //center; + + Vector2 Scale::get_center() { + return center; +} + + + void Scale::set_center(const Vector2 &val) { + center = val; + set_dirty(true); +} + + //scale; + + Vector2 Scale::get_scale() { + return scale; +} + + + void Scale::set_scale(const Vector2 &val) { + scale = val; + set_dirty(true); +} + +} + + Scale::Scale() { + image; + input; + center = Vector2(); + scale = Vector2(1, 1); + } + + Scale::~Scale() { + } + + + static void Scale::_bind_methods() { + ClassDB::bind_method(D_METHOD("get_image"), &Scale::get_image); + ClassDB::bind_method(D_METHOD("set_image", "value"), &Scale::set_image); + ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "image", PROPERTY_HINT_RESOURCE_TYPE, "Ref"), "set_image", "get_image"); + + + ClassDB::bind_method(D_METHOD("get_input"), &Scale::get_input); + ClassDB::bind_method(D_METHOD("set_input", "value"), &Scale::set_input); + ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "input", PROPERTY_HINT_RESOURCE_TYPE, "Ref"), "set_input", "get_input"); + + + ClassDB::bind_method(D_METHOD("get_center"), &Scale::get_center); + ClassDB::bind_method(D_METHOD("set_center", "value"), &Scale::set_center); + ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "center"), "set_center", "get_center"); + + + ClassDB::bind_method(D_METHOD("get_scale"), &Scale::get_scale); + ClassDB::bind_method(D_METHOD("set_scale", "value"), &Scale::set_scale); + ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "scale"), "set_scale", "get_scale"); + + + ClassDB::bind_method(D_METHOD("_init_properties"), &Scale::_init_properties); + ClassDB::bind_method(D_METHOD("_register_methods", "mm_graph_node"), &Scale::_register_methods); + ClassDB::bind_method(D_METHOD("_render", "material"), &Scale::_render); + ClassDB::bind_method(D_METHOD("_get_value_for", "uv", "pseed"), &Scale::_get_value_for); + ClassDB::bind_method(D_METHOD("get_center"), &Scale::get_center); + ClassDB::bind_method(D_METHOD("set_center", "val"), &Scale::set_center); + ClassDB::bind_method(D_METHOD("get_scale"), &Scale::get_scale); + ClassDB::bind_method(D_METHOD("set_scale", "val"), &Scale::set_scale); + + } + + + diff --git a/modules/material_maker/nodes/transform/scale.h b/modules/material_maker/nodes/transform/scale.h new file mode 100644 index 000000000..facbef5b0 --- /dev/null +++ b/modules/material_maker/nodes/transform/scale.h @@ -0,0 +1,51 @@ +#ifndef SCALE_H +#define SCALE_H + + +class Scale : public MMNode { + GDCLASS(Scale, MMNode); + + public: + + Ref get_image(); + void set_image(const Ref &val); + + Ref get_input(); + void set_input(const Ref &val); + + Vector2 get_center(); + void set_center(const Vector2 &val); + + Vector2 get_scale(); + void set_scale(const Vector2 &val); + + 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_center(); + void set_center(const Vector2 &val); + Vector2 get_scale(); + void set_scale(const Vector2 &val); + + Scale(); + ~Scale(); + + protected: + static void _bind_methods(); + + //tool + //export(Resource) + Ref image; + //export(Resource) + Ref input; + //export(Vector2) + Vector2 center = Vector2(); + //export(Vector2) + Vector2 scale = Vector2(1, 1); + //center + //scale +}; + + +#endif diff --git a/modules/material_maker/nodes/transform/shear.cpp b/modules/material_maker/nodes/transform/shear.cpp new file mode 100644 index 000000000..b8e9f3566 --- /dev/null +++ b/modules/material_maker/nodes/transform/shear.cpp @@ -0,0 +1,207 @@ + +#include "shear.h" + + +Ref Shear::get_image() { + return image; +} + +void Shear::set_image(const Ref &val) { +image = val; +} + + +Ref Shear::get_input() { + return input; +} + +void Shear::set_input(const Ref &val) { +input = val; +} + + +int Shear::get_direction() const { + return direction; +} + +void Shear::set_direction(const int val) { +direction = val; +} + + +float Shear::get_amount() const { + return amount; +} + +void Shear::set_amount(const float val) { +amount = val; +} + + +float Shear::get_center() const { + return center; +} + +void Shear::set_center(const float val) { +center = val; +} + + + + //tool; + //export(Resource) ; + Ref image; + //export(Resource) ; + Ref input; + //export(int, "Horizontal,Vertical") ; + int direction = 0; + //export(float) ; + float amount = 1; + //export(float) ; + float center = 0; + + void Shear::_init_properties() { + + if (!input) { + input = MMNodeUniversalProperty.new(); + input.default_type = MMNodeUniversalProperty.DEFAULT_TYPE_COLOR; + input.set_default_value(Color(0, 0, 0, 1)); +} + + input.input_slot_type = MMNodeUniversalProperty.SLOT_TYPE_UNIVERSAL; + input.slot_name = ">>> Input "; + + if (!image) { + image = MMNodeUniversalProperty.new(); + image.default_type = MMNodeUniversalProperty.DEFAULT_TYPE_IMAGE; +} + + //image.input_slot_type = MMNodeUniversalProperty.SLOT_TYPE_FLOAT; + image.output_slot_type = MMNodeUniversalProperty.SLOT_TYPE_IMAGE; + //image.force_override = true; + register_input_property(input); + register_output_property(image); +} + + + void Shear::_register_methods(const Variant &mm_graph_node) { + mm_graph_node.add_slot_label_universal(input); + mm_graph_node.add_slot_texture_universal(image); + mm_graph_node.add_slot_enum("get_direction", "set_direction", "Direction", [ "Horizontal", "Vertical" ]); + mm_graph_node.add_slot_float("get_amount", "set_amount", "Amount", 0.01); + mm_graph_node.add_slot_float("get_center", "set_center", "Center", 0.01); +} + + + void Shear::_render(const Variant &material) { + Ref img = render_image(material); + image.set_value(img); +} + + + Color Shear::_get_value_for(const Vector2 &uv, const int pseed) { + //$in($uv+$amount*($uv.yx-vec2($center))*vec2($direction)); + + if (direction == 0) { + return input.get_value(uv + amount * (Vector2(uv.y, uv.x) - Vector2(center, center)) * Vector2(1, 0)); +} + + + else if (direction == 1) { + return input.get_value(uv + amount * (Vector2(uv.y, uv.x) - Vector2(center, center)) * Vector2(0, 1)); +} + + return Color(0, 0, 0, 1); +} + + //direction; + + int Shear::get_direction() { + return direction; +} + + + void Shear::set_direction(const int val) { + direction = val; + set_dirty(true); +} + + //amount; + + float Shear::get_amount() { + return amount; +} + + + void Shear::set_amount(const float val) { + amount = val; + set_dirty(true); +} + + //center; + + float Shear::get_center() { + return center; +} + + + void Shear::set_center(const float val) { + center = val; + set_dirty(true); +} + +} + + Shear::Shear() { + image; + input; + direction = 0; + amount = 1; + center = 0; + } + + Shear::~Shear() { + } + + + static void Shear::_bind_methods() { + ClassDB::bind_method(D_METHOD("get_image"), &Shear::get_image); + ClassDB::bind_method(D_METHOD("set_image", "value"), &Shear::set_image); + ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "image", PROPERTY_HINT_RESOURCE_TYPE, "Ref"), "set_image", "get_image"); + + + ClassDB::bind_method(D_METHOD("get_input"), &Shear::get_input); + ClassDB::bind_method(D_METHOD("set_input", "value"), &Shear::set_input); + ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "input", PROPERTY_HINT_RESOURCE_TYPE, "Ref"), "set_input", "get_input"); + + + ClassDB::bind_method(D_METHOD("get_direction"), &Shear::get_direction); + ClassDB::bind_method(D_METHOD("set_direction", "value"), &Shear::set_direction); + ADD_PROPERTY(PropertyInfo(Variant::INT, "direction"), "set_direction", "get_direction"); + + + ClassDB::bind_method(D_METHOD("get_amount"), &Shear::get_amount); + ClassDB::bind_method(D_METHOD("set_amount", "value"), &Shear::set_amount); + ADD_PROPERTY(PropertyInfo(Variant::REAL, "amount"), "set_amount", "get_amount"); + + + ClassDB::bind_method(D_METHOD("get_center"), &Shear::get_center); + ClassDB::bind_method(D_METHOD("set_center", "value"), &Shear::set_center); + ADD_PROPERTY(PropertyInfo(Variant::REAL, "center"), "set_center", "get_center"); + + + ClassDB::bind_method(D_METHOD("_init_properties"), &Shear::_init_properties); + ClassDB::bind_method(D_METHOD("_register_methods", "mm_graph_node"), &Shear::_register_methods); + ClassDB::bind_method(D_METHOD("_render", "material"), &Shear::_render); + ClassDB::bind_method(D_METHOD("_get_value_for", "uv", "pseed"), &Shear::_get_value_for); + ClassDB::bind_method(D_METHOD("get_direction"), &Shear::get_direction); + ClassDB::bind_method(D_METHOD("set_direction", "val"), &Shear::set_direction); + ClassDB::bind_method(D_METHOD("get_amount"), &Shear::get_amount); + ClassDB::bind_method(D_METHOD("set_amount", "val"), &Shear::set_amount); + ClassDB::bind_method(D_METHOD("get_center"), &Shear::get_center); + ClassDB::bind_method(D_METHOD("set_center", "val"), &Shear::set_center); + + } + + + diff --git a/modules/material_maker/nodes/transform/shear.h b/modules/material_maker/nodes/transform/shear.h new file mode 100644 index 000000000..59f4e8fc7 --- /dev/null +++ b/modules/material_maker/nodes/transform/shear.h @@ -0,0 +1,59 @@ +#ifndef SHEAR_H +#define SHEAR_H + + +class Shear : public MMNode { + GDCLASS(Shear, MMNode); + + public: + + Ref get_image(); + void set_image(const Ref &val); + + Ref get_input(); + void set_input(const Ref &val); + + int get_direction() const; + void set_direction(const int val); + + float get_amount() const; + void set_amount(const float val); + + float get_center() const; + void set_center(const float val); + + 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); + int get_direction(); + void set_direction(const int val); + float get_amount(); + void set_amount(const float val); + float get_center(); + void set_center(const float val); + + Shear(); + ~Shear(); + + protected: + static void _bind_methods(); + + //tool + //export(Resource) + Ref image; + //export(Resource) + Ref input; + //export(int, "Horizontal,Vertical") + int direction = 0; + //export(float) + float amount = 1; + //export(float) + float center = 0; + //direction + //amount + //center +}; + + +#endif diff --git a/modules/material_maker/nodes/transform/tiler.cpp b/modules/material_maker/nodes/transform/tiler.cpp new file mode 100644 index 000000000..58ff44df6 --- /dev/null +++ b/modules/material_maker/nodes/transform/tiler.cpp @@ -0,0 +1,613 @@ + +#include "tiler.h" + + +Ref Tiler::get_input() { + return input; +} + +void Tiler::set_input(const Ref &val) { +input = val; +} + + +Ref Tiler::get_in_mask() { + return in_mask; +} + +void Tiler::set_in_mask(const Ref &val) { +in_mask = val; +} + + +Ref Tiler::get_output() { + return output; +} + +void Tiler::set_output(const Ref &val) { +output = val; +} + + +Ref Tiler::get_instance_map() { + return instance_map; +} + +void Tiler::set_instance_map(const Ref &val) { +instance_map = val; +} + + +Vector2 Tiler::get_tile() { + return tile; +} + +void Tiler::set_tile(const Vector2 &val) { +tile = val; +} + + +float Tiler::get_overlap() const { + return overlap; +} + +void Tiler::set_overlap(const float val) { +overlap = val; +} + + +int Tiler::get_select_inputs() const { + return select_inputs; +} + +void Tiler::set_select_inputs(const int val) { +select_inputs = val; +} + + +Vector2 Tiler::get_scale() { + return scale; +} + +void Tiler::set_scale(const Vector2 &val) { +scale = val; +} + + +float Tiler::get_fixed_offset() const { + return fixed_offset; +} + +void Tiler::set_fixed_offset(const float val) { +fixed_offset = val; +} + + +float Tiler::get_rnd_offset() const { + return rnd_offset; +} + +void Tiler::set_rnd_offset(const float val) { +rnd_offset = val; +} + + +float Tiler::get_rnd_rotate() const { + return rnd_rotate; +} + +void Tiler::set_rnd_rotate(const float val) { +rnd_rotate = val; +} + + +float Tiler::get_rnd_scale() const { + return rnd_scale; +} + +void Tiler::set_rnd_scale(const float val) { +rnd_scale = val; +} + + +float Tiler::get_rnd_value() const { + return rnd_value; +} + +void Tiler::set_rnd_value(const float val) { +rnd_value = val; +} + + +bool Tiler::get_variations() const { + return variations; +} + +void Tiler::set_variations(const bool val) { +variations = val; +} + + + + //tool; + //export(Resource) ; + Ref input; + //export(Resource) ; + Ref in_mask; + //export(Resource) ; + Ref output; + //export(Resource) ; + Ref instance_map; + //export(Vector2) ; + Vector2 tile = Vector2(4, 4); + //export(float) ; + float overlap = 1; + //export(int, "1,4,16") ; + int select_inputs = 0; + //export(Vector2) ; + Vector2 scale = Vector2(0.5, 0.5); + //export(float) ; + float fixed_offset = 0; + //export(float) ; + float rnd_offset = 0.25; + //export(float) ; + float rnd_rotate = 45; + //export(float) ; + float rnd_scale = 0.2; + //export(float) ; + float rnd_value = 2; + //export(bool) ; + bool variations = false; + + void Tiler::_init_properties() { + + if (!input) { + input = MMNodeUniversalProperty.new(); + input.default_type = MMNodeUniversalProperty.DEFAULT_TYPE_FLOAT; + input.set_default_value(0); +} + + input.input_slot_type = MMNodeUniversalProperty.SLOT_TYPE_UNIVERSAL; + input.slot_name = ">>> Input "; + + if (!in_mask) { + in_mask = MMNodeUniversalProperty.new(); + in_mask.default_type = MMNodeUniversalProperty.DEFAULT_TYPE_FLOAT; + in_mask.set_default_value(1); +} + + in_mask.input_slot_type = MMNodeUniversalProperty.SLOT_TYPE_UNIVERSAL; + in_mask.slot_name = ">>> Mask "; + + if (!output) { + output = MMNodeUniversalProperty.new(); + output.default_type = MMNodeUniversalProperty.DEFAULT_TYPE_IMAGE; +} + + output.output_slot_type = MMNodeUniversalProperty.SLOT_TYPE_IMAGE; + + if (!instance_map) { + instance_map = MMNodeUniversalProperty.new(); + instance_map.default_type = MMNodeUniversalProperty.DEFAULT_TYPE_IMAGE; +} + + instance_map.output_slot_type = MMNodeUniversalProperty.SLOT_TYPE_IMAGE; + register_input_property(input); + register_input_property(in_mask); + register_output_property(output); + register_output_property(instance_map); +} + + + void Tiler::_register_methods(const Variant &mm_graph_node) { + mm_graph_node.add_slot_label_universal(input); + mm_graph_node.add_slot_label_universal(in_mask); + mm_graph_node.add_slot_texture_universal(output); + mm_graph_node.add_slot_texture_universal(instance_map); + mm_graph_node.add_slot_vector2("get_tile", "set_tile", "Tile", 1); + mm_graph_node.add_slot_float("get_overlap", "set_overlap", "Overlap", 1); + mm_graph_node.add_slot_enum("get_select_inputs", "set_select_inputs", "Select inputs", [ "1", "4", "16" ]); + mm_graph_node.add_slot_vector2("get_scale", "set_scale", "Scale", 0.01); + mm_graph_node.add_slot_float("get_fixed_offset", "set_fixed_offset", "Fixed Offset", 0.01); + mm_graph_node.add_slot_float("get_rnd_offset", "set_rnd_offset", "Rnd Offset", 0.01); + mm_graph_node.add_slot_float("get_rnd_rotate", "set_rnd_rotate", "Rnd Rotate", 0.1); + mm_graph_node.add_slot_float("get_rnd_scale", "set_rnd_scale", "Rnd Scale", 0.01); + mm_graph_node.add_slot_float("get_rnd_value", "set_rnd_value", "Rnd Value", 0.01); +} + + //mm_graph_node.add_slot_bool("get_variations", "set_variations", "Variations"); + + void Tiler::_render(const Variant &material) { + Ref output_img = Image.new(); + Ref instance_map_img = Image.new(); + output_img.create(material.image_size.x, material.image_size.y, false, Image.FORMAT_RGBA8); + instance_map_img.create(material.image_size.x, material.image_size.y, false, Image.FORMAT_RGBA8); + output_img.lock(); + instance_map_img.lock(); + float w = material.image_size.x; + float h = material.image_size.y; + float pseed = randf() + randi(); + float ps = 1.0 / float(pseed); + int ix = int(material.image_size.x); + int iy = int(material.image_size.y); + + for (int x = 0; x < ix; ++x) { //x in range(ix) + + for (int y = 0; y < iy; ++y) { //y in range(iy) + Vector2 uv = Vector2(x / w, y / h); + //vec4 $(name_uv)_rch = tiler_$(name)($uv, vec2($tx, $ty), int($overlap), vec2(float($seed))); + Color rch = tiler_calc(uv, tile, overlap, Vector2(ps, ps)); + //Output, float, Shows the generated pattern; + //$(name_uv)_rch.a; + Color output_img_col = Color(rch.a, rch.a, rch.a, 1); + //Instance map, rgb, Shows a random color for each instance of the input image; + //$(name_uv)_rch.rgb; + Color instance_map_img_col = Color(rch.r, rch.g, rch.b, 1); + output_img.set_pixel(x, y, output_img_col); + instance_map_img.set_pixel(x, y, instance_map_img_col); +} + +} + + output_img.unlock(); + instance_map_img.unlock(); + output.set_value(output_img); + instance_map.set_value(instance_map_img); +} + + + Color Tiler::_get_value_for(const Vector2 &uv, const int pseed) { + return Color(); +} + + //tile; + + Vector2 Tiler::get_tile() { + return tile; +} + + + void Tiler::set_tile(const Vector2 &val) { + tile = val; + set_dirty(true); +} + + //overlap; + + float Tiler::get_overlap() { + return overlap; +} + + + void Tiler::set_overlap(const float val) { + overlap = val; + set_dirty(true); +} + + //select_inputs; + + int Tiler::get_select_inputs() { + return select_inputs; +} + + + void Tiler::set_select_inputs(const int val) { + select_inputs = val; + set_dirty(true); +} + + //scale; + + Vector2 Tiler::get_scale() { + return scale; +} + + + void Tiler::set_scale(const Vector2 &val) { + scale = val; + set_dirty(true); +} + + //fixed_offset; + + float Tiler::get_fixed_offset() { + return fixed_offset; +} + + + void Tiler::set_fixed_offset(const float val) { + fixed_offset = val; + set_dirty(true); +} + + //rnd_offset; + + float Tiler::get_rnd_offset() { + return rnd_offset; +} + + + void Tiler::set_rnd_offset(const float val) { + rnd_offset = val; + set_dirty(true); +} + + //rnd_rotate; + + float Tiler::get_rnd_rotate() { + return rnd_rotate; +} + + + void Tiler::set_rnd_rotate(const float val) { + rnd_rotate = val; + set_dirty(true); +} + + //rnd_scale; + + float Tiler::get_rnd_scale() { + return rnd_scale; +} + + + void Tiler::set_rnd_scale(const float val) { + rnd_scale = val; + set_dirty(true); +} + + //rnd_value; + + float Tiler::get_rnd_value() { + return rnd_value; +} + + + void Tiler::set_rnd_value(const float val) { + rnd_value = val; + set_dirty(true); +} + + //variations; + + bool Tiler::get_variations() { + return variations; +} + + + void Tiler::set_variations(const bool val) { + variations = val; + set_dirty(true); +} + + //----------------------; + //tiler.mmg; + //Tiles several occurences of an input image while adding randomness.; + //instance; + //vec4 tiler_$(name)(vec2 uv, vec2 tile, int overlap, vec2 _seed) {; + // float c = 0.0; + // vec3 rc = vec3(0.0); + // vec3 rc1; + // for (int dx = -overlap; dx <= overlap; ++dx) {; + // for (int dy = -overlap; dy <= overlap; ++dy) {; + // vec2 pos = fract((floor(uv*tile)+vec2(float(dx), float(dy))+vec2(0.5))/tile-vec2(0.5)); + // vec2 seed = rand2(pos+_seed); + // rc1 = rand3(seed); + // pos = fract(pos+vec2($fixed_offset/tile.x, 0.0)*floor(mod(pos.y*tile.y, 2.0))+$offset*seed/tile); + // float mask = $mask(fract(pos+vec2(0.5))); + //; + // if (mask > 0.01) {; + // vec2 pv = fract(uv - pos)-vec2(0.5); + // seed = rand2(seed); + // float angle = (seed.x * 2.0 - 1.0) * $rotate * 0.01745329251; + // float ca = cos(angle); + // float sa = sin(angle); + // pv = vec2(ca*pv.x+sa*pv.y, -sa*pv.x+ca*pv.y); + // pv *= (seed.y-0.5)*2.0*$scale+1.0; + // pv /= vec2($scale_x, $scale_y); + // pv += vec2(0.5); + // seed = rand2(seed); + // vec2 clamped_pv = clamp(pv, vec2(0.0), vec2(1.0)); + // if (pv.x != clamped_pv.x || pv.y != clamped_pv.y) {; + // continue; + // }; + //; + // $select_inputs; + //; + // float c1 = $in.variation(pv, $variations ? seed.x : 0.0)*mask*(1.0-$value*seed.x); + // c = max(c, c1); + // rc = mix(rc, rc1, step(c, c1)); + // }; + // }; + // }; + //; + // return vec4(rc, c); + //}; + //select_inputs enum; + //1, " "; + //4, "pv = clamp(0.5*(pv+floor(rand2(seed)*2.0)), vec2(0.0), vec2(1.0));"; + //16, "pv = clamp(0.25*(pv+floor(rand2(seed)*4.0)), vec2(0.0), vec2(1.0));"; + + Color Tiler::tiler_calc(const Vector2 &uv, const Vector2 &tile, const int overlap, const Vector2 &_seed) { + float c = 0.0; + Vector3 rc = Vector3(); + Vector3 rc1 = Vector3(); + //for (int dx = -overlap; dx <= overlap; ++dx) {; + + for (int dx = -overlap; dx < overlap; ++dx) { //dx in range(-overlap, overlap) + //for (int dy = -overlap; dy <= overlap; ++dy) {; + + for (int dy = -overlap; dy < overlap; ++dy) { //dy in range(-overlap, overlap) + Vector2 pos = MMAlgos.fractv2((MMAlgos.floorv2(uv * tile) + Vector2(dx, dy) + Vector2(0.5, 0.5)) / tile - Vector2(0.5, 0.5)); + Vector2 vseed = MMAlgos.rand2(pos+_seed); + rc1 = MMAlgos.rand3(vseed); + pos = MMAlgos.fractv2(pos + Vector2(fixed_offset / tile.x, 0.0) * floor(MMAlgos.modf(pos.y * tile.y, 2.0)) + rnd_offset * vseed / tile); + float mask = in_mask.get_value(MMAlgos.fractv2(pos + Vector2(0.5, 0.5))); + + if ((mask > 0.01)) { + Vector2 pv = MMAlgos.fractv2(uv - pos) - Vector2(0.5, 0.5); + vseed = MMAlgos.rand2(vseed); + float angle = (vseed.x * 2.0 - 1.0) * rnd_rotate * 0.01745329251; + float ca = cos(angle); + float sa = sin(angle); + pv = Vector2(ca * pv.x + sa * pv.y, -sa * pv.x + ca * pv.y); + pv *= (vseed.y-0.5) * 2.0 * rnd_scale + 1.0; + pv /= scale; + pv += Vector2(0.5, 0.5); + vseed = MMAlgos.rand2(vseed); + Vector2 clamped_pv = MMAlgos.clampv2(pv, Vector2(), Vector2(1, 1)); + + if ((pv.x != clamped_pv.x || pv.y != clamped_pv.y)) { + continue; +} + + //1, " "; + //4, "pv = clamp(0.5*(pv+floor(rand2(seed)*2.0)), vec2(0.0), vec2(1.0));"; + //16, "pv = clamp(0.25*(pv+floor(rand2(seed)*4.0)), vec2(0.0), vec2(1.0));"; + + if (select_inputs == 1) { + pv = MMAlgos.clampv2(0.5*(pv + MMAlgos.floorv2(MMAlgos.rand2(vseed)*2.0)), Vector2(), Vector2(1, 1)); +} + + + else if (select_inputs == 2) { + pv = MMAlgos.clampv2(0.25*(pv + MMAlgos.floorv2(MMAlgos.rand2(vseed)*4.0)), Vector2(), Vector2(1, 1)); +} + + //float c1 = $in.variation(pv, $variations ? vseed.x : 0.0) * mask * (1.0-$value*vseed.x); + float c1 = input.get_value(pv) * mask * (1.0 - rnd_value * vseed.x); + c = max(c, c1); + rc = lerp(rc, rc1, MMAlgos.step(c, c1)); +} + +} + +} + + return Color(rc.x, rc.y, rc.z, c); +} + +} + + Tiler::Tiler() { + input; + in_mask; + output; + instance_map; + tile = Vector2(4, 4); + overlap = 1; + select_inputs = 0; + scale = Vector2(0.5, 0.5); + fixed_offset = 0; + rnd_offset = 0.25; + rnd_rotate = 45; + rnd_scale = 0.2; + rnd_value = 2; + variations = false; + } + + Tiler::~Tiler() { + } + + + static void Tiler::_bind_methods() { + ClassDB::bind_method(D_METHOD("get_input"), &Tiler::get_input); + ClassDB::bind_method(D_METHOD("set_input", "value"), &Tiler::set_input); + ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "input", PROPERTY_HINT_RESOURCE_TYPE, "Ref"), "set_input", "get_input"); + + + ClassDB::bind_method(D_METHOD("get_in_mask"), &Tiler::get_in_mask); + ClassDB::bind_method(D_METHOD("set_in_mask", "value"), &Tiler::set_in_mask); + ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "in_mask", PROPERTY_HINT_RESOURCE_TYPE, "Ref"), "set_in_mask", "get_in_mask"); + + + ClassDB::bind_method(D_METHOD("get_output"), &Tiler::get_output); + ClassDB::bind_method(D_METHOD("set_output", "value"), &Tiler::set_output); + ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "output", PROPERTY_HINT_RESOURCE_TYPE, "Ref"), "set_output", "get_output"); + + + ClassDB::bind_method(D_METHOD("get_instance_map"), &Tiler::get_instance_map); + ClassDB::bind_method(D_METHOD("set_instance_map", "value"), &Tiler::set_instance_map); + ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "instance_map", PROPERTY_HINT_RESOURCE_TYPE, "Ref"), "set_instance_map", "get_instance_map"); + + + ClassDB::bind_method(D_METHOD("get_tile"), &Tiler::get_tile); + ClassDB::bind_method(D_METHOD("set_tile", "value"), &Tiler::set_tile); + ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "tile"), "set_tile", "get_tile"); + + + ClassDB::bind_method(D_METHOD("get_overlap"), &Tiler::get_overlap); + ClassDB::bind_method(D_METHOD("set_overlap", "value"), &Tiler::set_overlap); + ADD_PROPERTY(PropertyInfo(Variant::REAL, "overlap"), "set_overlap", "get_overlap"); + + + ClassDB::bind_method(D_METHOD("get_select_inputs"), &Tiler::get_select_inputs); + ClassDB::bind_method(D_METHOD("set_select_inputs", "value"), &Tiler::set_select_inputs); + ADD_PROPERTY(PropertyInfo(Variant::INT, "select_inputs"), "set_select_inputs", "get_select_inputs"); + + + ClassDB::bind_method(D_METHOD("get_scale"), &Tiler::get_scale); + ClassDB::bind_method(D_METHOD("set_scale", "value"), &Tiler::set_scale); + ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "scale"), "set_scale", "get_scale"); + + + ClassDB::bind_method(D_METHOD("get_fixed_offset"), &Tiler::get_fixed_offset); + ClassDB::bind_method(D_METHOD("set_fixed_offset", "value"), &Tiler::set_fixed_offset); + ADD_PROPERTY(PropertyInfo(Variant::REAL, "fixed_offset"), "set_fixed_offset", "get_fixed_offset"); + + + ClassDB::bind_method(D_METHOD("get_rnd_offset"), &Tiler::get_rnd_offset); + ClassDB::bind_method(D_METHOD("set_rnd_offset", "value"), &Tiler::set_rnd_offset); + ADD_PROPERTY(PropertyInfo(Variant::REAL, "rnd_offset"), "set_rnd_offset", "get_rnd_offset"); + + + ClassDB::bind_method(D_METHOD("get_rnd_rotate"), &Tiler::get_rnd_rotate); + ClassDB::bind_method(D_METHOD("set_rnd_rotate", "value"), &Tiler::set_rnd_rotate); + ADD_PROPERTY(PropertyInfo(Variant::REAL, "rnd_rotate"), "set_rnd_rotate", "get_rnd_rotate"); + + + ClassDB::bind_method(D_METHOD("get_rnd_scale"), &Tiler::get_rnd_scale); + ClassDB::bind_method(D_METHOD("set_rnd_scale", "value"), &Tiler::set_rnd_scale); + ADD_PROPERTY(PropertyInfo(Variant::REAL, "rnd_scale"), "set_rnd_scale", "get_rnd_scale"); + + + ClassDB::bind_method(D_METHOD("get_rnd_value"), &Tiler::get_rnd_value); + ClassDB::bind_method(D_METHOD("set_rnd_value", "value"), &Tiler::set_rnd_value); + ADD_PROPERTY(PropertyInfo(Variant::REAL, "rnd_value"), "set_rnd_value", "get_rnd_value"); + + + ClassDB::bind_method(D_METHOD("get_variations"), &Tiler::get_variations); + ClassDB::bind_method(D_METHOD("set_variations", "value"), &Tiler::set_variations); + ADD_PROPERTY(PropertyInfo(Variant::BOOL, "variations"), "set_variations", "get_variations"); + + + ClassDB::bind_method(D_METHOD("_init_properties"), &Tiler::_init_properties); + ClassDB::bind_method(D_METHOD("_register_methods", "mm_graph_node"), &Tiler::_register_methods); + ClassDB::bind_method(D_METHOD("_render", "material"), &Tiler::_render); + ClassDB::bind_method(D_METHOD("_get_value_for", "uv", "pseed"), &Tiler::_get_value_for); + ClassDB::bind_method(D_METHOD("get_tile"), &Tiler::get_tile); + ClassDB::bind_method(D_METHOD("set_tile", "val"), &Tiler::set_tile); + ClassDB::bind_method(D_METHOD("get_overlap"), &Tiler::get_overlap); + ClassDB::bind_method(D_METHOD("set_overlap", "val"), &Tiler::set_overlap); + ClassDB::bind_method(D_METHOD("get_select_inputs"), &Tiler::get_select_inputs); + ClassDB::bind_method(D_METHOD("set_select_inputs", "val"), &Tiler::set_select_inputs); + ClassDB::bind_method(D_METHOD("get_scale"), &Tiler::get_scale); + ClassDB::bind_method(D_METHOD("set_scale", "val"), &Tiler::set_scale); + ClassDB::bind_method(D_METHOD("get_fixed_offset"), &Tiler::get_fixed_offset); + ClassDB::bind_method(D_METHOD("set_fixed_offset", "val"), &Tiler::set_fixed_offset); + ClassDB::bind_method(D_METHOD("get_rnd_offset"), &Tiler::get_rnd_offset); + ClassDB::bind_method(D_METHOD("set_rnd_offset", "val"), &Tiler::set_rnd_offset); + ClassDB::bind_method(D_METHOD("get_rnd_rotate"), &Tiler::get_rnd_rotate); + ClassDB::bind_method(D_METHOD("set_rnd_rotate", "val"), &Tiler::set_rnd_rotate); + ClassDB::bind_method(D_METHOD("get_rnd_scale"), &Tiler::get_rnd_scale); + ClassDB::bind_method(D_METHOD("set_rnd_scale", "val"), &Tiler::set_rnd_scale); + ClassDB::bind_method(D_METHOD("get_rnd_value"), &Tiler::get_rnd_value); + ClassDB::bind_method(D_METHOD("set_rnd_value", "val"), &Tiler::set_rnd_value); + ClassDB::bind_method(D_METHOD("get_variations"), &Tiler::get_variations); + ClassDB::bind_method(D_METHOD("set_variations", "val"), &Tiler::set_variations); + ClassDB::bind_method(D_METHOD("tiler_calc", "uv", "tile", "overlap", "_seed"), &Tiler::tiler_calc); + + } + + + diff --git a/modules/material_maker/nodes/transform/tiler.h b/modules/material_maker/nodes/transform/tiler.h new file mode 100644 index 000000000..600169172 --- /dev/null +++ b/modules/material_maker/nodes/transform/tiler.h @@ -0,0 +1,174 @@ +#ifndef TILER_H +#define TILER_H + + +class Tiler : public MMNode { + GDCLASS(Tiler, MMNode); + + public: + + Ref get_input(); + void set_input(const Ref &val); + + Ref get_in_mask(); + void set_in_mask(const Ref &val); + + Ref get_output(); + void set_output(const Ref &val); + + Ref get_instance_map(); + void set_instance_map(const Ref &val); + + Vector2 get_tile(); + void set_tile(const Vector2 &val); + + float get_overlap() const; + void set_overlap(const float val); + + int get_select_inputs() const; + void set_select_inputs(const int val); + + Vector2 get_scale(); + void set_scale(const Vector2 &val); + + float get_fixed_offset() const; + void set_fixed_offset(const float val); + + float get_rnd_offset() const; + void set_rnd_offset(const float val); + + float get_rnd_rotate() const; + void set_rnd_rotate(const float val); + + float get_rnd_scale() const; + void set_rnd_scale(const float val); + + float get_rnd_value() const; + void set_rnd_value(const float val); + + bool get_variations() const; + void set_variations(const bool val); + + 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_tile(); + void set_tile(const Vector2 &val); + float get_overlap(); + void set_overlap(const float val); + int get_select_inputs(); + void set_select_inputs(const int val); + Vector2 get_scale(); + void set_scale(const Vector2 &val); + float get_fixed_offset(); + void set_fixed_offset(const float val); + float get_rnd_offset(); + void set_rnd_offset(const float val); + float get_rnd_rotate(); + void set_rnd_rotate(const float val); + float get_rnd_scale(); + void set_rnd_scale(const float val); + float get_rnd_value(); + void set_rnd_value(const float val); + bool get_variations(); + void set_variations(const bool val); + Color tiler_calc(const Vector2 &uv, const Vector2 &tile, const int overlap, const Vector2 &_seed); + + Tiler(); + ~Tiler(); + + protected: + static void _bind_methods(); + + //tool + //export(Resource) + Ref input; + //export(Resource) + Ref in_mask; + //export(Resource) + Ref output; + //export(Resource) + Ref instance_map; + //export(Vector2) + Vector2 tile = Vector2(4, 4); + //export(float) + float overlap = 1; + //export(int, "1,4,16") + int select_inputs = 0; + //export(Vector2) + Vector2 scale = Vector2(0.5, 0.5); + //export(float) + float fixed_offset = 0; + //export(float) + float rnd_offset = 0.25; + //export(float) + float rnd_rotate = 45; + //export(float) + float rnd_scale = 0.2; + //export(float) + float rnd_value = 2; + //export(bool) + bool variations = false; + //mm_graph_node.add_slot_bool("get_variations", "set_variations", "Variations") + //tile + //overlap + //select_inputs + //scale + //fixed_offset + //rnd_offset + //rnd_rotate + //rnd_scale + //rnd_value + //variations + //---------------------- + //tiler.mmg + //Tiles several occurences of an input image while adding randomness. + //instance + //vec4 tiler_$(name)(vec2 uv, vec2 tile, int overlap, vec2 _seed) { + // float c = 0.0; + // vec3 rc = vec3(0.0); + // vec3 rc1; + // for (int dx = -overlap; dx <= overlap; ++dx) { + // for (int dy = -overlap; dy <= overlap; ++dy) { + // vec2 pos = fract((floor(uv*tile)+vec2(float(dx), float(dy))+vec2(0.5))/tile-vec2(0.5)); + // vec2 seed = rand2(pos+_seed); + // rc1 = rand3(seed); + // pos = fract(pos+vec2($fixed_offset/tile.x, 0.0)*floor(mod(pos.y*tile.y, 2.0))+$offset*seed/tile); + // float mask = $mask(fract(pos+vec2(0.5))); + // + // if (mask > 0.01) { + // vec2 pv = fract(uv - pos)-vec2(0.5); + // seed = rand2(seed); + // float angle = (seed.x * 2.0 - 1.0) * $rotate * 0.01745329251; + // float ca = cos(angle); + // float sa = sin(angle); + // pv = vec2(ca*pv.x+sa*pv.y, -sa*pv.x+ca*pv.y); + // pv *= (seed.y-0.5)*2.0*$scale+1.0; + // pv /= vec2($scale_x, $scale_y); + // pv += vec2(0.5); + // seed = rand2(seed); + // vec2 clamped_pv = clamp(pv, vec2(0.0), vec2(1.0)); + // if (pv.x != clamped_pv.x || pv.y != clamped_pv.y) { + // continue; + // } + // + // $select_inputs + // + // float c1 = $in.variation(pv, $variations ? seed.x : 0.0)*mask*(1.0-$value*seed.x); + // c = max(c, c1); + // rc = mix(rc, rc1, step(c, c1)); + // } + // } + // } + // + // return vec4(rc, c); + //} + //select_inputs enum + //1, " " + //4, "pv = clamp(0.5*(pv+floor(rand2(seed)*2.0)), vec2(0.0), vec2(1.0));" + //16, "pv = clamp(0.25*(pv+floor(rand2(seed)*4.0)), vec2(0.0), vec2(1.0));" +}; + + +#endif diff --git a/modules/material_maker/nodes/transform/transform.cpp b/modules/material_maker/nodes/transform/transform.cpp new file mode 100644 index 000000000..fbde35920 --- /dev/null +++ b/modules/material_maker/nodes/transform/transform.cpp @@ -0,0 +1,296 @@ + +#include "transform.h" + + +Ref Transform::get_image() { + return image; +} + +void Transform::set_image(const Ref &val) { +image = val; +} + + +Ref Transform::get_input() { + return input; +} + +void Transform::set_input(const Ref &val) { +input = val; +} + + +Ref Transform::get_translate_x() { + return translate_x; +} + +void Transform::set_translate_x(const Ref &val) { +translate_x = val; +} + + +Ref Transform::get_translate_y() { + return translate_y; +} + +void Transform::set_translate_y(const Ref &val) { +translate_y = val; +} + + +Ref Transform::get_rotate() { + return rotate; +} + +void Transform::set_rotate(const Ref &val) { +rotate = val; +} + + +Ref Transform::get_scale_x() { + return scale_x; +} + +void Transform::set_scale_x(const Ref &val) { +scale_x = val; +} + + +Ref Transform::get_scale_y() { + return scale_y; +} + +void Transform::set_scale_y(const Ref &val) { +scale_y = val; +} + + +int Transform::get_mode() const { + return mode; +} + +void Transform::set_mode(const int val) { +mode = val; +} + + + + //tool; + //export(Resource) ; + Ref image; + //export(Resource) ; + Ref input; + //export(Resource) ; + Ref translate_x; + //export(Resource) ; + Ref translate_y; + //export(Resource) ; + Ref rotate; + //export(Resource) ; + Ref scale_x; + //export(Resource) ; + Ref scale_y; + //export(int, "Clamp,Repeat,Extend") ; + int mode = 0; + + void Transform::_init_properties() { + + if (!input) { + input = MMNodeUniversalProperty.new(); + input.default_type = MMNodeUniversalProperty.DEFAULT_TYPE_COLOR; + input.set_default_value(Color(0, 0, 0, 1)); +} + + input.input_slot_type = MMNodeUniversalProperty.SLOT_TYPE_UNIVERSAL; + input.slot_name = ">>> Input "; + + if (!image) { + image = MMNodeUniversalProperty.new(); + image.default_type = MMNodeUniversalProperty.DEFAULT_TYPE_IMAGE; +} + + //image.input_slot_type = MMNodeUniversalProperty.SLOT_TYPE_FLOAT; + image.output_slot_type = MMNodeUniversalProperty.SLOT_TYPE_IMAGE; + //image.force_override = true; + + if (!translate_x) { + translate_x = MMNodeUniversalProperty.new(); + translate_x.default_type = MMNodeUniversalProperty.DEFAULT_TYPE_FLOAT; + translate_x.set_default_value(0); + translate_x.value_step = 0.01; +} + + translate_x.input_slot_type = MMNodeUniversalProperty.SLOT_TYPE_UNIVERSAL; + translate_x.slot_name = "Translate X"; + + if (!translate_y) { + translate_y = MMNodeUniversalProperty.new(); + translate_y.default_type = MMNodeUniversalProperty.DEFAULT_TYPE_FLOAT; + translate_y.set_default_value(0); + translate_y.value_step = 0.01; +} + + translate_y.input_slot_type = MMNodeUniversalProperty.SLOT_TYPE_UNIVERSAL; + translate_y.slot_name = "Translate Y"; + + if (!rotate) { + rotate = MMNodeUniversalProperty.new(); + rotate.default_type = MMNodeUniversalProperty.DEFAULT_TYPE_FLOAT; + rotate.set_default_value(0); + rotate.value_step = 0.01; +} + + rotate.input_slot_type = MMNodeUniversalProperty.SLOT_TYPE_UNIVERSAL; + rotate.slot_name = "Rotate"; + + if (!scale_x) { + scale_x = MMNodeUniversalProperty.new(); + scale_x.default_type = MMNodeUniversalProperty.DEFAULT_TYPE_FLOAT; + scale_x.set_default_value(1); + scale_x.value_step = 0.01; +} + + scale_x.input_slot_type = MMNodeUniversalProperty.SLOT_TYPE_UNIVERSAL; + scale_x.slot_name = "Scale X"; + + if (!scale_y) { + scale_y = MMNodeUniversalProperty.new(); + scale_y.default_type = MMNodeUniversalProperty.DEFAULT_TYPE_FLOAT; + scale_y.set_default_value(1); + scale_y.value_step = 0.01; +} + + scale_y.input_slot_type = MMNodeUniversalProperty.SLOT_TYPE_UNIVERSAL; + scale_y.slot_name = "Scale Y"; + register_input_property(input); + register_output_property(image); + register_input_property(translate_x); + register_input_property(translate_y); + register_input_property(rotate); + register_input_property(scale_x); + register_input_property(scale_y); +} + + + void Transform::_register_methods(const Variant &mm_graph_node) { + mm_graph_node.add_slot_label_universal(input); + mm_graph_node.add_slot_texture_universal(image); + mm_graph_node.add_slot_float_universal(translate_x); + mm_graph_node.add_slot_float_universal(translate_y); + mm_graph_node.add_slot_float_universal(rotate); + mm_graph_node.add_slot_float_universal(scale_x); + mm_graph_node.add_slot_float_universal(scale_y); + mm_graph_node.add_slot_enum("get_mode", "set_mode", "Mode", [ "Clamp", "Repeat", "Extend" ]); +} + + + void Transform::_render(const Variant &material) { + Ref img = render_image(material); + image.set_value(img); +} + + + Color Transform::_get_value_for(const Vector2 &uv, const int pseed) { + //$i($mode(transform2($uv, vec2($translate_x*(2.0*$tx($uv)-1.0), $translate_y*(2.0*$ty($uv)-1.0)), $rotate*0.01745329251*(2.0*$r($uv)-1.0), vec2($scale_x*(2.0*$sx($uv)-1.0), $scale_y*(2.0*$sy($uv)-1.0)))))",; + //Mode:; + //Clamp -> transform2_clamp; + //Repeat -> fract; + //Extend -> ""; + Vector2 tr = Vector2(translate_x.get_default_value() * (2.0 * translate_x.get_value_or_zero(uv) - 1.0), translate_y.get_default_value() *(2.0 * translate_y.get_value_or_zero(uv) - 1.0)); + float rot = rotate.get_default_value() * 0.01745329251*(2.0 * rotate.get_value_or_zero(uv) - 1.0); + Vector2 sc = Vector2(scale_x.get_default_value() *(2.0 * scale_x.get_value_or_zero(uv) - 1.0), scale_y.get_default_value() *(2.0 * scale_y.get_value_or_zero(uv) - 1.0)); + Vector2 nuv = MMAlgos.transform2(uv, tr, rot, sc); + + if (mode == 0) { + nuv = MMAlgos.transform2_clamp(nuv); +} + + + else if (mode == 1) { + nuv = MMAlgos.fractv2(nuv); +} + + return input.get_value(nuv); +} + + //mode; + + int Transform::get_mode() { + return mode; +} + + + void Transform::set_mode(const int val) { + mode = val; + set_dirty(true); +} + +} + + Transform::Transform() { + image; + input; + translate_x; + translate_y; + rotate; + scale_x; + scale_y; + mode = 0; + } + + Transform::~Transform() { + } + + + static void Transform::_bind_methods() { + ClassDB::bind_method(D_METHOD("get_image"), &Transform::get_image); + ClassDB::bind_method(D_METHOD("set_image", "value"), &Transform::set_image); + ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "image", PROPERTY_HINT_RESOURCE_TYPE, "Ref"), "set_image", "get_image"); + + + ClassDB::bind_method(D_METHOD("get_input"), &Transform::get_input); + ClassDB::bind_method(D_METHOD("set_input", "value"), &Transform::set_input); + ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "input", PROPERTY_HINT_RESOURCE_TYPE, "Ref"), "set_input", "get_input"); + + + ClassDB::bind_method(D_METHOD("get_translate_x"), &Transform::get_translate_x); + ClassDB::bind_method(D_METHOD("set_translate_x", "value"), &Transform::set_translate_x); + ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "translate_x", PROPERTY_HINT_RESOURCE_TYPE, "Ref"), "set_translate_x", "get_translate_x"); + + + ClassDB::bind_method(D_METHOD("get_translate_y"), &Transform::get_translate_y); + ClassDB::bind_method(D_METHOD("set_translate_y", "value"), &Transform::set_translate_y); + ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "translate_y", PROPERTY_HINT_RESOURCE_TYPE, "Ref"), "set_translate_y", "get_translate_y"); + + + ClassDB::bind_method(D_METHOD("get_rotate"), &Transform::get_rotate); + ClassDB::bind_method(D_METHOD("set_rotate", "value"), &Transform::set_rotate); + ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "rotate", PROPERTY_HINT_RESOURCE_TYPE, "Ref"), "set_rotate", "get_rotate"); + + + ClassDB::bind_method(D_METHOD("get_scale_x"), &Transform::get_scale_x); + ClassDB::bind_method(D_METHOD("set_scale_x", "value"), &Transform::set_scale_x); + ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "scale_x", PROPERTY_HINT_RESOURCE_TYPE, "Ref"), "set_scale_x", "get_scale_x"); + + + ClassDB::bind_method(D_METHOD("get_scale_y"), &Transform::get_scale_y); + ClassDB::bind_method(D_METHOD("set_scale_y", "value"), &Transform::set_scale_y); + ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "scale_y", PROPERTY_HINT_RESOURCE_TYPE, "Ref"), "set_scale_y", "get_scale_y"); + + + ClassDB::bind_method(D_METHOD("get_mode"), &Transform::get_mode); + ClassDB::bind_method(D_METHOD("set_mode", "value"), &Transform::set_mode); + ADD_PROPERTY(PropertyInfo(Variant::INT, "mode"), "set_mode", "get_mode"); + + + ClassDB::bind_method(D_METHOD("_init_properties"), &Transform::_init_properties); + ClassDB::bind_method(D_METHOD("_register_methods", "mm_graph_node"), &Transform::_register_methods); + ClassDB::bind_method(D_METHOD("_render", "material"), &Transform::_render); + ClassDB::bind_method(D_METHOD("_get_value_for", "uv", "pseed"), &Transform::_get_value_for); + ClassDB::bind_method(D_METHOD("get_mode"), &Transform::get_mode); + ClassDB::bind_method(D_METHOD("set_mode", "val"), &Transform::set_mode); + + } + + + diff --git a/modules/material_maker/nodes/transform/transform.h b/modules/material_maker/nodes/transform/transform.h new file mode 100644 index 000000000..1bf9e605b --- /dev/null +++ b/modules/material_maker/nodes/transform/transform.h @@ -0,0 +1,68 @@ +#ifndef TRANSFORM_H +#define TRANSFORM_H + + +class Transform : public MMNode { + GDCLASS(Transform, MMNode); + + public: + + Ref get_image(); + void set_image(const Ref &val); + + Ref get_input(); + void set_input(const Ref &val); + + Ref get_translate_x(); + void set_translate_x(const Ref &val); + + Ref get_translate_y(); + void set_translate_y(const Ref &val); + + Ref get_rotate(); + void set_rotate(const Ref &val); + + Ref get_scale_x(); + void set_scale_x(const Ref &val); + + Ref get_scale_y(); + void set_scale_y(const Ref &val); + + int get_mode() const; + void set_mode(const int val); + + 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); + int get_mode(); + void set_mode(const int val); + + Transform(); + ~Transform(); + + protected: + static void _bind_methods(); + + //tool + //export(Resource) + Ref image; + //export(Resource) + Ref input; + //export(Resource) + Ref translate_x; + //export(Resource) + Ref translate_y; + //export(Resource) + Ref rotate; + //export(Resource) + Ref scale_x; + //export(Resource) + Ref scale_y; + //export(int, "Clamp,Repeat,Extend") + int mode = 0; + //mode +}; + + +#endif diff --git a/modules/material_maker/nodes/transform/translate.cpp b/modules/material_maker/nodes/transform/translate.cpp new file mode 100644 index 000000000..6ffda9332 --- /dev/null +++ b/modules/material_maker/nodes/transform/translate.cpp @@ -0,0 +1,133 @@ + +#include "translate.h" + + +Ref Translate::get_image() { + return image; +} + +void Translate::set_image(const Ref &val) { +image = val; +} + + +Ref Translate::get_input() { + return input; +} + +void Translate::set_input(const Ref &val) { +input = val; +} + + +Vector2 Translate::get_translation() { + return translation; +} + +void Translate::set_translation(const Vector2 &val) { +translation = val; +} + + + + //tool; + //export(Resource) ; + Ref image; + //export(Resource) ; + Ref input; + //export(Vector2) ; + Vector2 translation = Vector2(); + + void Translate::_init_properties() { + + if (!input) { + input = MMNodeUniversalProperty.new(); + input.default_type = MMNodeUniversalProperty.DEFAULT_TYPE_COLOR; + input.set_default_value(Color(0, 0, 0, 1)); +} + + input.input_slot_type = MMNodeUniversalProperty.SLOT_TYPE_UNIVERSAL; + input.slot_name = ">>> Input1 "; + + if (!image) { + image = MMNodeUniversalProperty.new(); + image.default_type = MMNodeUniversalProperty.DEFAULT_TYPE_IMAGE; +} + + //image.input_slot_type = MMNodeUniversalProperty.SLOT_TYPE_FLOAT; + image.output_slot_type = MMNodeUniversalProperty.SLOT_TYPE_IMAGE; + //image.force_override = true; + register_input_property(input); + register_output_property(image); +} + + + void Translate::_register_methods(const Variant &mm_graph_node) { + mm_graph_node.add_slot_label_universal(input); + mm_graph_node.add_slot_texture_universal(image); + mm_graph_node.add_slot_vector2("get_translation", "set_translation", "Translation", 0.01); +} + + + void Translate::_render(const Variant &material) { + Ref img = render_image(material); + image.set_value(img); +} + + + Color Translate::_get_value_for(const Vector2 &uv, const int pseed) { + //$i($uv-vec2($translate_x, $translate_y)); + return input.get_value(uv - translation); +} + + //translation; + + Vector2 Translate::get_translation() { + return translation; +} + + + void Translate::set_translation(const Vector2 &val) { + translation = val; + set_dirty(true); +} + +} + + Translate::Translate() { + image; + input; + translation = Vector2(); + } + + Translate::~Translate() { + } + + + static void Translate::_bind_methods() { + ClassDB::bind_method(D_METHOD("get_image"), &Translate::get_image); + ClassDB::bind_method(D_METHOD("set_image", "value"), &Translate::set_image); + ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "image", PROPERTY_HINT_RESOURCE_TYPE, "Ref"), "set_image", "get_image"); + + + ClassDB::bind_method(D_METHOD("get_input"), &Translate::get_input); + ClassDB::bind_method(D_METHOD("set_input", "value"), &Translate::set_input); + ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "input", PROPERTY_HINT_RESOURCE_TYPE, "Ref"), "set_input", "get_input"); + + + ClassDB::bind_method(D_METHOD("get_translation"), &Translate::get_translation); + ClassDB::bind_method(D_METHOD("set_translation", "value"), &Translate::set_translation); + ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "translation"), "set_translation", "get_translation"); + + + ClassDB::bind_method(D_METHOD("_init_properties"), &Translate::_init_properties); + ClassDB::bind_method(D_METHOD("_register_methods", "mm_graph_node"), &Translate::_register_methods); + ClassDB::bind_method(D_METHOD("_render", "material"), &Translate::_render); + ClassDB::bind_method(D_METHOD("_get_value_for", "uv", "pseed"), &Translate::_get_value_for); + ClassDB::bind_method(D_METHOD("get_translation"), &Translate::get_translation); + ClassDB::bind_method(D_METHOD("set_translation", "val"), &Translate::set_translation); + + } + + + diff --git a/modules/material_maker/nodes/transform/translate.h b/modules/material_maker/nodes/transform/translate.h new file mode 100644 index 000000000..911d81e79 --- /dev/null +++ b/modules/material_maker/nodes/transform/translate.h @@ -0,0 +1,43 @@ +#ifndef TRANSLATE_H +#define TRANSLATE_H + + +class Translate : public MMNode { + GDCLASS(Translate, MMNode); + + public: + + Ref get_image(); + void set_image(const Ref &val); + + Ref get_input(); + void set_input(const Ref &val); + + Vector2 get_translation(); + void set_translation(const Vector2 &val); + + 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_translation(); + void set_translation(const Vector2 &val); + + Translate(); + ~Translate(); + + protected: + static void _bind_methods(); + + //tool + //export(Resource) + Ref image; + //export(Resource) + Ref input; + //export(Vector2) + Vector2 translation = Vector2(); + //translation +}; + + +#endif diff --git a/modules/material_maker/nodes/uniform/greyscale_uniform.cpp b/modules/material_maker/nodes/uniform/greyscale_uniform.cpp new file mode 100644 index 000000000..3f3e8c9d9 --- /dev/null +++ b/modules/material_maker/nodes/uniform/greyscale_uniform.cpp @@ -0,0 +1,68 @@ + +#include "greyscale_uniform.h" + + +Ref GreyscaleUniform::get_uniform() { + return uniform; +} + +void GreyscaleUniform::set_uniform(const Ref &val) { +uniform = val; +} + + + + //tool; + //export(Resource) ; + Ref uniform; + + void GreyscaleUniform::_init_properties() { + + if (!uniform) { + uniform = MMNodeUniversalProperty.new(); + uniform.default_type = MMNodeUniversalProperty.DEFAULT_TYPE_FLOAT; + uniform.set_default_value(0.5); + uniform.slot_name = "Value (Color)"; + uniform.value_step = 0.01; + uniform.value_range = Vector2(0, 1); +} + + uniform.output_slot_type = MMNodeUniversalProperty.SLOT_TYPE_COLOR; + register_output_property(uniform); +} + + + void GreyscaleUniform::_register_methods(const Variant &mm_graph_node) { + mm_graph_node.add_slot_float_universal(uniform); +} + + + Color GreyscaleUniform::_get_value_for(const Vector2 &uv, const int pseed) { + float f = uniform.get_value(uv); + return Color(f, f, f, 1); +} + +} + + GreyscaleUniform::GreyscaleUniform() { + uniform; + } + + GreyscaleUniform::~GreyscaleUniform() { + } + + + static void GreyscaleUniform::_bind_methods() { + ClassDB::bind_method(D_METHOD("get_uniform"), &GreyscaleUniform::get_uniform); + ClassDB::bind_method(D_METHOD("set_uniform", "value"), &GreyscaleUniform::set_uniform); + ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "uniform", PROPERTY_HINT_RESOURCE_TYPE, "Ref"), "set_uniform", "get_uniform"); + + + ClassDB::bind_method(D_METHOD("_init_properties"), &GreyscaleUniform::_init_properties); + ClassDB::bind_method(D_METHOD("_register_methods", "mm_graph_node"), &GreyscaleUniform::_register_methods); + ClassDB::bind_method(D_METHOD("_get_value_for", "uv", "pseed"), &GreyscaleUniform::_get_value_for); + + } + + + diff --git a/modules/material_maker/nodes/uniform/greyscale_uniform.h b/modules/material_maker/nodes/uniform/greyscale_uniform.h new file mode 100644 index 000000000..fc0fe8586 --- /dev/null +++ b/modules/material_maker/nodes/uniform/greyscale_uniform.h @@ -0,0 +1,29 @@ +#ifndef GREYSCALE_UNIFORM_H +#define GREYSCALE_UNIFORM_H + + +class GreyscaleUniform : public MMNode { + GDCLASS(GreyscaleUniform, MMNode); + + public: + + Ref get_uniform(); + void set_uniform(const Ref &val); + + void _init_properties(); + void _register_methods(const Variant &mm_graph_node); + Color _get_value_for(const Vector2 &uv, const int pseed); + + GreyscaleUniform(); + ~GreyscaleUniform(); + + protected: + static void _bind_methods(); + + //tool + //export(Resource) + Ref uniform; +}; + + +#endif diff --git a/modules/material_maker/nodes/uniform/uniform.cpp b/modules/material_maker/nodes/uniform/uniform.cpp new file mode 100644 index 000000000..673ea2938 --- /dev/null +++ b/modules/material_maker/nodes/uniform/uniform.cpp @@ -0,0 +1,64 @@ + +#include "uniform.h" + + +Ref Uniform::get_uniform() { + return uniform; +} + +void Uniform::set_uniform(const Ref &val) { +uniform = val; +} + + + + //tool; + //export(Resource) ; + Ref uniform; + + void Uniform::_init_properties() { + + if (!uniform) { + uniform = MMNodeUniversalProperty.new(); + uniform.default_type = MMNodeUniversalProperty.DEFAULT_TYPE_COLOR; + uniform.set_default_value(Color(1, 1, 1, 1)); +} + + uniform.output_slot_type = MMNodeUniversalProperty.SLOT_TYPE_COLOR; + register_output_property(uniform); +} + + + void Uniform::_register_methods(const Variant &mm_graph_node) { + mm_graph_node.add_slot_color_universal(uniform); +} + + + Color Uniform::_get_value_for(const Vector2 &uv, const int pseed) { + return uniform.get_value(uv); +} + +} + + Uniform::Uniform() { + uniform; + } + + Uniform::~Uniform() { + } + + + static void Uniform::_bind_methods() { + ClassDB::bind_method(D_METHOD("get_uniform"), &Uniform::get_uniform); + ClassDB::bind_method(D_METHOD("set_uniform", "value"), &Uniform::set_uniform); + ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "uniform", PROPERTY_HINT_RESOURCE_TYPE, "Ref"), "set_uniform", "get_uniform"); + + + ClassDB::bind_method(D_METHOD("_init_properties"), &Uniform::_init_properties); + ClassDB::bind_method(D_METHOD("_register_methods", "mm_graph_node"), &Uniform::_register_methods); + ClassDB::bind_method(D_METHOD("_get_value_for", "uv", "pseed"), &Uniform::_get_value_for); + + } + + + diff --git a/modules/material_maker/nodes/uniform/uniform.h b/modules/material_maker/nodes/uniform/uniform.h new file mode 100644 index 000000000..551831074 --- /dev/null +++ b/modules/material_maker/nodes/uniform/uniform.h @@ -0,0 +1,29 @@ +#ifndef UNIFORM_H +#define UNIFORM_H + + +class Uniform : public MMNode { + GDCLASS(Uniform, MMNode); + + public: + + Ref get_uniform(); + void set_uniform(const Ref &val); + + void _init_properties(); + void _register_methods(const Variant &mm_graph_node); + Color _get_value_for(const Vector2 &uv, const int pseed); + + Uniform(); + ~Uniform(); + + protected: + static void _bind_methods(); + + //tool + //export(Resource) + Ref uniform; +}; + + +#endif