Value node.

This commit is contained in:
Relintai 2021-10-19 12:13:15 +02:00
parent 0cd3f2d8db
commit 98ade190f9
2 changed files with 77 additions and 23 deletions

View File

@ -1,6 +1,8 @@
[gd_resource type="Resource" load_steps=42 format=2]
[gd_resource type="Resource" load_steps=48 format=2]
[ext_resource path="res://addons/mat_maker_gd/nodes/mm_material.gd" type="Script" id=1]
[ext_resource path="res://addons/mat_maker_gd/nodes/noise/noise.gd" type="Script" id=2]
[ext_resource path="res://addons/mat_maker_gd/nodes/noise/value.gd" type="Script" id=3]
[ext_resource path="res://addons/mat_maker_gd/nodes/simple/shape.gd" type="Script" id=4]
[ext_resource path="res://addons/mat_maker_gd/nodes/mm_node_universal_property.gd" type="Script" id=5]
[ext_resource path="res://addons/mat_maker_gd/nodes/other/output_image.gd" type="Script" id=6]
@ -47,7 +49,7 @@ sides = 11
radius = SubResource( 4 )
edge = SubResource( 3 )
[sub_resource type="Resource" id=40]
[sub_resource type="Resource" id=43]
script = ExtResource( 5 )
default_type = 5
default_int = 0
@ -59,7 +61,7 @@ default_color = Color( 0, 0, 0, 1 )
[sub_resource type="Resource" id=6]
script = ExtResource( 6 )
graph_position = Vector2( 300, -400 )
image = SubResource( 40 )
image = SubResource( 43 )
postfix = "-test"
[sub_resource type="Resource" id=9]
@ -288,7 +290,40 @@ bevel = SubResource( 29 )
roundness = SubResource( 38 )
corner = 0.3
[sub_resource type="Resource" id=41]
script = ExtResource( 5 )
default_type = 5
default_int = 0
default_float = 0.0
default_vector2 = Vector2( 0, 0 )
default_vector3 = Vector3( 0, 0, 0 )
default_color = Color( 0, 0, 0, 1 )
[sub_resource type="Resource" id=42]
script = ExtResource( 2 )
graph_position = Vector2( 380, -220 )
image = SubResource( 41 )
grid_size = 64
density = 0.3
[sub_resource type="Resource" id=44]
script = ExtResource( 5 )
default_type = 5
default_int = 0
default_float = 0.0
default_vector2 = Vector2( 0, 0 )
default_vector3 = Vector3( 0, 0, 0 )
default_color = Color( 0, 0, 0, 1 )
[sub_resource type="Resource" id=45]
script = ExtResource( 3 )
graph_position = Vector2( 580, -220 )
image = SubResource( 44 )
scale = Vector2( 4.4, 4.2 )
iterations = 3
persistence = 0.5
[resource]
script = ExtResource( 1 )
image_size = Vector2( 128, 128 )
nodes = [ SubResource( 5 ), SubResource( 6 ), SubResource( 12 ), SubResource( 15 ), SubResource( 18 ), SubResource( 21 ), SubResource( 24 ), SubResource( 27 ), SubResource( 39 ) ]
nodes = [ SubResource( 5 ), SubResource( 6 ), SubResource( 12 ), SubResource( 15 ), SubResource( 18 ), SubResource( 21 ), SubResource( 24 ), SubResource( 27 ), SubResource( 39 ), SubResource( 42 ), SubResource( 45 ) ]

View File

@ -3,36 +3,39 @@ extends MMNode
var NoisePerlin = preload("res://addons/mat_maker_gd/nodes/common/noise_perlin.gd")
var image : Image
var tex : ImageTexture
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
func get_value_for(uv : Vector2, pseed : int) -> Color:
return NoisePerlin.perlinc(uv, scale, iterations, persistence, pseed)
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_int("get_iterations", "set_iterations", "iterations")#, Vector2(1, 10))
mm_graph_node.add_slot_float("get_persistence", "set_persistence", "persistence", 0.05)#, Vector2(0, 1))
mm_graph_node.add_slot_vector2("get_scale", "set_scale", "scale", 1)#, Vector2(1, 32))
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_iterations() -> int:
return iterations
func get_value_for(uv : Vector2, pseed : int) -> Color:
var ps : float = 1.0 / float(pseed)
func set_iterations(val : int) -> void:
iterations = val
#perlin($(uv), vec2($(scale_x), $(scale_y)), int($(iterations)), $(persistence), $(seed))
var f : float = NoisePerlin.perlin(uv, scale, iterations, persistence, pseed)
emit_changed()
return Color(f, f, f, 1)
func get_persistence() -> float:
return persistence
func _render(material) -> void:
var img : Image = render_image(material)
func set_persistence(val : float) -> void:
persistence = val
emit_changed()
image.set_value(img)
func get_scale() -> Vector2:
return scale
@ -40,4 +43,20 @@ func get_scale() -> Vector2:
func set_scale(val : Vector2) -> void:
scale = val
emit_changed()
set_dirty(true)
func get_iterations() -> int:
return iterations
func set_iterations(val : int) -> void:
iterations = val
set_dirty(true)
func get_persistence() -> float:
return persistence
func set_persistence(val : float) -> void:
persistence = val
set_dirty(true)