Cleaned up MMCircleMap, MMColorTiler, and the MMKaleidoscope nodes.

This commit is contained in:
Relintai 2022-06-17 01:14:46 +02:00
parent e1493ecac6
commit 0c759b2f16
9 changed files with 617 additions and 1025 deletions

View File

@ -61,6 +61,9 @@ sources = [
"nodes/transform/rotate.cpp",
"nodes/transform/repeat.cpp",
"nodes/transform/mirror.cpp",
"nodes/transform/kaleidoscope.cpp",
"nodes/transform/color_tiler.cpp",
"nodes/transform/circle_map.cpp",
]
if env["tools"]:

View File

@ -31,6 +31,8 @@ def get_doc_classes():
"MMRotate",
"MMRepeat",
"MMMirror",
"MMKaleidoscope",
"MMColorTiler",
]
def get_doc_path():

View File

@ -1,171 +1,112 @@
#include "circle_map.h"
#include "../../algos/mm_algos.h"
#include "../../editor/mm_graph_node.h"
#include "../mm_material.h"
Ref<Resource> CircleMap::get_image() {
return image;
Ref<MMNodeUniversalProperty> MMCircleMap::get_image() {
return image;
}
void CircleMap::set_image(const Ref<Resource> &val) {
image = val;
void MMCircleMap::set_image(const Ref<MMNodeUniversalProperty> &val) {
image = val;
}
Ref<Resource> CircleMap::get_input() {
return input;
Ref<MMNodeUniversalProperty> MMCircleMap::get_input() {
return input;
}
void CircleMap::set_input(const Ref<Resource> &val) {
input = val;
void MMCircleMap::set_input(const Ref<MMNodeUniversalProperty> &val) {
input = val;
}
float CircleMap::get_radius() const {
return radius;
float MMCircleMap::get_radius() const {
return radius;
}
void CircleMap::set_radius(const float val) {
radius = val;
void MMCircleMap::set_radius(const float val) {
radius = val;
if (radius == 0) {
radius = 0.000000001;
}
set_dirty(true);
}
int CircleMap::get_repeat() const {
return repeat;
int MMCircleMap::get_repeat() const {
return repeat;
}
void CircleMap::set_repeat(const int val) {
repeat = val;
void MMCircleMap::set_repeat(const int val) {
repeat = val;
set_dirty(true);
}
void MMCircleMap::_init_properties() {
if (!input.is_valid()) {
input.instance();
input->set_default_type(MMNodeUniversalProperty::DEFAULT_TYPE_COLOR);
input->set_default_value(Color(0, 0, 0, 1));
}
input->set_input_slot_type(MMNodeUniversalProperty::SLOT_TYPE_UNIVERSAL);
input->set_slot_name(">>> Input ");
//tool;
//export(Resource) ;
Ref<Resource> image;
//export(Resource) ;
Ref<Resource> input;
//export(float) ;
float radius = 1;
//export(int) ;
int repeat = 1;
if (!image.is_valid()) {
image.instance();
image->set_default_type(MMNodeUniversalProperty::DEFAULT_TYPE_IMAGE);
}
void CircleMap::_init_properties() {
//image.input_slot_type = MMNodeUniversalProperty.SLOT_TYPE_FLOAT;
image->set_output_slot_type(MMNodeUniversalProperty::SLOT_TYPE_IMAGE);
//image.force_override = true;
if (!input) {
input = MMNodeUniversalProperty.new();
input.default_type = MMNodeUniversalProperty.DEFAULT_TYPE_COLOR;
input.set_default_value(Color(0, 0, 0, 1));
register_input_property(input);
register_output_property(image);
}
input.input_slot_type = MMNodeUniversalProperty.SLOT_TYPE_UNIVERSAL;
input.slot_name = ">>> Input ";
if (!image) {
image = MMNodeUniversalProperty.new();
image.default_type = MMNodeUniversalProperty.DEFAULT_TYPE_IMAGE;
void MMCircleMap::_register_methods(MMGraphNode *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");
}
//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 MMCircleMap::_render(const Ref<MMMaterial> &material) {
Ref<Image> img = render_image(material);
image->set_value(img);
}
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");
Color MMCircleMap::_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 * Math::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);
}
void CircleMap::_render(const Variant &material) {
Ref<Image> img = render_image(material);
image.set_value(img);
MMCircleMap::MMCircleMap() {
radius = 1;
repeat = 1;
}
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);
MMCircleMap::~MMCircleMap() {
}
//radius;
void MMCircleMap::_bind_methods() {
ClassDB::bind_method(D_METHOD("get_image"), &MMCircleMap::get_image);
ClassDB::bind_method(D_METHOD("set_image", "value"), &MMCircleMap::set_image);
ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "image", PROPERTY_HINT_RESOURCE_TYPE, "MMNodeUniversalProperty"), "set_image", "get_image");
float CircleMap::get_radius() {
return radius;
ClassDB::bind_method(D_METHOD("get_input"), &MMCircleMap::get_input);
ClassDB::bind_method(D_METHOD("set_input", "value"), &MMCircleMap::set_input);
ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "input", PROPERTY_HINT_RESOURCE_TYPE, "MMNodeUniversalProperty"), "set_input", "get_input");
ClassDB::bind_method(D_METHOD("get_radius"), &MMCircleMap::get_radius);
ClassDB::bind_method(D_METHOD("set_radius", "value"), &MMCircleMap::set_radius);
ADD_PROPERTY(PropertyInfo(Variant::REAL, "radius"), "set_radius", "get_radius");
ClassDB::bind_method(D_METHOD("get_repeat"), &MMCircleMap::get_repeat);
ClassDB::bind_method(D_METHOD("set_repeat", "value"), &MMCircleMap::set_repeat);
ADD_PROPERTY(PropertyInfo(Variant::INT, "repeat"), "set_repeat", "get_repeat");
}
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<Resource>"), "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<Resource>"), "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);
}

View File

@ -1,51 +1,40 @@
#ifndef CIRCLE_MAP_H
#define CIRCLE_MAP_H
#ifndef MM_CIRCLE_MAP_H
#define MM_CIRCLE_MAP_H
#include "../mm_node.h"
#include "../mm_node_universal_property.h"
class CircleMap : public MMNode {
GDCLASS(CircleMap, MMNode);
class MMCircleMap : public MMNode {
GDCLASS(MMCircleMap, MMNode);
public:
public:
Ref<MMNodeUniversalProperty> get_image();
void set_image(const Ref<MMNodeUniversalProperty> &val);
Ref<Resource> get_image();
void set_image(const Ref<Resource> &val);
Ref<MMNodeUniversalProperty> get_input();
void set_input(const Ref<MMNodeUniversalProperty> &val);
Ref<Resource> get_input();
void set_input(const Ref<Resource> &val);
float get_radius() const;
void set_radius(const float val);
float get_radius() const;
void set_radius(const float val);
int get_repeat() const;
void set_repeat(const int val);
int get_repeat() const;
void set_repeat(const int val);
void _init_properties();
void _register_methods(MMGraphNode *mm_graph_node);
void _render(const Ref<MMMaterial> &material);
Color _get_value_for(const Vector2 &uv, const int pseed);
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);
MMCircleMap();
~MMCircleMap();
CircleMap();
~CircleMap();
protected:
static void _bind_methods();
protected:
static void _bind_methods();
//tool
//export(Resource)
Ref<Resource> image;
//export(Resource)
Ref<Resource> input;
//export(float)
float radius = 1;
//export(int)
int repeat = 1;
//radius
//repeat
Ref<MMNodeUniversalProperty> image;
Ref<MMNodeUniversalProperty> input;
float radius = 1;
int repeat = 1;
};
#endif

View File

@ -1,609 +1,412 @@
#include "color_tiler.h"
#include "../../algos/mm_algos.h"
#include "../../editor/mm_graph_node.h"
#include "../mm_material.h"
Ref<Resource> ColorTiler::get_input() {
return input;
Ref<MMNodeUniversalProperty> MMColorTiler::get_input() {
return input;
}
void ColorTiler::set_input(const Ref<Resource> &val) {
input = val;
void MMColorTiler::set_input(const Ref<MMNodeUniversalProperty> &val) {
input = val;
}
Ref<Resource> ColorTiler::get_in_mask() {
return in_mask;
}
void ColorTiler::set_in_mask(const Ref<Resource> &val) {
in_mask = val;
}
Ref<Resource> ColorTiler::get_output() {
return output;
}
void ColorTiler::set_output(const Ref<Resource> &val) {
output = val;
}
Ref<Resource> ColorTiler::get_instance_map() {
return instance_map;
}
void ColorTiler::set_instance_map(const Ref<Resource> &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<Resource> input;
//export(Resource) ;
Ref<Resource> in_mask;
//export(Resource) ;
Ref<Resource> output;
//export(Resource) ;
Ref<Resource> 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;
Ref<MMNodeUniversalProperty> MMColorTiler::get_in_mask() {
return in_mask;
}
output.output_slot_type = MMNodeUniversalProperty.SLOT_TYPE_IMAGE;
if (!instance_map) {
instance_map = MMNodeUniversalProperty.new();
instance_map.default_type = MMNodeUniversalProperty.DEFAULT_TYPE_IMAGE;
void MMColorTiler::set_in_mask(const Ref<MMNodeUniversalProperty> &val) {
in_mask = val;
}
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);
Ref<MMNodeUniversalProperty> MMColorTiler::get_output() {
return output;
}
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);
void MMColorTiler::set_output(const Ref<MMNodeUniversalProperty> &val) {
output = val;
}
//mm_graph_node.add_slot_bool("get_variations", "set_variations", "Variations");
void ColorTiler::_render(const Variant &material) {
Ref<Image> output_img = Image.new();
Ref<Image> 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]);
Ref<MMNodeUniversalProperty> MMColorTiler::get_instance_map() {
return instance_map;
}
void MMColorTiler::set_instance_map(const Ref<MMNodeUniversalProperty> &val) {
instance_map = val;
}
output_img.unlock();
instance_map_img.unlock();
output.set_value(output_img);
instance_map.set_value(instance_map_img);
Vector2 MMColorTiler::get_tile() {
return tile;
}
Color ColorTiler::_get_value_for(const Vector2 &uv, const int pseed) {
return Color();
void MMColorTiler::set_tile(const Vector2 &val) {
tile = val;
set_dirty(true);
}
//tile;
Vector2 ColorTiler::get_tile() {
return tile;
float MMColorTiler::get_overlap() const {
return overlap;
}
void ColorTiler::set_tile(const Vector2 &val) {
tile = val;
set_dirty(true);
void MMColorTiler::set_overlap(const float val) {
overlap = val;
set_dirty(true);
}
//overlap;
float ColorTiler::get_overlap() {
return overlap;
int MMColorTiler::get_select_inputs() const {
return select_inputs;
}
void ColorTiler::set_overlap(const float val) {
overlap = val;
set_dirty(true);
void MMColorTiler::set_select_inputs(const int val) {
select_inputs = val;
set_dirty(true);
}
//select_inputs;
int ColorTiler::get_select_inputs() {
return select_inputs;
Vector2 MMColorTiler::get_scale() {
return scale;
}
void ColorTiler::set_select_inputs(const int val) {
select_inputs = val;
set_dirty(true);
void MMColorTiler::set_scale(const Vector2 &val) {
scale = val;
set_dirty(true);
}
//scale;
Vector2 ColorTiler::get_scale() {
return scale;
float MMColorTiler::get_fixed_offset() const {
return fixed_offset;
}
void ColorTiler::set_scale(const Vector2 &val) {
scale = val;
set_dirty(true);
void MMColorTiler::set_fixed_offset(const float val) {
fixed_offset = val;
set_dirty(true);
}
//fixed_offset;
float ColorTiler::get_fixed_offset() {
return fixed_offset;
float MMColorTiler::get_rnd_offset() const {
return rnd_offset;
}
void ColorTiler::set_fixed_offset(const float val) {
fixed_offset = val;
set_dirty(true);
void MMColorTiler::set_rnd_offset(const float val) {
rnd_offset = val;
set_dirty(true);
}
//rnd_offset;
float ColorTiler::get_rnd_offset() {
return rnd_offset;
float MMColorTiler::get_rnd_rotate() const {
return rnd_rotate;
}
void ColorTiler::set_rnd_offset(const float val) {
rnd_offset = val;
set_dirty(true);
void MMColorTiler::set_rnd_rotate(const float val) {
rnd_rotate = val;
set_dirty(true);
}
//rnd_rotate;
float ColorTiler::get_rnd_rotate() {
return rnd_rotate;
float MMColorTiler::get_rnd_scale() const {
return rnd_scale;
}
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 MMColorTiler::set_rnd_scale(const float val) {
rnd_scale = val;
set_dirty(true);
}
void ColorTiler::set_rnd_scale(const float val) {
rnd_scale = val;
set_dirty(true);
}
//rnd_opacity;
float ColorTiler::get_rnd_opacity() {
return rnd_opacity;
float MMColorTiler::get_rnd_opacity() const {
return rnd_opacity;
}
void ColorTiler::set_rnd_opacity(const float val) {
rnd_opacity = val;
set_dirty(true);
void MMColorTiler::set_rnd_opacity(const float val) {
rnd_opacity = val;
set_dirty(true);
}
//variations;
bool ColorTiler::get_variations() {
return variations;
bool MMColorTiler::get_variations() const {
return variations;
}
void ColorTiler::set_variations(const bool val) {
variations = val;
set_dirty(true);
void MMColorTiler::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));";
void MMColorTiler::_init_properties() {
if (!input.is_valid()) {
input.instance();
input->set_default_type(MMNodeUniversalProperty::DEFAULT_TYPE_COLOR);
input->set_default_value(Color(0, 0, 0, 1));
}
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) {;
input->set_input_slot_type(MMNodeUniversalProperty::SLOT_TYPE_UNIVERSAL);
input->set_slot_name(">>> Input ");
for (int dx = -overlap; dx < overlap; ++dx) { //dx in range(-overlap, overlap)
//for (int dy = -overlap; dy <= overlap; ++dy) {;
if (!in_mask.is_valid()) {
in_mask.instance();
in_mask->set_default_type(MMNodeUniversalProperty::DEFAULT_TYPE_FLOAT);
in_mask->set_default_value(1);
}
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)));
in_mask->set_input_slot_type(MMNodeUniversalProperty::SLOT_TYPE_UNIVERSAL);
in_mask->set_slot_name(">>> Mask ");
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 (!output.is_valid()) {
output.instance();
output->set_default_type(MMNodeUniversalProperty::DEFAULT_TYPE_IMAGE);
}
if (select_inputs == 1) {
pv = MMAlgos.clampv2(0.5*(pv + MMAlgos.floorv2(MMAlgos.rand2(vseed)*2.0)), Vector2(), Vector2(1, 1));
}
output->set_output_slot_type(MMNodeUniversalProperty::SLOT_TYPE_IMAGE);
if (!instance_map.is_valid()) {
instance_map.instance();
instance_map->set_default_type(MMNodeUniversalProperty::DEFAULT_TYPE_IMAGE);
}
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);
}
}
instance_map->set_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);
}
PoolColorArray pc = PoolColorArray();
pc.append(Color(rc.x, rc.y, rc.z, 1));
pc.append(c);
return pc;
}
void MMColorTiler::_register_methods(MMGraphNode *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);
Array arr;
arr.push_back("1");
arr.push_back("4");
arr.push_back("16");
mm_graph_node->add_slot_enum("get_select_inputs", "set_select_inputs", "Select inputs", arr);
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 MMColorTiler::_render(const Ref<MMMaterial> &material) {
Ref<Image> output_img;
output_img.instance();
Ref<Image> instance_map_img;
instance_map_img.instance();
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 = Math::randf() + Math::rand();
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 MMColorTiler::_get_value_for(const Vector2 &uv, const int pseed) {
return Color();
}
//----------------------;
//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 MMColorTiler::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 inc = input->get_value(pv);
Color n = inc * 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 = c.linear_interpolate(n, na);
rc = rc.linear_interpolate(rc1, n.a);
}
}
}
PoolColorArray pc = PoolColorArray();
pc.append(Color(rc.x, rc.y, rc.z, 1));
pc.append(c);
return pc;
}
MMColorTiler::MMColorTiler() {
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;
}
MMColorTiler::~MMColorTiler() {
}
void MMColorTiler::_bind_methods() {
ClassDB::bind_method(D_METHOD("get_input"), &MMColorTiler::get_input);
ClassDB::bind_method(D_METHOD("set_input", "value"), &MMColorTiler::set_input);
ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "input", PROPERTY_HINT_RESOURCE_TYPE, "MMNodeUniversalProperty"), "set_input", "get_input");
ClassDB::bind_method(D_METHOD("get_in_mask"), &MMColorTiler::get_in_mask);
ClassDB::bind_method(D_METHOD("set_in_mask", "value"), &MMColorTiler::set_in_mask);
ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "in_mask", PROPERTY_HINT_RESOURCE_TYPE, "MMNodeUniversalProperty"), "set_in_mask", "get_in_mask");
ClassDB::bind_method(D_METHOD("get_output"), &MMColorTiler::get_output);
ClassDB::bind_method(D_METHOD("set_output", "value"), &MMColorTiler::set_output);
ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "output", PROPERTY_HINT_RESOURCE_TYPE, "MMNodeUniversalProperty"), "set_output", "get_output");
ClassDB::bind_method(D_METHOD("get_instance_map"), &MMColorTiler::get_instance_map);
ClassDB::bind_method(D_METHOD("set_instance_map", "value"), &MMColorTiler::set_instance_map);
ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "instance_map", PROPERTY_HINT_RESOURCE_TYPE, "MMNodeUniversalProperty"), "set_instance_map", "get_instance_map");
ClassDB::bind_method(D_METHOD("get_tile"), &MMColorTiler::get_tile);
ClassDB::bind_method(D_METHOD("set_tile", "value"), &MMColorTiler::set_tile);
ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "tile"), "set_tile", "get_tile");
ClassDB::bind_method(D_METHOD("get_overlap"), &MMColorTiler::get_overlap);
ClassDB::bind_method(D_METHOD("set_overlap", "value"), &MMColorTiler::set_overlap);
ADD_PROPERTY(PropertyInfo(Variant::REAL, "overlap"), "set_overlap", "get_overlap");
ClassDB::bind_method(D_METHOD("get_select_inputs"), &MMColorTiler::get_select_inputs);
ClassDB::bind_method(D_METHOD("set_select_inputs", "value"), &MMColorTiler::set_select_inputs);
ADD_PROPERTY(PropertyInfo(Variant::INT, "select_inputs"), "set_select_inputs", "get_select_inputs");
ClassDB::bind_method(D_METHOD("get_scale"), &MMColorTiler::get_scale);
ClassDB::bind_method(D_METHOD("set_scale", "value"), &MMColorTiler::set_scale);
ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "scale"), "set_scale", "get_scale");
ClassDB::bind_method(D_METHOD("get_fixed_offset"), &MMColorTiler::get_fixed_offset);
ClassDB::bind_method(D_METHOD("set_fixed_offset", "value"), &MMColorTiler::set_fixed_offset);
ADD_PROPERTY(PropertyInfo(Variant::REAL, "fixed_offset"), "set_fixed_offset", "get_fixed_offset");
ClassDB::bind_method(D_METHOD("get_rnd_offset"), &MMColorTiler::get_rnd_offset);
ClassDB::bind_method(D_METHOD("set_rnd_offset", "value"), &MMColorTiler::set_rnd_offset);
ADD_PROPERTY(PropertyInfo(Variant::REAL, "rnd_offset"), "set_rnd_offset", "get_rnd_offset");
ClassDB::bind_method(D_METHOD("get_rnd_rotate"), &MMColorTiler::get_rnd_rotate);
ClassDB::bind_method(D_METHOD("set_rnd_rotate", "value"), &MMColorTiler::set_rnd_rotate);
ADD_PROPERTY(PropertyInfo(Variant::REAL, "rnd_rotate"), "set_rnd_rotate", "get_rnd_rotate");
ClassDB::bind_method(D_METHOD("get_rnd_scale"), &MMColorTiler::get_rnd_scale);
ClassDB::bind_method(D_METHOD("set_rnd_scale", "value"), &MMColorTiler::set_rnd_scale);
ADD_PROPERTY(PropertyInfo(Variant::REAL, "rnd_scale"), "set_rnd_scale", "get_rnd_scale");
ClassDB::bind_method(D_METHOD("get_rnd_opacity"), &MMColorTiler::get_rnd_opacity);
ClassDB::bind_method(D_METHOD("set_rnd_opacity", "value"), &MMColorTiler::set_rnd_opacity);
ADD_PROPERTY(PropertyInfo(Variant::REAL, "rnd_opacity"), "set_rnd_opacity", "get_rnd_opacity");
ClassDB::bind_method(D_METHOD("get_variations"), &MMColorTiler::get_variations);
ClassDB::bind_method(D_METHOD("set_variations", "value"), &MMColorTiler::set_variations);
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "variations"), "set_variations", "get_variations");
ClassDB::bind_method(D_METHOD("tiler_calc", "uv", "tile", "overlap", "_seed"), &MMColorTiler::tiler_calc);
}
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<Resource>"), "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<Resource>"), "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<Resource>"), "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<Resource>"), "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);
}

