diff --git a/addons/procedural_material/node_base.gd b/addons/procedural_material/node_base.gd index 26dc502..0a456d9 100644 --- a/addons/procedural_material/node_base.gd +++ b/addons/procedural_material/node_base.gd @@ -7,7 +7,7 @@ var generated_variants = [] var property_widgets = [] func _ready(): - print("ready: "+name) + pass func initialize_properties(object_list): property_widgets = object_list @@ -41,6 +41,16 @@ func get_source(index = 0): return c return null +func get_source_f(source): + var rv + if source.has("rgb"): + rv = source.rgb+".r" + elif source.has("f"): + rv = source.f + else: + rv = "***error***" + return rv + func get_source_rgb(source): var rv if source.has("rgb"): @@ -71,14 +81,16 @@ func serialize(): type = type.right(type.find_last("/")+1) type = type.left(type.find_last(".")) var data = { name=name, type=type, node_position={x=offset.x, y=offset.y} } - for v in _get_state_variables(): + for w in property_widgets: + var v = w.name data[v] = serialize_element(get(v)) return data func deserialize(data): print("deserialize: "+name) offset = Vector2(data.node_position.x, data.node_position.y) - for v in _get_state_variables(): + for w in property_widgets: + var v = w.name set(v, deserialize_element(data[v])) print(" "+v+" = "+str(deserialize_element(data[v]))) update_property_widgets() diff --git a/addons/procedural_material/blend.gd b/addons/procedural_material/nodes/blend.gd similarity index 71% rename from addons/procedural_material/blend.gd rename to addons/procedural_material/nodes/blend.gd index dbdc3a9..e938928 100644 --- a/addons/procedural_material/blend.gd +++ b/addons/procedural_material/nodes/blend.gd @@ -13,7 +13,7 @@ func color_to_string(c): return "vec3("+str(c.r)+","+str(c.g)+","+str(c.b)+")" func get_shader_code(uv): - var rv = { defs="", code="", uv=null, rgb=null, f=null } + var rv = { defs="", code="" } var src0 = get_source(0) var src1 = get_source(1) var src2 = get_source(2) @@ -26,12 +26,15 @@ func get_shader_code(uv): if src2 != null: src2_code = src2.get_shader_code(uv) amount_str = str(src2_code.f) - if !generated: + if generated_variants.empty(): rv.defs = src0_code.defs+src1_code.defs+src2_code.defs + var variant_index = generated_variants.find(uv) + if variant_index == -1: + variant_index = generated_variants.size() + generated_variants.append(uv) rv.code = src0_code.code+src1_code.code+src2_code.code - rv.code += "vec3 "+name+"_rgb = mix("+get_source_rgb(src0_code)+", "+get_source_rgb(src1_code)+", "+amount_str+");\n" - generated = true - rv.rgb = name+"_rgb" + rv.code += "vec3 "+name+"_"+str(variant_index)+"_rgb = mix("+get_source_rgb(src0_code)+", "+get_source_rgb(src1_code)+", "+amount_str+");\n" + rv.rgb = name+"_"+str(variant_index)+"_rgb" return rv func _get_state_variables(): diff --git a/addons/procedural_material/blend.tscn b/addons/procedural_material/nodes/blend.tscn similarity index 83% rename from addons/procedural_material/blend.tscn rename to addons/procedural_material/nodes/blend.tscn index f763828..449773b 100644 --- a/addons/procedural_material/blend.tscn +++ b/addons/procedural_material/nodes/blend.tscn @@ -1,6 +1,6 @@ [gd_scene load_steps=3 format=2] -[ext_resource path="res://addons/procedural_material/blend.gd" type="Script" id=1] +[ext_resource path="res://addons/procedural_material/nodes/blend.gd" type="Script" id=1] [sub_resource type="Theme" id=1] @@ -11,10 +11,10 @@ anchor_left = 0.0 anchor_top = 0.0 anchor_right = 0.0 anchor_bottom = 0.0 -margin_left = 618.0 -margin_top = 148.0 -margin_right = 751.0 -margin_bottom = 310.0 +margin_left = 3.0 +margin_top = 4.0 +margin_right = 93.0 +margin_bottom = 87.0 rect_pivot_offset = Vector2( 0, 0 ) rect_clip_content = false mouse_filter = 1 @@ -35,18 +35,18 @@ slot/0/left_color = Color( 0.5, 0.5, 1, 1 ) slot/0/right_enabled = true slot/0/right_type = 0 slot/0/right_color = Color( 0.5, 0.5, 1, 1 ) -slot/1/left_enabled = false +slot/1/left_enabled = true slot/1/left_type = 0 -slot/1/left_color = Color( 1, 1, 1, 1 ) +slot/1/left_color = Color( 0.5, 0.5, 1, 1 ) slot/1/right_enabled = false slot/1/right_type = 0 -slot/1/right_color = Color( 1, 1, 1, 1 ) -slot/2/left_enabled = false +slot/1/right_color = Color( 0.5, 0.5, 1, 1 ) +slot/2/left_enabled = true slot/2/left_type = 0 -slot/2/left_color = Color( 1, 1, 1, 1 ) +slot/2/left_color = Color( 0.5, 0.5, 1, 1 ) slot/2/right_enabled = false slot/2/right_type = 0 -slot/2/right_color = Color( 1, 1, 1, 1 ) +slot/2/right_color = Color( 0.5, 0.5, 1, 1 ) script = ExtResource( 1 ) _sections_unfolded = [ "Theme" ] @@ -58,7 +58,7 @@ anchor_right = 0.0 anchor_bottom = 0.0 margin_left = 16.0 margin_top = 24.0 -margin_right = 117.0 +margin_right = 74.0 margin_bottom = 38.0 rect_pivot_offset = Vector2( 0, 0 ) rect_clip_content = false @@ -79,7 +79,7 @@ anchor_right = 0.0 anchor_bottom = 0.0 margin_left = 16.0 margin_top = 38.0 -margin_right = 117.0 +margin_right = 74.0 margin_bottom = 52.0 rect_pivot_offset = Vector2( 0, 0 ) rect_clip_content = false @@ -100,7 +100,7 @@ anchor_right = 0.0 anchor_bottom = 0.0 margin_left = 16.0 margin_top = 53.0 -margin_right = 117.0 +margin_right = 74.0 margin_bottom = 77.0 rect_pivot_offset = Vector2( 0, 0 ) rect_clip_content = false diff --git a/addons/procedural_material/bricks.gd b/addons/procedural_material/nodes/bricks.gd similarity index 100% rename from addons/procedural_material/bricks.gd rename to addons/procedural_material/nodes/bricks.gd diff --git a/addons/procedural_material/bricks.tscn b/addons/procedural_material/nodes/bricks.tscn similarity index 98% rename from addons/procedural_material/bricks.tscn rename to addons/procedural_material/nodes/bricks.tscn index 9bc1cf9..32f676e 100644 --- a/addons/procedural_material/bricks.tscn +++ b/addons/procedural_material/nodes/bricks.tscn @@ -1,6 +1,6 @@ [gd_scene load_steps=3 format=2] -[ext_resource path="res://addons/procedural_material/bricks.gd" type="Script" id=1] +[ext_resource path="res://addons/procedural_material/nodes/bricks.gd" type="Script" id=1] [sub_resource type="Theme" id=1] diff --git a/addons/procedural_material/colorize.gd b/addons/procedural_material/nodes/colorize.gd similarity index 56% rename from addons/procedural_material/colorize.gd rename to addons/procedural_material/nodes/colorize.gd index 6076d45..745a1e3 100644 --- a/addons/procedural_material/colorize.gd +++ b/addons/procedural_material/nodes/colorize.gd @@ -12,17 +12,20 @@ func color_to_string(c): return "vec3("+str(c.r)+","+str(c.g)+","+str(c.b)+")" func get_shader_code(uv): - var rv = { defs="", code="", uv=null, rgb=null, f=null } + var rv = { defs="", code="" } var src = get_source() if src == null: return rv var src_code = src.get_shader_code(uv) - if !generated: + if generated_variants.empty(): rv.defs = src_code.defs; - rv.code = src_code.code+"vec3 "+name+"_rgb = mix("+color_to_string(color0)+", "+color_to_string(color1)+", "+src_code.f+");\n" - generated = true + var variant_index = generated_variants.find(uv) + if variant_index == -1: + variant_index = generated_variants.size() + generated_variants.append(uv) + rv.code = src_code.code+"vec3 "+name+"_"+str(variant_index)+"_rgb = mix("+color_to_string(color0)+", "+color_to_string(color1)+", "+src_code.f+");\n" rv.f = src_code.f - rv.rgb = name+"_rgb" + rv.rgb = name+"_"+str(variant_index)+"_rgb" return rv func _get_state_variables(): diff --git a/addons/procedural_material/colorize.tscn b/addons/procedural_material/nodes/colorize.tscn similarity index 91% rename from addons/procedural_material/colorize.tscn rename to addons/procedural_material/nodes/colorize.tscn index 2723f8c..6840415 100644 --- a/addons/procedural_material/colorize.tscn +++ b/addons/procedural_material/nodes/colorize.tscn @@ -1,6 +1,7 @@ [gd_scene load_steps=3 format=2] -[ext_resource path="res://addons/procedural_material/colorize.gd" type="Script" id=1] +[ext_resource path="res://addons/procedural_material/nodes/colorize.gd" type="Script" id=1] + [sub_resource type="Theme" id=1] @@ -11,10 +12,10 @@ anchor_left = 0.0 anchor_top = 0.0 anchor_right = 0.0 anchor_bottom = 0.0 -margin_left = 618.0 -margin_top = 148.0 -margin_right = 751.0 -margin_bottom = 310.0 +margin_left = 1.0 +margin_top = 4.0 +margin_right = 98.0 +margin_bottom = 74.0 rect_pivot_offset = Vector2( 0, 0 ) rect_clip_content = false mouse_filter = 1 @@ -52,7 +53,7 @@ anchor_right = 0.0 anchor_bottom = 0.0 margin_left = 16.0 margin_top = 24.0 -margin_right = 117.0 +margin_right = 81.0 margin_bottom = 44.0 rect_pivot_offset = Vector2( 0, 0 ) rect_clip_content = false @@ -80,7 +81,7 @@ anchor_right = 0.0 anchor_bottom = 0.0 margin_left = 16.0 margin_top = 44.0 -margin_right = 117.0 +margin_right = 81.0 margin_bottom = 64.0 rect_pivot_offset = Vector2( 0, 0 ) rect_clip_content = false diff --git a/addons/procedural_material/iqnoise.gd b/addons/procedural_material/nodes/iqnoise.gd similarity index 59% rename from addons/procedural_material/iqnoise.gd rename to addons/procedural_material/nodes/iqnoise.gd index 3d42df3..0c90ca1 100644 --- a/addons/procedural_material/iqnoise.gd +++ b/addons/procedural_material/nodes/iqnoise.gd @@ -11,8 +11,12 @@ func _ready(): func get_shader_code(uv): var rv = { defs="", code="" } - if !generated: + if generated_variants.empty(): rv.defs = "float "+name+"_f(vec2 uv) { return iqnoise(uv, "+str(subdivide)+", "+str(u)+", "+str(v)+"); }\n" - generated = true - rv.f = name+"_f("+uv+")" + var variant_index = generated_variants.find(uv) + if variant_index == -1: + variant_index = generated_variants.size() + generated_variants.append(uv) + rv.code = "float "+name+"_"+str(variant_index)+"_f = "+name+"_f("+uv+");\n" + rv.f = name+"_"+str(variant_index)+"_f" return rv diff --git a/addons/procedural_material/iqnoise.tscn b/addons/procedural_material/nodes/iqnoise.tscn similarity index 97% rename from addons/procedural_material/iqnoise.tscn rename to addons/procedural_material/nodes/iqnoise.tscn index bc1286c..9fb28dd 100644 --- a/addons/procedural_material/iqnoise.tscn +++ b/addons/procedural_material/nodes/iqnoise.tscn @@ -1,6 +1,7 @@ [gd_scene load_steps=3 format=2] -[ext_resource path="res://addons/procedural_material/iqnoise.gd" type="Script" id=1] +[ext_resource path="res://addons/procedural_material/nodes/iqnoise.gd" type="Script" id=1] + [sub_resource type="Theme" id=1] diff --git a/addons/procedural_material/material.gd b/addons/procedural_material/nodes/material.gd similarity index 92% rename from addons/procedural_material/material.gd rename to addons/procedural_material/nodes/material.gd index efaea42..3e92909 100644 --- a/addons/procedural_material/material.gd +++ b/addons/procedural_material/nodes/material.gd @@ -5,7 +5,7 @@ func _ready(): set_slot(0, true, 0, Color(0.5, 0.5, 1), false, 0, Color(0.5, 0.5, 1)) func get_shader_code(uv): - var rv = { defs="", code="", rgb=null, f=null } + var rv = { defs="", code="" } var src = get_source() if src == null: rv.code += "void fragment() {\n" diff --git a/addons/procedural_material/material.tscn b/addons/procedural_material/nodes/material.tscn similarity index 86% rename from addons/procedural_material/material.tscn rename to addons/procedural_material/nodes/material.tscn index 6b26c55..8fa3c6d 100644 --- a/addons/procedural_material/material.tscn +++ b/addons/procedural_material/nodes/material.tscn @@ -1,6 +1,7 @@ [gd_scene load_steps=3 format=2] -[ext_resource path="res://addons/procedural_material/material.gd" type="Script" id=1] +[ext_resource path="res://addons/procedural_material/nodes/material.gd" type="Script" id=1] + [sub_resource type="Theme" id=1] @@ -11,10 +12,8 @@ anchor_left = 0.0 anchor_top = 0.0 anchor_right = 0.0 anchor_bottom = 0.0 -margin_left = 550.0 -margin_top = 226.0 -margin_right = 683.0 -margin_bottom = 419.0 +margin_right = 84.0 +margin_bottom = 43.0 rect_pivot_offset = Vector2( 0, 0 ) rect_clip_content = false mouse_filter = 1 @@ -46,7 +45,7 @@ anchor_right = 0.0 anchor_bottom = 0.0 margin_left = 16.0 margin_top = 24.0 -margin_right = 117.0 +margin_right = 68.0 margin_bottom = 38.0 rect_pivot_offset = Vector2( 0, 0 ) rect_clip_content = false diff --git a/addons/procedural_material/perlin.gd b/addons/procedural_material/nodes/perlin.gd similarity index 59% rename from addons/procedural_material/perlin.gd rename to addons/procedural_material/nodes/perlin.gd index ed767c8..f619446 100644 --- a/addons/procedural_material/perlin.gd +++ b/addons/procedural_material/nodes/perlin.gd @@ -10,8 +10,12 @@ func _ready(): func get_shader_code(uv): var rv = { defs="", code="" } - if !generated: + if generated_variants.empty(): rv.defs = "float "+name+"_f(vec2 uv) { return perlin(uv, "+str(iterations)+", "+str(turbulence)+"); }\n" - generated = true - rv.f = name+"_f("+uv+")" + var variant_index = generated_variants.find(uv) + if variant_index == -1: + variant_index = generated_variants.size() + generated_variants.append(uv) + rv.code = "float "+name+"_"+str(variant_index)+"_f = "+name+"_f("+uv+");\n" + rv.f = name+"_"+str(variant_index)+"_f" return rv diff --git a/addons/procedural_material/perlin.tscn b/addons/procedural_material/nodes/perlin.tscn similarity index 97% rename from addons/procedural_material/perlin.tscn rename to addons/procedural_material/nodes/perlin.tscn index f5de7a0..188d429 100644 --- a/addons/procedural_material/perlin.tscn +++ b/addons/procedural_material/nodes/perlin.tscn @@ -1,6 +1,7 @@ [gd_scene load_steps=3 format=2] -[ext_resource path="res://addons/procedural_material/perlin.gd" type="Script" id=1] +[ext_resource path="res://addons/procedural_material/nodes/perlin.gd" type="Script" id=1] + [sub_resource type="Theme" id=1] diff --git a/addons/procedural_material/nodes/sine.gd b/addons/procedural_material/nodes/sine.gd new file mode 100644 index 0000000..6516344 --- /dev/null +++ b/addons/procedural_material/nodes/sine.gd @@ -0,0 +1,21 @@ +tool +extends "res://addons/procedural_material/node_base.gd" + +var waves = 1.0 +var sharpness = 1.0 + +func _ready(): + set_slot(0, false, 0, Color(0.5, 0.5, 1), true, 0, Color(0.5, 0.5, 1)) + initialize_properties([ $waves, $sharpness ]) + +func get_shader_code(uv): + var rv = { defs="", code="" } + if generated_variants.empty(): + rv.defs = "float "+name+"_f(vec2 uv) { return sine(uv, "+str(waves)+", "+str(sharpness)+"); }\n" + var variant_index = generated_variants.find(uv) + if variant_index == -1: + variant_index = generated_variants.size() + generated_variants.append(uv) + rv.code = "float "+name+"_"+str(variant_index)+"_f = "+name+"_f("+uv+");\n" + rv.f = name+"_"+str(variant_index)+"_f" + return rv diff --git a/addons/procedural_material/sine.tscn b/addons/procedural_material/nodes/sine.tscn similarity index 89% rename from addons/procedural_material/sine.tscn rename to addons/procedural_material/nodes/sine.tscn index 31621a5..68392f5 100644 --- a/addons/procedural_material/sine.tscn +++ b/addons/procedural_material/nodes/sine.tscn @@ -1,6 +1,6 @@ [gd_scene load_steps=3 format=2] -[ext_resource path="res://addons/procedural_material/sine.gd" type="Script" id=1] +[ext_resource path="res://addons/procedural_material/nodes/sine.gd" type="Script" id=1] [sub_resource type="Theme" id=1] @@ -97,8 +97,4 @@ _sections_unfolded = [ "Caret", "Placeholder" ] [connection signal="close_request" from="." to="." method="queue_free"] -[connection signal="text_changed" from="waves" to="." method="_on_Count_text_changed"] - -[connection signal="text_changed" from="sharpness" to="." method="_on_Sharpness_text_changed"] - diff --git a/addons/procedural_material/transform.gd b/addons/procedural_material/nodes/transform.gd similarity index 91% rename from addons/procedural_material/transform.gd rename to addons/procedural_material/nodes/transform.gd index 6910457..4924d1e 100644 --- a/addons/procedural_material/transform.gd +++ b/addons/procedural_material/nodes/transform.gd @@ -8,7 +8,7 @@ func _ready(): initialize_properties([ $rotate ]) func get_shader_code(uv): - var rv = { defs="", code="", uv=null } + var rv = { defs="", code="" } var src = get_source() if src == null: return rv @@ -16,8 +16,8 @@ func get_shader_code(uv): var src_code = src.get_shader_code(rv.uv) if !generated: rv.defs = src_code.defs+"vec2 "+name+"_uv(vec2 uv) { return rotate(uv, "+str(angle)+"); }\n" - rv.code = src_code.code; generated = true + rv.code = src_code.code; if src_code.has("f"): rv.f = src_code.f if src_code.has("rgb"): diff --git a/addons/procedural_material/transform.tscn b/addons/procedural_material/nodes/transform.tscn similarity index 89% rename from addons/procedural_material/transform.tscn rename to addons/procedural_material/nodes/transform.tscn index 8142a38..3c6cab2 100644 --- a/addons/procedural_material/transform.tscn +++ b/addons/procedural_material/nodes/transform.tscn @@ -1,6 +1,6 @@ [gd_scene load_steps=3 format=2] -[ext_resource path="res://addons/procedural_material/transform.gd" type="Script" id=1] +[ext_resource path="res://addons/procedural_material/nodes/transform.gd" type="Script" id=1] [sub_resource type="Theme" id=1] @@ -11,10 +11,10 @@ anchor_left = 0.0 anchor_top = 0.0 anchor_right = 0.0 anchor_bottom = 0.0 -margin_left = 329.0 -margin_top = 117.0 -margin_right = 462.0 -margin_bottom = 279.0 +margin_left = 1.0 +margin_top = 1.0 +margin_right = 134.0 +margin_bottom = 163.0 rect_pivot_offset = Vector2( 0, 0 ) rect_clip_content = false mouse_filter = 1 diff --git a/addons/procedural_material/nodes/warp.gd b/addons/procedural_material/nodes/warp.gd new file mode 100644 index 0000000..9a6f9e6 --- /dev/null +++ b/addons/procedural_material/nodes/warp.gd @@ -0,0 +1,35 @@ +tool +extends "res://addons/procedural_material/node_base.gd" + +var amount = 0.0 + +func _ready(): + set_slot(0, true, 0, Color(0.5, 0.5, 1), true, 0, Color(0.5, 0.5, 1)) + set_slot(1, true, 0, Color(0.5, 0.5, 1), false, 0, Color(0.5, 0.5, 1)) + initialize_properties([ $amount ]) + +func get_shader_code(uv): + var rv = { defs="", code="" } + var src0 = get_source(0) + var src1 = get_source(1) + if src0 == null || src1 == null: + return rv + var variant_index = generated_variants.find(uv) + if variant_index == -1: + variant_index = generated_variants.size() + generated_variants.append(uv) + var src1_code0 = src1.get_shader_code(uv+"+vec2(0.01, 0.0)") + var src1_code1 = src1.get_shader_code(uv+"-vec2(0.01, 0.0)") + var src1_code2 = src1.get_shader_code(uv+"+vec2(0.0, 0.01)") + var src1_code3 = src1.get_shader_code(uv+"-vec2(0.0, 0.01)") + rv.defs = src1_code0.defs + rv.code = src1_code0.code+src1_code1.code+src1_code2.code+src1_code3.code + rv.code += "vec2 "+name+"_"+str(variant_index)+"_uv = "+uv+"+"+str(amount)+"*vec2("+get_source_f(src1_code0)+"-"+get_source_f(src1_code1)+", "+get_source_f(src1_code2)+"-"+get_source_f(src1_code3)+");\n" + var src0_code = src0.get_shader_code(name+"_"+str(variant_index)+"_uv") + rv.defs += src0_code.defs + rv.code += src0_code.code + rv.code += "vec3 "+name+"_"+str(variant_index)+"_rgb = "+get_source_rgb(src0_code)+";\n" + rv.code += "float "+name+"_"+str(variant_index)+"_f = "+get_source_f(src0_code)+";\n" + rv.rgb = name+"_"+str(variant_index)+"_rgb" + rv.f = name+"_"+str(variant_index)+"_f" + return rv diff --git a/addons/procedural_material/nodes/warp.tscn b/addons/procedural_material/nodes/warp.tscn new file mode 100644 index 0000000..14d3aac --- /dev/null +++ b/addons/procedural_material/nodes/warp.tscn @@ -0,0 +1,125 @@ +[gd_scene load_steps=3 format=2] + +[ext_resource path="res://addons/procedural_material/nodes/warp.gd" type="Script" id=1] + +[sub_resource type="Theme" id=1] + + +[node name="Warp" type="GraphNode" index="0"] + +anchor_left = 0.0 +anchor_top = 0.0 +anchor_right = 0.0 +anchor_bottom = 0.0 +margin_left = 1.0 +margin_top = 1.0 +margin_right = 91.0 +margin_bottom = 84.0 +rect_pivot_offset = Vector2( 0, 0 ) +rect_clip_content = false +mouse_filter = 1 +mouse_default_cursor_shape = 0 +size_flags_horizontal = 1 +size_flags_vertical = 1 +theme = SubResource( 1 ) +title = "Warp" +offset = Vector2( 0, 0 ) +show_close = true +resizable = false +selected = false +comment = false +overlay = 0 +slot/0/left_enabled = true +slot/0/left_type = 0 +slot/0/left_color = Color( 0.5, 0.5, 1, 1 ) +slot/0/right_enabled = true +slot/0/right_type = 0 +slot/0/right_color = Color( 0.5, 0.5, 1, 1 ) +slot/1/left_enabled = true +slot/1/left_type = 0 +slot/1/left_color = Color( 0.5, 0.5, 1, 1 ) +slot/1/right_enabled = false +slot/1/right_type = 0 +slot/1/right_color = Color( 0.5, 0.5, 1, 1 ) +slot/2/left_enabled = false +slot/2/left_type = 0 +slot/2/left_color = Color( 1, 1, 1, 1 ) +slot/2/right_enabled = false +slot/2/right_type = 0 +slot/2/right_color = Color( 1, 1, 1, 1 ) +script = ExtResource( 1 ) +_sections_unfolded = [ "Theme" ] + +[node name="Label1" type="Label" parent="." index="0"] + +anchor_left = 0.0 +anchor_top = 0.0 +anchor_right = 0.0 +anchor_bottom = 0.0 +margin_left = 16.0 +margin_top = 24.0 +margin_right = 74.0 +margin_bottom = 38.0 +rect_pivot_offset = Vector2( 0, 0 ) +rect_clip_content = false +mouse_filter = 2 +mouse_default_cursor_shape = 0 +size_flags_horizontal = 1 +size_flags_vertical = 4 +text = "Source" +percent_visible = 1.0 +lines_skipped = 0 +max_lines_visible = -1 + +[node name="Label2" type="Label" parent="." index="1"] + +anchor_left = 0.0 +anchor_top = 0.0 +anchor_right = 0.0 +anchor_bottom = 0.0 +margin_left = 16.0 +margin_top = 38.0 +margin_right = 74.0 +margin_bottom = 52.0 +rect_pivot_offset = Vector2( 0, 0 ) +rect_clip_content = false +mouse_filter = 2 +mouse_default_cursor_shape = 0 +size_flags_horizontal = 1 +size_flags_vertical = 4 +text = "Displace" +percent_visible = 1.0 +lines_skipped = 0 +max_lines_visible = -1 + +[node name="amount" type="LineEdit" parent="." index="2"] + +anchor_left = 0.0 +anchor_top = 0.0 +anchor_right = 0.0 +anchor_bottom = 0.0 +margin_left = 16.0 +margin_top = 53.0 +margin_right = 74.0 +margin_bottom = 77.0 +rect_pivot_offset = Vector2( 0, 0 ) +rect_clip_content = false +focus_mode = 2 +mouse_filter = 0 +mouse_default_cursor_shape = 1 +size_flags_horizontal = 1 +size_flags_vertical = 1 +text = "0.5" +focus_mode = 2 +context_menu_enabled = true +placeholder_alpha = 0.6 +caret_blink = false +caret_blink_speed = 0.65 +caret_position = 0 +_sections_unfolded = [ "Caret", "Placeholder" ] + +[connection signal="close_request" from="." to="." method="queue_free"] + +[connection signal="text_changed" from="amount" to="." method="_on_Rotate_text_changed"] + + diff --git a/addons/procedural_material/pm_editor.gd b/addons/procedural_material/pm_editor.gd index 716fdf9..d81cf17 100644 --- a/addons/procedural_material/pm_editor.gd +++ b/addons/procedural_material/pm_editor.gd @@ -11,6 +11,7 @@ const MENU = [ { name="iqnoise", description="IQ Noise" }, { name="perlin", description="Perlin noise" }, { name="transform", description="Transform" }, + { name="warp", description="Warp" }, { name="colorize", description="Colorize" }, { name="blend", description="Blend" } ] @@ -30,7 +31,7 @@ func _on_PopupMenu_id_pressed(id): if MENU[id].has("command"): call(MENU[id].command) elif MENU[id].has("name"): - node_type = load("res://addons/procedural_material/"+MENU[id].name+".tscn") + node_type = load("res://addons/procedural_material/nodes/"+MENU[id].name+".tscn") if node_type != null: var node = node_type.instance() $GraphEdit.add_child(node) @@ -56,7 +57,7 @@ func load_file(filename): var file = File.new() if file.open(filename, File.READ) != OK: return - var data = file.get_var() + var data = parse_json(file.get_as_text()) file.close() $GraphEdit.clear_connections() for c in $GraphEdit.get_children(): @@ -64,7 +65,9 @@ func load_file(filename): $GraphEdit.remove_child(c) c.free() for n in data.nodes: - var node_type = load("res://addons/procedural_material/"+n.type+".tscn") + if !n.has("type"): + continue + var node_type = load("res://addons/procedural_material/nodes/"+n.type+".tscn") if node_type != null: var node = node_type.instance() node.name = n.name @@ -91,7 +94,7 @@ func save_file(filename): data.connections = $GraphEdit.get_connection_list() var file = File.new() if file.open(filename, File.WRITE) == OK: - file.store_var(data) + file.store_string(to_json(data)) file.close() func generate_shader(): diff --git a/addons/procedural_material/pm_editor.tscn b/addons/procedural_material/pm_editor.tscn index 4c239e2..1d44132 100644 --- a/addons/procedural_material/pm_editor.tscn +++ b/addons/procedural_material/pm_editor.tscn @@ -2,7 +2,7 @@ [ext_resource path="res://addons/procedural_material/pm_editor.gd" type="Script" id=1] [ext_resource path="res://addons/procedural_material/graph_edit.gd" type="Script" id=2] -[ext_resource path="res://addons/procedural_material/material.tscn" type="PackedScene" id=3] +[ext_resource path="res://addons/procedural_material/nodes/material.tscn" type="PackedScene" id=3] [sub_resource type="Shader" id=1] @@ -100,11 +100,17 @@ float perlin(vec2 uv, int iterations, float turbulence) { return f/m; } -float Bricks_f(vec2 uv) { return bricks(uv, vec2(Null, Null), Null, Null, 0.2); } +float Perlin_f(vec2 uv) { return perlin(uv, 9, 0.5); } +float Bricks_f(vec2 uv) { return bricks(uv, vec2(3, 6), 0.5, 0.1, 0.1); } void fragment() { -float Bricks_0_f = Bricks_f(UV); -vec3 Colorize_rgb = mix(vec3(0.859375,0.198059,0.198059), vec3(0.890625,0.330505,0.111328), Bricks_0_f); -vec3 Material_rgb = Colorize_rgb; +float Perlin_0_f = Perlin_f(UV+vec2(0.01, 0.0)); +float Perlin_1_f = Perlin_f(UV-vec2(0.01, 0.0)); +float Perlin_2_f = Perlin_f(UV+vec2(0.0, 0.01)); +float Perlin_3_f = Perlin_f(UV-vec2(0.0, 0.01)); +vec2 Warp_0_uv = UV+0.5*vec2(Perlin_0_f-Perlin_1_f, Perlin_2_f-Perlin_3_f); +float Bricks_0_f = Bricks_f(Warp_0_uv); +vec3 Warp_0_rgb = vec3(Bricks_0_f); +vec3 Material_rgb = Warp_0_rgb; COLOR = vec4(Material_rgb, 1.0); } " @@ -156,10 +162,6 @@ _sections_unfolded = [ "Mouse" ] [node name="Material" parent="GraphEdit" index="0" instance=ExtResource( 3 )] -margin_left = 0.0 -margin_top = 0.0 -margin_right = 84.0 -margin_bottom = 43.0 _sections_unfolded = [ "Anchor", "Margin", "Mouse", "Theme", "slot" ] [node name="PopupMenu" type="PopupMenu" parent="GraphEdit" index="1"] @@ -181,7 +183,7 @@ mouse_default_cursor_shape = 0 size_flags_horizontal = 1 size_flags_vertical = 1 popup_exclusive = false -items = [ "Load texture", null, 0, false, false, 0, 0, null, "", false, "Save texture", null, 0, false, false, 1, 0, null, "", false, "Sine", null, 0, false, false, 2, 0, null, "", false, "Bricks", null, 0, false, false, 3, 0, null, "", false, "IQ Noise", null, 0, false, false, 4, 0, null, "", false, "Perlin noise", null, 0, false, false, 5, 0, null, "", false, "Transform", null, 0, false, false, 6, 0, null, "", false, "Colorize", null, 0, false, false, 7, 0, null, "", false, "Blend", null, 0, false, false, 8, 0, null, "", false ] +items = [ "Load texture", null, 0, false, false, 0, 0, null, "", false, "Save texture", null, 0, false, false, 1, 0, null, "", false, "Sine", null, 0, false, false, 2, 0, null, "", false, "Bricks", null, 0, false, false, 3, 0, null, "", false, "IQ Noise", null, 0, false, false, 4, 0, null, "", false, "Perlin noise", null, 0, false, false, 5, 0, null, "", false, "Transform", null, 0, false, false, 6, 0, null, "", false, "Warp", null, 0, false, false, 7, 0, null, "", false, "Colorize", null, 0, false, false, 8, 0, null, "", false, "Blend", null, 0, false, false, 9, 0, null, "", false ] hide_on_state_item_selection = false _sections_unfolded = [ "Rect" ] diff --git a/addons/procedural_material/sine.gd b/addons/procedural_material/sine.gd deleted file mode 100644 index 1d73db1..0000000 --- a/addons/procedural_material/sine.gd +++ /dev/null @@ -1,28 +0,0 @@ -tool -extends "res://addons/procedural_material/node_base.gd" - -var waves = 1.0 -var sharpness = 1.0 - -func _ready(): - set_slot(0, false, 0, Color(0.5, 0.5, 1), true, 0, Color(0.5, 0.5, 1)) - initialize_properties([ $waves, $sharpness ]) - -func get_shader_code(uv): - var rv = { defs="", code="", rgb=null, f=null } - if !generated: - rv.defs = "float "+name+"_f(vec2 uv) { return sine(uv, "+str(waves)+", "+str(sharpness)+"); }\n" - generated = true - rv.f = name+"_f("+uv+")" - return rv - -func _on_Count_text_changed(new_text): - waves = float(new_text) - get_parent().get_parent().generate_shader() - -func _on_Sharpness_text_changed(new_text): - sharpness = float(new_text) - get_parent().get_parent().generate_shader() - -func _get_state_variables(): - return [ "waves", "sharpness" ] diff --git a/examples/bricks.ptex b/examples/bricks.ptex index 935294e..885611c 100644 Binary files a/examples/bricks.ptex and b/examples/bricks.ptex differ