From 7ef34acfbff2a9a5b7e65a1be87517590b739670 Mon Sep 17 00:00:00 2001 From: Relintai Date: Tue, 19 Oct 2021 12:44:02 +0200 Subject: [PATCH] Color noise node. --- .../mat_maker_gd/nodes/common/commons.gd | 18 ------- .../mat_maker_gd/nodes/common/noises.gd | 22 ++++++++ .../mat_maker_gd/nodes/noise/color_noise.gd | 52 +++++++++++++++++++ 3 files changed, 74 insertions(+), 18 deletions(-) create mode 100644 game/addons/mat_maker_gd/nodes/noise/color_noise.gd diff --git a/game/addons/mat_maker_gd/nodes/common/commons.gd b/game/addons/mat_maker_gd/nodes/common/commons.gd index add0fefe..b39e02bf 100644 --- a/game/addons/mat_maker_gd/nodes/common/commons.gd +++ b/game/addons/mat_maker_gd/nodes/common/commons.gd @@ -351,21 +351,3 @@ static func ThickLine(uv : Vector2, posA : Vector2, posB : Vector2, radiusInv : var finalGray : float = clamp(1.0 - d1 * radiusInv, 0.0, 1.0); return finalGray; - -#vec3 color_dots(vec2 uv, float size, float seed) { -# vec2 seed2 = rand2(vec2(seed, 1.0-seed)); -# uv /= size; -# vec2 point_pos = floor(uv)+vec2(0.5); -# return rand3(seed2+point_pos); -#} - -static func color_dots(uv : Vector2, size : float, pseed : int) -> Vector3: - var seed2 : Vector2 = rand2(Vector2(float(pseed), 1.0 - float(pseed))); - uv /= size; - var point_pos : Vector2 = floorv2(uv) + Vector2(0.5, 0.5); - return rand3(seed2 + point_pos); - -static func noise_color(uv : Vector2, pseed : int) -> Color: - var v : Vector3 = color_dots(((uv)), 1.0/512.000000000, pseed); - - return Color(v.x, v.y, v.z, 1) diff --git a/game/addons/mat_maker_gd/nodes/common/noises.gd b/game/addons/mat_maker_gd/nodes/common/noises.gd index b6c000dc..60acf8ac 100644 --- a/game/addons/mat_maker_gd/nodes/common/noises.gd +++ b/game/addons/mat_maker_gd/nodes/common/noises.gd @@ -123,3 +123,25 @@ static func dots(uv : Vector2, size : float, density : float, pseed : float) -> # # return mix(linear, smoothed, interpolation);\n #} + +#vec3 color_dots(vec2 uv, float size, float seed) { +# vec2 seed2 = rand2(vec2(seed, 1.0-seed)); +# uv /= size; +# vec2 point_pos = floor(uv)+vec2(0.5); +# return rand3(seed2+point_pos); +#} + +static func color_dots(uv : Vector2, size : float, pseed : float) -> Vector3: + var seed2 : Vector2 = Commons.rand2(Vector2(pseed, 1.0 - pseed)) + + uv /= size + + var point_pos : Vector2 = Commons.floorv2(uv) + Vector2(0.5, 0.5) + + return Commons.rand3(seed2 + point_pos) + +static func noise_color(uv : Vector2, size : float, pseed : float) -> Color: + var v : Vector3 = color_dots(uv, 1.0 / size, pseed) + + return Color(v.x, v.y, v.z, 1) + diff --git a/game/addons/mat_maker_gd/nodes/noise/color_noise.gd b/game/addons/mat_maker_gd/nodes/noise/color_noise.gd new file mode 100644 index 00000000..d5dbdee3 --- /dev/null +++ b/game/addons/mat_maker_gd/nodes/noise/color_noise.gd @@ -0,0 +1,52 @@ +tool +extends MMNode + +var Noises = preload("res://addons/mat_maker_gd/nodes/common/noises.gd") + +export(Resource) var image : Resource + +export(int) var size : int = 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 + + +func _init_properties(): + if !image: + image = MMNodeUniversalProperty.new() + image.default_type = MMNodeUniversalProperty.MMNodeUniversalPropertyDefaultType.DEFAULT_TYPE_IMAGE + + image.output_slot_type = MMNodeUniversalProperty.SlotTypes.SLOT_TYPE_IMAGE + + register_output_property(image) + +func _register_methods(mm_graph_node) -> void: + mm_graph_node.add_slot_texture_universal(image) + mm_graph_node.add_slot_int("get_size", "set_size", "Size")#, Vector2(1, 10)) + +func get_value_for(uv : Vector2, pseed : int) -> Color: + var ps : float = 1.0 / float(pseed) + + #color_dots($(uv), 1.0/$(size), $(seed)) + return Noises.noise_color(uv, float(size), ps) + +func _render(material) -> void: + var img : Image = render_image(material) + + image.set_value(img) + +func get_size() -> int: + return size + +func set_size(val : int) -> void: + size = val + + set_dirty(true)