View File

@ -1,175 +1,84 @@
#ifndef COLOR_TILER_H
#define COLOR_TILER_H
#ifndef MM_COLOR_TILER_H
#define MM_COLOR_TILER_H
#include "../mm_node.h"
#include "../mm_node_universal_property.h"
class ColorTiler : public MMNode {
GDCLASS(ColorTiler, MMNode);
class MMColorTiler : public MMNode {
GDCLASS(MMColorTiler, MMNode);
public:
public:
Ref<MMNodeUniversalProperty> get_input();
void set_input(const Ref<MMNodeUniversalProperty> &val);
Ref<Resource> get_input();
void set_input(const Ref<Resource> &val);
Ref<MMNodeUniversalProperty> get_in_mask();
void set_in_mask(const Ref<MMNodeUniversalProperty> &val);
Ref<Resource> get_in_mask();
void set_in_mask(const Ref<Resource> &val);
Ref<MMNodeUniversalProperty> get_output();
void set_output(const Ref<MMNodeUniversalProperty> &val);
Ref<Resource> get_output();
void set_output(const Ref<Resource> &val);
Ref<MMNodeUniversalProperty> get_instance_map();
void set_instance_map(const Ref<MMNodeUniversalProperty> &val);
Ref<Resource> get_instance_map();
void set_instance_map(const Ref<Resource> &val);
Vector2 get_tile();
void set_tile(const Vector2 &val);
Vector2 get_tile();
void set_tile(const Vector2 &val);
float get_overlap() const;
void set_overlap(const float val);
float get_overlap() const;
void set_overlap(const float val);
int get_select_inputs() const;
void set_select_inputs(const int val);
int get_select_inputs() const;
void set_select_inputs(const int val);
Vector2 get_scale();
void set_scale(const Vector2 &val);
Vector2 get_scale();
void set_scale(const Vector2 &val);
float get_fixed_offset() const;
void set_fixed_offset(const float 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_offset() const;
void set_rnd_offset(const float val);
float get_rnd_rotate() const;
void set_rnd_rotate(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_scale() const;
void set_rnd_scale(const float val);
float get_rnd_opacity() const;
void set_rnd_opacity(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);
bool get_variations() const;
void set_variations(const bool val);
void _init_properties();
void _register_methods(MMGraphNode *mm_graph_node);
void _render(const Ref<MMMaterial> &material);
Color _get_value_for(const Vector2 &uv, const int pseed);
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);
PoolColorArray tiler_calc(const Vector2 &uv, const Vector2 &tile, const int overlap, const Vector2 &_seed);
ColorTiler();
~ColorTiler();
MMColorTiler();
~MMColorTiler();
protected:
static void _bind_methods();
protected:
static void _bind_methods();
//tool
//export(Resource)
Ref<Resource> input;
//export(Resource)
Ref<Resource> in_mask;
//export(Resource)
Ref<Resource> output;
//export(Resource)
Ref<Resource> 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));"
Ref<MMNodeUniversalProperty> input;
Ref<MMNodeUniversalProperty> in_mask;
Ref<MMNodeUniversalProperty> output;
Ref<MMNodeUniversalProperty> instance_map;
Vector2 tile = Vector2(4, 4);
float overlap = 1;
//export(int, "1,4,16")
int select_inputs = 0;
Vector2 scale = Vector2(0.5, 0.5);
float fixed_offset = 0;
float rnd_offset = 0.25;
float rnd_rotate = 45;
float rnd_scale = 0.2;
float rnd_opacity = 0;
bool variations = false;
};
#endif

