broken_seals/game/addons/mat_maker_gd/nodes/noise/value.gd

63 lines
1.7 KiB
GDScript3
Raw Normal View History

tool
extends MMNode
var NoisePerlin = preload("res://addons/mat_maker_gd/nodes/common/noise_perlin.gd")
2021-10-01 23:07:05 +02:00
2021-10-19 12:13:15 +02:00
export(Resource) var image : Resource
export(Vector2) var scale : Vector2 = Vector2(4, 4)
export(int) var iterations : int = 3
export(float) var persistence : float = 0.5
2021-10-19 12:13:15 +02:00
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:
2021-10-19 12:13:15 +02:00
mm_graph_node.add_slot_texture_universal(image)
mm_graph_node.add_slot_vector2("get_scale", "set_scale", "Scale")#, Vector2(1, 10))
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)#, Vector2(0, 1))
func get_value_for(uv : Vector2, pseed : int) -> Color:
var ps : float = 1.0 / float(pseed)
#perlin($(uv), vec2($(scale_x), $(scale_y)), int($(iterations)), $(persistence), $(seed))
2021-10-19 12:21:56 +02:00
var f : float = NoisePerlin.perlin(uv, scale, iterations, persistence, ps)
2021-10-19 12:13:15 +02:00
return Color(f, f, f, 1)
func _render(material) -> void:
var img : Image = render_image(material)
image.set_value(img)
func get_scale() -> Vector2:
return scale
func set_scale(val : Vector2) -> void:
scale = val
set_dirty(true)
2021-10-04 14:58:15 +02:00
func get_iterations() -> int:
return iterations
func set_iterations(val : int) -> void:
iterations = val
2021-10-19 12:13:15 +02:00
set_dirty(true)
2021-10-04 14:58:15 +02:00
func get_persistence() -> float:
return persistence
func set_persistence(val : float) -> void:
persistence = val
2021-10-19 12:13:15 +02:00
set_dirty(true)