mirror of
https://github.com/Relintai/broken_seals.git
synced 2024-11-13 20:47:19 +01:00
Noise node.
This commit is contained in:
parent
dade6413b3
commit
0cd3f2d8db
@ -30,15 +30,6 @@ const Commons = preload("res://addons/mat_maker_gd/nodes/common/commons.gd")
|
||||
#grid_size, float, default: 4, min: 2, max: 12, step: 1
|
||||
#density, float, default: 0.5, min: 0, max: 1, step: 0.01
|
||||
|
||||
|
||||
#float dots(vec2 uv, float size, float density, float seed) {
|
||||
# vec2 seed2 = rand2(vec2(seed, 1.0-seed));
|
||||
# uv /= size;
|
||||
# vec2 point_pos = floor(uv)+vec2(0.5);
|
||||
# float color = step(rand(seed2+point_pos), density);
|
||||
# return color;
|
||||
#}
|
||||
|
||||
#----------------------
|
||||
#noise_anisotropic.mmg
|
||||
#Generates x-axis interpolated value noise
|
||||
@ -102,9 +93,20 @@ const Commons = preload("res://addons/mat_maker_gd/nodes/common/commons.gd")
|
||||
# }
|
||||
# ],
|
||||
|
||||
static func dots(uv : Vector2, size : float, density : float, pseed : float) -> float:
|
||||
return 0.0
|
||||
#float dots(vec2 uv, float size, float density, float seed) {
|
||||
# vec2 seed2 = rand2(vec2(seed, 1.0-seed));
|
||||
# uv /= size;
|
||||
# vec2 point_pos = floor(uv)+vec2(0.5);
|
||||
# float color = step(rand(seed2+point_pos), density);
|
||||
# return color;
|
||||
#}
|
||||
|
||||
static func dots(uv : Vector2, size : float, density : float, pseed : float) -> float:
|
||||
var seed2 : Vector2 = Commons.rand2(Vector2(pseed, 1.0 - pseed))
|
||||
uv /= size
|
||||
var point_pos : Vector2 = Commons.floorv2(uv) + Vector2(0.5, 0.5)
|
||||
var color : float = Commons.step(Commons.rand2(seed2 + point_pos).x, density);
|
||||
return color
|
||||
|
||||
#float anisotropic(vec2 uv, vec2 size, float seed, float smoothness, float interpolation) {\n\
|
||||
# tvec2 seed2 = rand2(vec2(seed, 1.0-seed));\n\t\n\t
|
||||
|
52
game/addons/mat_maker_gd/nodes/noise/noise.gd
Normal file
52
game/addons/mat_maker_gd/nodes/noise/noise.gd
Normal file
@ -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 grid_size : int = 16
|
||||
export(float) var density : float = 0.5
|
||||
|
||||
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_grid_size", "set_grid_size", "Grid Size")#, Vector2(1, 10))
|
||||
mm_graph_node.add_slot_float("get_density", "set_density", "Density", 0.01)#, Vector2(0, 1))
|
||||
|
||||
func get_value_for(uv : Vector2, pseed : int) -> Color:
|
||||
var ps : float = 1.0 / float(pseed)
|
||||
|
||||
#return dots(uv, 1.0/$(size), $(density), $(seed));
|
||||
var f : float = Noises.dots(uv, 1.0 / float(grid_size), density, ps)
|
||||
|
||||
return Color(f, f, f, 1)
|
||||
|
||||
func _render(material) -> void:
|
||||
var img : Image = render_image(material)
|
||||
|
||||
image.set_value(img)
|
||||
|
||||
func get_grid_size() -> int:
|
||||
return grid_size
|
||||
|
||||
func set_grid_size(val : int) -> void:
|
||||
grid_size = val
|
||||
|
||||
set_dirty(true)
|
||||
|
||||
func get_density() -> float:
|
||||
return density
|
||||
|
||||
func set_density(val : float) -> void:
|
||||
density = val
|
||||
|
||||
set_dirty(true)
|
Loading…
Reference in New Issue
Block a user