View File

@ -1,165 +1,105 @@
#include "kaleidoscope.h"
#include "../../algos/mm_algos.h"
#include "../../editor/mm_graph_node.h"
#include "../mm_material.h"
Ref<Resource> Kaleidoscope::get_image() {
return image;
Ref<MMNodeUniversalProperty> MMKaleidoscope::get_image() {
return image;
}
void Kaleidoscope::set_image(const Ref<Resource> &val) {
image = val;
void MMKaleidoscope::set_image(const Ref<MMNodeUniversalProperty> &val) {
image = val;
}
Ref<Resource> Kaleidoscope::get_input() {
return input;
Ref<MMNodeUniversalProperty> MMKaleidoscope::get_input() {
return input;
}
void Kaleidoscope::set_input(const Ref<Resource> &val) {
input = val;
void MMKaleidoscope::set_input(const Ref<MMNodeUniversalProperty> &val) {
input = val;
}
int Kaleidoscope::get_count() const {
return count;
int MMKaleidoscope::get_count() const {
return count;
}
void Kaleidoscope::set_count(const int val) {
count = val;
void MMKaleidoscope::set_count(const int val) {
count = val;
set_dirty(true);
}
float Kaleidoscope::get_offset() const {
return offset;
float MMKaleidoscope::get_offset() const {
return offset;
}
void Kaleidoscope::set_offset(const float val) {
offset = val;
void MMKaleidoscope::set_offset(const float val) {
offset = val;
set_dirty(true);
}
void MMKaleidoscope::_init_properties() {
if (!input.is_valid()) {
input.instance();
input->set_default_type(MMNodeUniversalProperty::DEFAULT_TYPE_COLOR);
input->set_default_value(Color(0, 0, 0, 1));
}
input->set_input_slot_type(MMNodeUniversalProperty::SLOT_TYPE_UNIVERSAL);
input->set_slot_name(">>> Input ");
//tool;
//export(Resource) ;
Ref<Resource> image;
//export(Resource) ;
Ref<Resource> input;
//export(int) ;
int count = 5;
//export(float) ;
float offset = 0;
if (!image.is_valid()) {
image.instance();
image->set_default_type(MMNodeUniversalProperty::DEFAULT_TYPE_IMAGE);
}
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));
//image.input_slot_type = MMNodeUniversalProperty.SLOT_TYPE_FLOAT;
image->set_output_slot_type(MMNodeUniversalProperty::SLOT_TYPE_IMAGE);
//image.force_override = true;
register_input_property(input);
register_output_property(image);
}
input.input_slot_type = MMNodeUniversalProperty.SLOT_TYPE_UNIVERSAL;
input.slot_name = ">>> Input ";
if (!image) {
image = MMNodeUniversalProperty.new();
image.default_type = MMNodeUniversalProperty.DEFAULT_TYPE_IMAGE;
void MMKaleidoscope::_register_methods(MMGraphNode *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);
}
//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 MMKaleidoscope::_render(const Ref<MMMaterial> &material) {
Ref<Image> img = render_image(material);
image->set_value(img);
}
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);
Color MMKaleidoscope::_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));
}
void Kaleidoscope::_render(const Variant &material) {
Ref<Image> img = render_image(material);
image.set_value(img);
MMKaleidoscope::MMKaleidoscope() {
count = 5;
offset = 0;
}
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));
MMKaleidoscope::~MMKaleidoscope() {
}
//count;
void MMKaleidoscope::_bind_methods() {
ClassDB::bind_method(D_METHOD("get_image"), &MMKaleidoscope::get_image);
ClassDB::bind_method(D_METHOD("set_image", "value"), &MMKaleidoscope::set_image);
ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "image", PROPERTY_HINT_RESOURCE_TYPE, "Ref<MMNodeUniversalProperty>"), "set_image", "get_image");
int Kaleidoscope::get_count() {
return count;
ClassDB::bind_method(D_METHOD("get_input"), &MMKaleidoscope::get_input);
ClassDB::bind_method(D_METHOD("set_input", "value"), &MMKaleidoscope::set_input);
ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "input", PROPERTY_HINT_RESOURCE_TYPE, "Ref<MMNodeUniversalProperty>"), "set_input", "get_input");
ClassDB::bind_method(D_METHOD("get_count"), &MMKaleidoscope::get_count);
ClassDB::bind_method(D_METHOD("set_count", "value"), &MMKaleidoscope::set_count);
ADD_PROPERTY(PropertyInfo(Variant::INT, "count"), "set_count", "get_count");
ClassDB::bind_method(D_METHOD("get_offset"), &MMKaleidoscope::get_offset);
ClassDB::bind_method(D_METHOD("set_offset", "value"), &MMKaleidoscope::set_offset);
ADD_PROPERTY(PropertyInfo(Variant::REAL, "offset"), "set_offset", "get_offset");
}
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<Resource>"), "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<Resource>"), "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);
}

View File

@ -1,51 +1,47 @@
#ifndef KALEIDOSCOPE_H
#define KALEIDOSCOPE_H
#ifndef MM_KALEIDOSCOPE_H
#define MM_KALEIDOSCOPE_H
#include "../mm_node.h"
#include "../mm_node_universal_property.h"
class Kaleidoscope : public MMNode {
GDCLASS(Kaleidoscope, MMNode);
class MMKaleidoscope : public MMNode {
GDCLASS(MMKaleidoscope, MMNode);
public:
public:
Ref<MMNodeUniversalProperty> get_image();
void set_image(const Ref<MMNodeUniversalProperty> &val);
Ref<Resource> get_image();
void set_image(const Ref<Resource> &val);
Ref<MMNodeUniversalProperty> get_input();
void set_input(const Ref<MMNodeUniversalProperty> &val);
Ref<Resource> get_input();
void set_input(const Ref<Resource> &val);
int get_count() const;
void set_count(const int val);
int get_count() const;
void set_count(const int val);
float get_offset() const;
void set_offset(const float val);
float get_offset() const;
void set_offset(const float val);
void _init_properties();
void _register_methods(MMGraphNode *mm_graph_node);
void _render(const Ref<MMMaterial> &material);
Color _get_value_for(const Vector2 &uv, const int pseed);
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);
MMKaleidoscope();
~MMKaleidoscope();
Kaleidoscope();
~Kaleidoscope();
protected:
static void _bind_methods();
protected:
static void _bind_methods();
//tool
//export(Resource)
Ref<Resource> image;
//export(Resource)
Ref<Resource> input;
//export(int)
int count = 5;
//export(float)
float offset = 0;
//count
//offset
//tool
//export(MMNodeUniversalProperty)
Ref<MMNodeUniversalProperty> image;
//export(MMNodeUniversalProperty)
Ref<MMNodeUniversalProperty> input;
//export(int)
int count = 5;
//export(float)
float offset = 0;
//count
//offset
};
#endif

View File

@ -45,6 +45,9 @@ SOFTWARE.
#include "nodes/uniform/greyscale_uniform.h"
#include "nodes/uniform/uniform.h"
#include "nodes/transform/circle_map.h"
#include "nodes/transform/color_tiler.h"
#include "nodes/transform/kaleidoscope.h"
#include "nodes/transform/mirror.h"
#include "nodes/transform/repeat.h"
#include "nodes/transform/rotate.h"
@ -91,6 +94,12 @@ void register_material_maker_types() {
MMAlgos::register_node_class("Transform", "MMRepeat");
ClassDB::register_class<MMMirror>();
MMAlgos::register_node_class("Transform", "MMMirror");
ClassDB::register_class<MMKaleidoscope>();
MMAlgos::register_node_class("Transform", "MMKaleidoscope");
ClassDB::register_class<MMColorTiler>();
MMAlgos::register_node_class("Transform", "MMColorTiler");
ClassDB::register_class<MMCircleMap>();
MMAlgos::register_node_class("Transform", "MMCircleMap");
_mm_algos_singleton = memnew(_MMAlgos);
Engine::get_singleton()->add_singleton(Engine::Singleton("MMAlgos", _MMAlgos::get_singleton()));