From cfae489ad073a5291144a150a72eeeeede3f575b Mon Sep 17 00:00:00 2001 From: RodZill4 Date: Wed, 31 Jul 2019 20:53:00 +0200 Subject: [PATCH 001/133] Started refactoring to build an export_plugin and separate UI from texture generation --- addons/material_maker/engine/gen_base.gd | 4 + addons/material_maker/engine/gen_buffer.gd | 2 + .../material_maker/engine/gen_convolution.gd | 2 + addons/material_maker/engine/gen_graph.gd | 2 + addons/material_maker/engine/gen_material.gd | 11 + addons/material_maker/engine/gen_shader.gd | 14 ++ addons/material_maker/engine/loader.gd | 33 +++ .../import_plugin/ptex_import.gd | 48 +++++ addons/material_maker/main_window.tscn | 29 ++- addons/material_maker/plugin.gd | 12 ++ addons/material_maker/pm_editor.gd | 124 ----------- addons/material_maker/pm_editor.tscn | 192 ------------------ default_env.tres | 1 - icon.png.import | 5 + project.godot | 45 +++- 15 files changed, 190 insertions(+), 334 deletions(-) create mode 100644 addons/material_maker/engine/gen_base.gd create mode 100644 addons/material_maker/engine/gen_buffer.gd create mode 100644 addons/material_maker/engine/gen_convolution.gd create mode 100644 addons/material_maker/engine/gen_graph.gd create mode 100644 addons/material_maker/engine/gen_material.gd create mode 100644 addons/material_maker/engine/gen_shader.gd create mode 100644 addons/material_maker/engine/loader.gd create mode 100644 addons/material_maker/import_plugin/ptex_import.gd delete mode 100644 addons/material_maker/pm_editor.gd delete mode 100644 addons/material_maker/pm_editor.tscn diff --git a/addons/material_maker/engine/gen_base.gd b/addons/material_maker/engine/gen_base.gd new file mode 100644 index 0000000..05e0beb --- /dev/null +++ b/addons/material_maker/engine/gen_base.gd @@ -0,0 +1,4 @@ +extends Node +class_name MMGenBase + + diff --git a/addons/material_maker/engine/gen_buffer.gd b/addons/material_maker/engine/gen_buffer.gd new file mode 100644 index 0000000..80d36bf --- /dev/null +++ b/addons/material_maker/engine/gen_buffer.gd @@ -0,0 +1,2 @@ +extends MMGenBase +class_name MMGenBuffer diff --git a/addons/material_maker/engine/gen_convolution.gd b/addons/material_maker/engine/gen_convolution.gd new file mode 100644 index 0000000..acf1e5e --- /dev/null +++ b/addons/material_maker/engine/gen_convolution.gd @@ -0,0 +1,2 @@ +extends MMGenBase +class_name MMGenConvolution diff --git a/addons/material_maker/engine/gen_graph.gd b/addons/material_maker/engine/gen_graph.gd new file mode 100644 index 0000000..a5caacc --- /dev/null +++ b/addons/material_maker/engine/gen_graph.gd @@ -0,0 +1,2 @@ +extends MMGenBase +class_name MMGenGraph diff --git a/addons/material_maker/engine/gen_material.gd b/addons/material_maker/engine/gen_material.gd new file mode 100644 index 0000000..37f2e00 --- /dev/null +++ b/addons/material_maker/engine/gen_material.gd @@ -0,0 +1,11 @@ +extends MMGenBase +class_name MMGenMaterial + +func generate_material(): + print("Generating material") + var material = SpatialMaterial.new() + return material + +func initialize(data: Dictionary): + if data.has("name"): + name = data.name diff --git a/addons/material_maker/engine/gen_shader.gd b/addons/material_maker/engine/gen_shader.gd new file mode 100644 index 0000000..6607849 --- /dev/null +++ b/addons/material_maker/engine/gen_shader.gd @@ -0,0 +1,14 @@ +extends MMGenBase +class_name MMGenShader + +var config +var parameters + +func configure(c: Dictionary): + config = c + +func initialize(data: Dictionary): + if data.has("name"): + name = data.name + if data.has("parameters"): + parameters = data.parameters diff --git a/addons/material_maker/engine/loader.gd b/addons/material_maker/engine/loader.gd new file mode 100644 index 0000000..b99f823 --- /dev/null +++ b/addons/material_maker/engine/loader.gd @@ -0,0 +1,33 @@ +extends Object +class_name MMGenLoader + +func load_gen(filename: String) -> MMGenBase: + var file = File.new() + if file.open(filename, File.READ) == OK: + var data = parse_json(file.get_as_text()) + return create_gen(data) + return null + +func create_gen(data) -> MMGenBase: + var generator = null + if data.has("connections") and data.has("nodes"): + generator = MMGenGraph.new() + for n in data.nodes: + var g = create_gen(n) + if g != null: + generator.add_child(g) + elif data.has("type"): + if data.type == "material": + generator = MMGenMaterial.new() + else: + generator = MMGenShader.new() + var file = File.new() + if file.open("res://addons/material_maker/nodes/"+data.type+".mmn", File.READ) == OK: + var config = parse_json(file.get_as_text()) + print("loaded description "+data.type+".mmn") + generator.configure(config) + else: + print("Cannot find description for "+data.type) + if generator != null and data.has("parameters"): + generator.initialize(data) + return generator diff --git a/addons/material_maker/import_plugin/ptex_import.gd b/addons/material_maker/import_plugin/ptex_import.gd new file mode 100644 index 0000000..d92265b --- /dev/null +++ b/addons/material_maker/import_plugin/ptex_import.gd @@ -0,0 +1,48 @@ +extends EditorImportPlugin + +var plugin = null + +func _init(p): + plugin = p + +func _ready(): + pass # Replace with function body. + +func get_import_options(preset : int): + return [] + +func get_import_order(): + return 1 + +func get_importer_name(): + return "MaterialMakerImporter" + +func get_option_visibility(option: String, options: Dictionary): + return false + +func get_preset_count(): + return 1 + +func get_preset_name(preset: int) -> String: + return "Default" + +func get_priority(): + return 1 + +func get_recognized_extensions(): + return [ "ptex" ] + +func get_resource_type(): + return "Material" + +func get_save_extension(): + return "tres" + +func get_visible_name(): + return "Material Maker Importer" + +func import(source_file: String, save_path: String, options: Dictionary, platform_variants: Array, gen_files: Array) -> int: + var material = SpatialMaterial.new() + var filename = save_path + "." + get_save_extension() + ResourceSaver.save(filename, plugin.generate_material(source_file)) + return OK diff --git a/addons/material_maker/main_window.tscn b/addons/material_maker/main_window.tscn index 716a83b..835eb56 100644 --- a/addons/material_maker/main_window.tscn +++ b/addons/material_maker/main_window.tscn @@ -21,7 +21,7 @@ size_flags_horizontal = 3 size_flags_vertical = 3 [node name="Menu" type="HBoxContainer" parent="VBoxContainer"] -margin_right = 1024.0 +margin_right = 1280.0 margin_bottom = 20.0 [node name="File" type="MenuButton" parent="VBoxContainer/Menu"] @@ -53,19 +53,19 @@ items = [ "User manual", null, 0, false, false, 17, 0, null, "", false, "Report [node name="HBoxContainer" type="HSplitContainer" parent="VBoxContainer"] margin_top = 24.0 -margin_right = 1024.0 -margin_bottom = 600.0 +margin_right = 1280.0 +margin_bottom = 720.0 size_flags_vertical = 3 [node name="VBoxContainer" type="VSplitContainer" parent="VBoxContainer/HBoxContainer"] -margin_right = 250.0 -margin_bottom = 576.0 +margin_right = 314.0 +margin_bottom = 696.0 size_flags_horizontal = 3 size_flags_vertical = 3 [node name="Library" type="Tree" parent="VBoxContainer/HBoxContainer/VBoxContainer"] -margin_right = 250.0 -margin_bottom = 282.0 +margin_right = 314.0 +margin_bottom = 342.0 rect_min_size = Vector2( 100, 100 ) size_flags_horizontal = 3 size_flags_vertical = 3 @@ -76,21 +76,21 @@ script = ExtResource( 2 ) anchor_left = 0.0 anchor_right = 0.0 margin_left = 0.0 -margin_top = 294.0 -margin_right = 250.0 -margin_bottom = 576.0 +margin_top = 354.0 +margin_right = 314.0 +margin_bottom = 696.0 [node name="Projects" type="Panel" parent="VBoxContainer/HBoxContainer"] -margin_left = 262.0 -margin_right = 1024.0 -margin_bottom = 576.0 +margin_left = 326.0 +margin_right = 1280.0 +margin_bottom = 696.0 size_flags_horizontal = 3 size_flags_vertical = 3 size_flags_stretch_ratio = 3.0 script = ExtResource( 4 ) [node name="Tabs" type="Tabs" parent="VBoxContainer/HBoxContainer/Projects"] -margin_right = 762.0 +margin_right = 954.0 margin_bottom = 24.0 tab_align = 0 tab_close_display_policy = 1 @@ -105,7 +105,6 @@ debug_path = "D:/Dev/mmdebug_" [node name="NodeFactory" type="Node" parent="."] script = ExtResource( 6 ) - [connection signal="no_more_tabs" from="VBoxContainer/HBoxContainer/Projects" to="." method="new_material"] [connection signal="resized" from="VBoxContainer/HBoxContainer/Projects" to="VBoxContainer/HBoxContainer/Projects" method="_on_Projects_resized"] [connection signal="tab_changed" from="VBoxContainer/HBoxContainer/Projects" to="." method="_on_Projects_tab_changed"] diff --git a/addons/material_maker/plugin.gd b/addons/material_maker/plugin.gd index 44ab3f9..7af04c7 100644 --- a/addons/material_maker/plugin.gd +++ b/addons/material_maker/plugin.gd @@ -3,9 +3,12 @@ extends EditorPlugin var mm_button = null var material_maker = null +var importer = null func _enter_tree(): add_tool_menu_item("Material Maker", self, "open_material_maker") + importer = preload("res://addons/material_maker/import_plugin/ptex_import.gd").new(self) + add_import_plugin(importer) func _exit_tree(): remove_tool_menu_item("Material Maker") @@ -13,6 +16,9 @@ func _exit_tree(): material_maker.hide() material_maker.queue_free() material_maker = null + if importer != null: + remove_import_plugin(importer) + importer = null func _get_state(): var s = { mm_button=mm_button, material_maker=material_maker } @@ -36,3 +42,9 @@ func close_material_maker(): material_maker.hide() material_maker.queue_free() material_maker = null + +func generate_material(ptex_filename: String) -> Material: + var loader = MMGenLoader.new() + var generator = loader.load_gen(ptex_filename) + add_child(generator) + return generator.get_node("Material").generate_material() diff --git a/addons/material_maker/pm_editor.gd b/addons/material_maker/pm_editor.gd deleted file mode 100644 index 12c7010..0000000 --- a/addons/material_maker/pm_editor.gd +++ /dev/null @@ -1,124 +0,0 @@ -tool -extends Container - -var popup_menu = null -var popup_position = Vector2(0, 0) - -var texture_preview_material = null - -var preview_maximized = false - -const MENU = [ - { command="new_texture", description="New material" }, - { command="load_texture", description="Load material" }, - { command="save_texture", description="Save material" }, - { command="save_texture_as", description="Save material as..." }, - { command="export_texture", description="Export material" }, - { }, - { submenu="generator", description="Generator" }, - { name="image", description="Image", in_submenu="generator" }, - { name="pattern", description="Pattern", in_submenu="generator" }, - { name="bricks", description="Bricks", in_submenu="generator" }, - { name="perlin", description="Perlin noise", in_submenu="generator" }, - { name="voronoi", description="Voronoi Noise", in_submenu="generator" }, - { submenu="filter", description="Filter" }, - { name="colorize", description="Colorize", in_submenu="filter" }, - { name="blend", description="Blend", in_submenu="filter" }, - { name="transform", description="Transform", in_submenu="filter" }, - { name="warp", description="Warp", in_submenu="filter" }, - { name="normal_map", description="Normal Map", in_submenu="filter" } -] - -func _ready(): - # Duplicate the material we'll modify and store the shaders - $Preview/Preview/SelectedPreview.material = $Preview/Preview/SelectedPreview.material.duplicate(true) - texture_preview_material = $Preview/Preview/SelectedPreview.material - $GraphEdit.add_valid_connection_type(0, 0) - # create or update popup menu - if popup_menu != null: - popup_menu.queue_free() - popup_menu = create_menu() - $GraphEdit.add_child(popup_menu) - -func create_menu(in_submenu = null): - var menu = PopupMenu.new() - menu.connect("id_pressed", self, "_on_PopupMenu_id_pressed") - for i in MENU.size(): - if MENU[i].has("in_submenu"): - if in_submenu != MENU[i].in_submenu: - continue - elif in_submenu != null: - continue - if MENU[i].has("submenu"): - var submenu = create_menu(MENU[i].submenu) - menu.add_child(submenu) - menu.add_submenu_item(MENU[i].description, submenu.get_name()) - elif MENU[i].has("description"): - menu.add_item(MENU[i].description, i) - else: - menu.add_separator() - return menu - -func _on_GraphEdit_popup_request(position): - popup_position = position - popup_menu.popup(Rect2(position, popup_menu.rect_size)) - -func _on_PopupMenu_id_pressed(id): - var node_type = null - if MENU[id].has("command"): - call(MENU[id].command) - elif MENU[id].has("name"): - $GraphEdit.create_node({type=MENU[id].name}, popup_position) - -func set_save_path(graph_edit, path): - if !Engine.editor_hint: - if path != null: - OS.set_window_title("Procedural textures (%s)" % path) - else: - OS.set_window_title("Procedural textures") - -func new_texture(): - $GraphEdit.new_material() - -func load_texture(): - $GraphEdit.load_file() - -func save_texture(): - $GraphEdit.save_file() - -func save_texture_as(): - $GraphEdit.save_file_as() - -func export_texture(): - $GraphEdit.export_textures() - -func get_selected_node(): - var rv = null - for c in $GraphEdit.get_children(): - if c is GraphNode && c.selected: - if rv != null: - return null - else: - rv = c - return rv - -func generate_shader(): - var selected_node = get_selected_node() - if $GraphEdit/Material != null: - $GraphEdit/Material.update_materials($Preview/Preview.get_materials()) - if selected_node != null: - $GraphEdit.setup_material($Preview/Preview.get_2d_material(), selected_node.get_textures(), selected_node.generate_shader()) - -func _on_GraphEdit_node_selected(node): - var selected_node = get_selected_node() - if selected_node != null: - $GraphEdit.setup_material($Preview/Preview.get_2d_material(), selected_node.get_textures(), selected_node.generate_shader()) - -func _on_SelectedPreview_gui_input(ev): - if ev is InputEventMouseButton && ev.button_index == 1 && ev.doubleclick: - if preview_maximized: - $Preview/Preview/SelectedPreview/SelectedPreviewAnimation.play("minimize") - else: - $Preview/Preview/SelectedPreview/SelectedPreviewAnimation.play("maximize") - preview_maximized = !preview_maximized - diff --git a/addons/material_maker/pm_editor.tscn b/addons/material_maker/pm_editor.tscn deleted file mode 100644 index e57e80c..0000000 --- a/addons/material_maker/pm_editor.tscn +++ /dev/null @@ -1,192 +0,0 @@ -[gd_scene load_steps=8 format=2] - -[ext_resource path="res://addons/material_maker/pm_editor.gd" type="Script" id=1] -[ext_resource path="res://addons/material_maker/graph_edit.tscn" type="PackedScene" id=2] -[ext_resource path="res://addons/material_maker/preview.tscn" type="PackedScene" id=3] - -[sub_resource type="Shader" id=5] - -code = "shader_type canvas_item; - -void fragment() { - COLOR = vec4(1.0); -} -" -_sections_unfolded = [ "Resource" ] - -[sub_resource type="ShaderMaterial" id=6] - -render_priority = 0 -shader = SubResource( 5 ) - -[sub_resource type="Animation" id=3] - -length = 0.2 -loop = false -step = 0.1 -tracks/0/type = "value" -tracks/0/path = NodePath(".:rect_position") -tracks/0/interp = 1 -tracks/0/loop_wrap = true -tracks/0/imported = false -tracks/0/enabled = true -tracks/0/keys = { -"times": PoolRealArray( 0, 0.2 ), -"transitions": PoolRealArray( 1, 1 ), -"update": 0, -"values": [ Vector2( 3, 251 ), Vector2( 2, 2 ) ] -} -tracks/1/type = "value" -tracks/1/path = NodePath(".:rect_size") -tracks/1/interp = 1 -tracks/1/loop_wrap = true -tracks/1/imported = false -tracks/1/enabled = true -tracks/1/keys = { -"times": PoolRealArray( 0, 0.2 ), -"transitions": PoolRealArray( 1, 1 ), -"update": 0, -"values": [ Vector2( 96, 96 ), Vector2( 346, 346 ) ] -} -tracks/2/type = "value" -tracks/2/path = NodePath("MaterialPreview:render_target_update_mode") -tracks/2/interp = 1 -tracks/2/loop_wrap = true -tracks/2/imported = false -tracks/2/enabled = true -tracks/2/keys = { -"times": PoolRealArray( 0.2 ), -"transitions": PoolRealArray( 1 ), -"update": 1, -"values": [ 0 ] -} - -[sub_resource type="Animation" id=4] - -length = 0.2 -loop = false -step = 0.1 -tracks/0/type = "value" -tracks/0/path = NodePath(".:rect_position") -tracks/0/interp = 1 -tracks/0/loop_wrap = true -tracks/0/imported = false -tracks/0/enabled = true -tracks/0/keys = { -"times": PoolRealArray( 0, 0.2 ), -"transitions": PoolRealArray( 1, 1 ), -"update": 0, -"values": [ Vector2( 2, 2 ), Vector2( 2, 252 ) ] -} -tracks/1/type = "value" -tracks/1/path = NodePath(".:rect_size") -tracks/1/interp = 1 -tracks/1/loop_wrap = true -tracks/1/imported = false -tracks/1/enabled = true -tracks/1/keys = { -"times": PoolRealArray( 0, 0.2 ), -"transitions": PoolRealArray( 1, 1 ), -"update": 0, -"values": [ Vector2( 346, 346 ), Vector2( 96, 96 ) ] -} -tracks/2/type = "value" -tracks/2/path = NodePath("MaterialPreview:render_target_update_mode") -tracks/2/interp = 1 -tracks/2/loop_wrap = true -tracks/2/imported = false -tracks/2/enabled = true -tracks/2/keys = { -"times": PoolRealArray( 0 ), -"transitions": PoolRealArray( 1 ), -"update": 1, -"values": [ 3 ] -} - -[node name="ProceduralMaterialEditor" type="MarginContainer" index="0"] - -anchor_left = 0.0 -anchor_top = 0.0 -anchor_right = 1.0 -anchor_bottom = 1.0 -margin_bottom = -2.0 -rect_min_size = Vector2( 500, 300 ) -rect_pivot_offset = Vector2( 0, 0 ) -rect_clip_content = false -mouse_filter = 0 -mouse_default_cursor_shape = 0 -size_flags_horizontal = 1 -size_flags_vertical = 1 -custom_constants/margin_left = 0 -script = ExtResource( 1 ) -_sections_unfolded = [ "Rect" ] - -[node name="GraphEdit" parent="." index="0" instance=ExtResource( 2 )] - -anchor_right = 0.0 -anchor_bottom = 0.0 -margin_right = 1280.0 -margin_bottom = 718.0 - -[node name="Preview" type="Container" parent="." index="1"] - -anchor_left = 0.0 -anchor_top = 0.0 -anchor_right = 0.0 -anchor_bottom = 0.0 -margin_right = 1280.0 -margin_bottom = 718.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 = 1 -_sections_unfolded = [ "Mouse" ] - -[node name="Preview" parent="Preview" index="0" instance=ExtResource( 3 )] - -[node name="SelectedPreview" type="ColorRect" parent="Preview/Preview" index="4"] - -visible = false -material = SubResource( 6 ) -anchor_left = 0.0 -anchor_top = 0.0 -anchor_right = 0.0 -anchor_bottom = 0.0 -margin_left = 2.0 -margin_top = 2.0 -margin_right = 348.0 -margin_bottom = 348.0 -rect_min_size = Vector2( 96, 96 ) -rect_pivot_offset = Vector2( 0, 0 ) -rect_clip_content = false -mouse_filter = 0 -mouse_default_cursor_shape = 0 -size_flags_horizontal = 8 -size_flags_vertical = 0 -color = Color( 1, 1, 1, 1 ) -_sections_unfolded = [ "Material", "Mouse", "Rect" ] - -[node name="SelectedPreviewAnimation" type="AnimationPlayer" parent="Preview/Preview/SelectedPreview" index="0"] - -root_node = NodePath("..") -autoplay = "" -playback_process_mode = 1 -playback_default_blend_time = 0.0 -playback_speed = 1.0 -anims/maximize = SubResource( 3 ) -anims/minimize = SubResource( 4 ) -blend_times = [ ] - -[connection signal="graph_changed" from="GraphEdit" to="." method="generate_shader"] - -[connection signal="node_selected" from="GraphEdit" to="." method="_on_GraphEdit_node_selected"] - -[connection signal="popup_request" from="GraphEdit" to="." method="_on_GraphEdit_popup_request"] - -[connection signal="save_path_changed" from="GraphEdit" to="." method="set_save_path"] - -[connection signal="gui_input" from="Preview/Preview/SelectedPreview" to="." method="_on_SelectedPreview_gui_input"] - - diff --git a/default_env.tres b/default_env.tres index 4b7cb0a..d37b59d 100644 --- a/default_env.tres +++ b/default_env.tres @@ -11,4 +11,3 @@ ground_curve = 0.01 [resource] background_mode = 2 background_sky = SubResource( 1 ) - diff --git a/icon.png.import b/icon.png.import index 0041ef8..96cbf46 100644 --- a/icon.png.import +++ b/icon.png.import @@ -3,6 +3,9 @@ importer="texture" type="StreamTexture" path="res://.import/icon.png-487276ed1e3a0c39cad0279d744ee560.stex" +metadata={ +"vram_texture": false +} [deps] @@ -14,6 +17,7 @@ dest_files=[ "res://.import/icon.png-487276ed1e3a0c39cad0279d744ee560.stex" ] compress/mode=0 compress/lossy_quality=0.7 compress/hdr_mode=0 +compress/bptc_ldr=0 compress/normal_map=0 flags/repeat=0 flags/filter=true @@ -23,6 +27,7 @@ flags/srgb=2 process/fix_alpha_border=true process/premult_alpha=false process/HDR_as_SRGB=false +process/invert_color=false stream=false size_limit=0 detect_3d=true diff --git a/project.godot b/project.godot index 473d017..4dc1aa7 100644 --- a/project.godot +++ b/project.godot @@ -8,9 +8,50 @@ config_version=4 -_global_script_classes=[ ] +_global_script_classes=[ { +"base": "Node", +"class": "MMGenBase", +"language": "GDScript", +"path": "res://addons/material_maker/engine/gen_base.gd" +}, { +"base": "MMGenBase", +"class": "MMGenBuffer", +"language": "GDScript", +"path": "res://addons/material_maker/engine/gen_buffer.gd" +}, { +"base": "MMGenBase", +"class": "MMGenConvolution", +"language": "GDScript", +"path": "res://addons/material_maker/engine/gen_convolution.gd" +}, { +"base": "MMGenBase", +"class": "MMGenGraph", +"language": "GDScript", +"path": "res://addons/material_maker/engine/gen_graph.gd" +}, { +"base": "Object", +"class": "MMGenLoader", +"language": "GDScript", +"path": "res://addons/material_maker/engine/loader.gd" +}, { +"base": "MMGenBase", +"class": "MMGenMaterial", +"language": "GDScript", +"path": "res://addons/material_maker/engine/gen_material.gd" +}, { +"base": "MMGenBase", +"class": "MMGenShader", +"language": "GDScript", +"path": "res://addons/material_maker/engine/gen_shader.gd" +} ] _global_script_class_icons={ - +"MMGenBase": "", +"MMGenBuffer": "", +"MMGenConvolution": "", +"MMGenGraph": "", +"MMGenLoader": "", +"MMGenMaterial": "", +"MMGenShader": "" } [application] From 66f88f3f46a25e9ffb4bf4fc01c57a7fe104ef7c Mon Sep 17 00:00:00 2001 From: RodZill4 Date: Fri, 2 Aug 2019 08:17:32 +0200 Subject: [PATCH 002/133] More shader generation refactoring --- addons/material_maker/engine/gen_base.gd | 64 +++++++++ addons/material_maker/engine/gen_graph.gd | 9 ++ addons/material_maker/engine/gen_material.gd | 113 +++++++++++++++- addons/material_maker/engine/gen_shader.gd | 130 ++++++++++++++++++- addons/material_maker/engine/loader.gd | 17 ++- addons/material_maker/nodes/blur/blur.gd | 2 +- addons/material_maker/plugin.gd | 3 +- 7 files changed, 325 insertions(+), 13 deletions(-) diff --git a/addons/material_maker/engine/gen_base.gd b/addons/material_maker/engine/gen_base.gd index 05e0beb..40b008e 100644 --- a/addons/material_maker/engine/gen_base.gd +++ b/addons/material_maker/engine/gen_base.gd @@ -1,4 +1,68 @@ +tool extends Node class_name MMGenBase +class OutputPort: + var generator : MMGenBase = null + var output_index : int = 0 + + func _init(g : MMGenBase, o : int): + generator = g + output_index = o + + func get_shader(): + return generator.get_shader(output_index) + + func get_globals(): + return generator.get_globals() +var parameters = null + +func get_seed(): + return 0 + +func get_source(input_index : int): + return get_parent().get_port_source(name, input_index) + +func get_input_shader(input_index : int): + var source = get_source(input_index) + if source != null: + return source.get_shader() + +func get_shader(output_index : int): + return get_shader_code("UV", output_index); + +# this will need an output index for switch +func get_globals(): + var list = [] + for i in range(10): + var source = get_source(i) + if source != null: + var source_list = source.get_globals() + for g in source_list: + if list.find(g) == -1: + list.append(g) + return list + +func get_shader_code(uv, slot = 0): + var rv + rv = _get_shader_code(uv, slot) + if !rv.has("f"): + if rv.has("rgb"): + rv.f = "(dot("+rv.rgb+", vec3(1.0))/3.0)" + elif rv.has("rgba"): + rv.f = "(dot("+rv.rgba+".rgb, vec3(1.0))/3.0)" + else: + rv.f = "0.0" + if !rv.has("rgb"): + if rv.has("rgba"): + rv.rgb = rv.rgba+".rgb" + else: + rv.rgb = "vec3("+rv.f+")" + if !rv.has("rgba"): + rv.rgba = "vec4("+rv.rgb+", 1.0)" + rv.globals = get_globals() + return rv + +func _get_shader_code(uv : String, output_index : int): + return null diff --git a/addons/material_maker/engine/gen_graph.gd b/addons/material_maker/engine/gen_graph.gd index a5caacc..af73b8d 100644 --- a/addons/material_maker/engine/gen_graph.gd +++ b/addons/material_maker/engine/gen_graph.gd @@ -1,2 +1,11 @@ +tool extends MMGenBase class_name MMGenGraph + +var connections = null + +func get_port_source(gen_name: String, input_index: int) -> OutputPort: + for c in connections: + if c.to == gen_name and c.to_port == input_index: + return OutputPort.new(get_node(c.from), c.from_port) + return null diff --git a/addons/material_maker/engine/gen_material.gd b/addons/material_maker/engine/gen_material.gd index 37f2e00..2853e2f 100644 --- a/addons/material_maker/engine/gen_material.gd +++ b/addons/material_maker/engine/gen_material.gd @@ -1,11 +1,122 @@ +tool extends MMGenBase class_name MMGenMaterial +var texture_list + +var material +var generated_textures = {} + +const TEXTURE_LIST = [ + { port=0, texture="albedo" }, + { port=1, texture="metallic" }, + { port=2, texture="roughness" }, + { port=3, texture="emission" }, + { port=4, texture="normal_map" }, + { port=5, texture="ambient_occlusion" }, + { port=6, texture="depth_map" } +] + +const ADDON_TEXTURE_LIST = [ + { port=0, texture="albedo" }, + { port=3, texture="emission" }, + { port=4, texture="normal_map" }, + { ports=[1, 2, 5], default_values=["0.0", "1.0", "1.0"], texture="mrao" }, + { port=6, texture="depth_map" } +] + +func _ready(): + texture_list = TEXTURE_LIST + if Engine.editor_hint: + texture_list = ADDON_TEXTURE_LIST + for t in texture_list: + generated_textures[t.texture] = { shader=null, source=null, texture=null } + material = SpatialMaterial.new() + func generate_material(): print("Generating material") - var material = SpatialMaterial.new() + print(get_source(0).get_shader()) return material func initialize(data: Dictionary): if data.has("name"): name = data.name + +func get_generated_texture(slot, file_prefix = null): + if file_prefix != null: + var file_name = "%s_%s.png" % [ file_prefix, slot ] + if File.new().file_exists(file_name): + return load(file_name) + else: + return null + else: + return generated_textures[slot].texture + +func update_spatial_material(m, file_prefix = null): + var texture + m.albedo_color = parameters.albedo_color + m.albedo_texture = get_generated_texture("albedo", file_prefix) + m.metallic = parameters.metallic + m.roughness = parameters.roughness + if Engine.editor_hint: + texture = get_generated_texture("mrao", file_prefix) + m.metallic_texture = texture + m.metallic_texture_channel = SpatialMaterial.TEXTURE_CHANNEL_RED + m.roughness_texture = texture + m.roughness_texture_channel = SpatialMaterial.TEXTURE_CHANNEL_GREEN + else: + m.metallic_texture = get_generated_texture("metallic", file_prefix) + m.roughness_texture = get_generated_texture("roughness", file_prefix) + texture = get_generated_texture("emission", file_prefix) + if texture != null: + m.emission_enabled = true + m.emission_energy = parameters.emission_energy + m.emission_texture = texture + else: + m.emission_enabled = false + texture = get_generated_texture("normal_map", file_prefix) + if texture != null: + m.normal_enabled = true + m.normal_texture = texture + else: + m.normal_enabled = false + if Engine.editor_hint: + if (generated_textures.mrao.mask & (1 << 2)) != 0: + m.ao_enabled = true + m.ao_light_affect = parameters.ao_light_affect + m.ao_texture = m.metallic_texture + m.ao_texture_channel = SpatialMaterial.TEXTURE_CHANNEL_BLUE + else: + m.ao_enabled = false + else: + texture = get_generated_texture("ambient_occlusion", file_prefix) + if texture != null: + m.ao_enabled = true + m.ao_light_affect = parameters.ao_light_affect + m.ao_texture = texture + else: + m.ao_enabled = false + texture = get_generated_texture("depth_map", file_prefix) + if texture != null: + m.depth_enabled = true + m.depth_scale = parameters.depth_scale + m.depth_texture = texture + else: + m.depth_enabled = false + +func export_textures(prefix, size = null): + if size == null: + size = int(pow(2, 8+parameters.resolution)) + for t in texture_list: + var texture = generated_textures[t.texture].texture + if texture != null: + var image = texture.get_data() + image.save_png("%s_%s.png" % [ prefix, t.texture ]) + if Engine.editor_hint: + var resource_filesystem = get_parent().editor_interface.get_resource_filesystem() + resource_filesystem.scan() + yield(resource_filesystem, "filesystem_changed") + var new_material = SpatialMaterial.new() + update_spatial_material(new_material, prefix) + ResourceSaver.save("%s.tres" % [ prefix ], new_material) + resource_filesystem.scan() diff --git a/addons/material_maker/engine/gen_shader.gd b/addons/material_maker/engine/gen_shader.gd index 6607849..8c6c916 100644 --- a/addons/material_maker/engine/gen_shader.gd +++ b/addons/material_maker/engine/gen_shader.gd @@ -1,14 +1,136 @@ +tool extends MMGenBase class_name MMGenShader -var config -var parameters +var model_data = null +var generated_variants = [] -func configure(c: Dictionary): - config = c +func set_model_data(data: Dictionary): + model_data = data func initialize(data: Dictionary): if data.has("name"): name = data.name if data.has("parameters"): parameters = data.parameters + +func find_keyword_call(string, keyword): + var search_string = "$%s(" % keyword + var position = string.find(search_string) + if position == -1: + return null + var parenthesis_level = 0 + var parameter_begin = position+search_string.length() + var parameter_end = -1 + for i in range(parameter_begin, string.length()): + if string[i] == '(': + parenthesis_level += 1 + elif string[i] == ')': + if parenthesis_level == 0: + return string.substr(parameter_begin, i-parameter_begin) + parenthesis_level -= 1 + return "" + +func replace_input(string, input, type, src, default): + var required_defs = "" + var required_code = "" + while true: + var uv = find_keyword_call(string, input) + if uv == null: + break + elif uv == "": + print("syntax error") + break + var src_code + if src == null: + src_code = subst(default, "(%s)" % uv) + else: + src_code = src.get_shader_code(uv) + src_code.string = src_code[type] + required_defs += src_code.defs + required_code += src_code.code + string = string.replace("$%s(%s)" % [ input, uv ], src_code.string) + return { string=string, defs=required_defs, code=required_code } + +func is_word_letter(l): + return "azertyuiopqsdfghjklmwxcvbnAZERTYUIOPQSDFGHJKLMWXCVBN1234567890_".find(l) != -1 + +func replace_variable(string, variable, value): + string = string.replace("$(%s)" % variable, value) + var keyword_size = variable.length()+1 + var new_string = "" + while !string.empty(): + var pos = string.find("$"+variable) + if pos == -1: + new_string += string + break + new_string += string.left(pos) + string = string.right(pos) + if string.empty() or !is_word_letter(string[0]): + new_string += value + else: + new_string += "$"+variable + string = string.right(keyword_size) + return new_string + +func subst(string, uv = ""): + var required_defs = "" + var required_code = "" + string = replace_variable(string, "name", name) + string = replace_variable(string, "seed", str(get_seed())) + if uv != "": + string = replace_variable(string, "uv", "("+uv+")") + if model_data.has("parameters") and typeof(model_data.parameters) == TYPE_ARRAY: + for p in model_data.parameters: + if !p.has("name") or !p.has("type"): + continue + var value = parameters[p.name] + var value_string = null + if p.type == "float": + value_string = "%.9f" % value + elif p.type == "size": + value_string = "%.9f" % pow(2, value+p.first) + elif p.type == "enum": + value_string = p.values[value].value + elif p.type == "color": + value_string = "vec4(%.9f, %.9f, %.9f, %.9f)" % [ value.r, value.g, value.b, value.a ] + if value_string != null: + string = replace_variable(string, p.name, value_string) + if model_data.has("inputs") and typeof(model_data.inputs) == TYPE_ARRAY: + for i in range(model_data.inputs.size()): + var input = model_data.inputs[i] + var source = get_source(i) + var result = replace_input(string, input.name, input.type, source, input.default) + string = result.string + required_defs += result.defs + required_code += result.code + return { string=string, defs=required_defs, code=required_code } + +func _get_shader_code(uv, slot = 0): + var output_info = [ { field="rgba", type="vec4" }, { field="rgb", type="vec3" }, { field="f", type="float" } ] + var rv = { defs="", code="" } + var variant_string = uv+","+str(slot) + if model_data != null and model_data.has("outputs") and model_data.outputs.size() > slot: + var output = model_data.outputs[slot] + if model_data.has("instance") && generated_variants.empty(): + rv.defs = subst(model_data.instance).string + var variant_index = generated_variants.find(variant_string) + if variant_index == -1: + variant_index = generated_variants.size() + generated_variants.append(variant_string) + for t in output_info: + if output.has(t.field): + var subst_output = subst(output[t.field], uv) + rv.defs += subst_output.defs + rv.code += subst_output.code + rv.code += "%s %s_%d_%d_%s = %s;\n" % [ t.type, name, slot, variant_index, t.field, subst_output.string ] + for t in output_info: + if output.has(t.field): + rv[t.field] = "%s_%d_%d_%s" % [ name, slot, variant_index, t.field ] + return rv + +func get_globals(): + var list = .get_globals() + if typeof(model_data) == TYPE_DICTIONARY and model_data.has("global") and list.find(model_data.global) == -1: + list.append(model_data.global) + return list diff --git a/addons/material_maker/engine/loader.gd b/addons/material_maker/engine/loader.gd index b99f823..357c5cc 100644 --- a/addons/material_maker/engine/loader.gd +++ b/addons/material_maker/engine/loader.gd @@ -1,3 +1,4 @@ +tool extends Object class_name MMGenLoader @@ -16,18 +17,22 @@ func create_gen(data) -> MMGenBase: var g = create_gen(n) if g != null: generator.add_child(g) + generator.connections = data.connections elif data.has("type"): if data.type == "material": generator = MMGenMaterial.new() else: generator = MMGenShader.new() - var file = File.new() - if file.open("res://addons/material_maker/nodes/"+data.type+".mmn", File.READ) == OK: - var config = parse_json(file.get_as_text()) - print("loaded description "+data.type+".mmn") - generator.configure(config) + if data.type == "custom": + pass else: - print("Cannot find description for "+data.type) + var file = File.new() + if file.open("res://addons/material_maker/nodes/"+data.type+".mmn", File.READ) == OK: + var model_data = parse_json(file.get_as_text()) + print("loaded description "+data.type+".mmn") + generator.set_model_data(model_data) + else: + print("Cannot find description for "+data.type) if generator != null and data.has("parameters"): generator.initialize(data) return generator diff --git a/addons/material_maker/nodes/blur/blur.gd b/addons/material_maker/nodes/blur/blur.gd index c2a8b49..e713b28 100644 --- a/addons/material_maker/nodes/blur/blur.gd +++ b/addons/material_maker/nodes/blur/blur.gd @@ -63,7 +63,7 @@ func get_textures(): list[name] = saved_texture return list -func _get_shader_code(uv): +func _get_shader_code(uv, slot = 0): var rv = { defs="", code="" } var src = get_source() if src == null: diff --git a/addons/material_maker/plugin.gd b/addons/material_maker/plugin.gd index 7af04c7..5260dc2 100644 --- a/addons/material_maker/plugin.gd +++ b/addons/material_maker/plugin.gd @@ -47,4 +47,5 @@ func generate_material(ptex_filename: String) -> Material: var loader = MMGenLoader.new() var generator = loader.load_gen(ptex_filename) add_child(generator) - return generator.get_node("Material").generate_material() + var material = generator.get_node("Material") + return material.generate_material() From bcdac09cd7b8a61092280c9b1fc6737165ac4784 Mon Sep 17 00:00:00 2001 From: Rodolphe Suescun Date: Fri, 9 Aug 2019 08:16:24 +0200 Subject: [PATCH 003/133] More progress on refactoring and more Basic import plugin works. Added gradient parameter to custom node. hsv_adjust now supports alpha channel. Remove deprecated scenes. --- addons/material_maker/engine/gen_base.gd | 8 +- addons/material_maker/engine/gen_material.gd | 16 +- addons/material_maker/engine/gen_shader.gd | 13 +- addons/material_maker/engine/loader.gd | 5 +- addons/material_maker/engine/renderer.gd | 92 +++++++ addons/material_maker/engine/renderer.tscn | 34 +++ addons/material_maker/graph_edit.gd | 2 +- .../import_plugin/ptex_import.gd | 6 +- addons/material_maker/node_base.gd | 1 + addons/material_maker/nodes/adjust_hsv.mmn | 2 +- .../nodes/adjust_hsv/adjust_hsv.gd | 24 -- .../nodes/adjust_hsv/adjust_hsv.tscn | 256 ------------------ addons/material_maker/nodes/blend/blend.tscn | 124 +-------- addons/material_maker/nodes/colorize.mmn | 1 + .../material_maker/nodes/colorize/colorize.gd | 25 -- .../nodes/colorize/colorize.tscn | 51 ---- .../material_maker/nodes/custom/custom.tscn | 91 +------ addons/material_maker/nodes/node_generic.gd | 11 +- addons/material_maker/plugin.cfg | 2 +- addons/material_maker/plugin.gd | 5 +- addons/material_maker/renderer.tscn | 46 +--- addons/material_maker/types/gradient.gd | 7 + .../material_maker/widgets/gradient_editor.gd | 7 +- .../widgets/node_editor/parameter.tscn | 156 ++--------- .../widgets/node_editor/parameter_enum.gd | 5 +- .../widgets/node_editor/parameter_gradient.gd | 18 ++ .../node_editor/parameter_gradient.tscn | 19 ++ project.godot | 14 +- 28 files changed, 290 insertions(+), 751 deletions(-) create mode 100644 addons/material_maker/engine/renderer.gd create mode 100644 addons/material_maker/engine/renderer.tscn delete mode 100644 addons/material_maker/nodes/adjust_hsv/adjust_hsv.gd delete mode 100644 addons/material_maker/nodes/adjust_hsv/adjust_hsv.tscn create mode 100644 addons/material_maker/nodes/colorize.mmn delete mode 100644 addons/material_maker/nodes/colorize/colorize.gd delete mode 100644 addons/material_maker/nodes/colorize/colorize.tscn create mode 100644 addons/material_maker/widgets/node_editor/parameter_gradient.gd create mode 100644 addons/material_maker/widgets/node_editor/parameter_gradient.tscn diff --git a/addons/material_maker/engine/gen_base.gd b/addons/material_maker/engine/gen_base.gd index 40b008e..dbbf966 100644 --- a/addons/material_maker/engine/gen_base.gd +++ b/addons/material_maker/engine/gen_base.gd @@ -13,10 +13,14 @@ class OutputPort: func get_shader(): return generator.get_shader(output_index) + func get_shader_code(uv): + return generator.get_shader_code(uv, output_index) + func get_globals(): return generator.get_globals() - -var parameters = null + + func to_str(): + return generator.name+"("+str(output_index)+")" func get_seed(): return 0 diff --git a/addons/material_maker/engine/gen_material.gd b/addons/material_maker/engine/gen_material.gd index 2853e2f..0cc33cb 100644 --- a/addons/material_maker/engine/gen_material.gd +++ b/addons/material_maker/engine/gen_material.gd @@ -2,9 +2,11 @@ tool extends MMGenBase class_name MMGenMaterial +var parameters = {} + var texture_list -var material +var material : SpatialMaterial var generated_textures = {} const TEXTURE_LIST = [ @@ -33,9 +35,15 @@ func _ready(): generated_textures[t.texture] = { shader=null, source=null, texture=null } material = SpatialMaterial.new() -func generate_material(): - print("Generating material") - print(get_source(0).get_shader()) +func generate_material(renderer : MMGenRenderer): + var source = get_source(0) + if source != null: + var shader : String = renderer.generate_shader(source) + var status = renderer.render_shader(shader, {}, 512) + while status is GDScriptFunctionState: + status = yield(status, "completed") + renderer.get_texture().get_data().save_png("res://test.png") + material.albedo_texture = load("res://test.png") return material func initialize(data: Dictionary): diff --git a/addons/material_maker/engine/gen_shader.gd b/addons/material_maker/engine/gen_shader.gd index 8c6c916..42502b4 100644 --- a/addons/material_maker/engine/gen_shader.gd +++ b/addons/material_maker/engine/gen_shader.gd @@ -3,6 +3,7 @@ extends MMGenBase class_name MMGenShader var model_data = null +var parameters = {} var generated_variants = [] func set_model_data(data: Dictionary): @@ -94,6 +95,8 @@ func subst(string, uv = ""): value_string = p.values[value].value elif p.type == "color": value_string = "vec4(%.9f, %.9f, %.9f, %.9f)" % [ value.r, value.g, value.b, value.a ] + elif p.type == "gradient": + value_string = p.name+"_gradient_fct" if value_string != null: string = replace_variable(string, p.name, value_string) if model_data.has("inputs") and typeof(model_data.inputs) == TYPE_ARRAY: @@ -112,8 +115,16 @@ func _get_shader_code(uv, slot = 0): var variant_string = uv+","+str(slot) if model_data != null and model_data.has("outputs") and model_data.outputs.size() > slot: var output = model_data.outputs[slot] + rv.defs = "" if model_data.has("instance") && generated_variants.empty(): - rv.defs = subst(model_data.instance).string + rv.defs += subst(model_data.instance).string + for p in model_data.parameters: + if p.type == "gradient": + var g = parameters[p.name] + if !(g is MMGradient): + g = MMGradient.new() + g.deserialize(parameters[p.name]) + rv.defs += g.get_shader(p.name+"_gradient_fct") var variant_index = generated_variants.find(variant_string) if variant_index == -1: variant_index = generated_variants.size() diff --git a/addons/material_maker/engine/loader.gd b/addons/material_maker/engine/loader.gd index 357c5cc..c85b46b 100644 --- a/addons/material_maker/engine/loader.gd +++ b/addons/material_maker/engine/loader.gd @@ -24,15 +24,18 @@ func create_gen(data) -> MMGenBase: else: generator = MMGenShader.new() if data.type == "custom": - pass + generator.set_model_data(data.model_data) else: var file = File.new() if file.open("res://addons/material_maker/nodes/"+data.type+".mmn", File.READ) == OK: var model_data = parse_json(file.get_as_text()) print("loaded description "+data.type+".mmn") generator.set_model_data(model_data) + file.close() else: print("Cannot find description for "+data.type) + else: + print(data) if generator != null and data.has("parameters"): generator.initialize(data) return generator diff --git a/addons/material_maker/engine/renderer.gd b/addons/material_maker/engine/renderer.gd new file mode 100644 index 0000000..966c603 --- /dev/null +++ b/addons/material_maker/engine/renderer.gd @@ -0,0 +1,92 @@ +tool +extends Viewport +class_name MMGenRenderer + +export(String) var debug_path = null +var debug_file_index : int = 0 + +var rendering : bool = false + +func _ready(): + $ColorRect.material = $ColorRect.material.duplicate(true) + +static func generate_shader(src_code): + var code + code = "shader_type canvas_item;\n" + code += "render_mode blend_disabled;\n" + var file = File.new() + file.open("res://addons/material_maker/common.shader", File.READ) + code += file.get_as_text() + code += "\n" + if src_code.has("globals"): + for g in src_code.globals: + code += g + var shader_code = src_code.defs + shader_code += "void fragment() {\n" + shader_code += src_code.code + shader_code += "COLOR = "+src_code.rgba+";\n" + shader_code += "}\n" + #print("GENERATED SHADER:\n"+shader_code) + code += shader_code + return code + +static func generate_combined_shader(red_code, green_code, blue_code): + var code + code = "shader_type canvas_item;\n" + code += "render_mode blend_disabled;\n" + var file = File.new() + file.open("res://addons/material_maker/common.shader", File.READ) + code += file.get_as_text() + code += "\n" + if red_code.has("globals"): + for g in red_code.globals: + code += g + if green_code.has("globals"): + for g in green_code.globals: + code += g + if blue_code.has("globals"): + for g in blue_code.globals: + code += g + var shader_code = "" + shader_code += red_code.defs + shader_code += green_code.defs + shader_code += blue_code.defs + shader_code += "void fragment() {\n" + shader_code += red_code.code + shader_code += green_code.code + shader_code += blue_code.code + shader_code += "COLOR = vec4("+red_code.f+", "+green_code.f+", "+blue_code.f+", 1.0);\n" + shader_code += "}\n" + #print("GENERATED COMBINED SHADER:\n"+shader_code) + code += shader_code + return code + +func setup_material(shader_material, textures, shader_code): + for k in textures.keys(): + shader_material.set_shader_param(k+"_tex", textures[k]) + shader_material.shader.code = shader_code + +func render_shader(shader, textures, render_size): + if rendering: + return false + rendering = true + if debug_path != null and debug_path != "": + var f = File.new() + f.open(debug_path+str(debug_file_index)+".shader", File.WRITE) + f.store_string(shader) + f.close() + debug_file_index += 1 + size = Vector2(render_size, render_size) + $ColorRect.rect_position = Vector2(0, 0) + $ColorRect.rect_size = size + var shader_material = $ColorRect.material + shader_material.shader.code = shader + if textures != null: + for k in textures.keys(): + shader_material.set_shader_param(k+"_tex", textures[k]) + render_target_update_mode = Viewport.UPDATE_ONCE + update_worlds() + yield(get_tree(), "idle_frame") + yield(get_tree(), "idle_frame") + rendering = false + return true \ No newline at end of file diff --git a/addons/material_maker/engine/renderer.tscn b/addons/material_maker/engine/renderer.tscn new file mode 100644 index 0000000..ab81c35 --- /dev/null +++ b/addons/material_maker/engine/renderer.tscn @@ -0,0 +1,34 @@ +[gd_scene load_steps=4 format=2] + +[ext_resource path="res://addons/material_maker/engine/renderer.gd" type="Script" id=1] + +[sub_resource type="Shader" id=1] +code = "shader_type canvas_item; + +void fragment() { + COLOR = vec4(1.0); +} +" + +[sub_resource type="ShaderMaterial" id=2] +shader = SubResource( 1 ) + +[node name="Renderer" type="Viewport"] +own_world = true +transparent_bg = true +hdr = false +usage = 0 +render_target_v_flip = true +render_target_update_mode = 1 +gui_disable_input = true +script = ExtResource( 1 ) +debug_path = null + +[node name="ColorRect" type="ColorRect" parent="."] +material = SubResource( 2 ) +margin_right = 40.0 +margin_bottom = 40.0 + +[node name="Timer" type="Timer" parent="."] +wait_time = 0.1 +one_shot = true diff --git a/addons/material_maker/graph_edit.gd b/addons/material_maker/graph_edit.gd index 2f86432..17034ae 100644 --- a/addons/material_maker/graph_edit.gd +++ b/addons/material_maker/graph_edit.gd @@ -159,7 +159,7 @@ func do_load_file(filename): file.close() clear_material() for n in data.nodes: - var node = create_nodes(n) + create_nodes(n) for c in data.connections: connect_node(c.from, c.from_port, c.to, c.to_port) set_save_path(filename) diff --git a/addons/material_maker/import_plugin/ptex_import.gd b/addons/material_maker/import_plugin/ptex_import.gd index d92265b..3987b46 100644 --- a/addons/material_maker/import_plugin/ptex_import.gd +++ b/addons/material_maker/import_plugin/ptex_import.gd @@ -42,7 +42,9 @@ func get_visible_name(): return "Material Maker Importer" func import(source_file: String, save_path: String, options: Dictionary, platform_variants: Array, gen_files: Array) -> int: - var material = SpatialMaterial.new() var filename = save_path + "." + get_save_extension() - ResourceSaver.save(filename, plugin.generate_material(source_file)) + var material = plugin.generate_material(source_file) + while material is GDScriptFunctionState: + material = yield(material, "completed") + ResourceSaver.save(filename, material) return OK diff --git a/addons/material_maker/node_base.gd b/addons/material_maker/node_base.gd index 4747384..bfacd22 100644 --- a/addons/material_maker/node_base.gd +++ b/addons/material_maker/node_base.gd @@ -77,6 +77,7 @@ func update_property_widgets(): elif o is ColorPickerButton: o.color = parameters[o.name] elif o is Control and o.filename == "res://addons/material_maker/widgets/gradient_editor.tscn": + print("Updating "+o.name+" = "+str(parameters[o.name].to_string())) o.value = parameters[o.name] else: print("Failed to update "+o.name) diff --git a/addons/material_maker/nodes/adjust_hsv.mmn b/addons/material_maker/nodes/adjust_hsv.mmn index 04f5a6e..ecb72dd 100644 --- a/addons/material_maker/nodes/adjust_hsv.mmn +++ b/addons/material_maker/nodes/adjust_hsv.mmn @@ -1 +1 @@ -{"global":"vec3 rgb_to_hsv(vec3 c) {\n\tvec4 K = vec4(0.0, -1.0 / 3.0, 2.0 / 3.0, -1.0);\n\tvec4 p = c.g < c.b ? vec4(c.bg, K.wz) : vec4(c.gb, K.xy);\n\tvec4 q = c.r < p.x ? vec4(p.xyw, c.r) : vec4(c.r, p.yzx);\n\n\tfloat d = q.x - min(q.w, q.y);\n\tfloat e = 1.0e-10;\n\treturn vec3(abs(q.z + (q.w - q.y) / (6.0 * d + e)), d / (q.x + e), q.x);\n}\n\nvec3 hsv_to_rgb(vec3 c) {\n\tvec4 K = vec4(1.0, 2.0 / 3.0, 1.0 / 3.0, 3.0);\n\tvec3 p = abs(fract(c.xxx + K.xyz) * 6.0 - K.www);\n\treturn c.z * mix(K.xxx, clamp(p - K.xxx, 0.0, 1.0), c.y);\n}\n","inputs":[{"default":"vec3($uv.x, $uv.y, 0.0)","label":"","name":"in","type":"rgb"}],"instance":"vec3 $(name)_f(vec3 c) {\n\tvec3 hsv = rgb_to_hsv(c);\n\treturn hsv_to_rgb(vec3(fract(hsv.x+$(hue)), clamp(hsv.y*$(saturation), 0.0, 1.0), clamp(hsv.z*$(value), 0.0, 1.0)));\n}","name":"AdjustHSV","outputs":[{"rgb":"$(name)_f($in($(uv)))"}],"parameters":[{"default":0,"label":"Hue","max":0.5,"min":-0.5,"name":"hue","step":0,"type":"float"},{"default":1,"label":"Saturation","max":2,"min":0,"name":"saturation","step":0,"type":"float"},{"default":1,"label":"Value","max":2,"min":0,"name":"value","step":0,"type":"float"}]} \ No newline at end of file +{"global":"vec3 rgb_to_hsv(vec3 c) {\n\tvec4 K = vec4(0.0, -1.0 / 3.0, 2.0 / 3.0, -1.0);\n\tvec4 p = c.g < c.b ? vec4(c.bg, K.wz) : vec4(c.gb, K.xy);\n\tvec4 q = c.r < p.x ? vec4(p.xyw, c.r) : vec4(c.r, p.yzx);\n\n\tfloat d = q.x - min(q.w, q.y);\n\tfloat e = 1.0e-10;\n\treturn vec3(abs(q.z + (q.w - q.y) / (6.0 * d + e)), d / (q.x + e), q.x);\n}\n\nvec3 hsv_to_rgb(vec3 c) {\n\tvec4 K = vec4(1.0, 2.0 / 3.0, 1.0 / 3.0, 3.0);\n\tvec3 p = abs(fract(c.xxx + K.xyz) * 6.0 - K.www);\n\treturn c.z * mix(K.xxx, clamp(p - K.xxx, 0.0, 1.0), c.y);\n}\n","inputs":[{"default":"vec4($uv.x, $uv.y, 0.0, 1.0)","label":"","name":"in","type":"rgba"}],"instance":"vec4 $(name)_f(vec4 c) {\n\tvec3 hsv = rgb_to_hsv(c.rgb);\n\treturn vec4(hsv_to_rgb(vec3(fract(hsv.x+$(hue)), clamp(hsv.y*$(saturation), 0.0, 1.0), clamp(hsv.z*$(value), 0.0, 1.0))), c.a);\n}","name":"AdjustHSV","outputs":[{"rgba":"$(name)_f($in($(uv)))"}],"parameters":[{"default":0,"label":"Hue","max":0.5,"min":-0.5,"name":"hue","step":0,"type":"float"},{"default":1,"label":"Saturation","max":2,"min":0,"name":"saturation","step":0,"type":"float"},{"default":1,"label":"Value","max":2,"min":0,"name":"value","step":0,"type":"float"}]} \ No newline at end of file diff --git a/addons/material_maker/nodes/adjust_hsv/adjust_hsv.gd b/addons/material_maker/nodes/adjust_hsv/adjust_hsv.gd deleted file mode 100644 index 714c314..0000000 --- a/addons/material_maker/nodes/adjust_hsv/adjust_hsv.gd +++ /dev/null @@ -1,24 +0,0 @@ -tool -extends "res://addons/material_maker/node_base.gd" - -func _ready(): - initialize_properties([ $HBoxContainer1/hue, $HBoxContainer2/saturation, $HBoxContainer3/value ]) - -func _get_shader_code(uv, output = 0): - var rv = { defs="", code="" } - var src = get_source() - var src_code = { defs="", code="", rgb="vec3(0.0)" } - if src == null: - return rv - src_code = src.get_shader_code(uv) - if generated_variants.empty(): - rv.defs = src_code.defs; - rv.defs += "vec3 %s_rgb(vec3 c) { vec3 hsv = rgb2hsv(c); return hsv2rgb(vec3(fract(hsv.x+%.9f), clamp(hsv.y*%.9f, 0.0, 1.0), clamp(hsv.z*%.9f, 0.0, 1.0))); }\n" % [ name, parameters.hue, parameters.saturation, parameters.value ] - 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 - rv.code += "vec3 %s_%d_rgb = %s_rgb(%s);\n" % [ name, variant_index, name, src_code.rgb ] - rv.rgb = "%s_%d_rgb" % [ name, variant_index ] - return rv diff --git a/addons/material_maker/nodes/adjust_hsv/adjust_hsv.tscn b/addons/material_maker/nodes/adjust_hsv/adjust_hsv.tscn deleted file mode 100644 index 42905b5..0000000 --- a/addons/material_maker/nodes/adjust_hsv/adjust_hsv.tscn +++ /dev/null @@ -1,256 +0,0 @@ -[gd_scene load_steps=3 format=2] - -[ext_resource path="res://addons/material_maker/nodes/adjust_hsv/adjust_hsv.gd" type="Script" id=1] - -[sub_resource type="Theme" id=1] - - -[node name="AdjustHSV" type="GraphNode" index="0"] - -anchor_left = 0.0 -anchor_top = 0.0 -anchor_right = 0.0 -anchor_bottom = 0.0 -margin_top = 1.0 -margin_right = 111.0 -margin_bottom = 74.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 = "AdjustHSV" -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.498039, 0.498039, 1, 1 ) -slot/0/right_enabled = true -slot/0/right_type = 0 -slot/0/right_color = Color( 0.494118, 0.494118, 1, 1 ) -slot/1/left_enabled = false -slot/1/left_type = 0 -slot/1/left_color = Color( 0.756863, 0.756863, 0.756863, 1 ) -slot/1/right_enabled = false -slot/1/right_type = 0 -slot/1/right_color = Color( 0.756863, 0.756863, 0.756863, 1 ) -slot/2/left_enabled = false -slot/2/left_type = 0 -slot/2/left_color = Color( 0.756863, 0.756863, 0.756863, 1 ) -slot/2/right_enabled = false -slot/2/right_type = 0 -slot/2/right_color = Color( 0.756863, 0.756863, 0.756863, 1 ) -script = ExtResource( 1 ) -_sections_unfolded = [ "Theme", "slot", "slot/0", "slot/1", "slot/2" ] - -[node name="HBoxContainer1" type="HBoxContainer" 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 = 184.0 -margin_bottom = 40.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 -alignment = 0 - -[node name="Label" type="Label" parent="HBoxContainer1" index="0"] - -anchor_left = 0.0 -anchor_top = 0.0 -anchor_right = 0.0 -anchor_bottom = 0.0 -margin_top = 1.0 -margin_right = 64.0 -margin_bottom = 15.0 -rect_pivot_offset = Vector2( 0, 0 ) -rect_clip_content = false -mouse_filter = 2 -mouse_default_cursor_shape = 0 -size_flags_horizontal = 3 -size_flags_vertical = 4 -text = "Hue" -percent_visible = 1.0 -lines_skipped = 0 -max_lines_visible = -1 - -[node name="hue" type="HSlider" parent="HBoxContainer1" index="1"] - -anchor_left = 0.0 -anchor_top = 0.0 -anchor_right = 0.0 -anchor_bottom = 0.0 -margin_left = 68.0 -margin_right = 168.0 -margin_bottom = 16.0 -rect_min_size = Vector2( 100, 0 ) -rect_pivot_offset = Vector2( 0, 0 ) -rect_clip_content = false -focus_mode = 2 -mouse_filter = 0 -mouse_default_cursor_shape = 0 -size_flags_horizontal = 1 -size_flags_vertical = 0 -min_value = -0.5 -max_value = 0.5 -step = 0.02 -page = 0.0 -value = 0.0 -exp_edit = false -rounded = false -editable = true -tick_count = 0 -ticks_on_borders = false -focus_mode = 2 -_sections_unfolded = [ "Rect" ] - -[node name="HBoxContainer2" type="HBoxContainer" 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 = 40.0 -margin_right = 184.0 -margin_bottom = 56.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 -alignment = 0 - -[node name="Label" type="Label" parent="HBoxContainer2" index="0"] - -anchor_left = 0.0 -anchor_top = 0.0 -anchor_right = 0.0 -anchor_bottom = 0.0 -margin_top = 1.0 -margin_right = 64.0 -margin_bottom = 15.0 -rect_pivot_offset = Vector2( 0, 0 ) -rect_clip_content = false -mouse_filter = 2 -mouse_default_cursor_shape = 0 -size_flags_horizontal = 3 -size_flags_vertical = 4 -text = "Saturation" -percent_visible = 1.0 -lines_skipped = 0 -max_lines_visible = -1 - -[node name="saturation" type="HSlider" parent="HBoxContainer2" index="1"] - -anchor_left = 0.0 -anchor_top = 0.0 -anchor_right = 0.0 -anchor_bottom = 0.0 -margin_left = 68.0 -margin_right = 168.0 -margin_bottom = 16.0 -rect_min_size = Vector2( 100, 0 ) -rect_pivot_offset = Vector2( 0, 0 ) -rect_clip_content = false -focus_mode = 2 -mouse_filter = 0 -mouse_default_cursor_shape = 0 -size_flags_horizontal = 1 -size_flags_vertical = 0 -min_value = 0.0 -max_value = 2.0 -step = 0.1 -page = 0.0 -value = 1.0 -exp_edit = false -rounded = false -editable = true -tick_count = 0 -ticks_on_borders = false -focus_mode = 2 -_sections_unfolded = [ "Rect" ] - -[node name="HBoxContainer3" type="HBoxContainer" 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 = 57.0 -margin_right = 184.0 -margin_bottom = 73.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 -alignment = 0 - -[node name="Label" type="Label" parent="HBoxContainer3" index="0"] - -anchor_left = 0.0 -anchor_top = 0.0 -anchor_right = 0.0 -anchor_bottom = 0.0 -margin_top = 1.0 -margin_right = 64.0 -margin_bottom = 15.0 -rect_pivot_offset = Vector2( 0, 0 ) -rect_clip_content = false -mouse_filter = 2 -mouse_default_cursor_shape = 0 -size_flags_horizontal = 3 -size_flags_vertical = 4 -text = "Value" -percent_visible = 1.0 -lines_skipped = 0 -max_lines_visible = -1 - -[node name="value" type="HSlider" parent="HBoxContainer3" index="1"] - -anchor_left = 0.0 -anchor_top = 0.0 -anchor_right = 0.0 -anchor_bottom = 0.0 -margin_left = 68.0 -margin_right = 168.0 -margin_bottom = 16.0 -rect_min_size = Vector2( 100, 0 ) -rect_pivot_offset = Vector2( 0, 0 ) -rect_clip_content = false -focus_mode = 2 -mouse_filter = 0 -mouse_default_cursor_shape = 0 -size_flags_horizontal = 1 -size_flags_vertical = 0 -min_value = 0.0 -max_value = 2.0 -step = 0.1 -page = 0.0 -value = 1.0 -exp_edit = false -rounded = false -editable = true -tick_count = 0 -ticks_on_borders = false -focus_mode = 2 -_sections_unfolded = [ "Rect" ] - - diff --git a/addons/material_maker/nodes/blend/blend.tscn b/addons/material_maker/nodes/blend/blend.tscn index 17c3443..acafef4 100644 --- a/addons/material_maker/nodes/blend/blend.tscn +++ b/addons/material_maker/nodes/blend/blend.tscn @@ -4,30 +4,14 @@ [sub_resource type="Theme" id=1] - -[node name="Blend" type="GraphNode" index="0"] - -anchor_left = 0.0 -anchor_top = 0.0 -anchor_right = 0.0 -anchor_bottom = 0.0 +[node name="Blend" type="GraphNode"] margin_left = 1.0 margin_right = 160.0 margin_bottom = 104.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 = "Blend" -offset = Vector2( 0, 0 ) show_close = true -resizable = false -selected = false -comment = false -overlay = 0 slot/0/left_enabled = false slot/0/left_type = 0 slot/0/left_color = Color( 1, 1, 1, 1 ) @@ -53,140 +37,46 @@ slot/3/right_enabled = false slot/3/right_type = 0 slot/3/right_color = Color( 1, 1, 1, 0.501961 ) script = ExtResource( 1 ) -_sections_unfolded = [ "Mouse", "Theme", "slot", "slot/0", "slot/1", "slot/2", "slot/3" ] -[node name="blend_type" type="OptionButton" parent="." index="0"] - -anchor_left = 0.0 -anchor_top = 0.0 -anchor_right = 0.0 -anchor_bottom = 0.0 +[node name="blend_type" type="OptionButton" parent="."] margin_left = 16.0 margin_top = 24.0 margin_right = 143.0 margin_bottom = 44.0 -rect_pivot_offset = Vector2( 0, 0 ) -rect_clip_content = false -focus_mode = 2 -mouse_filter = 0 -mouse_default_cursor_shape = 0 -size_flags_horizontal = 1 -size_flags_vertical = 1 -toggle_mode = false -action_mode = 0 -enabled_focus_mode = 2 -shortcut = null -group = null text = "Normal" -flat = false -align = 0 items = [ "Normal", null, false, 0, null, "Dissolve", null, false, 1, null, "Multiply", null, false, 2, null, "Screen", null, false, 3, null, "Overlay", null, false, 4, null, "Hard Light", null, false, 5, null, "Soft Light", null, false, 6, null, "Burn", null, false, 7, null, "Dodge", null, false, 8, null, "Lighten", null, false, 9, null, "Darken", null, false, 10, null, "Difference", null, false, 11, null ] selected = 0 -[node name="Label1" type="Label" parent="." index="1"] - -anchor_left = 0.0 -anchor_top = 0.0 -anchor_right = 0.0 -anchor_bottom = 0.0 +[node name="Label1" type="Label" parent="."] margin_left = 16.0 margin_top = 44.0 margin_right = 143.0 margin_bottom = 58.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 1" -percent_visible = 1.0 -lines_skipped = 0 -max_lines_visible = -1 -[node name="Label2" type="Label" parent="." index="2"] - -anchor_left = 0.0 -anchor_top = 0.0 -anchor_right = 0.0 -anchor_bottom = 0.0 +[node name="Label2" type="Label" parent="."] margin_left = 16.0 margin_top = 59.0 margin_right = 143.0 margin_bottom = 73.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 2" -percent_visible = 1.0 -lines_skipped = 0 -max_lines_visible = -1 -[node name="HBoxContainer" type="HBoxContainer" parent="." index="3"] - -anchor_left = 0.0 -anchor_top = 0.0 -anchor_right = 0.0 -anchor_bottom = 0.0 +[node name="HBoxContainer" type="HBoxContainer" parent="."] margin_left = 16.0 margin_top = 74.0 margin_right = 143.0 margin_bottom = 98.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 -alignment = 0 -[node name="Label3" type="Label" parent="HBoxContainer" index="0"] - -anchor_left = 0.0 -anchor_top = 0.0 -anchor_right = 0.0 -anchor_bottom = 0.0 +[node name="Label3" type="Label" parent="HBoxContainer"] margin_top = 5.0 margin_right = 49.0 margin_bottom = 19.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 = "Opacity" -percent_visible = 1.0 -lines_skipped = 0 -max_lines_visible = -1 -[node name="amount" type="SpinBox" parent="HBoxContainer" index="1"] - -anchor_left = 0.0 -anchor_top = 0.0 -anchor_right = 0.0 -anchor_bottom = 0.0 +[node name="amount" type="SpinBox" parent="HBoxContainer"] margin_left = 53.0 margin_right = 127.0 margin_bottom = 24.0 -rect_pivot_offset = Vector2( 0, 0 ) -rect_clip_content = false -mouse_filter = 0 -mouse_default_cursor_shape = 0 -size_flags_horizontal = 1 -size_flags_vertical = 1 -min_value = 0.0 max_value = 1.0 step = 0.05 -page = 0.0 value = 0.5 -exp_edit = false -rounded = false -editable = true -prefix = "" -suffix = "" - - diff --git a/addons/material_maker/nodes/colorize.mmn b/addons/material_maker/nodes/colorize.mmn new file mode 100644 index 0000000..f2fd928 --- /dev/null +++ b/addons/material_maker/nodes/colorize.mmn @@ -0,0 +1 @@ +{"global":"","inputs":[{"default":"0.0","label":"Input","name":"input","type":"f"}],"instance":"","name":"Colorize","outputs":[{"rgba":"$gradient($input($uv))"}],"parameters":[{"default":{"points":[{"a":1,"b":0,"g":0,"pos":0,"r":0},{"a":1,"b":1,"g":1,"pos":1,"r":1}],"type":"Gradient"},"label":"","name":"gradient","type":"gradient"}]} \ No newline at end of file diff --git a/addons/material_maker/nodes/colorize/colorize.gd b/addons/material_maker/nodes/colorize/colorize.gd deleted file mode 100644 index e2deaff..0000000 --- a/addons/material_maker/nodes/colorize/colorize.gd +++ /dev/null @@ -1,25 +0,0 @@ -tool -extends "res://addons/material_maker/node_base.gd" - -func _ready(): - initialize_properties([ $gradient ]) - -func _get_shader_code(uv, slot = 0): - var rv = { defs="", code="" } - var src = get_source() - if src == null: - return rv - var src_code = src.get_shader_code(uv) - if generated_variants.empty(): - rv.defs = src_code.defs+parameters.gradient.get_shader("%s_gradient" % name); - 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+"vec4 %s_%d_rgba = %s_gradient(%s);\n" % [ name, variant_index, name, src_code.f ] - rv.rgba = "%s_%d_rgba" % [ name, variant_index ] - return rv - -func _on_Control_updated(v): - parameters.gradient = v - update_shaders() diff --git a/addons/material_maker/nodes/colorize/colorize.tscn b/addons/material_maker/nodes/colorize/colorize.tscn deleted file mode 100644 index 9026162..0000000 --- a/addons/material_maker/nodes/colorize/colorize.tscn +++ /dev/null @@ -1,51 +0,0 @@ -[gd_scene load_steps=4 format=2] - -[ext_resource path="res://addons/material_maker/nodes/colorize/colorize.gd" type="Script" id=1] -[ext_resource path="res://addons/material_maker/widgets/gradient_editor.tscn" type="PackedScene" id=2] - -[sub_resource type="Theme" id=1] - - -[node name="Colorize" 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 = 4.0 -margin_right = 133.0 -margin_bottom = 72.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 = "Colorize" -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.756863, 0.756863, 0.756863, 1 ) -slot/0/right_enabled = true -slot/0/right_type = 0 -slot/0/right_color = Color( 0, 1, 0, 0.502745 ) -script = ExtResource( 1 ) -_sections_unfolded = [ "Theme", "slot", "slot/0" ] - -[node name="gradient" parent="." index="0" instance=ExtResource( 2 )] - -margin_left = 16.0 -margin_top = 24.0 -margin_right = 136.0 -margin_bottom = 54.0 - -[connection signal="updated" from="gradient" to="." method="_on_Control_updated"] - - diff --git a/addons/material_maker/nodes/custom/custom.tscn b/addons/material_maker/nodes/custom/custom.tscn index 407d493..20f190a 100644 --- a/addons/material_maker/nodes/custom/custom.tscn +++ b/addons/material_maker/nodes/custom/custom.tscn @@ -6,28 +6,13 @@ [ext_resource path="res://addons/material_maker/icons/save.png" type="Texture" id=4] [node name="Custom" type="GraphNode"] - -anchor_left = 0.0 -anchor_top = 0.0 -anchor_right = 0.0 -anchor_bottom = 0.0 margin_left = 1.0 margin_top = 2.0 margin_right = 95.0 margin_bottom = 53.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 title = "Custom" -offset = Vector2( 0, 0 ) show_close = true -resizable = false -selected = false -comment = false -overlay = 0 slot/0/left_enabled = false slot/0/left_type = 0 slot/0/left_color = Color( 1, 1, 1, 1 ) @@ -37,99 +22,31 @@ slot/0/right_color = Color( 1, 1, 1, 1 ) script = ExtResource( 1 ) model = null -[node name="CustomNodeButtons" type="HBoxContainer" parent="." index="0"] - -anchor_left = 0.0 -anchor_top = 0.0 -anchor_right = 0.0 -anchor_bottom = 0.0 +[node name="CustomNodeButtons" type="HBoxContainer" parent="."] margin_left = 16.0 margin_top = 24.0 margin_right = 107.0 margin_bottom = 46.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 -alignment = 0 -[node name="Edit" type="Button" parent="CustomNodeButtons" index="0"] - -anchor_left = 0.0 -anchor_top = 0.0 -anchor_right = 0.0 -anchor_bottom = 0.0 +[node name="Edit" type="Button" parent="CustomNodeButtons"] margin_right = 27.0 margin_bottom = 22.0 -rect_pivot_offset = Vector2( 0, 0 ) -rect_clip_content = false -focus_mode = 2 -mouse_filter = 0 -mouse_default_cursor_shape = 0 -size_flags_horizontal = 1 -size_flags_vertical = 1 -toggle_mode = false -enabled_focus_mode = 2 -shortcut = null -group = null icon = ExtResource( 2 ) flat = true -align = 1 -[node name="Load" type="Button" parent="CustomNodeButtons" index="1"] - -anchor_left = 0.0 -anchor_top = 0.0 -anchor_right = 0.0 -anchor_bottom = 0.0 +[node name="Load" type="Button" parent="CustomNodeButtons"] margin_left = 31.0 margin_right = 59.0 margin_bottom = 22.0 -rect_pivot_offset = Vector2( 0, 0 ) -rect_clip_content = false -focus_mode = 2 -mouse_filter = 0 -mouse_default_cursor_shape = 0 -size_flags_horizontal = 1 -size_flags_vertical = 1 -toggle_mode = false -enabled_focus_mode = 2 -shortcut = null -group = null icon = ExtResource( 3 ) flat = true -align = 1 -[node name="Save" type="Button" parent="CustomNodeButtons" index="2"] - -anchor_left = 0.0 -anchor_top = 0.0 -anchor_right = 0.0 -anchor_bottom = 0.0 +[node name="Save" type="Button" parent="CustomNodeButtons"] margin_left = 63.0 margin_right = 91.0 margin_bottom = 22.0 -rect_pivot_offset = Vector2( 0, 0 ) -rect_clip_content = false -focus_mode = 2 -mouse_filter = 0 -mouse_default_cursor_shape = 0 -size_flags_horizontal = 1 -size_flags_vertical = 1 -toggle_mode = false -enabled_focus_mode = 2 -shortcut = null -group = null icon = ExtResource( 4 ) flat = true -align = 1 - [connection signal="pressed" from="CustomNodeButtons/Edit" to="." method="_on_Edit_pressed"] - [connection signal="pressed" from="CustomNodeButtons/Load" to="." method="_on_Load_pressed"] - [connection signal="pressed" from="CustomNodeButtons/Save" to="." method="_on_Save_pressed"] - - diff --git a/addons/material_maker/nodes/node_generic.gd b/addons/material_maker/nodes/node_generic.gd index ee97367..4af631b 100644 --- a/addons/material_maker/nodes/node_generic.gd +++ b/addons/material_maker/nodes/node_generic.gd @@ -31,6 +31,7 @@ func set_model(m): print("set_model error "+str(m)) func update_node(data): + print("node_generic.update_node") if typeof(data) != TYPE_DICTIONARY: return if !data.has("name"): @@ -85,6 +86,8 @@ func update_node(data): control = CheckBox.new() elif p.type == "color": control = ColorPickerButton.new() + elif p.type == "gradient": + control = preload("res://addons/material_maker/widgets/gradient_editor.tscn").instance() if control != null: var label = p.name control.name = label @@ -222,6 +225,8 @@ func subst(string, uv = ""): value_string = p.values[value].value elif p.type == "color": value_string = "vec4(%.9f, %.9f, %.9f, %.9f)" % [ value.r, value.g, value.b, value.a ] + elif p.type == "gradient": + value_string = p.name+"_gradient_fct" if value_string != null: string = replace_variable(string, p.name, value_string) if model_data.has("inputs") and typeof(model_data.inputs) == TYPE_ARRAY: @@ -240,8 +245,12 @@ func _get_shader_code(uv, slot = 0): var variant_string = uv+","+str(slot) if model_data != null and model_data.has("outputs") and model_data.outputs.size() > slot: var output = model_data.outputs[slot] + rv.defs = "" if model_data.has("instance") && generated_variants.empty(): - rv.defs = subst(model_data.instance).string + rv.defs += subst(model_data.instance).string + for p in model_data.parameters: + if p.type == "gradient": + rv.defs += parameters[p.name].get_shader(p.name+"_gradient_fct") var variant_index = generated_variants.find(variant_string) if variant_index == -1: variant_index = generated_variants.size() diff --git a/addons/material_maker/plugin.cfg b/addons/material_maker/plugin.cfg index b7abdb3..27726c0 100644 --- a/addons/material_maker/plugin.cfg +++ b/addons/material_maker/plugin.cfg @@ -3,5 +3,5 @@ name="MaterialMaker" description="Procedural Material creation tool" author="RodZilla" -version="0.5" +version="0.6" script="plugin.gd" diff --git a/addons/material_maker/plugin.gd b/addons/material_maker/plugin.gd index 5260dc2..95c143e 100644 --- a/addons/material_maker/plugin.gd +++ b/addons/material_maker/plugin.gd @@ -4,11 +4,14 @@ extends EditorPlugin var mm_button = null var material_maker = null var importer = null +var renderer = null func _enter_tree(): add_tool_menu_item("Material Maker", self, "open_material_maker") importer = preload("res://addons/material_maker/import_plugin/ptex_import.gd").new(self) add_import_plugin(importer) + renderer = preload("res://addons/material_maker/engine/renderer.tscn").instance() + add_child(renderer) func _exit_tree(): remove_tool_menu_item("Material Maker") @@ -48,4 +51,4 @@ func generate_material(ptex_filename: String) -> Material: var generator = loader.load_gen(ptex_filename) add_child(generator) var material = generator.get_node("Material") - return material.generate_material() + return material.generate_material(renderer) diff --git a/addons/material_maker/renderer.tscn b/addons/material_maker/renderer.tscn index 49f0def..f5f08de 100644 --- a/addons/material_maker/renderer.tscn +++ b/addons/material_maker/renderer.tscn @@ -3,7 +3,6 @@ [ext_resource path="res://addons/material_maker/renderer.gd" type="Script" id=1] [sub_resource type="Shader" id=1] - code = "shader_type canvas_item; void fragment() { @@ -12,61 +11,24 @@ void fragment() { " [sub_resource type="ShaderMaterial" id=2] - -render_priority = 0 shader = SubResource( 1 ) -[node name="Renderer" type="Viewport" index="0"] - -arvr = false -size = Vector2( 0, 0 ) +[node name="Renderer" type="Viewport"] own_world = true -world = null transparent_bg = true msaa = 2 hdr = false -disable_3d = false -usage = 2 -debug_draw = 0 render_target_v_flip = true -render_target_clear_mode = 0 render_target_update_mode = 1 -audio_listener_enable_2d = false -audio_listener_enable_3d = false -physics_object_picking = false gui_disable_input = true -gui_snap_controls_to_pixels = true -shadow_atlas_size = 0 -shadow_atlas_quad_0 = 2 -shadow_atlas_quad_1 = 2 -shadow_atlas_quad_2 = 3 -shadow_atlas_quad_3 = 4 script = ExtResource( 1 ) -_sections_unfolded = [ "GUI", "Render Target", "Rendering" ] - -[node name="ColorRect" type="ColorRect" parent="." index="0"] +debug_path = null +[node name="ColorRect" type="ColorRect" parent="."] material = SubResource( 2 ) -anchor_left = 0.0 -anchor_top = 0.0 -anchor_right = 0.0 -anchor_bottom = 0.0 margin_right = 40.0 margin_bottom = 40.0 -rect_pivot_offset = Vector2( 0, 0 ) -rect_clip_content = false -mouse_filter = 0 -mouse_default_cursor_shape = 0 -size_flags_horizontal = 1 -size_flags_vertical = 1 -color = Color( 1, 1, 1, 1 ) -_sections_unfolded = [ "Material", "Rect" ] -[node name="Timer" type="Timer" parent="." index="1"] - -process_mode = 1 +[node name="Timer" type="Timer" parent="."] wait_time = 0.1 one_shot = true -autostart = false - - diff --git a/addons/material_maker/types/gradient.gd b/addons/material_maker/types/gradient.gd index 1dc72d5..894e20e 100644 --- a/addons/material_maker/types/gradient.gd +++ b/addons/material_maker/types/gradient.gd @@ -1,4 +1,5 @@ extends Object +class_name MMGradient class CustomSorter: static func compare(a, b): @@ -10,6 +11,12 @@ var sorted = true func _ready(): pass +func to_string(): + var rv = PoolStringArray() + for p in points: + rv.append("("+str(p.v)+","+str(p.c)+")") + return rv.join(",") + func duplicate(): var copy = get_script().new() copy.clear() diff --git a/addons/material_maker/widgets/gradient_editor.gd b/addons/material_maker/widgets/gradient_editor.gd index 8b4c463..9c209fc 100644 --- a/addons/material_maker/widgets/gradient_editor.gd +++ b/addons/material_maker/widgets/gradient_editor.gd @@ -43,13 +43,11 @@ class GradientCursor: var value = null setget set_value -const Gradient = preload("res://addons/material_maker/types/gradient.gd") - -signal updated +signal updated(value) func _ready(): $Gradient.material = $Gradient.material.duplicate(true) - set_value(Gradient.new()) + set_value(MMGradient.new()) func set_value(v): value = v @@ -58,6 +56,7 @@ func set_value(v): remove_child(c) c.free() for p in value.points: + print(p) add_cursor(p.v*(rect_size.x-GradientCursor.WIDTH), p.c) update_shader() diff --git a/addons/material_maker/widgets/node_editor/parameter.tscn b/addons/material_maker/widgets/node_editor/parameter.tscn index 906ee9a..71b5cfe 100644 --- a/addons/material_maker/widgets/node_editor/parameter.tscn +++ b/addons/material_maker/widgets/node_editor/parameter.tscn @@ -1,4 +1,4 @@ -[gd_scene load_steps=8 format=2] +[gd_scene load_steps=9 format=2] [ext_resource path="res://addons/material_maker/widgets/node_editor/parameter.gd" type="Script" id=1] [ext_resource path="res://addons/material_maker/icons/minus.png" type="Texture" id=2] @@ -7,172 +7,72 @@ [ext_resource path="res://addons/material_maker/widgets/node_editor/parameter_enum.tscn" type="PackedScene" id=5] [ext_resource path="res://addons/material_maker/widgets/node_editor/parameter_boolean.tscn" type="PackedScene" id=6] [ext_resource path="res://addons/material_maker/widgets/node_editor/parameter_color.tscn" type="PackedScene" id=7] +[ext_resource path="res://addons/material_maker/widgets/node_editor/parameter_gradient.tscn" type="PackedScene" id=8] -[node name="Parameter" type="HBoxContainer" index="0"] - -anchor_left = 0.0 -anchor_top = 0.0 -anchor_right = 0.0 -anchor_bottom = 0.0 +[node name="Parameter" type="HBoxContainer"] margin_right = 201.0 margin_bottom = 24.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 -alignment = 0 script = ExtResource( 1 ) -[node name="Delete" type="Button" parent="." index="0"] - -anchor_left = 0.0 -anchor_top = 0.0 -anchor_right = 0.0 -anchor_bottom = 0.0 +[node name="Delete" type="Button" parent="."] margin_right = 28.0 -margin_bottom = 24.0 -rect_pivot_offset = Vector2( 0, 0 ) -rect_clip_content = false -focus_mode = 2 -mouse_filter = 0 -mouse_default_cursor_shape = 0 -size_flags_horizontal = 1 -size_flags_vertical = 1 -toggle_mode = false -enabled_focus_mode = 2 -shortcut = null -group = null +margin_bottom = 30.0 icon = ExtResource( 2 ) flat = true -align = 1 -[node name="Name" type="LineEdit" parent="." index="1"] - -anchor_left = 0.0 -anchor_top = 0.0 -anchor_right = 0.0 -anchor_bottom = 0.0 +[node name="Name" type="LineEdit" parent="."] margin_left = 32.0 margin_right = 102.0 -margin_bottom = 24.0 +margin_bottom = 30.0 rect_min_size = Vector2( 70, 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 = "name" -focus_mode = 2 -context_menu_enabled = true -placeholder_alpha = 0.6 -caret_blink = false -caret_blink_speed = 0.65 -caret_position = 0 -_sections_unfolded = [ "Rect" ] -[node name="Label" type="LineEdit" parent="." index="2"] - -anchor_left = 0.0 -anchor_top = 0.0 -anchor_right = 0.0 -anchor_bottom = 0.0 +[node name="Label" type="LineEdit" parent="."] margin_left = 106.0 margin_right = 176.0 -margin_bottom = 24.0 +margin_bottom = 30.0 rect_min_size = Vector2( 70, 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 = "Label" -focus_mode = 2 -context_menu_enabled = true -placeholder_alpha = 0.6 -caret_blink = false -caret_blink_speed = 0.65 -caret_position = 0 -_sections_unfolded = [ "Rect" ] -[node name="Type" type="OptionButton" parent="." index="3"] - -anchor_left = 0.0 -anchor_top = 0.0 -anchor_right = 0.0 -anchor_bottom = 0.0 +[node name="Type" type="OptionButton" parent="."] margin_left = 180.0 -margin_right = 247.0 -margin_bottom = 24.0 -rect_pivot_offset = Vector2( 0, 0 ) -rect_clip_content = false -focus_mode = 2 -mouse_filter = 0 -mouse_default_cursor_shape = 0 -size_flags_horizontal = 1 -size_flags_vertical = 1 -toggle_mode = false -action_mode = 0 -enabled_focus_mode = 2 -shortcut = null -group = null +margin_right = 249.0 +margin_bottom = 30.0 text = "float" -flat = false -align = 0 -items = [ "float", null, false, -1, null, "size", null, false, -1, null, "enum", null, false, -1, null, "boolean", null, false, -1, null ] +items = [ "float", null, false, -1, null, "size", null, false, -1, null, "enum", null, false, -1, null, "boolean", null, false, -1, null, "color", null, false, -1, null ] selected = 0 -[node name="Types" type="HBoxContainer" parent="." index="4"] +[node name="Types" type="HBoxContainer" parent="."] +margin_left = 253.0 +margin_right = 800.0 +margin_bottom = 30.0 -anchor_left = 0.0 -anchor_top = 0.0 -anchor_right = 0.0 -anchor_bottom = 0.0 -margin_left = 251.0 -margin_right = 251.0 -margin_bottom = 24.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 -alignment = 0 - -[node name="float" parent="Types" index="0" instance=ExtResource( 3 )] - -visible = false - -[node name="size" parent="Types" index="1" instance=ExtResource( 4 )] +[node name="float" parent="Types" instance=ExtResource( 3 )] +margin_bottom = 30.0 +[node name="size" parent="Types" instance=ExtResource( 4 )] visible = false margin_left = 551.0 margin_right = 796.0 -[node name="enum" parent="Types" index="2" instance=ExtResource( 5 )] - +[node name="enum" parent="Types" instance=ExtResource( 5 )] visible = false margin_left = 800.0 margin_right = 839.0 -[node name="boolean" parent="Types" index="3" instance=ExtResource( 6 )] - +[node name="boolean" parent="Types" instance=ExtResource( 6 )] margin_left = 843.0 margin_right = 917.0 -[node name="color" parent="Types" index="4" instance=ExtResource( 7 )] - +[node name="color" parent="Types" instance=ExtResource( 7 )] visible = false margin_left = 551.0 margin_right = 563.0 +[node name="gradient" parent="Types" instance=ExtResource( 8 )] +visible = false +margin_left = 551.0 +margin_right = 725.0 +margin_bottom = 30.0 [connection signal="pressed" from="Delete" to="." method="_on_Delete_pressed"] - [connection signal="item_selected" from="Type" to="." method="_on_Type_item_selected"] - - diff --git a/addons/material_maker/widgets/node_editor/parameter_enum.gd b/addons/material_maker/widgets/node_editor/parameter_enum.gd index efa3a4a..b89e6eb 100644 --- a/addons/material_maker/widgets/node_editor/parameter_enum.gd +++ b/addons/material_maker/widgets/node_editor/parameter_enum.gd @@ -21,7 +21,10 @@ func get_model_data(): func set_model_data(data): enum_values = data.values.duplicate() - enum_current = data.default + if data.has("default"): + enum_current = data.default + else: + enum_current = 0 update_enum_list() func update_enum_list(): diff --git a/addons/material_maker/widgets/node_editor/parameter_gradient.gd b/addons/material_maker/widgets/node_editor/parameter_gradient.gd new file mode 100644 index 0000000..813a794 --- /dev/null +++ b/addons/material_maker/widgets/node_editor/parameter_gradient.gd @@ -0,0 +1,18 @@ +tool +extends HBoxContainer + +onready var default = $Default + +func _ready(): + pass + +func get_model_data(): + var data = {} + data.default = default.value.serialize() + return data + +func set_model_data(data): + if data.has("default"): + var v = MMGradient.new() + v.deserialize(data.default) + default.value = v diff --git a/addons/material_maker/widgets/node_editor/parameter_gradient.tscn b/addons/material_maker/widgets/node_editor/parameter_gradient.tscn new file mode 100644 index 0000000..c42e3e9 --- /dev/null +++ b/addons/material_maker/widgets/node_editor/parameter_gradient.tscn @@ -0,0 +1,19 @@ +[gd_scene load_steps=3 format=2] + +[ext_resource path="res://addons/material_maker/widgets/node_editor/parameter_gradient.gd" type="Script" id=1] +[ext_resource path="res://addons/material_maker/widgets/gradient_editor.tscn" type="PackedScene" id=2] + +[node name="gradient" type="HBoxContainer"] +margin_right = 148.0 +margin_bottom = 24.0 +script = ExtResource( 1 ) + +[node name="LabelDefault" type="Label" parent="."] +margin_top = 8.0 +margin_right = 50.0 +margin_bottom = 22.0 +text = "Default:" + +[node name="Default" parent="." instance=ExtResource( 2 )] +margin_left = 54.0 +margin_right = 174.0 diff --git a/project.godot b/project.godot index 4dc1aa7..5c9962d 100644 --- a/project.godot +++ b/project.godot @@ -39,10 +39,20 @@ _global_script_classes=[ { "language": "GDScript", "path": "res://addons/material_maker/engine/gen_material.gd" }, { +"base": "Viewport", +"class": "MMGenRenderer", +"language": "GDScript", +"path": "res://addons/material_maker/engine/renderer.gd" +}, { "base": "MMGenBase", "class": "MMGenShader", "language": "GDScript", "path": "res://addons/material_maker/engine/gen_shader.gd" +}, { +"base": "Object", +"class": "MMGradient", +"language": "GDScript", +"path": "res://addons/material_maker/types/gradient.gd" } ] _global_script_class_icons={ "MMGenBase": "", @@ -51,7 +61,9 @@ _global_script_class_icons={ "MMGenGraph": "", "MMGenLoader": "", "MMGenMaterial": "", -"MMGenShader": "" +"MMGenRenderer": "", +"MMGenShader": "", +"MMGradient": "" } [application] From 57c28993db021e60ab3528f87443a02dbc500366 Mon Sep 17 00:00:00 2001 From: Rodolphe Suescun Date: Mon, 12 Aug 2019 15:58:42 +0200 Subject: [PATCH 004/133] Refactored basic load and preview functions in graph editor --- addons/material_maker/engine/gen_base.gd | 48 ++- addons/material_maker/engine/gen_context.gd | 17 + addons/material_maker/engine/gen_material.gd | 5 +- addons/material_maker/engine/gen_shader.gd | 21 +- addons/material_maker/engine/loader.gd | 35 +- addons/material_maker/graph_edit.gd | 66 ++- addons/material_maker/graph_edit.tscn | 42 +- addons/material_maker/main_window.gd | 39 +- addons/material_maker/main_window.tscn | 8 +- addons/material_maker/new.ptex | 1 + addons/material_maker/node_factory.gd | 2 +- .../nodes/{custom => }/custom.gd | 0 .../nodes/{custom => }/custom.tscn | 2 +- addons/material_maker/nodes/generic.gd | 134 ++++++ addons/material_maker/nodes/generic.tscn | 10 + .../nodes/{material => }/material.gd | 2 + .../nodes/{material => }/material.tscn | 28 +- addons/material_maker/preview.gd | 6 +- addons/material_maker/preview.tscn | 401 ++---------------- addons/material_maker/window_dialog.tscn | 16 +- export_presets.cfg | 10 + project.godot | 6 + 22 files changed, 341 insertions(+), 558 deletions(-) create mode 100644 addons/material_maker/engine/gen_context.gd create mode 100644 addons/material_maker/new.ptex rename addons/material_maker/nodes/{custom => }/custom.gd (100%) rename addons/material_maker/nodes/{custom => }/custom.tscn (94%) create mode 100644 addons/material_maker/nodes/generic.gd create mode 100644 addons/material_maker/nodes/generic.tscn rename addons/material_maker/nodes/{material => }/material.gd (99%) rename addons/material_maker/nodes/{material => }/material.tscn (99%) diff --git a/addons/material_maker/engine/gen_base.gd b/addons/material_maker/engine/gen_base.gd index dbbf966..b7f818f 100644 --- a/addons/material_maker/engine/gen_base.gd +++ b/addons/material_maker/engine/gen_base.gd @@ -22,9 +22,15 @@ class OutputPort: func to_str(): return generator.name+"("+str(output_index)+")" +var position : Vector2 = Vector2(0, 0) +var parameters = {} + func get_seed(): return 0 +func get_type(): + return "generic" + func get_source(input_index : int): return get_parent().get_port_source(name, input_index) @@ -33,8 +39,8 @@ func get_input_shader(input_index : int): if source != null: return source.get_shader() -func get_shader(output_index : int): - return get_shader_code("UV", output_index); +func get_shader(output_index : int, context = MMGenContext.new()): + return get_shader_code("UV", output_index, context); # this will need an output index for switch func get_globals(): @@ -48,25 +54,25 @@ func get_globals(): list.append(g) return list -func get_shader_code(uv, slot = 0): - var rv - rv = _get_shader_code(uv, slot) - if !rv.has("f"): - if rv.has("rgb"): - rv.f = "(dot("+rv.rgb+", vec3(1.0))/3.0)" - elif rv.has("rgba"): - rv.f = "(dot("+rv.rgba+".rgb, vec3(1.0))/3.0)" - else: - rv.f = "0.0" - if !rv.has("rgb"): - if rv.has("rgba"): - rv.rgb = rv.rgba+".rgb" - else: - rv.rgb = "vec3("+rv.f+")" - if !rv.has("rgba"): - rv.rgba = "vec4("+rv.rgb+", 1.0)" - rv.globals = get_globals() +func get_shader_code(uv, slot = 0, context = MMGenContext.new()): + var rv = _get_shader_code(uv, slot, context) + if rv != null: + if !rv.has("f"): + if rv.has("rgb"): + rv.f = "(dot("+rv.rgb+", vec3(1.0))/3.0)" + elif rv.has("rgba"): + rv.f = "(dot("+rv.rgba+".rgb, vec3(1.0))/3.0)" + else: + rv.f = "0.0" + if !rv.has("rgb"): + if rv.has("rgba"): + rv.rgb = rv.rgba+".rgb" + else: + rv.rgb = "vec3("+rv.f+")" + if !rv.has("rgba"): + rv.rgba = "vec4("+rv.rgb+", 1.0)" + rv.globals = get_globals() return rv -func _get_shader_code(uv : String, output_index : int): +func _get_shader_code(uv : String, output_index : int, context = MMGenContext.new()): return null diff --git a/addons/material_maker/engine/gen_context.gd b/addons/material_maker/engine/gen_context.gd new file mode 100644 index 0000000..7555d1a --- /dev/null +++ b/addons/material_maker/engine/gen_context.gd @@ -0,0 +1,17 @@ +extends Object +class_name MMGenContext + +var variants : Dictionary = {} + +func has_variant(generator): + return variants.has(generator) + +func get_variant(generator, uv): + var rv = -1 + if variants.has(generator): + rv = variants[generator].find(uv) + if rv == -1: + variants[generator].push(uv) + else: + variants[generator] = [uv] + return rv diff --git a/addons/material_maker/engine/gen_material.gd b/addons/material_maker/engine/gen_material.gd index 0cc33cb..c071ed0 100644 --- a/addons/material_maker/engine/gen_material.gd +++ b/addons/material_maker/engine/gen_material.gd @@ -2,8 +2,6 @@ tool extends MMGenBase class_name MMGenMaterial -var parameters = {} - var texture_list var material : SpatialMaterial @@ -27,6 +25,9 @@ const ADDON_TEXTURE_LIST = [ { port=6, texture="depth_map" } ] +func get_type(): + return "material" + func _ready(): texture_list = TEXTURE_LIST if Engine.editor_hint: diff --git a/addons/material_maker/engine/gen_shader.gd b/addons/material_maker/engine/gen_shader.gd index 42502b4..93947ba 100644 --- a/addons/material_maker/engine/gen_shader.gd +++ b/addons/material_maker/engine/gen_shader.gd @@ -3,7 +3,6 @@ extends MMGenBase class_name MMGenShader var model_data = null -var parameters = {} var generated_variants = [] func set_model_data(data: Dictionary): @@ -32,7 +31,7 @@ func find_keyword_call(string, keyword): parenthesis_level -= 1 return "" -func replace_input(string, input, type, src, default): +func replace_input(string, context, input, type, src, default): var required_defs = "" var required_code = "" while true: @@ -74,7 +73,7 @@ func replace_variable(string, variable, value): string = string.right(keyword_size) return new_string -func subst(string, uv = ""): +func subst(string, context, uv = ""): var required_defs = "" var required_code = "" string = replace_variable(string, "name", name) @@ -103,21 +102,23 @@ func subst(string, uv = ""): for i in range(model_data.inputs.size()): var input = model_data.inputs[i] var source = get_source(i) - var result = replace_input(string, input.name, input.type, source, input.default) + var result = replace_input(string, context, input.name, input.type, source, input.default) string = result.string required_defs += result.defs required_code += result.code return { string=string, defs=required_defs, code=required_code } -func _get_shader_code(uv, slot = 0): +func _get_shader_code(uv, slot = 0, context = MMGenContext.new()): + if context == null: + context = {} var output_info = [ { field="rgba", type="vec4" }, { field="rgb", type="vec3" }, { field="f", type="float" } ] var rv = { defs="", code="" } var variant_string = uv+","+str(slot) if model_data != null and model_data.has("outputs") and model_data.outputs.size() > slot: var output = model_data.outputs[slot] rv.defs = "" - if model_data.has("instance") && generated_variants.empty(): - rv.defs += subst(model_data.instance).string + if model_data.has("instance") && !context.has_variant(self): + rv.defs += subst(model_data.instance, context).string for p in model_data.parameters: if p.type == "gradient": var g = parameters[p.name] @@ -125,13 +126,13 @@ func _get_shader_code(uv, slot = 0): g = MMGradient.new() g.deserialize(parameters[p.name]) rv.defs += g.get_shader(p.name+"_gradient_fct") - var variant_index = generated_variants.find(variant_string) + var variant_index = context.get_variant(self, variant_string) if variant_index == -1: - variant_index = generated_variants.size() + variant_index = context.get_variant(self, variant_string) generated_variants.append(variant_string) for t in output_info: if output.has(t.field): - var subst_output = subst(output[t.field], uv) + var subst_output = subst(output[t.field], context, uv) rv.defs += subst_output.defs rv.code += subst_output.code rv.code += "%s %s_%d_%d_%s = %s;\n" % [ t.type, name, slot, variant_index, t.field, subst_output.string ] diff --git a/addons/material_maker/engine/loader.gd b/addons/material_maker/engine/loader.gd index c85b46b..64adda6 100644 --- a/addons/material_maker/engine/loader.gd +++ b/addons/material_maker/engine/loader.gd @@ -18,24 +18,33 @@ func create_gen(data) -> MMGenBase: if g != null: generator.add_child(g) generator.connections = data.connections + elif data.has("model_data"): + generator = MMGenShader.new() + generator.set_model_data(data.model_data) elif data.has("type"): if data.type == "material": generator = MMGenMaterial.new() else: - generator = MMGenShader.new() - if data.type == "custom": - generator.set_model_data(data.model_data) + var file = File.new() + if file.open("res://addons/material_maker/library/"+data.type+".mml", File.READ) == OK: + var model_data = parse_json(file.get_as_text()) + print("loaded description "+data.type+".mml") + generator = create_gen(model_data) + file.close() + elif file.open("res://addons/material_maker/nodes/"+data.type+".mmn", File.READ) == OK: + generator = MMGenShader.new() + var model_data = parse_json(file.get_as_text()) + print("loaded description "+data.type+".mmn") + generator.set_model_data(model_data) + file.close() else: - var file = File.new() - if file.open("res://addons/material_maker/nodes/"+data.type+".mmn", File.READ) == OK: - var model_data = parse_json(file.get_as_text()) - print("loaded description "+data.type+".mmn") - generator.set_model_data(model_data) - file.close() - else: - print("Cannot find description for "+data.type) + print("Cannot find description for "+data.type) else: print(data) - if generator != null and data.has("parameters"): - generator.initialize(data) + if generator != null: + if data.has("node_position"): + generator.position.x = data.node_position.x + generator.position.y = data.node_position.y + if data.has("parameters"): + generator.initialize(data) return generator diff --git a/addons/material_maker/graph_edit.gd b/addons/material_maker/graph_edit.gd index 17034ae..c1e1572 100644 --- a/addons/material_maker/graph_edit.gd +++ b/addons/material_maker/graph_edit.gd @@ -5,9 +5,11 @@ var editor_interface = null var node_factory = null var renderer = null -var save_path = null +var save_path = null setget set_save_path var need_save = false +var generator = null + signal save_path_changed signal graph_changed @@ -141,48 +143,28 @@ func create_nodes(data, position = null): connect_node(names[c.from], c.from_port, "Material" if c.to == "Material" else names[c.to], c.to_port) return null -func load_file(): - var dialog = FileDialog.new() - add_child(dialog) - dialog.rect_min_size = Vector2(500, 500) - dialog.access = FileDialog.ACCESS_FILESYSTEM - dialog.mode = FileDialog.MODE_OPEN_FILE - dialog.add_filter("*.ptex;Procedural textures file") - dialog.connect("file_selected", self, "do_load_file") - dialog.popup_centered() - -func do_load_file(filename): - var file = File.new() - if file.open(filename, File.READ) != OK: - return - var data = parse_json(file.get_as_text()) - file.close() +func load_file(filename): clear_material() - for n in data.nodes: - create_nodes(n) - for c in data.connections: - connect_node(c.from, c.from_port, c.to, c.to_port) - set_save_path(filename) - set_need_save(false) - center_view() + var loader = MMGenLoader.new() + generator = loader.load_gen(filename) + if generator != null: + add_child(generator) + for g in generator.get_children(): + print(g.get_type()) + var node = node_factory.create_node(g.get_type()) + if node != null: + node.name = "node_"+g.name + add_node(node) + node.generator = g + node.offset = g.position + if generator.get("connections") != null: + for c in generator.connections: + .connect_node("node_"+c.from, c.from_port, "node_"+c.to, c.to_port) + set_save_path(filename) + set_need_save(false) + center_view() -func save_file(): - if save_path != null: - do_save_file(save_path) - else: - save_file_as() - -func save_file_as(): - var dialog = FileDialog.new() - add_child(dialog) - dialog.rect_min_size = Vector2(500, 500) - dialog.access = FileDialog.ACCESS_FILESYSTEM - dialog.mode = FileDialog.MODE_SAVE_FILE - dialog.add_filter("*.ptex;Procedural textures file") - dialog.connect("file_selected", self, "do_save_file") - dialog.popup_centered() - -func do_save_file(filename): +func save_file(filename): var data = { nodes = [] } for c in get_children(): if c is GraphNode: @@ -270,7 +252,7 @@ func center_view(): func send_changed_signal(): set_need_save(true) - $Timer.start() + #$Timer.start() func do_send_changed_signal(): emit_signal("graph_changed") diff --git a/addons/material_maker/graph_edit.tscn b/addons/material_maker/graph_edit.tscn index 3d9f9ed..f00404f 100644 --- a/addons/material_maker/graph_edit.tscn +++ b/addons/material_maker/graph_edit.tscn @@ -1,54 +1,30 @@ [gd_scene load_steps=4 format=2] [ext_resource path="res://addons/material_maker/graph_edit.gd" type="Script" id=1] -[ext_resource path="res://addons/material_maker/nodes/material/material.tscn" type="PackedScene" id=2] +[ext_resource path="res://addons/material_maker/nodes/material.tscn" type="PackedScene" id=2] [sub_resource type="Theme" id=1] - -[node name="GraphEdit" type="GraphEdit" index="0"] - +[node name="GraphEdit" type="GraphEdit"] self_modulate = Color( 1, 1, 1, 0 ) -anchor_left = 0.0 -anchor_top = 0.0 anchor_right = 1.0 anchor_bottom = 1.0 -rect_pivot_offset = Vector2( 0, 0 ) -rect_clip_content = true -focus_mode = 2 -mouse_filter = 0 -mouse_default_cursor_shape = 0 -size_flags_horizontal = 1 -size_flags_vertical = 1 right_disconnects = true -scroll_offset = Vector2( -458.75, -292.25 ) -snap_distance = 20 +scroll_offset = Vector2( -325, -250 ) use_snap = false -zoom = 1.0 script = ExtResource( 1 ) -_sections_unfolded = [ "Material", "Mouse", "Visibility" ] -[node name="Material" parent="." index="0" instance=ExtResource( 2 )] - -margin_left = 658.75 -margin_top = 292.25 -margin_right = 888.75 -margin_bottom = 512.25 +[node name="Material" parent="." instance=ExtResource( 2 )] +margin_left = 525.0 +margin_top = 250.0 +margin_right = 755.0 +margin_bottom = 470.0 theme = SubResource( 1 ) offset = Vector2( 200, 0 ) -_sections_unfolded = [ "Anchor", "Margin", "Mouse", "Theme", "slot", "slot/0", "slot/1", "slot/2", "slot/3", "slot/4", "slot/5" ] -[node name="Timer" type="Timer" parent="." index="1"] - -process_mode = 1 +[node name="Timer" type="Timer" parent="."] wait_time = 0.2 one_shot = true -autostart = false - [connection signal="connection_request" from="." to="." method="connect_node"] - [connection signal="disconnection_request" from="." to="." method="disconnect_node"] - [connection signal="timeout" from="Timer" to="." method="do_send_changed_signal"] - - diff --git a/addons/material_maker/main_window.gd b/addons/material_maker/main_window.gd index d7e5c79..7b25a61 100644 --- a/addons/material_maker/main_window.gd +++ b/addons/material_maker/main_window.gd @@ -7,6 +7,8 @@ var recent_files_submenu = null var editor_interface = null var current_tab = null +onready var renderer = $Renderer + const MENU = [ { menu="File", command="new_material", description="New material" }, { menu="File", command="load_material", shortcut="Control+O", description="Load material" }, @@ -140,7 +142,6 @@ func load_material(): dialog.access = FileDialog.ACCESS_FILESYSTEM dialog.mode = FileDialog.MODE_OPEN_FILES dialog.add_filter("*.ptex;Procedural textures file") - #dialog.connect("file_selected", self, "do_load_material") dialog.connect("files_selected", self, "do_load_materials") dialog.popup_centered() @@ -150,10 +151,8 @@ func do_load_materials(filenames): func do_load_material(filename): var graph_edit = $VBoxContainer/HBoxContainer/Projects.get_current_tab_control() - var node_count = 0 - if graph_edit == null: - node_count = 123 # So test below succeeds... - else: + var node_count = 2 # So test below succeeds if graph_edit is null... + if graph_edit != null: for c in graph_edit.get_children(): if c is GraphNode: node_count += 1 @@ -161,18 +160,28 @@ func do_load_material(filename): break if node_count > 1: graph_edit = new_pane() - graph_edit.do_load_file(filename) + graph_edit.load_file(filename) add_recent(filename) func save_material(): var graph_edit = $VBoxContainer/HBoxContainer/Projects.get_current_tab_control() if graph_edit != null: - graph_edit.save_file() - + if graph_edit.save_path != null: + graph_edit.save_file(graph_edit.save_path) + else: + save_material_as() + func save_material_as(): var graph_edit = $VBoxContainer/HBoxContainer/Projects.get_current_tab_control() if graph_edit != null: - graph_edit.save_file_as() + var dialog = FileDialog.new() + add_child(dialog) + dialog.rect_min_size = Vector2(500, 500) + dialog.access = FileDialog.ACCESS_FILESYSTEM + dialog.mode = FileDialog.MODE_SAVE_FILE + dialog.add_filter("*.ptex;Procedural textures file") + dialog.connect("file_selected", graph_edit, "save_file") + dialog.popup_centered() func close_material(): $VBoxContainer/HBoxContainer/Projects.close_tab() @@ -298,7 +307,17 @@ func update_preview_2d(node = null): node = n break if node != null: - graph_edit.renderer.setup_material(preview.get_2d_material(), node.get_textures(), node.generate_shader()) + print(node.name) + var source = node.generator.get_shader(0) + if source != null: + var shader : String = renderer.generate_shader(source) + var status = renderer.render_shader(shader, {}, 1024) + while status is GDScriptFunctionState: + status = yield(status, "completed") + var image = renderer.get_texture().get_data() + var tex = ImageTexture.new() + tex.create_from_image(image) + preview.set_2d(tex) func _on_Projects_tab_changed(tab): var new_tab = $VBoxContainer/HBoxContainer/Projects.get_current_tab_control() diff --git a/addons/material_maker/main_window.tscn b/addons/material_maker/main_window.tscn index 835eb56..1ee2d32 100644 --- a/addons/material_maker/main_window.tscn +++ b/addons/material_maker/main_window.tscn @@ -4,7 +4,7 @@ [ext_resource path="res://addons/material_maker/library.gd" type="Script" id=2] [ext_resource path="res://addons/material_maker/preview.tscn" type="PackedScene" id=3] [ext_resource path="res://addons/material_maker/widgets/tabs.gd" type="Script" id=4] -[ext_resource path="res://addons/material_maker/renderer.tscn" type="PackedScene" id=5] +[ext_resource path="res://addons/material_maker/engine/renderer.tscn" type="PackedScene" id=5] [ext_resource path="res://addons/material_maker/node_factory.gd" type="Script" id=6] [node name="MainWindow" type="Panel"] @@ -96,12 +96,6 @@ tab_align = 0 tab_close_display_policy = 1 [node name="Renderer" parent="." instance=ExtResource( 5 )] -handle_input_locally = false -msaa = 0 -hdr = true -disable_3d = true -usage = 0 -debug_path = "D:/Dev/mmdebug_" [node name="NodeFactory" type="Node" parent="."] script = ExtResource( 6 ) diff --git a/addons/material_maker/new.ptex b/addons/material_maker/new.ptex new file mode 100644 index 0000000..4d41f06 --- /dev/null +++ b/addons/material_maker/new.ptex @@ -0,0 +1 @@ +{"connections":[],"nodes":[{"name":"Material","node_position":{"x":307,"y":-53},"parameters":{"albedo_color":{"a":1,"b":1,"g":1,"r":1,"type":"Color"},"ao_light_affect":1,"depth_scale":1,"emission_energy":1,"metallic":1,"normal_scale":1,"resolution":1,"roughness":1},"type":"material"}]} \ No newline at end of file diff --git a/addons/material_maker/node_factory.gd b/addons/material_maker/node_factory.gd index 90e8032..f37f2cf 100644 --- a/addons/material_maker/node_factory.gd +++ b/addons/material_maker/node_factory.gd @@ -12,7 +12,7 @@ func create_node(type): node = preload("res://addons/material_maker/nodes/node_generic.gd").new() node.model = type else: - var node_type = load("res://addons/material_maker/nodes/"+type+"/"+type+".tscn") + var node_type = load("res://addons/material_maker/nodes/"+type+".tscn") if node_type != null: node = node_type.instance() return node diff --git a/addons/material_maker/nodes/custom/custom.gd b/addons/material_maker/nodes/custom.gd similarity index 100% rename from addons/material_maker/nodes/custom/custom.gd rename to addons/material_maker/nodes/custom.gd diff --git a/addons/material_maker/nodes/custom/custom.tscn b/addons/material_maker/nodes/custom.tscn similarity index 94% rename from addons/material_maker/nodes/custom/custom.tscn rename to addons/material_maker/nodes/custom.tscn index 20f190a..d9e6ba0 100644 --- a/addons/material_maker/nodes/custom/custom.tscn +++ b/addons/material_maker/nodes/custom.tscn @@ -1,6 +1,6 @@ [gd_scene load_steps=5 format=2] -[ext_resource path="res://addons/material_maker/nodes/custom/custom.gd" type="Script" id=1] +[ext_resource path="res://addons/material_maker/nodes/custom.gd" type="Script" id=1] [ext_resource path="res://addons/material_maker/icons/edit.png" type="Texture" id=2] [ext_resource path="res://addons/material_maker/icons/load.png" type="Texture" id=3] [ext_resource path="res://addons/material_maker/icons/save.png" type="Texture" id=4] diff --git a/addons/material_maker/nodes/generic.gd b/addons/material_maker/nodes/generic.gd new file mode 100644 index 0000000..31723f4 --- /dev/null +++ b/addons/material_maker/nodes/generic.gd @@ -0,0 +1,134 @@ +extends GraphNode + +var generator = null setget set_generator + +var uses_seed : bool = false + +var parameters = {} +var model_data = {} + +# Called when the node enters the scene tree for the first time. +func _ready(): + pass # Replace with function body. + +func set_generator(g): + generator = g + update_node(g.model_data) + +func initialize_properties(p): + pass + +func update_node(data): + print("node_generic.update_node") + if typeof(data) != TYPE_DICTIONARY: + return + if !data.has("name"): + return + # Clean node + parameters = {} + var custom_node_buttons = null + for c in get_children(): + if c.name != "CustomNodeButtons": + remove_child(c) + c.queue_free() + else: + custom_node_buttons = c + # Rebuild node + title = data.name + model_data = data + uses_seed = false + if model_data.has("instance") and model_data.instance.find("$(seed)"): + uses_seed = true + if model_data.has("parameters") and typeof(model_data.parameters) == TYPE_ARRAY: + var control_list = [] + var sizer = null + for p in model_data.parameters: + if !p.has("name") or !p.has("type"): + continue + var control = null + if p.type == "float": + if p.has("widget") and p.widget == "spinbox": + control = SpinBox.new() + else: + control = HSlider.new() + control.min_value = p.min + control.max_value = p.max + control.step = 0 if !p.has("step") else p.step + if p.has("default"): + control.value = p.default + control.rect_min_size.x = 80 + parameters[p.name] = 0.5*(p.min+p.max) + elif p.type == "size": + control = OptionButton.new() + for i in range(p.first, p.last+1): + var s = pow(2, i) + control.add_item("%dx%d" % [ s, s ]) + control.selected = 0 if !p.has("default") else p.default-p.first + elif p.type == "enum": + control = OptionButton.new() + for i in range(p.values.size()): + var value = p.values[i] + control.add_item(value.name) + control.selected = 0 if !p.has("default") else p.default + elif p.type == "boolean": + control = CheckBox.new() + elif p.type == "color": + control = ColorPickerButton.new() + elif p.type == "gradient": + control = preload("res://addons/material_maker/widgets/gradient_editor.tscn").instance() + if control != null: + var label = p.name + control.name = label + control_list.append(control) + if p.has("label"): + label = p.label + if sizer == null or label != "nonewline": + sizer = HBoxContainer.new() + sizer.size_flags_horizontal = SIZE_EXPAND | SIZE_FILL + add_child(sizer) + if label != "" && label != "nonewline": + var label_widget = Label.new() + label_widget.text = label + label_widget.size_flags_horizontal = SIZE_EXPAND | SIZE_FILL + sizer.add_child(label_widget) + control.size_flags_horizontal = SIZE_EXPAND | SIZE_FILL + sizer.add_child(control) + initialize_properties(control_list) + else: + model_data.parameters = [] + if model_data.has("inputs") and typeof(model_data.inputs) == TYPE_ARRAY: + for i in range(model_data.inputs.size()): + var input = model_data.inputs[i] + var enable_left = false + var color_left = Color(0.5, 0.5, 0.5) + if typeof(input) == TYPE_DICTIONARY: + if input.type == "rgb": + enable_left = true + color_left = Color(0.5, 0.5, 1.0) + elif input.type == "rgba": + enable_left = true + color_left = Color(0.0, 0.5, 0.0, 0.5) + else: + enable_left = true + set_slot(i, enable_left, 0, color_left, false, 0, Color()) + else: + model_data.inputs = [] + if model_data.has("outputs") and typeof(model_data.outputs) == TYPE_ARRAY: + for i in range(model_data.outputs.size()): + var output = model_data.outputs[i] + var enable_right = false + var color_right = Color(0.5, 0.5, 0.5) + if typeof(output) == TYPE_DICTIONARY: + if output.has("rgb"): + enable_right = true + color_right = Color(0.5, 0.5, 1.0) + elif output.has("rgba"): + enable_right = true + color_right = Color(0.0, 0.5, 0.0, 0.5) + elif output.has("f"): + enable_right = true + set_slot(i, is_slot_enabled_left(i), get_slot_type_left(i), get_slot_color_left(i), enable_right, 0, color_right) + else: + model_data.outputs = [] + if custom_node_buttons != null: + move_child(custom_node_buttons, get_child_count()-1) diff --git a/addons/material_maker/nodes/generic.tscn b/addons/material_maker/nodes/generic.tscn new file mode 100644 index 0000000..3bdc771 --- /dev/null +++ b/addons/material_maker/nodes/generic.tscn @@ -0,0 +1,10 @@ +[gd_scene load_steps=2 format=2] + +[ext_resource path="res://addons/material_maker/nodes/generic.gd" type="Script" id=1] + +[node name="Generic" type="GraphNode"] +margin_right = 82.0 +margin_bottom = 29.0 +title = "Generic" +show_close = true +script = ExtResource( 1 ) diff --git a/addons/material_maker/nodes/material/material.gd b/addons/material_maker/nodes/material.gd similarity index 99% rename from addons/material_maker/nodes/material/material.gd rename to addons/material_maker/nodes/material.gd index bee9320..79a497b 100644 --- a/addons/material_maker/nodes/material/material.gd +++ b/addons/material_maker/nodes/material.gd @@ -1,6 +1,8 @@ tool extends "res://addons/material_maker/node_base.gd" +var generator = null + var texture_list var current_material_list = [] diff --git a/addons/material_maker/nodes/material/material.tscn b/addons/material_maker/nodes/material.tscn similarity index 99% rename from addons/material_maker/nodes/material/material.tscn rename to addons/material_maker/nodes/material.tscn index d52981b..3f4b924 100644 --- a/addons/material_maker/nodes/material/material.tscn +++ b/addons/material_maker/nodes/material.tscn @@ -1,12 +1,10 @@ [gd_scene load_steps=3 format=2] -[ext_resource path="res://addons/material_maker/nodes/material/material.gd" type="Script" id=1] +[ext_resource path="res://addons/material_maker/nodes/material.gd" type="Script" id=1] [sub_resource type="Theme" id=1] - [node name="Material" type="GraphNode" index="0"] - anchor_left = 0.0 anchor_top = 0.0 anchor_right = 0.0 @@ -79,7 +77,6 @@ script = ExtResource( 1 ) _sections_unfolded = [ "Theme", "slot", "slot/0", "slot/1", "slot/2", "slot/5", "slot/7" ] [node name="resolution" type="OptionButton" parent="." index="0"] - anchor_left = 0.0 anchor_top = 0.0 anchor_right = 0.0 @@ -107,7 +104,6 @@ items = [ "256x256", null, false, 0, null, "512x512", null, false, 1, null, "102 selected = 1 [node name="Albedo" type="HBoxContainer" parent="." index="1"] - anchor_left = 0.0 anchor_top = 0.0 anchor_right = 0.0 @@ -125,7 +121,6 @@ size_flags_vertical = 1 alignment = 0 [node name="Label" type="Label" parent="Albedo" index="0"] - anchor_left = 0.0 anchor_top = 0.0 anchor_right = 0.0 @@ -146,7 +141,6 @@ max_lines_visible = -1 _sections_unfolded = [ "Size Flags" ] [node name="albedo_color" type="ColorPickerButton" parent="Albedo" index="1"] - anchor_left = 0.0 anchor_top = 0.0 anchor_right = 0.0 @@ -173,7 +167,6 @@ edit_alpha = false _sections_unfolded = [ "Rect", "Size Flags" ] [node name="Metallic" type="HBoxContainer" parent="." index="2"] - editor/display_folded = true anchor_left = 0.0 anchor_top = 0.0 @@ -192,7 +185,6 @@ size_flags_vertical = 1 alignment = 0 [node name="Label" type="Label" parent="Metallic" index="0"] - anchor_left = 0.0 anchor_top = 0.0 anchor_right = 0.0 @@ -213,7 +205,6 @@ max_lines_visible = -1 _sections_unfolded = [ "Size Flags" ] [node name="metallic" type="SpinBox" parent="Metallic" index="1"] - anchor_left = 0.0 anchor_top = 0.0 anchor_right = 0.0 @@ -240,7 +231,6 @@ suffix = "" _sections_unfolded = [ "Rect" ] [node name="Roughness" type="HBoxContainer" parent="." index="3"] - editor/display_folded = true anchor_left = 0.0 anchor_top = 0.0 @@ -259,7 +249,6 @@ size_flags_vertical = 1 alignment = 0 [node name="Label" type="Label" parent="Roughness" index="0"] - anchor_left = 0.0 anchor_top = 0.0 anchor_right = 0.0 @@ -280,7 +269,6 @@ max_lines_visible = -1 _sections_unfolded = [ "Size Flags" ] [node name="roughness" type="SpinBox" parent="Roughness" index="1"] - anchor_left = 0.0 anchor_top = 0.0 anchor_right = 0.0 @@ -307,7 +295,6 @@ suffix = "" _sections_unfolded = [ "Rect" ] [node name="Emission" type="HBoxContainer" parent="." index="4"] - editor/display_folded = true anchor_left = 0.0 anchor_top = 0.0 @@ -326,7 +313,6 @@ size_flags_vertical = 1 alignment = 0 [node name="Label" type="Label" parent="Emission" index="0"] - anchor_left = 0.0 anchor_top = 0.0 anchor_right = 0.0 @@ -347,7 +333,6 @@ max_lines_visible = -1 _sections_unfolded = [ "Size Flags" ] [node name="emission_energy" type="SpinBox" parent="Emission" index="1"] - anchor_left = 0.0 anchor_top = 0.0 anchor_right = 0.0 @@ -374,7 +359,6 @@ suffix = "" _sections_unfolded = [ "Rect" ] [node name="NormalMap" type="HBoxContainer" parent="." index="5"] - editor/display_folded = true anchor_left = 0.0 anchor_top = 0.0 @@ -393,7 +377,6 @@ size_flags_vertical = 1 alignment = 0 [node name="Label" type="Label" parent="NormalMap" index="0"] - anchor_left = 0.0 anchor_top = 0.0 anchor_right = 0.0 @@ -414,7 +397,6 @@ max_lines_visible = -1 _sections_unfolded = [ "Size Flags" ] [node name="normal_scale" type="SpinBox" parent="NormalMap" index="1"] - anchor_left = 0.0 anchor_top = 0.0 anchor_right = 0.0 @@ -441,7 +423,6 @@ suffix = "" _sections_unfolded = [ "Rect" ] [node name="AmbientOcclusion" type="HBoxContainer" parent="." index="6"] - editor/display_folded = true anchor_left = 0.0 anchor_top = 0.0 @@ -460,7 +441,6 @@ size_flags_vertical = 1 alignment = 0 [node name="Label" type="Label" parent="AmbientOcclusion" index="0"] - anchor_left = 0.0 anchor_top = 0.0 anchor_right = 0.0 @@ -481,7 +461,6 @@ max_lines_visible = -1 _sections_unfolded = [ "Size Flags" ] [node name="ao_light_affect" type="SpinBox" parent="AmbientOcclusion" index="1"] - anchor_left = 0.0 anchor_top = 0.0 anchor_right = 0.0 @@ -508,7 +487,6 @@ suffix = "" _sections_unfolded = [ "Rect" ] [node name="DepthMap" type="HBoxContainer" parent="." index="7"] - editor/display_folded = true anchor_left = 0.0 anchor_top = 0.0 @@ -527,7 +505,6 @@ size_flags_vertical = 1 alignment = 0 [node name="Label" type="Label" parent="DepthMap" index="0"] - anchor_left = 0.0 anchor_top = 0.0 anchor_right = 0.0 @@ -548,7 +525,6 @@ max_lines_visible = -1 _sections_unfolded = [ "Size Flags" ] [node name="depth_scale" type="SpinBox" parent="DepthMap" index="1"] - anchor_left = 0.0 anchor_top = 0.0 anchor_right = 0.0 @@ -573,5 +549,3 @@ editable = true prefix = "" suffix = "" _sections_unfolded = [ "Rect" ] - - diff --git a/addons/material_maker/preview.gd b/addons/material_maker/preview.gd index 142817f..8d23fd3 100644 --- a/addons/material_maker/preview.gd +++ b/addons/material_maker/preview.gd @@ -29,9 +29,9 @@ func _on_Model_item_selected(id): func get_materials(): return [ $MaterialPreview/Objects/Cube.get_surface_material(0), $MaterialPreview/Objects/Sphere.get_surface_material(0) ] - -func get_2d_material(): - return $Preview2D.material + +func set_2d(tex: Texture): + $Preview2D.material.set_shader_param("tex", tex) func _on_Preview_resized(): if preview_maximized: diff --git a/addons/material_maker/preview.tscn b/addons/material_maker/preview.tscn index d8b9881..f84c456 100644 --- a/addons/material_maker/preview.tscn +++ b/addons/material_maker/preview.tscn @@ -1,13 +1,11 @@ -[gd_scene load_steps=13 format=2] +[gd_scene load_steps=14 format=2] [ext_resource path="res://addons/material_maker/preview.gd" type="Script" id=1] [ext_resource path="res://addons/material_maker/panoramas/park.hdr" type="Texture" id=2] +[ext_resource path="res://icon.png" type="Texture" id=3] [sub_resource type="Animation" id=1] - -length = 1.0 loop = true -step = 0.1 tracks/0/type = "value" tracks/0/path = NodePath("MaterialPreview/Objects:rotation_degrees") tracks/0/interp = 1 @@ -22,9 +20,6 @@ tracks/0/keys = { } [sub_resource type="ArrayMesh" id=2] - -blend_shape_mode = 1 -custom_aabb = AABB( 0, 0, 0, 0, 0, 0 ) surfaces/0 = { "aabb": AABB( -1, -1, -1, 2.00001, 2, 2 ), "array_data": PoolByteArray( 0, 60, 0, 188, 255, 187, 0, 60, 0, 129, 0, 0, 126, 0, 0, 129, 252, 59, 251, 59, 0, 188, 0, 188, 255, 59, 0, 60, 0, 129, 0, 0, 127, 0, 0, 129, 4, 18, 60, 25, 0, 60, 0, 188, 0, 60, 0, 60, 0, 129, 0, 0, 127, 0, 0, 129, 252, 59, 60, 25, 255, 187, 0, 188, 0, 188, 0, 60, 0, 129, 0, 0, 127, 0, 0, 129, 4, 18, 251, 59, 0, 60, 0, 60, 255, 187, 0, 60, 0, 127, 0, 0, 0, 0, 129, 129, 252, 59, 251, 59, 0, 188, 0, 60, 255, 59, 0, 60, 0, 127, 0, 0, 0, 0, 129, 129, 4, 18, 60, 25, 255, 187, 0, 60, 0, 188, 0, 60, 0, 127, 0, 0, 0, 0, 129, 129, 252, 59, 60, 25, 255, 59, 0, 60, 0, 60, 0, 60, 0, 127, 0, 0, 0, 0, 129, 129, 4, 18, 251, 59, 0, 60, 0, 188, 255, 187, 0, 60, 127, 0, 0, 0, 0, 0, 129, 129, 252, 59, 251, 59, 255, 59, 0, 60, 0, 60, 0, 60, 127, 0, 0, 0, 0, 0, 129, 129, 4, 18, 60, 25, 0, 60, 0, 60, 255, 187, 0, 60, 127, 0, 0, 0, 0, 0, 129, 129, 252, 59, 60, 25, 0, 60, 0, 188, 0, 60, 0, 60, 127, 0, 0, 0, 0, 0, 129, 129, 4, 18, 251, 59, 0, 60, 0, 188, 0, 60, 0, 60, 0, 0, 127, 0, 127, 0, 0, 129, 252, 59, 251, 59, 0, 188, 0, 60, 255, 59, 0, 60, 0, 0, 127, 0, 127, 0, 0, 129, 4, 18, 60, 25, 255, 59, 0, 60, 0, 60, 0, 60, 0, 0, 127, 0, 127, 0, 0, 129, 252, 59, 60, 25, 0, 188, 0, 188, 255, 59, 0, 60, 0, 0, 127, 0, 126, 0, 0, 129, 4, 18, 251, 59, 0, 188, 0, 188, 255, 59, 0, 60, 129, 0, 0, 0, 0, 0, 127, 129, 252, 59, 251, 59, 255, 187, 0, 60, 0, 188, 0, 60, 129, 0, 0, 0, 0, 0, 126, 129, 4, 18, 60, 25, 0, 188, 0, 60, 255, 59, 0, 60, 129, 0, 0, 0, 0, 0, 127, 129, 252, 59, 60, 25, 255, 187, 0, 188, 0, 188, 0, 60, 129, 0, 0, 0, 0, 0, 127, 129, 4, 18, 251, 59, 0, 60, 0, 60, 255, 187, 0, 60, 0, 0, 129, 0, 129, 0, 0, 129, 4, 18, 60, 25, 255, 187, 0, 188, 0, 188, 0, 60, 0, 0, 129, 0, 130, 0, 0, 129, 252, 59, 251, 59, 0, 60, 0, 188, 255, 187, 0, 60, 0, 0, 129, 0, 129, 0, 0, 129, 4, 18, 251, 59, 255, 187, 0, 60, 0, 188, 0, 60, 0, 0, 129, 0, 129, 0, 0, 129, 252, 59, 60, 25 ), @@ -37,42 +32,10 @@ surfaces/0 = { "skeleton_aabb": [ ], "vertex_count": 24 } -_sections_unfolded = [ "surface_1" ] [sub_resource type="SpatialMaterial" id=3] - -render_priority = 0 -flags_transparent = false -flags_unshaded = false -flags_vertex_lighting = false -flags_no_depth_test = false -flags_use_point_size = false -flags_world_triplanar = false -flags_fixed_size = false -flags_albedo_tex_force_srgb = false -vertex_color_use_as_albedo = false -vertex_color_is_srgb = false -params_diffuse_mode = 0 -params_specular_mode = 0 -params_blend_mode = 0 -params_cull_mode = 0 -params_depth_draw_mode = 0 -params_line_width = 1.0 -params_point_size = 1.0 -params_billboard_mode = 0 -params_grow = false -params_use_alpha_scissor = false -albedo_color = Color( 1, 1, 1, 1 ) metallic = 1.0 metallic_specular = 1.0 -metallic_texture_channel = 0 -roughness = 1.0 -roughness_texture_channel = 0 -emission_enabled = false -normal_enabled = false -rim_enabled = false -clearcoat_enabled = false -anisotropy_enabled = false ao_enabled = true ao_light_affect = 0.0 ao_on_uv2 = false @@ -82,26 +45,10 @@ depth_scale = 0.5 depth_deep_parallax = true depth_min_layers = 8 depth_max_layers = 32 -subsurf_scatter_enabled = false -transmission_enabled = false -refraction_enabled = false -detail_enabled = false -uv1_scale = Vector3( 1, 1, 1 ) -uv1_offset = Vector3( 0, 0, 0 ) -uv1_triplanar = false -uv1_triplanar_sharpness = 1.0 -uv2_scale = Vector3( 1, 1, 1 ) -uv2_offset = Vector3( 0, 0, 0 ) -uv2_triplanar = false -uv2_triplanar_sharpness = 1.0 -proximity_fade_enable = false -distance_fade_enable = false -_sections_unfolded = [ "Ambient Occlusion", "Depth" ] +depth_flip_tangent = false +depth_flip_binormal = false [sub_resource type="ArrayMesh" id=4] - -blend_shape_mode = 1 -custom_aabb = AABB( 0, 0, 0, 0, 0, 0 ) surfaces/0 = { "aabb": AABB( -1, -1, -1, 2, 2, 2 ), "array_data": PoolByteArray( 0, 0, 0, 188, 0, 188, 0, 60, 0, 172, 162, 0, 129, 0, 0, 129, 201, 58, 209, 59, 31, 54, 0, 60, 100, 187, 0, 60, 36, 84, 169, 0, 139, 0, 208, 129, 73, 57, 198, 37, 0, 0, 0, 60, 0, 188, 0, 60, 0, 84, 162, 0, 129, 0, 0, 129, 201, 58, 198, 37, 31, 54, 0, 188, 100, 187, 0, 60, 36, 172, 169, 0, 139, 0, 208, 129, 73, 57, 209, 59, 168, 57, 0, 60, 168, 185, 0, 60, 67, 84, 189, 0, 167, 0, 167, 129, 147, 55, 198, 37, 168, 57, 0, 188, 168, 185, 0, 60, 67, 172, 189, 0, 167, 0, 167, 129, 147, 55, 209, 59, 100, 59, 0, 60, 31, 182, 0, 60, 87, 84, 220, 0, 208, 0, 139, 129, 147, 52, 198, 37, 100, 59, 0, 188, 31, 182, 0, 60, 87, 172, 220, 0, 208, 0, 139, 129, 147, 52, 209, 59, 0, 60, 0, 60, 0, 0, 0, 60, 94, 84, 0, 0, 0, 0, 130, 129, 77, 46, 198, 37, 0, 60, 0, 188, 0, 0, 0, 60, 94, 172, 0, 0, 0, 0, 129, 129, 77, 46, 209, 59, 100, 59, 0, 60, 31, 54, 0, 60, 87, 84, 36, 0, 48, 0, 139, 129, 178, 173, 198, 37, 100, 59, 0, 188, 31, 54, 0, 60, 87, 172, 36, 0, 48, 0, 139, 129, 178, 173, 209, 59, 168, 57, 0, 60, 168, 57, 0, 60, 67, 84, 67, 0, 89, 0, 167, 129, 108, 180, 198, 37, 168, 57, 0, 188, 168, 57, 0, 60, 67, 172, 67, 0, 89, 0, 167, 129, 108, 180, 209, 59, 31, 54, 0, 60, 100, 59, 0, 60, 36, 84, 87, 0, 117, 0, 208, 129, 108, 183, 198, 37, 31, 54, 0, 188, 100, 59, 0, 60, 36, 172, 87, 0, 117, 0, 208, 129, 108, 183, 209, 59, 0, 0, 0, 60, 0, 60, 0, 60, 0, 84, 94, 0, 127, 0, 0, 129, 54, 185, 198, 37, 0, 0, 0, 188, 0, 60, 0, 60, 0, 172, 94, 0, 127, 0, 0, 129, 54, 185, 209, 59, 31, 182, 0, 60, 100, 59, 0, 60, 220, 84, 87, 0, 117, 0, 48, 129, 182, 186, 198, 37, 31, 182, 0, 188, 100, 59, 0, 60, 220, 172, 87, 0, 117, 0, 48, 129, 182, 186, 209, 59, 168, 185, 0, 60, 168, 57, 0, 60, 189, 84, 67, 0, 89, 0, 89, 129, 27, 188, 198, 37, 168, 185, 0, 188, 168, 57, 0, 60, 189, 172, 67, 0, 89, 0, 89, 129, 27, 188, 209, 59, 100, 187, 0, 60, 31, 54, 0, 60, 169, 84, 36, 0, 48, 0, 117, 129, 219, 188, 198, 37, 100, 187, 0, 188, 31, 54, 0, 60, 169, 172, 36, 0, 48, 0, 117, 129, 219, 188, 209, 59, 0, 188, 0, 60, 0, 0, 0, 60, 162, 84, 0, 0, 11, 12, 125, 129, 155, 189, 198, 37, 0, 188, 0, 188, 0, 0, 0, 60, 162, 172, 0, 0, 11, 244, 125, 129, 155, 189, 209, 59, 0, 188, 0, 188, 0, 0, 0, 60, 162, 172, 0, 0, 245, 12, 125, 129, 100, 62, 209, 59, 100, 187, 0, 60, 31, 182, 0, 60, 169, 84, 220, 0, 208, 0, 117, 129, 164, 61, 198, 37, 0, 188, 0, 60, 0, 0, 0, 60, 162, 84, 0, 0, 245, 244, 125, 129, 100, 62, 198, 37, 100, 187, 0, 188, 31, 182, 0, 60, 169, 172, 220, 0, 208, 0, 117, 129, 164, 61, 209, 59, 168, 185, 0, 60, 168, 185, 0, 60, 189, 84, 189, 0, 167, 0, 89, 129, 228, 60, 198, 37, 168, 185, 0, 188, 168, 185, 0, 60, 189, 172, 189, 0, 167, 0, 89, 129, 228, 60, 209, 59, 31, 54, 0, 60, 100, 187, 0, 60, 0, 127, 0, 0, 127, 0, 0, 129, 81, 57, 138, 43, 31, 182, 0, 60, 100, 187, 0, 60, 0, 127, 0, 0, 127, 0, 0, 129, 201, 52, 138, 43, 0, 0, 0, 60, 0, 188, 0, 60, 0, 127, 0, 0, 127, 0, 0, 129, 181, 55, 198, 37, 168, 185, 0, 60, 168, 185, 0, 60, 0, 127, 0, 0, 127, 0, 0, 129, 157, 48, 50, 49, 100, 187, 0, 60, 31, 182, 0, 60, 0, 127, 0, 0, 127, 0, 0, 129, 56, 41, 19, 53, 0, 188, 0, 60, 0, 0, 0, 60, 0, 127, 0, 0, 127, 0, 0, 129, 140, 28, 0, 56, 100, 187, 0, 60, 31, 54, 0, 60, 0, 127, 0, 0, 127, 0, 0, 129, 56, 41, 118, 57, 168, 185, 0, 60, 168, 57, 0, 60, 0, 127, 0, 0, 127, 0, 0, 129, 157, 48, 179, 58, 31, 182, 0, 60, 100, 59, 0, 60, 0, 127, 0, 0, 127, 0, 0, 129, 201, 52, 135, 59, 0, 0, 0, 60, 0, 60, 0, 60, 0, 127, 0, 0, 127, 0, 0, 129, 181, 55, 209, 59, 31, 54, 0, 60, 100, 59, 0, 60, 0, 127, 0, 0, 127, 0, 0, 129, 81, 57, 135, 59, 168, 57, 0, 60, 168, 57, 0, 60, 0, 127, 0, 0, 127, 0, 0, 129, 142, 58, 179, 58, 100, 59, 0, 60, 31, 54, 0, 60, 0, 127, 0, 0, 127, 0, 0, 129, 98, 59, 118, 57, 0, 60, 0, 60, 0, 0, 0, 60, 0, 127, 0, 0, 127, 0, 0, 129, 172, 59, 0, 56, 100, 59, 0, 60, 31, 182, 0, 60, 0, 127, 0, 0, 127, 0, 0, 129, 98, 59, 19, 53, 168, 57, 0, 60, 168, 185, 0, 60, 0, 127, 0, 0, 127, 0, 0, 129, 142, 58, 50, 49, 31, 182, 0, 60, 100, 187, 0, 60, 220, 84, 169, 0, 139, 0, 48, 129, 36, 60, 198, 37, 31, 182, 0, 188, 100, 187, 0, 60, 220, 172, 169, 0, 139, 0, 48, 129, 36, 60, 209, 59, 0, 0, 0, 188, 0, 188, 0, 60, 0, 129, 0, 0, 127, 0, 0, 127, 181, 55, 198, 37, 168, 57, 0, 188, 168, 185, 0, 60, 0, 129, 0, 0, 127, 0, 0, 127, 142, 58, 50, 49, 31, 54, 0, 188, 100, 187, 0, 60, 0, 129, 0, 0, 127, 0, 0, 127, 81, 57, 138, 43, 100, 59, 0, 188, 31, 182, 0, 60, 0, 129, 0, 0, 127, 0, 0, 127, 98, 59, 19, 53, 0, 60, 0, 188, 0, 0, 0, 60, 0, 129, 0, 0, 127, 0, 0, 127, 172, 59, 0, 56, 100, 59, 0, 188, 31, 54, 0, 60, 0, 129, 0, 0, 127, 0, 0, 127, 98, 59, 118, 57, 168, 57, 0, 188, 168, 57, 0, 60, 0, 129, 0, 0, 127, 0, 0, 127, 142, 58, 179, 58, 31, 54, 0, 188, 100, 59, 0, 60, 0, 129, 0, 0, 127, 0, 0, 127, 81, 57, 135, 59, 0, 0, 0, 188, 0, 60, 0, 60, 0, 129, 0, 0, 127, 0, 0, 127, 181, 55, 209, 59, 31, 182, 0, 188, 100, 59, 0, 60, 0, 129, 0, 0, 127, 0, 0, 127, 201, 52, 135, 59, 168, 185, 0, 188, 168, 57, 0, 60, 0, 129, 0, 0, 127, 0, 0, 127, 157, 48, 179, 58, 100, 187, 0, 188, 31, 54, 0, 60, 0, 129, 0, 0, 127, 0, 0, 127, 56, 41, 118, 57, 0, 188, 0, 188, 0, 0, 0, 60, 0, 129, 0, 0, 127, 0, 0, 127, 140, 28, 0, 56, 100, 187, 0, 188, 31, 182, 0, 60, 0, 129, 0, 0, 127, 0, 0, 127, 56, 41, 19, 53, 168, 185, 0, 188, 168, 185, 0, 60, 0, 129, 0, 0, 127, 0, 0, 127, 157, 48, 50, 49, 31, 182, 0, 188, 100, 187, 0, 60, 0, 129, 0, 0, 127, 0, 0, 127, 201, 52, 138, 43 ), @@ -113,51 +60,14 @@ surfaces/0 = { "skeleton_aabb": [ ], "vertex_count": 66 } -_sections_unfolded = [ "surface_1" ] [sub_resource type="SphereMesh" id=5] - -custom_aabb = AABB( 0, 0, 0, 0, 0, 0 ) radius = 1.5 height = 3.0 -radial_segments = 64 -rings = 32 -is_hemisphere = false [sub_resource type="SpatialMaterial" id=6] - -render_priority = 0 -flags_transparent = false -flags_unshaded = false -flags_vertex_lighting = false -flags_no_depth_test = false -flags_use_point_size = false -flags_world_triplanar = false -flags_fixed_size = false -flags_albedo_tex_force_srgb = false -vertex_color_use_as_albedo = false -vertex_color_is_srgb = false -params_diffuse_mode = 0 -params_specular_mode = 0 -params_blend_mode = 0 -params_cull_mode = 0 -params_depth_draw_mode = 0 -params_line_width = 1.0 -params_point_size = 1.0 -params_billboard_mode = 0 -params_grow = false -params_use_alpha_scissor = false -albedo_color = Color( 1, 1, 1, 1 ) metallic = 1.0 metallic_specular = 1.0 -metallic_texture_channel = 0 -roughness = 1.0 -roughness_texture_channel = 0 -emission_enabled = false -normal_enabled = false -rim_enabled = false -clearcoat_enabled = false -anisotropy_enabled = false ao_enabled = true ao_light_affect = 0.0 ao_on_uv2 = false @@ -167,373 +77,118 @@ depth_scale = 0.5 depth_deep_parallax = true depth_min_layers = 8 depth_max_layers = 32 -subsurf_scatter_enabled = false -transmission_enabled = false -refraction_enabled = false -detail_enabled = false +depth_flip_tangent = false +depth_flip_binormal = false uv1_scale = Vector3( -5, -5, 5 ) -uv1_offset = Vector3( 0, 0, 0 ) -uv1_triplanar = false -uv1_triplanar_sharpness = 1.0 -uv2_scale = Vector3( 1, 1, 1 ) -uv2_offset = Vector3( 0, 0, 0 ) -uv2_triplanar = false -uv2_triplanar_sharpness = 1.0 -proximity_fade_enable = false -distance_fade_enable = false -_sections_unfolded = [ "Ambient Occlusion", "Depth", "UV1" ] [sub_resource type="PanoramaSky" id=7] - radiance_size = 2 panorama = ExtResource( 2 ) [sub_resource type="Environment" id=8] - background_mode = 2 background_sky = SubResource( 7 ) -background_sky_custom_fov = 0.0 -background_color = Color( 0, 0, 0, 1 ) -background_energy = 1.0 -background_canvas_max_layer = 0 -ambient_light_color = Color( 0, 0, 0, 1 ) -ambient_light_energy = 1.0 -ambient_light_sky_contribution = 1.0 -fog_enabled = false -fog_color = Color( 0.5, 0.6, 0.7, 1 ) -fog_sun_color = Color( 1, 0.9, 0.7, 1 ) -fog_sun_amount = 0.0 -fog_depth_enabled = true -fog_depth_begin = 10.0 -fog_depth_curve = 1.0 -fog_transmit_enabled = false -fog_transmit_curve = 1.0 -fog_height_enabled = false -fog_height_min = 0.0 -fog_height_max = 100.0 -fog_height_curve = 1.0 -tonemap_mode = 0 -tonemap_exposure = 1.0 -tonemap_white = 1.0 -auto_exposure_enabled = false -auto_exposure_scale = 0.4 -auto_exposure_min_luma = 0.05 -auto_exposure_max_luma = 8.0 -auto_exposure_speed = 0.5 -ss_reflections_enabled = false -ss_reflections_max_steps = 64 -ss_reflections_fade_in = 0.15 -ss_reflections_fade_out = 2.0 -ss_reflections_depth_tolerance = 0.2 -ss_reflections_roughness = true -ssao_enabled = false -ssao_radius = 1.0 -ssao_intensity = 1.0 -ssao_radius2 = 0.0 -ssao_intensity2 = 1.0 -ssao_bias = 0.01 -ssao_light_affect = 0.0 -ssao_color = Color( 0, 0, 0, 1 ) -ssao_quality = 0 -ssao_blur = 3 -ssao_edge_sharpness = 4.0 -dof_blur_far_enabled = false -dof_blur_far_distance = 10.0 -dof_blur_far_transition = 5.0 -dof_blur_far_amount = 0.1 -dof_blur_far_quality = 1 -dof_blur_near_enabled = false -dof_blur_near_distance = 2.0 -dof_blur_near_transition = 1.0 -dof_blur_near_amount = 0.1 -dof_blur_near_quality = 1 -glow_enabled = false -glow_levels/1 = false -glow_levels/2 = false -glow_levels/3 = true -glow_levels/4 = false -glow_levels/5 = true -glow_levels/6 = false -glow_levels/7 = false -glow_intensity = 0.8 -glow_strength = 1.0 -glow_bloom = 0.0 -glow_blend_mode = 2 -glow_hdr_threshold = 1.0 -glow_hdr_scale = 2.0 -glow_bicubic_upscale = false -adjustment_enabled = false -adjustment_brightness = 1.0 -adjustment_contrast = 1.0 -adjustment_saturation = 1.0 -_sections_unfolded = [ "Background" ] [sub_resource type="Shader" id=9] - code = "shader_type canvas_item; -" + +uniform sampler2D tex; + +void fragment() { + COLOR = texture(tex, UV); +}" [sub_resource type="ShaderMaterial" id=10] - -render_priority = 0 shader = SubResource( 9 ) +shader_param/tex = ExtResource( 3 ) [node name="Preview" type="ViewportContainer"] - anchor_left = 1.0 -anchor_top = 0.0 anchor_right = 1.0 -anchor_bottom = 0.0 margin_left = -398.0 margin_top = 3.0 margin_right = -3.0 margin_bottom = 373.0 rect_min_size = Vector2( 200, 200 ) -rect_pivot_offset = Vector2( 0, 0 ) -rect_clip_content = false mouse_filter = 2 -mouse_default_cursor_shape = 0 size_flags_horizontal = 3 size_flags_vertical = 3 stretch = true -stretch_shrink = 1 script = ExtResource( 1 ) -_sections_unfolded = [ "Anchor", "Grow Direction", "Margin", "Mouse", "Rect", "Size Flags" ] -[node name="ObjectRotate" type="AnimationPlayer" parent="." index="0"] - -root_node = NodePath("..") +[node name="ObjectRotate" type="AnimationPlayer" parent="."] autoplay = "rotate" -playback_process_mode = 1 -playback_default_blend_time = 0.0 playback_speed = 0.1 anims/rotate = SubResource( 1 ) -blend_times = [ ] -_sections_unfolded = [ "Playback Options" ] -[node name="MaterialPreview" type="Viewport" parent="." index="1"] - -arvr = false +[node name="MaterialPreview" type="Viewport" parent="."] size = Vector2( 395, 370 ) own_world = true -world = null -transparent_bg = false -msaa = 0 -hdr = true -disable_3d = false -usage = 2 -debug_draw = 0 -render_target_v_flip = false +handle_input_locally = false render_target_clear_mode = 1 render_target_update_mode = 3 -audio_listener_enable_2d = false -audio_listener_enable_3d = false -physics_object_picking = false -gui_disable_input = false -gui_snap_controls_to_pixels = true -shadow_atlas_size = 0 -shadow_atlas_quad_0 = 2 -shadow_atlas_quad_1 = 2 -shadow_atlas_quad_2 = 3 -shadow_atlas_quad_3 = 4 -_sections_unfolded = [ "GUI", "Render Target" ] -[node name="Objects" type="Spatial" parent="MaterialPreview" index="0"] +[node name="Objects" type="Spatial" parent="MaterialPreview"] +transform = Transform( -0.956327, 0, -0.292284, 0, 1, 0, 0.292284, 0, -0.956327, 0, 0, 0 ) -transform = Transform( 0.999464, 0, 0.0326148, 0, 1, 0, -0.0326148, 0, 0.999464, 0, 0, 0 ) -_sections_unfolded = [ "Transform" ] - -[node name="Cube" type="MeshInstance" parent="MaterialPreview/Objects" index="0"] - -layers = 1 -material_override = null -cast_shadow = 1 -extra_cull_margin = 0.0 -use_in_baked_light = false -lod_min_distance = 0.0 -lod_min_hysteresis = 0.0 -lod_max_distance = 0.0 -lod_max_hysteresis = 0.0 +[node name="Cube" type="MeshInstance" parent="MaterialPreview/Objects"] mesh = SubResource( 2 ) -skeleton = NodePath("..") material/0 = SubResource( 3 ) -_sections_unfolded = [ "Geometry", "Transform", "material" ] - -[node name="Cylinder" type="MeshInstance" parent="MaterialPreview/Objects" index="1"] +[node name="Cylinder" type="MeshInstance" parent="MaterialPreview/Objects"] visible = false -layers = 1 -material_override = null -cast_shadow = 1 -extra_cull_margin = 0.0 -use_in_baked_light = false -lod_min_distance = 0.0 -lod_min_hysteresis = 0.0 -lod_max_distance = 0.0 -lod_max_hysteresis = 0.0 mesh = SubResource( 4 ) -skeleton = NodePath("..") material/0 = SubResource( 3 ) -_sections_unfolded = [ "Geometry", "Transform", "material" ] - -[node name="Sphere" type="MeshInstance" parent="MaterialPreview/Objects" index="2"] +[node name="Sphere" type="MeshInstance" parent="MaterialPreview/Objects"] visible = false -layers = 1 -material_override = null -cast_shadow = 1 -extra_cull_margin = 0.0 -use_in_baked_light = false -lod_min_distance = 0.0 -lod_min_hysteresis = 0.0 -lod_max_distance = 0.0 -lod_max_hysteresis = 0.0 mesh = SubResource( 5 ) -skeleton = NodePath("..") material/0 = SubResource( 6 ) -_sections_unfolded = [ "Geometry", "Transform", "material" ] - -[node name="OmniLight" type="OmniLight" parent="MaterialPreview" index="1"] +[node name="OmniLight" type="OmniLight" parent="MaterialPreview"] transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 1.04729, 1.80471, -2.51024 ) -layers = 1 -light_color = Color( 1, 1, 1, 1 ) -light_energy = 1.0 -light_indirect_energy = 1.0 -light_negative = false -light_specular = 0.5 -light_bake_mode = 1 -light_cull_mask = -1 -shadow_enabled = false -shadow_color = Color( 0, 0, 0, 1 ) -shadow_bias = 0.15 -shadow_contact = 0.0 -shadow_reverse_cull_face = false -editor_only = false omni_range = 6.46518 -omni_attenuation = 1.0 -omni_shadow_mode = 1 -omni_shadow_detail = 1 -_sections_unfolded = [ "Shadow" ] - -[node name="Camera" type="Camera" parent="MaterialPreview" index="2"] +[node name="Camera" type="Camera" parent="MaterialPreview"] transform = Transform( 1, 0, 0, 0, 0.766044, 0.642787, 0, -0.642787, 0.766044, 0, 1.83022, 2.2549 ) -keep_aspect = 1 -cull_mask = 1048575 environment = SubResource( 8 ) -h_offset = 0.0 -v_offset = 0.0 -doppler_tracking = 0 -projection = 0 current = true -fov = 70.0 -size = 1.0 -near = 0.05 -far = 100.0 -_sections_unfolded = [ "Transform" ] - -[node name="WorldEnvironment" type="WorldEnvironment" parent="MaterialPreview" index="3"] +[node name="WorldEnvironment" type="WorldEnvironment" parent="MaterialPreview"] environment = SubResource( 8 ) -[node name="Config" type="HBoxContainer" parent="." index="2"] - -anchor_left = 0.0 -anchor_top = 0.0 +[node name="Config" type="HBoxContainer" parent="."] anchor_right = 1.0 -anchor_bottom = 0.0 margin_bottom = 20.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 -alignment = 0 -[node name="Model" type="OptionButton" parent="Config" index="0"] - -anchor_left = 0.0 -anchor_top = 0.0 -anchor_right = 0.0 -anchor_bottom = 0.0 +[node name="Model" type="OptionButton" parent="Config"] margin_right = 100.0 margin_bottom = 20.0 rect_min_size = Vector2( 100, 0 ) -rect_pivot_offset = Vector2( 0, 0 ) -rect_clip_content = false -focus_mode = 2 -mouse_filter = 0 -mouse_default_cursor_shape = 0 -size_flags_horizontal = 1 -size_flags_vertical = 1 -toggle_mode = false -action_mode = 0 -enabled_focus_mode = 2 -shortcut = null -group = null text = "Cube" -flat = false -align = 0 items = [ "Cube", null, false, 0, null, "Cylinder", null, false, 1, null, "Sphere", null, false, 2, null ] selected = 0 -_sections_unfolded = [ "Margin", "Rect" ] -[node name="Environment" type="OptionButton" parent="Config" index="1"] - -anchor_left = 0.0 -anchor_top = 0.0 -anchor_right = 0.0 -anchor_bottom = 0.0 +[node name="Environment" type="OptionButton" parent="Config"] margin_left = 104.0 margin_right = 204.0 margin_bottom = 20.0 rect_min_size = Vector2( 100, 0 ) -rect_pivot_offset = Vector2( 0, 0 ) -rect_clip_content = false -focus_mode = 2 -mouse_filter = 0 -mouse_default_cursor_shape = 0 -size_flags_horizontal = 1 -size_flags_vertical = 1 -toggle_mode = false -action_mode = 0 -enabled_focus_mode = 2 -shortcut = null -group = null text = "Park" -flat = false -align = 0 items = [ "Experiment", null, false, 0, null, "Lobby", null, false, 1, null, "Night", null, false, 2, null, "Park", null, false, 3, null, "Schelde", null, false, 4, null ] selected = 3 -_sections_unfolded = [ "Rect" ] - -[node name="Preview2D" type="ColorRect" parent="." index="3"] +[node name="Preview2D" type="ColorRect" parent="."] material = SubResource( 10 ) -anchor_left = 0.0 anchor_top = 1.0 -anchor_right = 0.0 anchor_bottom = 1.0 margin_top = -64.0 margin_right = 64.0 rect_min_size = Vector2( 64, 64 ) -rect_pivot_offset = Vector2( 0, 0 ) -rect_clip_content = false mouse_filter = 1 -mouse_default_cursor_shape = 0 size_flags_horizontal = 0 size_flags_vertical = 8 -color = Color( 1, 1, 1, 1 ) -_sections_unfolded = [ "Anchor", "Material", "Mouse", "Rect", "Size Flags" ] - [connection signal="resized" from="." to="." method="_on_Preview_resized"] - [connection signal="item_selected" from="Config/Model" to="." method="_on_Model_item_selected"] - [connection signal="item_selected" from="Config/Environment" to="." method="_on_Environment_item_selected"] - [connection signal="gui_input" from="Preview2D" to="." method="_on_Preview2D_gui_input"] - - diff --git a/addons/material_maker/window_dialog.tscn b/addons/material_maker/window_dialog.tscn index 0d2b9de..f70fdb5 100644 --- a/addons/material_maker/window_dialog.tscn +++ b/addons/material_maker/window_dialog.tscn @@ -3,24 +3,10 @@ [ext_resource path="res://addons/material_maker/main_window.tscn" type="PackedScene" id=1] [node name="WindowDialog" type="WindowDialog"] - -anchor_left = 0.0 -anchor_top = 0.0 -anchor_right = 0.0 -anchor_bottom = 0.0 margin_right = 1124.0 margin_bottom = 619.0 -rect_pivot_offset = Vector2( 0, 0 ) -rect_clip_content = false -mouse_filter = 0 -mouse_default_cursor_shape = 0 -size_flags_horizontal = 1 -size_flags_vertical = 1 popup_exclusive = true window_title = "Material Maker" resizable = true -_sections_unfolded = [ "Popup" ] - -[node name="MainWindow" parent="." index="1" instance=ExtResource( 1 )] - +[node name="MainWindow" parent="." instance=ExtResource( 1 )] diff --git a/export_presets.cfg b/export_presets.cfg index a33c086..5fbff90 100644 --- a/export_presets.cfg +++ b/export_presets.cfg @@ -8,13 +8,18 @@ export_filter="resources" export_files=PoolStringArray( "res://addons/material_maker/common.shader", "res://addons/material_maker/graph_edit.gd", "res://addons/material_maker/graph_edit.tscn", "res://addons/material_maker/icons/add.png", "res://addons/material_maker/icons/add_config.png", "res://addons/material_maker/icons/add_link.png", "res://addons/material_maker/icons/config.png", "res://addons/material_maker/icons/edit.png", "res://addons/material_maker/icons/icon.png", "res://addons/material_maker/icons/link.png", "res://addons/material_maker/icons/load.png", "res://addons/material_maker/icons/minus.png", "res://addons/material_maker/icons/plus.png", "res://addons/material_maker/icons/remove.png", "res://addons/material_maker/icons/save.png", "res://addons/material_maker/library.gd", "res://addons/material_maker/main_window.gd", "res://addons/material_maker/main_window.tscn", "res://addons/material_maker/node_base.gd", "res://addons/material_maker/node_factory.gd", "res://addons/material_maker/nodes/adjust_hsv.gd", "res://addons/material_maker/nodes/adjust_hsv.tscn", "res://addons/material_maker/nodes/adjust_hsv/adjust_hsv.gd", "res://addons/material_maker/nodes/adjust_hsv/adjust_hsv.tscn", "res://addons/material_maker/nodes/blend.gd", "res://addons/material_maker/nodes/blend.tscn", "res://addons/material_maker/nodes/blend/blend.gd", "res://addons/material_maker/nodes/blend/blend.tscn", "res://addons/material_maker/nodes/blur.gd", "res://addons/material_maker/nodes/blur.tscn", "res://addons/material_maker/nodes/blur/blur.gd", "res://addons/material_maker/nodes/blur/blur.tscn", "res://addons/material_maker/nodes/bricks.gd", "res://addons/material_maker/nodes/bricks.tscn", "res://addons/material_maker/nodes/bricks/bricks.gd", "res://addons/material_maker/nodes/bricks/bricks.tscn", "res://addons/material_maker/nodes/colorize.gd", "res://addons/material_maker/nodes/colorize.tscn", "res://addons/material_maker/nodes/colorize/colorize.gd", "res://addons/material_maker/nodes/colorize/colorize.tscn", "res://addons/material_maker/nodes/combine.gd", "res://addons/material_maker/nodes/combine.tscn", "res://addons/material_maker/nodes/combine/combine.gd", "res://addons/material_maker/nodes/combine/combine.tscn", "res://addons/material_maker/nodes/comment.gd", "res://addons/material_maker/nodes/comment.tscn", "res://addons/material_maker/nodes/comment/comment.gd", "res://addons/material_maker/nodes/comment/comment.tscn", "res://addons/material_maker/nodes/compound.tscn", "res://addons/material_maker/nodes/custom/custom.gd", "res://addons/material_maker/nodes/custom/custom.tscn", "res://addons/material_maker/nodes/decompose.gd", "res://addons/material_maker/nodes/decompose.tscn", "res://addons/material_maker/nodes/decompose/decompose.gd", "res://addons/material_maker/nodes/decompose/decompose.tscn", "res://addons/material_maker/nodes/emboss.gd", "res://addons/material_maker/nodes/emboss.tscn", "res://addons/material_maker/nodes/emboss/emboss.gd", "res://addons/material_maker/nodes/emboss/emboss.tscn", "res://addons/material_maker/nodes/export.gd", "res://addons/material_maker/nodes/export.tscn", "res://addons/material_maker/nodes/export/export.gd", "res://addons/material_maker/nodes/export/export.tscn", "res://addons/material_maker/nodes/godot_logo.png", "res://addons/material_maker/nodes/image.gd", "res://addons/material_maker/nodes/image.tscn", "res://addons/material_maker/nodes/image/godot_logo.png", "res://addons/material_maker/nodes/image/image.gd", "res://addons/material_maker/nodes/image/image.tscn", "res://addons/material_maker/nodes/material.gd", "res://addons/material_maker/nodes/material.tscn", "res://addons/material_maker/nodes/material/material.gd", "res://addons/material_maker/nodes/material/material.tscn", "res://addons/material_maker/nodes/node_generic.gd", "res://addons/material_maker/nodes/noise.gd", "res://addons/material_maker/nodes/noise.tscn", "res://addons/material_maker/nodes/noise/noise.gd", "res://addons/material_maker/nodes/noise/noise.tscn", "res://addons/material_maker/nodes/normal_map.gd", "res://addons/material_maker/nodes/normal_map.tscn", "res://addons/material_maker/nodes/normal_map/normal_map.gd", "res://addons/material_maker/nodes/normal_map/normal_map.tscn", "res://addons/material_maker/nodes/pattern.gd", "res://addons/material_maker/nodes/pattern.tscn", "res://addons/material_maker/nodes/pattern/pattern.gd", "res://addons/material_maker/nodes/pattern/pattern.tscn", "res://addons/material_maker/nodes/perlin.gd", "res://addons/material_maker/nodes/perlin.tscn", "res://addons/material_maker/nodes/perlin/perlin.gd", "res://addons/material_maker/nodes/perlin/perlin.tscn", "res://addons/material_maker/nodes/remote.gd", "res://addons/material_maker/nodes/remote.tscn", "res://addons/material_maker/nodes/remote/remote.gd", "res://addons/material_maker/nodes/remote/remote.tscn", "res://addons/material_maker/nodes/shape/shape.gd", "res://addons/material_maker/nodes/shape/shape.tscn", "res://addons/material_maker/nodes/switch.gd", "res://addons/material_maker/nodes/switch.tscn", "res://addons/material_maker/nodes/switch/switch.gd", "res://addons/material_maker/nodes/switch/switch.tscn", "res://addons/material_maker/nodes/transform.gd", "res://addons/material_maker/nodes/transform.tscn", "res://addons/material_maker/nodes/transform/transform.gd", "res://addons/material_maker/nodes/transform/transform.tscn", "res://addons/material_maker/nodes/uniform.gd", "res://addons/material_maker/nodes/uniform.tscn", "res://addons/material_maker/nodes/uniform/uniform.gd", "res://addons/material_maker/nodes/uniform/uniform.tscn", "res://addons/material_maker/nodes/voronoi.gd", "res://addons/material_maker/nodes/voronoi.tscn", "res://addons/material_maker/nodes/voronoi/voronoi.gd", "res://addons/material_maker/nodes/voronoi/voronoi.tscn", "res://addons/material_maker/nodes/warp.gd", "res://addons/material_maker/nodes/warp.tscn", "res://addons/material_maker/nodes/warp/warp.gd", "res://addons/material_maker/nodes/warp/warp.tscn", "res://addons/material_maker/panoramas/experiment.hdr", "res://addons/material_maker/panoramas/lobby.hdr", "res://addons/material_maker/panoramas/night.hdr", "res://addons/material_maker/panoramas/park.hdr", "res://addons/material_maker/panoramas/schelde.hdr", "res://addons/material_maker/pm_editor.gd", "res://addons/material_maker/pm_editor.tscn", "res://addons/material_maker/preview.gd", "res://addons/material_maker/preview.tscn", "res://addons/material_maker/renderer.gd", "res://addons/material_maker/renderer.tscn", "res://addons/material_maker/types/gradient.gd", "res://addons/material_maker/types/types.gd", "res://addons/material_maker/widgets/about.gd", "res://addons/material_maker/widgets/about.tscn", "res://addons/material_maker/widgets/facebook.png", "res://addons/material_maker/widgets/github.png", "res://addons/material_maker/widgets/gradient_editor.gd", "res://addons/material_maker/widgets/gradient_editor.tscn", "res://addons/material_maker/widgets/icon.png", "res://addons/material_maker/widgets/line_dialog.gd", "res://addons/material_maker/widgets/line_dialog.tscn", "res://addons/material_maker/widgets/linked_widgets/config_control.gd", "res://addons/material_maker/widgets/linked_widgets/config_control.tscn", "res://addons/material_maker/widgets/linked_widgets/editable_label.gd", "res://addons/material_maker/widgets/linked_widgets/editable_label.tscn", "res://addons/material_maker/widgets/linked_widgets/link.gd", "res://addons/material_maker/widgets/linked_widgets/linked_control.gd", "res://addons/material_maker/widgets/linked_widgets/linked_control.tscn", "res://addons/material_maker/widgets/linked_widgets/linked_control_base.gd", "res://addons/material_maker/widgets/linked_widgets/linked_control_buttons.gd", "res://addons/material_maker/widgets/linked_widgets/linked_control_buttons.tscn", "res://addons/material_maker/widgets/node_editor.tscn", "res://addons/material_maker/widgets/node_editor/enum_editor.gd", "res://addons/material_maker/widgets/node_editor/enum_editor.tscn", "res://addons/material_maker/widgets/node_editor/input.gd", "res://addons/material_maker/widgets/node_editor/input.tscn", "res://addons/material_maker/widgets/node_editor/node_editor.gd", "res://addons/material_maker/widgets/node_editor/node_editor.tscn", "res://addons/material_maker/widgets/node_editor/output.gd", "res://addons/material_maker/widgets/node_editor/output.tscn", "res://addons/material_maker/widgets/node_editor/parameter.gd", "res://addons/material_maker/widgets/node_editor/parameter.tscn", "res://addons/material_maker/widgets/node_editor/parameter_boolean.gd", "res://addons/material_maker/widgets/node_editor/parameter_boolean.tscn", "res://addons/material_maker/widgets/node_editor/parameter_color.gd", "res://addons/material_maker/widgets/node_editor/parameter_color.tscn", "res://addons/material_maker/widgets/node_editor/parameter_enum.gd", "res://addons/material_maker/widgets/node_editor/parameter_enum.tscn", "res://addons/material_maker/widgets/node_editor/parameter_float.gd", "res://addons/material_maker/widgets/node_editor/parameter_float.tscn", "res://addons/material_maker/widgets/node_editor/parameter_size.gd", "res://addons/material_maker/widgets/node_editor/parameter_size.tscn", "res://addons/material_maker/widgets/tabs.gd", "res://addons/material_maker/widgets/text_dialog.gd", "res://addons/material_maker/widgets/text_dialog.tscn", "res://addons/material_maker/widgets/twitter.png", "res://addons/material_maker/widgets/youtube.png", "res://addons/material_maker/window_dialog.tscn", "res://icon.png" ) include_filter="*.json,*.mmn,res://addons/material_maker/library/base/*.png" exclude_filter="*.ptex" +export_path="D:/Dev/material_maker.exe" patch_list=PoolStringArray( ) +script_export_mode=1 +script_encryption_key="" [preset.0.options] +texture_format/bptc=false texture_format/s3tc=true texture_format/etc=true texture_format/etc2=true +texture_format/no_bptc_fallbacks=true binary_format/64_bits=true custom_template/release="" custom_template/debug="" @@ -37,13 +42,18 @@ export_filter="resources" export_files=PoolStringArray( "res://addons/material_maker/common.shader", "res://addons/material_maker/graph_edit.gd", "res://addons/material_maker/graph_edit.tscn", "res://addons/material_maker/icons/add.png", "res://addons/material_maker/icons/add_config.png", "res://addons/material_maker/icons/add_link.png", "res://addons/material_maker/icons/config.png", "res://addons/material_maker/icons/edit.png", "res://addons/material_maker/icons/icon.png", "res://addons/material_maker/icons/link.png", "res://addons/material_maker/icons/load.png", "res://addons/material_maker/icons/minus.png", "res://addons/material_maker/icons/plus.png", "res://addons/material_maker/icons/remove.png", "res://addons/material_maker/icons/save.png", "res://addons/material_maker/library.gd", "res://addons/material_maker/main_window.gd", "res://addons/material_maker/main_window.tscn", "res://addons/material_maker/node_base.gd", "res://addons/material_maker/node_factory.gd", "res://addons/material_maker/nodes/adjust_hsv.gd", "res://addons/material_maker/nodes/adjust_hsv.tscn", "res://addons/material_maker/nodes/adjust_hsv/adjust_hsv.gd", "res://addons/material_maker/nodes/adjust_hsv/adjust_hsv.tscn", "res://addons/material_maker/nodes/blend.gd", "res://addons/material_maker/nodes/blend.tscn", "res://addons/material_maker/nodes/blend/blend.gd", "res://addons/material_maker/nodes/blend/blend.tscn", "res://addons/material_maker/nodes/blur.gd", "res://addons/material_maker/nodes/blur.tscn", "res://addons/material_maker/nodes/blur/blur.gd", "res://addons/material_maker/nodes/blur/blur.tscn", "res://addons/material_maker/nodes/bricks.gd", "res://addons/material_maker/nodes/bricks.tscn", "res://addons/material_maker/nodes/bricks/bricks.gd", "res://addons/material_maker/nodes/bricks/bricks.tscn", "res://addons/material_maker/nodes/colorize.gd", "res://addons/material_maker/nodes/colorize.tscn", "res://addons/material_maker/nodes/colorize/colorize.gd", "res://addons/material_maker/nodes/colorize/colorize.tscn", "res://addons/material_maker/nodes/combine.gd", "res://addons/material_maker/nodes/combine.tscn", "res://addons/material_maker/nodes/combine/combine.gd", "res://addons/material_maker/nodes/combine/combine.tscn", "res://addons/material_maker/nodes/comment.gd", "res://addons/material_maker/nodes/comment.tscn", "res://addons/material_maker/nodes/comment/comment.gd", "res://addons/material_maker/nodes/comment/comment.tscn", "res://addons/material_maker/nodes/compound.tscn", "res://addons/material_maker/nodes/custom/custom.gd", "res://addons/material_maker/nodes/custom/custom.tscn", "res://addons/material_maker/nodes/decompose.gd", "res://addons/material_maker/nodes/decompose.tscn", "res://addons/material_maker/nodes/decompose/decompose.gd", "res://addons/material_maker/nodes/decompose/decompose.tscn", "res://addons/material_maker/nodes/emboss.gd", "res://addons/material_maker/nodes/emboss.tscn", "res://addons/material_maker/nodes/emboss/emboss.gd", "res://addons/material_maker/nodes/emboss/emboss.tscn", "res://addons/material_maker/nodes/export.gd", "res://addons/material_maker/nodes/export.tscn", "res://addons/material_maker/nodes/export/export.gd", "res://addons/material_maker/nodes/export/export.tscn", "res://addons/material_maker/nodes/godot_logo.png", "res://addons/material_maker/nodes/image.gd", "res://addons/material_maker/nodes/image.tscn", "res://addons/material_maker/nodes/image/godot_logo.png", "res://addons/material_maker/nodes/image/image.gd", "res://addons/material_maker/nodes/image/image.tscn", "res://addons/material_maker/nodes/material.gd", "res://addons/material_maker/nodes/material.tscn", "res://addons/material_maker/nodes/material/material.gd", "res://addons/material_maker/nodes/material/material.tscn", "res://addons/material_maker/nodes/node_generic.gd", "res://addons/material_maker/nodes/noise.gd", "res://addons/material_maker/nodes/noise.tscn", "res://addons/material_maker/nodes/noise/noise.gd", "res://addons/material_maker/nodes/noise/noise.tscn", "res://addons/material_maker/nodes/normal_map.gd", "res://addons/material_maker/nodes/normal_map.tscn", "res://addons/material_maker/nodes/normal_map/normal_map.gd", "res://addons/material_maker/nodes/normal_map/normal_map.tscn", "res://addons/material_maker/nodes/pattern.gd", "res://addons/material_maker/nodes/pattern.tscn", "res://addons/material_maker/nodes/pattern/pattern.gd", "res://addons/material_maker/nodes/pattern/pattern.tscn", "res://addons/material_maker/nodes/perlin.gd", "res://addons/material_maker/nodes/perlin.tscn", "res://addons/material_maker/nodes/perlin/perlin.gd", "res://addons/material_maker/nodes/perlin/perlin.tscn", "res://addons/material_maker/nodes/remote.gd", "res://addons/material_maker/nodes/remote.tscn", "res://addons/material_maker/nodes/remote/remote.gd", "res://addons/material_maker/nodes/remote/remote.tscn", "res://addons/material_maker/nodes/shape/shape.gd", "res://addons/material_maker/nodes/shape/shape.tscn", "res://addons/material_maker/nodes/switch.gd", "res://addons/material_maker/nodes/switch.tscn", "res://addons/material_maker/nodes/switch/switch.gd", "res://addons/material_maker/nodes/switch/switch.tscn", "res://addons/material_maker/nodes/transform.gd", "res://addons/material_maker/nodes/transform.tscn", "res://addons/material_maker/nodes/transform/transform.gd", "res://addons/material_maker/nodes/transform/transform.tscn", "res://addons/material_maker/nodes/uniform.gd", "res://addons/material_maker/nodes/uniform.tscn", "res://addons/material_maker/nodes/uniform/uniform.gd", "res://addons/material_maker/nodes/uniform/uniform.tscn", "res://addons/material_maker/nodes/voronoi.gd", "res://addons/material_maker/nodes/voronoi.tscn", "res://addons/material_maker/nodes/voronoi/voronoi.gd", "res://addons/material_maker/nodes/voronoi/voronoi.tscn", "res://addons/material_maker/nodes/warp.gd", "res://addons/material_maker/nodes/warp.tscn", "res://addons/material_maker/nodes/warp/warp.gd", "res://addons/material_maker/nodes/warp/warp.tscn", "res://addons/material_maker/panoramas/experiment.hdr", "res://addons/material_maker/panoramas/lobby.hdr", "res://addons/material_maker/panoramas/night.hdr", "res://addons/material_maker/panoramas/park.hdr", "res://addons/material_maker/panoramas/schelde.hdr", "res://addons/material_maker/pm_editor.gd", "res://addons/material_maker/pm_editor.tscn", "res://addons/material_maker/preview.gd", "res://addons/material_maker/preview.tscn", "res://addons/material_maker/renderer.gd", "res://addons/material_maker/renderer.tscn", "res://addons/material_maker/types/gradient.gd", "res://addons/material_maker/types/types.gd", "res://addons/material_maker/widgets/about.gd", "res://addons/material_maker/widgets/about.tscn", "res://addons/material_maker/widgets/facebook.png", "res://addons/material_maker/widgets/github.png", "res://addons/material_maker/widgets/gradient_editor.gd", "res://addons/material_maker/widgets/gradient_editor.tscn", "res://addons/material_maker/widgets/icon.png", "res://addons/material_maker/widgets/line_dialog.gd", "res://addons/material_maker/widgets/line_dialog.tscn", "res://addons/material_maker/widgets/linked_widgets/config_control.gd", "res://addons/material_maker/widgets/linked_widgets/config_control.tscn", "res://addons/material_maker/widgets/linked_widgets/editable_label.gd", "res://addons/material_maker/widgets/linked_widgets/editable_label.tscn", "res://addons/material_maker/widgets/linked_widgets/link.gd", "res://addons/material_maker/widgets/linked_widgets/linked_control.gd", "res://addons/material_maker/widgets/linked_widgets/linked_control.tscn", "res://addons/material_maker/widgets/linked_widgets/linked_control_base.gd", "res://addons/material_maker/widgets/linked_widgets/linked_control_buttons.gd", "res://addons/material_maker/widgets/linked_widgets/linked_control_buttons.tscn", "res://addons/material_maker/widgets/node_editor.tscn", "res://addons/material_maker/widgets/node_editor/enum_editor.gd", "res://addons/material_maker/widgets/node_editor/enum_editor.tscn", "res://addons/material_maker/widgets/node_editor/input.gd", "res://addons/material_maker/widgets/node_editor/input.tscn", "res://addons/material_maker/widgets/node_editor/node_editor.gd", "res://addons/material_maker/widgets/node_editor/node_editor.tscn", "res://addons/material_maker/widgets/node_editor/output.gd", "res://addons/material_maker/widgets/node_editor/output.tscn", "res://addons/material_maker/widgets/node_editor/parameter.gd", "res://addons/material_maker/widgets/node_editor/parameter.tscn", "res://addons/material_maker/widgets/node_editor/parameter_boolean.gd", "res://addons/material_maker/widgets/node_editor/parameter_boolean.tscn", "res://addons/material_maker/widgets/node_editor/parameter_color.gd", "res://addons/material_maker/widgets/node_editor/parameter_color.tscn", "res://addons/material_maker/widgets/node_editor/parameter_enum.gd", "res://addons/material_maker/widgets/node_editor/parameter_enum.tscn", "res://addons/material_maker/widgets/node_editor/parameter_float.gd", "res://addons/material_maker/widgets/node_editor/parameter_float.tscn", "res://addons/material_maker/widgets/node_editor/parameter_size.gd", "res://addons/material_maker/widgets/node_editor/parameter_size.tscn", "res://addons/material_maker/widgets/tabs.gd", "res://addons/material_maker/widgets/text_dialog.gd", "res://addons/material_maker/widgets/text_dialog.tscn", "res://addons/material_maker/widgets/twitter.png", "res://addons/material_maker/widgets/youtube.png", "res://addons/material_maker/window_dialog.tscn", "res://icon.png" ) include_filter="*.json,*.mmn,res://addons/material_maker/library/base/*.png" exclude_filter="*.ptex" +export_path="" patch_list=PoolStringArray( ) +script_export_mode=1 +script_encryption_key="" [preset.1.options] +texture_format/bptc=false texture_format/s3tc=true texture_format/etc=false texture_format/etc2=false +texture_format/no_bptc_fallbacks=true binary_format/64_bits=true custom_template/release="" custom_template/debug="" diff --git a/project.godot b/project.godot index 5c9962d..7bbdcd1 100644 --- a/project.godot +++ b/project.godot @@ -19,6 +19,11 @@ _global_script_classes=[ { "language": "GDScript", "path": "res://addons/material_maker/engine/gen_buffer.gd" }, { +"base": "Object", +"class": "MMGenContext", +"language": "GDScript", +"path": "res://addons/material_maker/engine/gen_context.gd" +}, { "base": "MMGenBase", "class": "MMGenConvolution", "language": "GDScript", @@ -57,6 +62,7 @@ _global_script_classes=[ { _global_script_class_icons={ "MMGenBase": "", "MMGenBuffer": "", +"MMGenContext": "", "MMGenConvolution": "", "MMGenGraph": "", "MMGenLoader": "", From 049250e073ca9937e6a39d31ee69af0e8a57d5c9 Mon Sep 17 00:00:00 2001 From: Rodolphe Suescun Date: Tue, 13 Aug 2019 13:38:11 +0200 Subject: [PATCH 005/133] Added graph node initialization --- addons/material_maker/engine/gen_graph.gd | 3 ++ addons/material_maker/graph_edit.gd | 25 +++++----- addons/material_maker/nodes/generic.gd | 58 +++++++++++++++++++++-- 3 files changed, 70 insertions(+), 16 deletions(-) diff --git a/addons/material_maker/engine/gen_graph.gd b/addons/material_maker/engine/gen_graph.gd index af73b8d..4a5310b 100644 --- a/addons/material_maker/engine/gen_graph.gd +++ b/addons/material_maker/engine/gen_graph.gd @@ -9,3 +9,6 @@ func get_port_source(gen_name: String, input_index: int) -> OutputPort: if c.to == gen_name and c.to_port == input_index: return OutputPort.new(get_node(c.from), c.from_port) return null + +func connect_children(src, src_index : int, dst, dst_index : int): + pass \ No newline at end of file diff --git a/addons/material_maker/graph_edit.gd b/addons/material_maker/graph_edit.gd index c1e1572..192f12b 100644 --- a/addons/material_maker/graph_edit.gd +++ b/addons/material_maker/graph_edit.gd @@ -29,7 +29,7 @@ func _gui_input(event): func get_source(node, port): for c in get_connection_list(): - if c.to == node && c.to_port == port: + if c.to == node and c.to_port == port: return { node=c.from, slot=c.from_port } func offset_from_global_position(global_position): @@ -40,6 +40,13 @@ func add_node(node): node.connect("close_request", self, "remove_node", [ node ]) func connect_node(from, from_slot, to, to_slot): + print("Connecting "+str(from)+"("+str(from_slot)+") to "+str(to)+"("+str(to_slot)+")") + if generator.connect_children(get_node(from).generator, from_slot, get_node(to).generator, to_slot): + var disconnect = get_source(to, to_slot) + if disconnect != null: + .disconnect_node(disconnect.node, disconnect.slot, to, to_slot) + .connect_node(from, from_slot, to, to_slot) + send_changed_signal() var source_list = [ from ] # Check if the new connection creates a cycle in the graph while !source_list.empty(): @@ -50,10 +57,6 @@ func connect_node(from, from_slot, to, to_slot): for c in get_connection_list(): if c.to == source and source_list.find(c.from) == -1: source_list.append(c.from) - var disconnect = get_source(to, to_slot) - if disconnect != null: - .disconnect_node(disconnect.node, disconnect.slot, to, to_slot) - .connect_node(from, from_slot, to, to_slot) send_changed_signal() return true @@ -121,7 +124,7 @@ func create_nodes(data, position = null): if data.has("type"): var node = node_factory.create_node(data.type) if node != null: - if data.has("name") && !has_node(data.name): + if data.has("name") and !has_node(data.name): node.name = data.name else: node.name = get_free_name(data.type) @@ -181,21 +184,21 @@ func export_textures(size = null): if save_path != null: var prefix = save_path.left(save_path.rfind(".")) for c in get_children(): - if c is GraphNode && c.has_method("export_textures"): + if c is GraphNode and c.has_method("export_textures"): c.export_textures(prefix, size) # Cut / copy / paste func remove_selection(): for c in get_children(): - if c is GraphNode and c.selected && c.name != "Material": + if c is GraphNode and c.selected and c.name != "Material": remove_node(c) func serialize_selection(): var data = { nodes = [], connections = [] } var nodes = [] for c in get_children(): - if c is GraphNode and c.selected && c.name != "Material": + if c is GraphNode and c.selected and c.name != "Material": nodes.append(c) if nodes.empty(): return null @@ -217,7 +220,7 @@ func serialize_selection(): func can_copy(): for c in get_children(): - if c is GraphNode and c.selected && c.name != "Material": + if c is GraphNode and c.selected and c.name != "Material": return true return false @@ -252,7 +255,7 @@ func center_view(): func send_changed_signal(): set_need_save(true) - #$Timer.start() + $Timer.start() func do_send_changed_signal(): emit_signal("graph_changed") diff --git a/addons/material_maker/nodes/generic.gd b/addons/material_maker/nodes/generic.gd index 31723f4..27ed64c 100644 --- a/addons/material_maker/nodes/generic.gd +++ b/addons/material_maker/nodes/generic.gd @@ -2,6 +2,8 @@ extends GraphNode var generator = null setget set_generator +var controls = [] + var uses_seed : bool = false var parameters = {} @@ -15,8 +17,54 @@ func set_generator(g): generator = g update_node(g.model_data) -func initialize_properties(p): - pass +func initialize_properties(): + for o in controls: + if o == null: + print("error in node "+name) + elif o is LineEdit: + o.text = str(generator.parameters[o.name]) + o.connect("text_changed", self, "_on_text_changed", [ o.name ]) + elif o is SpinBox: + o.value = generator.parameters[o.name] + o.connect("value_changed", self, "_on_value_changed", [ o.name ]) + elif o is HSlider: + o.value = generator.parameters[o.name] + o.connect("value_changed", self, "_on_value_changed", [ o.name ]) + elif o is OptionButton: + o.selected = generator.parameters[o.name] + o.connect("item_selected", self, "_on_value_changed", [ o.name ]) + elif o is CheckBox: + o.pressed = generator.parameters[o.name] + o.connect("toggled", self, "_on_value_changed", [ o.name ]) + elif o is ColorPickerButton: + o.color = generator.parameters[o.name] + o.connect("color_changed", self, "_on_color_changed", [ o.name ]) + elif o is Control and o.filename == "res://addons/material_maker/widgets/gradient_editor.tscn": + var gradient : MMGradient = MMGradient.new() + gradient.deserialize(generator.parameters[o.name]) + o.value = gradient + o.connect("updated", self, "_on_gradient_changed", [ o.name ]) + else: + print("unsupported widget "+str(o)) + +func update_shaders(): + get_parent().send_changed_signal() + +func _on_text_changed(new_text, variable): + generator.parameters[variable] = float(new_text) + update_shaders() + +func _on_value_changed(new_value, variable): + generator.parameters[variable] = new_value + update_shaders() + +func _on_color_changed(new_color, variable): + generator.parameters[variable] = new_color + update_shaders() + +func _on_gradient_changed(new_gradient, variable): + generator.parameters[variable] = new_gradient + update_shaders() func update_node(data): print("node_generic.update_node") @@ -40,7 +88,7 @@ func update_node(data): if model_data.has("instance") and model_data.instance.find("$(seed)"): uses_seed = true if model_data.has("parameters") and typeof(model_data.parameters) == TYPE_ARRAY: - var control_list = [] + controls = [] var sizer = null for p in model_data.parameters: if !p.has("name") or !p.has("type"): @@ -79,7 +127,7 @@ func update_node(data): if control != null: var label = p.name control.name = label - control_list.append(control) + controls.append(control) if p.has("label"): label = p.label if sizer == null or label != "nonewline": @@ -93,7 +141,7 @@ func update_node(data): sizer.add_child(label_widget) control.size_flags_horizontal = SIZE_EXPAND | SIZE_FILL sizer.add_child(control) - initialize_properties(control_list) + initialize_properties() else: model_data.parameters = [] if model_data.has("inputs") and typeof(model_data.inputs) == TYPE_ARRAY: From a8dffae7cf4c7ce67f463611899f7014ff5ead0d Mon Sep 17 00:00:00 2001 From: Rodolphe Suescun Date: Wed, 14 Aug 2019 09:02:38 +0200 Subject: [PATCH 006/133] Fixed connecting/disconnecting generators --- addons/material_maker/engine/gen_graph.gd | 28 +++++++++++++++++++++-- addons/material_maker/graph_edit.gd | 17 +++----------- addons/material_maker/main_window.gd | 1 - addons/material_maker/preview.tscn | 6 ++--- 4 files changed, 31 insertions(+), 21 deletions(-) diff --git a/addons/material_maker/engine/gen_graph.gd b/addons/material_maker/engine/gen_graph.gd index 4a5310b..f87007f 100644 --- a/addons/material_maker/engine/gen_graph.gd +++ b/addons/material_maker/engine/gen_graph.gd @@ -10,5 +10,29 @@ func get_port_source(gen_name: String, input_index: int) -> OutputPort: return OutputPort.new(get_node(c.from), c.from_port) return null -func connect_children(src, src_index : int, dst, dst_index : int): - pass \ No newline at end of file +func connect_children(from, from_port : int, to, to_port : int): + # disconnect target + while true: + var remove = -1 + for i in connections.size(): + if connections[i].to == to.name and connections[i].to_port == to_port: + remove = i + break + if remove == -1: + break + connections.remove(remove) + # create new connection + connections.append({from=from.name, from_port=from_port, to=to.name, to_port=to_port}) + return true + +func disconnect_children(from, from_port : int, to, to_port : int): + while true: + var remove = -1 + for i in connections.size(): + if connections[i].from == from.name and connections[i].from_port == from_port and connections[i].to == to.name and connections[i].to_port == to_port: + remove = i + break + if remove == -1: + break + connections.remove(remove) + return true \ No newline at end of file diff --git a/addons/material_maker/graph_edit.gd b/addons/material_maker/graph_edit.gd index 192f12b..ab5d07c 100644 --- a/addons/material_maker/graph_edit.gd +++ b/addons/material_maker/graph_edit.gd @@ -47,22 +47,11 @@ func connect_node(from, from_slot, to, to_slot): .disconnect_node(disconnect.node, disconnect.slot, to, to_slot) .connect_node(from, from_slot, to, to_slot) send_changed_signal() - var source_list = [ from ] - # Check if the new connection creates a cycle in the graph - while !source_list.empty(): - var source = source_list.pop_front() - if source == to: - #print("cannot connect %s to %s (%s)" % [from, to, source]) - return false - for c in get_connection_list(): - if c.to == source and source_list.find(c.from) == -1: - source_list.append(c.from) - send_changed_signal() - return true func disconnect_node(from, from_slot, to, to_slot): - .disconnect_node(from, from_slot, to, to_slot) - send_changed_signal(); + if generator.disconnect_children(get_node(from).generator, from_slot, get_node(to).generator, to_slot): + .disconnect_node(from, from_slot, to, to_slot) + send_changed_signal(); func remove_node(node): var node_name = node.name diff --git a/addons/material_maker/main_window.gd b/addons/material_maker/main_window.gd index 7b25a61..8e9516d 100644 --- a/addons/material_maker/main_window.gd +++ b/addons/material_maker/main_window.gd @@ -307,7 +307,6 @@ func update_preview_2d(node = null): node = n break if node != null: - print(node.name) var source = node.generator.get_shader(0) if source != null: var shader : String = renderer.generate_shader(source) diff --git a/addons/material_maker/preview.tscn b/addons/material_maker/preview.tscn index f84c456..3b8d8f6 100644 --- a/addons/material_maker/preview.tscn +++ b/addons/material_maker/preview.tscn @@ -1,8 +1,7 @@ -[gd_scene load_steps=14 format=2] +[gd_scene load_steps=13 format=2] [ext_resource path="res://addons/material_maker/preview.gd" type="Script" id=1] [ext_resource path="res://addons/material_maker/panoramas/park.hdr" type="Texture" id=2] -[ext_resource path="res://icon.png" type="Texture" id=3] [sub_resource type="Animation" id=1] loop = true @@ -100,7 +99,6 @@ void fragment() { [sub_resource type="ShaderMaterial" id=10] shader = SubResource( 9 ) -shader_param/tex = ExtResource( 3 ) [node name="Preview" type="ViewportContainer"] anchor_left = 1.0 @@ -129,7 +127,7 @@ render_target_clear_mode = 1 render_target_update_mode = 3 [node name="Objects" type="Spatial" parent="MaterialPreview"] -transform = Transform( -0.956327, 0, -0.292284, 0, 1, 0, 0.292284, 0, -0.956327, 0, 0, 0 ) +transform = Transform( 0.979431, 0, -0.201756, 0, 1, 0, 0.201756, 0, 0.979431, 0, 0, 0 ) [node name="Cube" type="MeshInstance" parent="MaterialPreview/Objects"] mesh = SubResource( 2 ) From 470e55b2126b198c440c0d3ea26a1ad0570a88f5 Mon Sep 17 00:00:00 2001 From: Rodolphe Suescun Date: Wed, 14 Aug 2019 15:55:39 +0200 Subject: [PATCH 007/133] Added nodes removal & new node creation --- addons/material_maker/graph_edit.gd | 30 ++++++++++++++++++++++----- addons/material_maker/graph_edit.tscn | 13 +----------- addons/material_maker/main_window.gd | 4 ++++ addons/material_maker/new.ptex | 2 +- 4 files changed, 31 insertions(+), 18 deletions(-) diff --git a/addons/material_maker/graph_edit.gd b/addons/material_maker/graph_edit.gd index ab5d07c..ab70da9 100644 --- a/addons/material_maker/graph_edit.gd +++ b/addons/material_maker/graph_edit.gd @@ -54,12 +54,13 @@ func disconnect_node(from, from_slot, to, to_slot): send_changed_signal(); func remove_node(node): + generator.remove_node(node.generator) var node_name = node.name for c in get_connection_list(): if c.from == node_name or c.to == node_name: disconnect_node(c.from, c.from_port, c.to, c.to_port) - send_changed_signal() node.queue_free() + send_changed_signal() # Global operations on graph @@ -91,13 +92,33 @@ func clear_material(): if c is GraphNode: remove_child(c) c.free() + if generator != null: + remove_child(generator) + generator.free() + generator = null send_changed_signal() func new_material(): + print("New material") clear_material() - create_nodes({name="Material", type="material"}) - set_save_path(null) - center_view() + var loader = MMGenLoader.new() + generator = loader.create_gen({nodes=[{name="Material", type="material"}], connections=[]}) + if generator != null: + print("Not null !") + add_child(generator) + for g in generator.get_children(): + var node = node_factory.create_node(g.get_type()) + if node != null: + node.name = "node_"+g.name + add_node(node) + node.generator = g + node.offset = g.position + if generator.get("connections") != null: + for c in generator.connections: + .connect_node("node_"+c.from, c.from_port, "node_"+c.to, c.to_port) + set_save_path(filename) + set_need_save(false) + center_view() func get_free_name(type): var i = 0 @@ -142,7 +163,6 @@ func load_file(filename): if generator != null: add_child(generator) for g in generator.get_children(): - print(g.get_type()) var node = node_factory.create_node(g.get_type()) if node != null: node.name = "node_"+g.name diff --git a/addons/material_maker/graph_edit.tscn b/addons/material_maker/graph_edit.tscn index f00404f..04a242f 100644 --- a/addons/material_maker/graph_edit.tscn +++ b/addons/material_maker/graph_edit.tscn @@ -1,9 +1,6 @@ -[gd_scene load_steps=4 format=2] +[gd_scene load_steps=2 format=2] [ext_resource path="res://addons/material_maker/graph_edit.gd" type="Script" id=1] -[ext_resource path="res://addons/material_maker/nodes/material.tscn" type="PackedScene" id=2] - -[sub_resource type="Theme" id=1] [node name="GraphEdit" type="GraphEdit"] self_modulate = Color( 1, 1, 1, 0 ) @@ -14,14 +11,6 @@ scroll_offset = Vector2( -325, -250 ) use_snap = false script = ExtResource( 1 ) -[node name="Material" parent="." instance=ExtResource( 2 )] -margin_left = 525.0 -margin_top = 250.0 -margin_right = 755.0 -margin_bottom = 470.0 -theme = SubResource( 1 ) -offset = Vector2( 200, 0 ) - [node name="Timer" type="Timer" parent="."] wait_time = 0.2 one_shot = true diff --git a/addons/material_maker/main_window.gd b/addons/material_maker/main_window.gd index 8e9516d..ffda4e7 100644 --- a/addons/material_maker/main_window.gd +++ b/addons/material_maker/main_window.gd @@ -133,6 +133,7 @@ func new_pane(): func new_material(): var graph_edit = new_pane() + graph_edit.new_material() graph_edit.update_tab_title() func load_material(): @@ -153,11 +154,14 @@ func do_load_material(filename): var graph_edit = $VBoxContainer/HBoxContainer/Projects.get_current_tab_control() var node_count = 2 # So test below succeeds if graph_edit is null... if graph_edit != null: + node_count = 0 for c in graph_edit.get_children(): if c is GraphNode: + print(c.name) node_count += 1 if node_count > 1: break + print(node_count) if node_count > 1: graph_edit = new_pane() graph_edit.load_file(filename) diff --git a/addons/material_maker/new.ptex b/addons/material_maker/new.ptex index 4d41f06..df087f9 100644 --- a/addons/material_maker/new.ptex +++ b/addons/material_maker/new.ptex @@ -1 +1 @@ -{"connections":[],"nodes":[{"name":"Material","node_position":{"x":307,"y":-53},"parameters":{"albedo_color":{"a":1,"b":1,"g":1,"r":1,"type":"Color"},"ao_light_affect":1,"depth_scale":1,"emission_energy":1,"metallic":1,"normal_scale":1,"resolution":1,"roughness":1},"type":"material"}]} \ No newline at end of file +{"connections":[],"nodes":[{"name":"Material","node_position":{"x":300,"y":0},"parameters":{"albedo_color":{"a":1,"b":1,"g":1,"r":1,"type":"Color"},"ao_light_affect":1,"depth_scale":1,"emission_energy":1,"metallic":1,"normal_scale":1,"resolution":1,"roughness":1},"type":"material"}]} \ No newline at end of file From b614ab50ed9e132b8eab1a39d29697977947cd0b Mon Sep 17 00:00:00 2001 From: Rodolphe Suescun Date: Thu, 15 Aug 2019 11:53:21 +0200 Subject: [PATCH 008/133] Reimplemented generator instanciation --- addons/material_maker/engine/gen_graph.gd | 2 +- addons/material_maker/engine/gen_shader.gd | 6 ++- addons/material_maker/engine/loader.gd | 27 ++++++++-- addons/material_maker/graph_edit.gd | 63 +++++++--------------- addons/material_maker/nodes/generic.gd | 7 ++- addons/material_maker/types/types.gd | 3 ++ project.godot | 8 ++- test.ptex | 1 + 8 files changed, 62 insertions(+), 55 deletions(-) create mode 100644 test.ptex diff --git a/addons/material_maker/engine/gen_graph.gd b/addons/material_maker/engine/gen_graph.gd index f87007f..9f3c861 100644 --- a/addons/material_maker/engine/gen_graph.gd +++ b/addons/material_maker/engine/gen_graph.gd @@ -2,7 +2,7 @@ tool extends MMGenBase class_name MMGenGraph -var connections = null +var connections = [] func get_port_source(gen_name: String, input_index: int) -> OutputPort: for c in connections: diff --git a/addons/material_maker/engine/gen_shader.gd b/addons/material_maker/engine/gen_shader.gd index 93947ba..8441cdb 100644 --- a/addons/material_maker/engine/gen_shader.gd +++ b/addons/material_maker/engine/gen_shader.gd @@ -7,12 +7,16 @@ var generated_variants = [] func set_model_data(data: Dictionary): model_data = data + for p in model_data.parameters: + if !parameters.has(p.name) and p.has("default"): + parameters[p.name] = MMType.deserialize_value(p.default) func initialize(data: Dictionary): if data.has("name"): name = data.name if data.has("parameters"): - parameters = data.parameters + for p in data.parameters.keys(): + parameters[p] = data.parameters[p] func find_keyword_call(string, keyword): var search_string = "$%s(" % keyword diff --git a/addons/material_maker/engine/loader.gd b/addons/material_maker/engine/loader.gd index 64adda6..13a01f6 100644 --- a/addons/material_maker/engine/loader.gd +++ b/addons/material_maker/engine/loader.gd @@ -9,15 +9,29 @@ func load_gen(filename: String) -> MMGenBase: return create_gen(data) return null +func add_to_gen_graph(gen_graph, generators, connections): + var rv = { generators=[], connections=[] } + for n in generators: + var g = create_gen(n) + if g != null: + var name = g.name + var index = 1 + while gen_graph.has_node(name): + index += 1 + name = g.name + "_" + str(index) + g.name = name + gen_graph.add_child(g) + rv.generators.append(g) + for c in connections: + gen_graph.connections.append(c) + rv.connections.append(c) + return rv + func create_gen(data) -> MMGenBase: var generator = null if data.has("connections") and data.has("nodes"): generator = MMGenGraph.new() - for n in data.nodes: - var g = create_gen(n) - if g != null: - generator.add_child(g) - generator.connections = data.connections + add_to_gen_graph(generator, data.nodes, data.connections) elif data.has("model_data"): generator = MMGenShader.new() generator.set_model_data(data.model_data) @@ -39,9 +53,12 @@ func create_gen(data) -> MMGenBase: file.close() else: print("Cannot find description for "+data.type) + generator.name = data.type else: print(data) if generator != null: + if data.has("name"): + generator.name = data.name if data.has("node_position"): generator.position.x = data.node_position.x generator.position.y = data.node_position.y diff --git a/addons/material_maker/graph_edit.gd b/addons/material_maker/graph_edit.gd index ab70da9..484c524 100644 --- a/addons/material_maker/graph_edit.gd +++ b/addons/material_maker/graph_edit.gd @@ -98,24 +98,24 @@ func clear_material(): generator = null send_changed_signal() +func update_graph(generators, connections): + for g in generators: + var node = node_factory.create_node(g.get_type()) + if node != null: + node.name = "node_"+g.name + add_node(node) + node.generator = g + node.offset = g.position + for c in connections: + .connect_node("node_"+c.from, c.from_port, "node_"+c.to, c.to_port) + func new_material(): - print("New material") clear_material() var loader = MMGenLoader.new() generator = loader.create_gen({nodes=[{name="Material", type="material"}], connections=[]}) if generator != null: - print("Not null !") add_child(generator) - for g in generator.get_children(): - var node = node_factory.create_node(g.get_type()) - if node != null: - node.name = "node_"+g.name - add_node(node) - node.generator = g - node.offset = g.position - if generator.get("connections") != null: - for c in generator.connections: - .connect_node("node_"+c.from, c.from_port, "node_"+c.to, c.to_port) + update_graph(generator.get_children(), generator.connections) set_save_path(filename) set_need_save(false) center_view() @@ -132,29 +132,11 @@ func create_nodes(data, position = null): if data == null: return if data.has("type"): - var node = node_factory.create_node(data.type) - if node != null: - if data.has("name") and !has_node(data.name): - node.name = data.name - else: - node.name = get_free_name(data.type) - add_node(node) - node.deserialize(data) - if position != null: - node.offset += position - send_changed_signal() - return node - else: - if typeof(data.nodes) == TYPE_ARRAY and typeof(data.connections) == TYPE_ARRAY: - var names = {} - for c in data.nodes: - var node = create_nodes(c, position) - if node != null: - names[c.name] = node.name - node.selected = true - for c in data.connections: - connect_node(names[c.from], c.from_port, "Material" if c.to == "Material" else names[c.to], c.to_port) - return null + data = { nodes=[data], connections=[] } + if typeof(data.nodes) == TYPE_ARRAY and typeof(data.connections) == TYPE_ARRAY: + var loader = MMGenLoader.new() + var new_stuff = loader.add_to_gen_graph(generator, data.nodes, data.connections) + update_graph(new_stuff.generators, new_stuff.connections) func load_file(filename): clear_material() @@ -162,16 +144,7 @@ func load_file(filename): generator = loader.load_gen(filename) if generator != null: add_child(generator) - for g in generator.get_children(): - var node = node_factory.create_node(g.get_type()) - if node != null: - node.name = "node_"+g.name - add_node(node) - node.generator = g - node.offset = g.position - if generator.get("connections") != null: - for c in generator.connections: - .connect_node("node_"+c.from, c.from_port, "node_"+c.to, c.to_port) + update_graph(generator.get_children(), generator.connections) set_save_path(filename) set_need_save(false) center_view() diff --git a/addons/material_maker/nodes/generic.gd b/addons/material_maker/nodes/generic.gd index 27ed64c..b86a653 100644 --- a/addons/material_maker/nodes/generic.gd +++ b/addons/material_maker/nodes/generic.gd @@ -21,7 +21,10 @@ func initialize_properties(): for o in controls: if o == null: print("error in node "+name) - elif o is LineEdit: + continue + if !generator.parameters.has(o.name): + continue + if o is LineEdit: o.text = str(generator.parameters[o.name]) o.connect("text_changed", self, "_on_text_changed", [ o.name ]) elif o is SpinBox: @@ -37,7 +40,7 @@ func initialize_properties(): o.pressed = generator.parameters[o.name] o.connect("toggled", self, "_on_value_changed", [ o.name ]) elif o is ColorPickerButton: - o.color = generator.parameters[o.name] + o.color = MMType.deserialize_value(generator.parameters[o.name]) o.connect("color_changed", self, "_on_color_changed", [ o.name ]) elif o is Control and o.filename == "res://addons/material_maker/widgets/gradient_editor.tscn": var gradient : MMGradient = MMGradient.new() diff --git a/addons/material_maker/types/types.gd b/addons/material_maker/types/types.gd index ce4181c..a8d135f 100644 --- a/addons/material_maker/types/types.gd +++ b/addons/material_maker/types/types.gd @@ -1,4 +1,5 @@ extends Node +class_name MMType const Gradient = preload("res://addons/material_maker/types/gradient.gd") @@ -18,6 +19,8 @@ static func deserialize_value(data): var gradient = Gradient.new() gradient.deserialize(data) return gradient + elif data.has("r") and data.has("g") and data.has("b") and data.has("a"): + return Color(data.r, data.g, data.b, data.a) # in previous releases, Gradients were serialized as arrays elif typeof(data) == TYPE_ARRAY: var gradient = Gradient.new() diff --git a/project.godot b/project.godot index 7bbdcd1..42fc611 100644 --- a/project.godot +++ b/project.godot @@ -58,6 +58,11 @@ _global_script_classes=[ { "class": "MMGradient", "language": "GDScript", "path": "res://addons/material_maker/types/gradient.gd" +}, { +"base": "Node", +"class": "MMType", +"language": "GDScript", +"path": "res://addons/material_maker/types/types.gd" } ] _global_script_class_icons={ "MMGenBase": "", @@ -69,7 +74,8 @@ _global_script_class_icons={ "MMGenMaterial": "", "MMGenRenderer": "", "MMGenShader": "", -"MMGradient": "" +"MMGradient": "", +"MMType": "" } [application] diff --git a/test.ptex b/test.ptex new file mode 100644 index 0000000..3094556 --- /dev/null +++ b/test.ptex @@ -0,0 +1 @@ +{"connections":[{"from":"bricks_0","from_port":0,"to":"custom_0","to_port":0},{"from":"custom_0","from_port":0,"to":"adjust_hsv_0","to_port":0},{"from":"adjust_hsv_0","from_port":0,"to":"Material","to_port":0}],"nodes":[{"name":"Material","node_position":{"x":143,"y":-210},"parameters":{"albedo_color":{"a":1,"b":1,"g":1,"r":1,"type":"Color"},"ao_light_affect":1,"depth_scale":1,"emission_energy":1,"metallic":1,"normal_scale":1,"resolution":1,"roughness":1},"type":"material"},{"model_data":{"global":"","inputs":[{"default":"0.0","label":"Input","name":"input","type":"f"}],"instance":"","name":"Colorize","outputs":[{"rgba":"$gradient($input($uv))"}],"parameters":[{"default":{"points":[{"a":1,"b":0,"g":0,"pos":0,"r":0},{"a":1,"b":1,"g":1,"pos":1,"r":1}],"type":"Gradient"},"label":"Gradient","name":"gradient","type":"gradient"}]},"name":"custom_0","node_position":{"x":-433,"y":-109.416656},"parameters":{"gradient":{"points":[{"a":1,"b":0,"g":0,"pos":0,"r":0},{"a":1,"b":0,"g":0,"pos":0.517045,"r":1},{"a":0,"b":1,"g":1,"pos":1,"r":1}],"type":"Gradient"}},"type":"custom"},{"name":"adjust_hsv_0","node_position":{"x":-135.541687,"y":-150.597229},"parameters":{"hue":0,"saturation":1,"value":1},"type":"adjust_hsv"},{"name":"bricks_0","node_position":{"x":-599,"y":-332},"parameters":{"bevel":0.209961,"columns":3,"mortar":0.116211,"pattern":0,"repeat":1,"row_offset":0.5,"rows":6},"type":"bricks"}]} \ No newline at end of file From e9a21454c1921b7ad8e186eec21c2620bb9848b8 Mon Sep 17 00:00:00 2001 From: Rodolphe Suescun Date: Sat, 17 Aug 2019 17:35:48 +0200 Subject: [PATCH 009/133] More refactoring on rtexture generation --- addons/material_maker/engine/gen_base.gd | 49 +++- addons/material_maker/engine/gen_buffer.gd | 20 ++ addons/material_maker/engine/gen_context.gd | 5 + .../material_maker/engine/gen_convolution.gd | 1 + addons/material_maker/engine/gen_graph.gd | 7 +- addons/material_maker/engine/gen_material.gd | 1 + addons/material_maker/engine/gen_shader.gd | 66 ++--- addons/material_maker/engine/loader.gd | 18 +- addons/material_maker/engine/renderer.gd | 1 + addons/material_maker/graph_edit.gd | 4 +- addons/material_maker/library/base.json | 240 ++++++++++-------- addons/material_maker/main_window.gd | 10 +- addons/material_maker/node_factory.gd | 2 + addons/material_maker/nodes/bricks.mmn | 2 +- addons/material_maker/nodes/generic.gd | 146 +++++------ addons/material_maker/plugin.gd | 5 +- addons/material_maker/types/gradient.gd | 59 +++-- test.png | Bin 0 -> 1096 bytes test.ptex | 159 +++++++++++- 19 files changed, 533 insertions(+), 262 deletions(-) create mode 100644 test.png diff --git a/addons/material_maker/engine/gen_base.gd b/addons/material_maker/engine/gen_base.gd index b7f818f..7ff6546 100644 --- a/addons/material_maker/engine/gen_base.gd +++ b/addons/material_maker/engine/gen_base.gd @@ -9,7 +9,7 @@ class OutputPort: func _init(g : MMGenBase, o : int): generator = g output_index = o - + """ func get_shader(): return generator.get_shader(output_index) @@ -18,19 +18,43 @@ class OutputPort: func get_globals(): return generator.get_globals() - + """ func to_str(): return generator.name+"("+str(output_index)+")" var position : Vector2 = Vector2(0, 0) var parameters = {} +func _ready(): + init_parameters() + +func init_parameters(): + for p in get_parameter_defs(): + print(p) + if !parameters.has(p.name): + if p.has("default"): + parameters[p.name] = MMType.deserialize_value(p.default) + else: + print("No default value for parameter "+p.name) + func get_seed(): return 0 func get_type(): return "generic" +func get_type_name(): + return "Unnamed" + +func get_parameter_defs(): + return [] + +func get_input_defs(): + return [] + +func get_output_defs(): + return [] + func get_source(input_index : int): return get_parent().get_port_source(name, input_index) @@ -39,7 +63,7 @@ func get_input_shader(input_index : int): if source != null: return source.get_shader() -func get_shader(output_index : int, context = MMGenContext.new()): +func get_shader(output_index : int, context): return get_shader_code("UV", output_index, context); # this will need an output index for switch @@ -48,14 +72,25 @@ func get_globals(): for i in range(10): var source = get_source(i) if source != null: - var source_list = source.get_globals() + var source_list = source.generator.get_globals() for g in source_list: if list.find(g) == -1: list.append(g) return list -func get_shader_code(uv, slot = 0, context = MMGenContext.new()): - var rv = _get_shader_code(uv, slot, context) +func render(output_index : int, renderer : MMGenRenderer, size : int): + var context : MMGenContext = MMGenContext.new(renderer) + var source = get_shader_code("UV", output_index, context) + if source == null: + return false + var shader : String = renderer.generate_shader(source) + var status = renderer.render_shader(shader, {}, 1024) + while status is GDScriptFunctionState: + status = yield(status, "completed") + return status + +func get_shader_code(uv : String, output_index : int, context : MMGenContext): + var rv = _get_shader_code(uv, output_index, context) if rv != null: if !rv.has("f"): if rv.has("rgb"): @@ -74,5 +109,5 @@ func get_shader_code(uv, slot = 0, context = MMGenContext.new()): rv.globals = get_globals() return rv -func _get_shader_code(uv : String, output_index : int, context = MMGenContext.new()): +func _get_shader_code(uv : String, output_index : int, context : MMGenContext): return null diff --git a/addons/material_maker/engine/gen_buffer.gd b/addons/material_maker/engine/gen_buffer.gd index 80d36bf..0ba7296 100644 --- a/addons/material_maker/engine/gen_buffer.gd +++ b/addons/material_maker/engine/gen_buffer.gd @@ -1,2 +1,22 @@ +tool extends MMGenBase class_name MMGenBuffer + +func _ready(): + if !parameters.has("size"): + parameters.size = 4 + +func get_type(): + return "buffer" + +func get_type_name(): + return "Buffer" + +func get_parameter_defs(): + return [ { name="size", type="size", first=4, last=11, default=4 } ] + +func get_input_defs(): + return [ ] + +func get_output_defs(): + return [ ] diff --git a/addons/material_maker/engine/gen_context.gd b/addons/material_maker/engine/gen_context.gd index 7555d1a..25e0a75 100644 --- a/addons/material_maker/engine/gen_context.gd +++ b/addons/material_maker/engine/gen_context.gd @@ -1,8 +1,13 @@ +tool extends Object class_name MMGenContext +var renderer : MMGenRenderer var variants : Dictionary = {} +func _init(r : MMGenRenderer): + renderer = r + func has_variant(generator): return variants.has(generator) diff --git a/addons/material_maker/engine/gen_convolution.gd b/addons/material_maker/engine/gen_convolution.gd index acf1e5e..aae09ef 100644 --- a/addons/material_maker/engine/gen_convolution.gd +++ b/addons/material_maker/engine/gen_convolution.gd @@ -1,2 +1,3 @@ +tool extends MMGenBase class_name MMGenConvolution diff --git a/addons/material_maker/engine/gen_graph.gd b/addons/material_maker/engine/gen_graph.gd index 9f3c861..25b78b5 100644 --- a/addons/material_maker/engine/gen_graph.gd +++ b/addons/material_maker/engine/gen_graph.gd @@ -4,10 +4,15 @@ class_name MMGenGraph var connections = [] +func get_type(): + return "graph" + func get_port_source(gen_name: String, input_index: int) -> OutputPort: for c in connections: if c.to == gen_name and c.to_port == input_index: - return OutputPort.new(get_node(c.from), c.from_port) + var src_gen = get_node(c.from) + if src_gen != null: + return OutputPort.new(get_node(c.from), c.from_port) return null func connect_children(from, from_port : int, to, to_port : int): diff --git a/addons/material_maker/engine/gen_material.gd b/addons/material_maker/engine/gen_material.gd index c071ed0..7e208de 100644 --- a/addons/material_maker/engine/gen_material.gd +++ b/addons/material_maker/engine/gen_material.gd @@ -43,6 +43,7 @@ func generate_material(renderer : MMGenRenderer): var status = renderer.render_shader(shader, {}, 512) while status is GDScriptFunctionState: status = yield(status, "completed") + print("Render status: "+str(status)) renderer.get_texture().get_data().save_png("res://test.png") material.albedo_texture = load("res://test.png") return material diff --git a/addons/material_maker/engine/gen_shader.gd b/addons/material_maker/engine/gen_shader.gd index 8441cdb..2800908 100644 --- a/addons/material_maker/engine/gen_shader.gd +++ b/addons/material_maker/engine/gen_shader.gd @@ -2,21 +2,26 @@ tool extends MMGenBase class_name MMGenShader -var model_data = null +var shader_model : Dictionary = {} var generated_variants = [] -func set_model_data(data: Dictionary): - model_data = data - for p in model_data.parameters: - if !parameters.has(p.name) and p.has("default"): - parameters[p.name] = MMType.deserialize_value(p.default) +func get_type(): + return "shader" -func initialize(data: Dictionary): - if data.has("name"): - name = data.name - if data.has("parameters"): - for p in data.parameters.keys(): - parameters[p] = data.parameters[p] +func get_type_name(): + if shader_model.has("name"): + return shader_model.name + return .get_type_name() + +func get_parameter_defs(): + if shader_model == null or !shader_model.has("parameters"): + return [] + else: + return shader_model.parameters + +func set_shader_model(data: Dictionary): + shader_model = data + init_parameters() func find_keyword_call(string, keyword): var search_string = "$%s(" % keyword @@ -49,7 +54,8 @@ func replace_input(string, context, input, type, src, default): if src == null: src_code = subst(default, "(%s)" % uv) else: - src_code = src.get_shader_code(uv) + print(src.to_str()) + src_code = src.generator.get_shader_code(uv, src.output_index, context) src_code.string = src_code[type] required_defs += src_code.defs required_code += src_code.code @@ -84,8 +90,8 @@ func subst(string, context, uv = ""): string = replace_variable(string, "seed", str(get_seed())) if uv != "": string = replace_variable(string, "uv", "("+uv+")") - if model_data.has("parameters") and typeof(model_data.parameters) == TYPE_ARRAY: - for p in model_data.parameters: + if shader_model.has("parameters") and typeof(shader_model.parameters) == TYPE_ARRAY: + for p in shader_model.parameters: if !p.has("name") or !p.has("type"): continue var value = parameters[p.name] @@ -102,9 +108,9 @@ func subst(string, context, uv = ""): value_string = p.name+"_gradient_fct" if value_string != null: string = replace_variable(string, p.name, value_string) - if model_data.has("inputs") and typeof(model_data.inputs) == TYPE_ARRAY: - for i in range(model_data.inputs.size()): - var input = model_data.inputs[i] + if shader_model.has("inputs") and typeof(shader_model.inputs) == TYPE_ARRAY: + for i in range(shader_model.inputs.size()): + var input = shader_model.inputs[i] var source = get_source(i) var result = replace_input(string, context, input.name, input.type, source, input.default) string = result.string @@ -112,18 +118,16 @@ func subst(string, context, uv = ""): required_code += result.code return { string=string, defs=required_defs, code=required_code } -func _get_shader_code(uv, slot = 0, context = MMGenContext.new()): - if context == null: - context = {} +func _get_shader_code(uv : String, output_index : int, context : MMGenContext): var output_info = [ { field="rgba", type="vec4" }, { field="rgb", type="vec3" }, { field="f", type="float" } ] var rv = { defs="", code="" } - var variant_string = uv+","+str(slot) - if model_data != null and model_data.has("outputs") and model_data.outputs.size() > slot: - var output = model_data.outputs[slot] + var variant_string = uv+","+str(output_index) + if shader_model != null and shader_model.has("outputs") and shader_model.outputs.size() > output_index: + var output = shader_model.outputs[output_index] rv.defs = "" - if model_data.has("instance") && !context.has_variant(self): - rv.defs += subst(model_data.instance, context).string - for p in model_data.parameters: + if shader_model.has("instance") && !context.has_variant(self): + rv.defs += subst(shader_model.instance, context).string + for p in shader_model.parameters: if p.type == "gradient": var g = parameters[p.name] if !(g is MMGradient): @@ -139,14 +143,14 @@ func _get_shader_code(uv, slot = 0, context = MMGenContext.new()): var subst_output = subst(output[t.field], context, uv) rv.defs += subst_output.defs rv.code += subst_output.code - rv.code += "%s %s_%d_%d_%s = %s;\n" % [ t.type, name, slot, variant_index, t.field, subst_output.string ] + rv.code += "%s %s_%d_%d_%s = %s;\n" % [ t.type, name, output_index, variant_index, t.field, subst_output.string ] for t in output_info: if output.has(t.field): - rv[t.field] = "%s_%d_%d_%s" % [ name, slot, variant_index, t.field ] + rv[t.field] = "%s_%d_%d_%s" % [ name, output_index, variant_index, t.field ] return rv func get_globals(): var list = .get_globals() - if typeof(model_data) == TYPE_DICTIONARY and model_data.has("global") and list.find(model_data.global) == -1: - list.append(model_data.global) + if typeof(shader_model) == TYPE_DICTIONARY and shader_model.has("global") and list.find(shader_model.global) == -1: + list.append(shader_model.global) return list diff --git a/addons/material_maker/engine/loader.gd b/addons/material_maker/engine/loader.gd index 13a01f6..a225295 100644 --- a/addons/material_maker/engine/loader.gd +++ b/addons/material_maker/engine/loader.gd @@ -32,28 +32,29 @@ func create_gen(data) -> MMGenBase: if data.has("connections") and data.has("nodes"): generator = MMGenGraph.new() add_to_gen_graph(generator, data.nodes, data.connections) - elif data.has("model_data"): + elif data.has("shader_model"): generator = MMGenShader.new() - generator.set_model_data(data.model_data) + generator.set_shader_model(data.shader_model) elif data.has("type"): if data.type == "material": generator = MMGenMaterial.new() + elif data.type == "buffer": + generator = MMGenBuffer.new() else: var file = File.new() if file.open("res://addons/material_maker/library/"+data.type+".mml", File.READ) == OK: - var model_data = parse_json(file.get_as_text()) print("loaded description "+data.type+".mml") - generator = create_gen(model_data) + generator = create_gen(parse_json(file.get_as_text())) file.close() elif file.open("res://addons/material_maker/nodes/"+data.type+".mmn", File.READ) == OK: generator = MMGenShader.new() - var model_data = parse_json(file.get_as_text()) print("loaded description "+data.type+".mmn") - generator.set_model_data(model_data) + generator.set_shader_model(parse_json(file.get_as_text())) file.close() else: print("Cannot find description for "+data.type) - generator.name = data.type + if generator != null: + generator.name = data.type else: print(data) if generator != null: @@ -63,5 +64,6 @@ func create_gen(data) -> MMGenBase: generator.position.x = data.node_position.x generator.position.y = data.node_position.y if data.has("parameters"): - generator.initialize(data) + for p in data.parameters.keys(): + generator.parameters[p] = data.parameters[p] return generator diff --git a/addons/material_maker/engine/renderer.gd b/addons/material_maker/engine/renderer.gd index 966c603..2662bd6 100644 --- a/addons/material_maker/engine/renderer.gd +++ b/addons/material_maker/engine/renderer.gd @@ -68,6 +68,7 @@ func setup_material(shader_material, textures, shader_code): func render_shader(shader, textures, render_size): if rendering: + print("Already rendering...") return false rendering = true if debug_path != null and debug_path != "": diff --git a/addons/material_maker/graph_edit.gd b/addons/material_maker/graph_edit.gd index 484c524..4dc11ef 100644 --- a/addons/material_maker/graph_edit.gd +++ b/addons/material_maker/graph_edit.gd @@ -128,7 +128,7 @@ func get_free_name(type): return node_name i += 1 -func create_nodes(data, position = null): +func create_nodes(data, position : Vector2 = Vector2(0, 0)): if data == null: return if data.has("type"): @@ -136,6 +136,8 @@ func create_nodes(data, position = null): if typeof(data.nodes) == TYPE_ARRAY and typeof(data.connections) == TYPE_ARRAY: var loader = MMGenLoader.new() var new_stuff = loader.add_to_gen_graph(generator, data.nodes, data.connections) + for g in new_stuff.generators: + g.position += position update_graph(new_stuff.generators, new_stuff.connections) func load_file(filename): diff --git a/addons/material_maker/library/base.json b/addons/material_maker/library/base.json index efe2dd9..7e16e24 100644 --- a/addons/material_maker/library/base.json +++ b/addons/material_maker/library/base.json @@ -28,124 +28,156 @@ "tree_item":"Generators/Pattern", "icon":"pattern", "type":"pattern", - "mix":0, - "x_scale":4, - "x_wave":0, - "y_scale":4, - "y_wave":0 + "parameters":{ + "mix":0, + "x_scale":4, + "x_wave":0, + "y_scale":4, + "y_wave":0 + } }, { - "tree_item": "Generators/Pattern/Checkerboard", - "type": "pattern", - "icon": "checkerboard", - "mix": 4, - "x_scale": 4, - "x_wave": 2, - "y_scale": 4, - "y_wave": 2 + "tree_item": "Generators/Pattern/Checkerboard", + "type": "pattern", + "icon": "checkerboard", + "parameters":{ + "mix": 4, + "x_scale": 4, + "x_wave": 2, + "y_scale": 4, + "y_wave": 2 + } }, { "tree_item":"Generators/Bricks", "type":"bricks", "icon":"bricks", - "bevel":0.1, - "columns":3, - "mortar":0.1, - "row_offset":0.5, - "rows":6 + "parameters":{ + "bevel":0.1, + "columns":3, + "mortar":0.1, + "row_offset":0.5, + "rows":6 + } }, { - "tree_item": "Generators/Bricks/Tiles", - "type": "bricks", - "icon": "tiles", - "bevel": 0.05, - "columns": 4, - "mortar": 0.05, - "row_offset": 0, - "rows": 4 + "tree_item": "Generators/Bricks/Tiles", + "type": "bricks", + "icon": "tiles", + "parameters":{ + "bevel": 0.05, + "columns": 4, + "mortar": 0.05, + "row_offset": 0, + "rows": 4 + } + }, + { + "tree_item": "Generators/Bricks/BasketWeave", + "type": "bricks", + "icon": "basketweave", + "parameters":{ + "bevel": 0.05, + "columns": 2, + "mortar": 0.05, + "pattern": 3, + "repeat": 2, + "row_offset": 0, + "rows": 2 + } }, { - "tree_item": "Generators/Bricks/BasketWeave", - "type": "bricks", - "icon": "basketweave", - "bevel": 0.05, - "columns": 2, - "mortar": 0.05, - "pattern": 3, - "repeat": 2, - "row_offset": 0, - "rows": 2 + "tree_item": "Generators/Bricks/HerringBone", + "type": "bricks", + "icon": "herringbone", + "parameters":{ + "bevel": 0.05, + "columns": 2, + "mortar": 0.05, + "pattern": 2, + "repeat": 2, + "row_offset": 0, + "rows": 2 + } }, { - "tree_item": "Generators/Bricks/HerringBone", - "type": "bricks", - "icon": "herringbone", - "bevel": 0.05, - "columns": 2, - "mortar": 0.05, - "pattern": 2, - "repeat": 2, - "row_offset": 0, - "rows": 2 - }, - { - "tree_item": "Generators/Bricks/SpanishBond", - "type": "bricks", - "icon": "spanishbond", - "bevel": 0.05, - "columns": 2, - "mortar": 0.05, - "pattern": 4, - "repeat": 2, - "row_offset": 0, - "rows": 2 + "tree_item": "Generators/Bricks/SpanishBond", + "type": "bricks", + "icon": "spanishbond", + "parameters":{ + "bevel": 0.05, + "columns": 2, + "mortar": 0.05, + "pattern": 4, + "repeat": 2, + "row_offset": 0, + "rows": 2 + } }, { "tree_item":"Generators/Noise", "type":"noise", "icon":"noise", - "size":4, - "density":0.5 + "parameters":{ + "size":4, + "density":0.5 + } }, { "tree_item":"Generators/Perlin Noise", "type":"perlin", "icon":"perlin", - "iterations":3, - "persistence":0.5, - "scale_x":4, - "scale_y":4 + "parameters":{ + "iterations":3, + "persistence":0.5, + "scale_x":4, + "scale_y":4 + } }, { "tree_item":"Generators/Voronoi Noise", "type":"voronoi", "icon":"voronoi", - "intensity":1, - "scale_x":4, - "scale_y":4 + "parameters":{ + "intensity":1, + "scale_x":4, + "scale_y":4 + } + }, + { + "tree_item":"Filters/Buffer", + "type":"buffer" }, { "tree_item":"Filters/AdjustHSV", "type":"adjust_hsv", - "hue":0, - "saturation":1, - "value":1 + "parameters":{ + "hue":0, + "saturation":1, + "value":1 + } }, { "tree_item":"Filters/Colorize", "type":"colorize", - "gradient":[{"b":0,"g":0,"pos":0,"r":0},{"b":1,"g":1,"pos":1,"r":1}] + "parameters":{ + "gradient":[{"b":0,"g":0,"pos":0,"r":0},{"b":1,"g":1,"pos":1,"r":1}] + } }, { "tree_item":"Filters/Blend", "type":"blend", - "amount":0.5, - "blend_type":0 + "parameters":{ + "amount":0.5, + "blend_type":0 + } }, { "tree_item":"Filters/Blur", "type":"blur", - "sigma":1.0 + "parameters":{ + "sigma":1.0 + } }, { "tree_item":"Filters/Combine", @@ -158,45 +190,55 @@ { "tree_item":"Filters/Emboss", "type":"emboss", - "direction":0 + "parameters":{ + "direction":0 + } }, { "tree_item":"Filters/Normal map", "type":"normal_map", - "amount":0.5 + "parameters":{ + "amount":0.5 + } }, { "tree_item":"Filters/Transform", "type":"transform", - "rotate":0, - "scale_x":1, - "scale_y":1, - "translate_x":0, - "translate_y":0 + "parameters":{ + "rotate":0, + "scale_x":1, + "scale_y":1, + "translate_x":0, + "translate_y":0 + } }, { "tree_item":"Filters/Warp", "type":"warp", - "amount":0.5 + "parameters":{ + "amount":0.5 + } }, { - "tree_item": "Filters/Colorize/Invert", - "type": "colorize", - "icon": "invert", - "gradient": [ - { - "b": 1, - "g": 1, - "pos": 0, - "r": 1 - }, - { - "b": 0, - "g": 0, - "pos": 1, - "r": 0 - } - ] + "tree_item": "Filters/Colorize/Invert", + "type": "colorize", + "icon": "invert", + "parameters":{ + "gradient": [ + { + "b": 1, + "g": 1, + "pos": 0, + "r": 1 + }, + { + "b": 0, + "g": 0, + "pos": 1, + "r": 0 + } + ] + } }, { "tree_item":"Miscellaneous/Comment", diff --git a/addons/material_maker/main_window.gd b/addons/material_maker/main_window.gd index ffda4e7..138c227 100644 --- a/addons/material_maker/main_window.gd +++ b/addons/material_maker/main_window.gd @@ -311,12 +311,10 @@ func update_preview_2d(node = null): node = n break if node != null: - var source = node.generator.get_shader(0) - if source != null: - var shader : String = renderer.generate_shader(source) - var status = renderer.render_shader(shader, {}, 1024) - while status is GDScriptFunctionState: - status = yield(status, "completed") + var status = node.generator.render(0, renderer, 1024) + while status is GDScriptFunctionState: + status = yield(status, "completed") + if status: var image = renderer.get_texture().get_data() var tex = ImageTexture.new() tex.create_from_image(image) diff --git a/addons/material_maker/node_factory.gd b/addons/material_maker/node_factory.gd index f37f2cf..c8dd4b5 100644 --- a/addons/material_maker/node_factory.gd +++ b/addons/material_maker/node_factory.gd @@ -15,4 +15,6 @@ func create_node(type): var node_type = load("res://addons/material_maker/nodes/"+type+".tscn") if node_type != null: node = node_type.instance() + else: + node = preload("res://addons/material_maker/nodes/generic.tscn").instance() return node diff --git a/addons/material_maker/nodes/bricks.mmn b/addons/material_maker/nodes/bricks.mmn index 7893471..24bee6b 100644 --- a/addons/material_maker/nodes/bricks.mmn +++ b/addons/material_maker/nodes/bricks.mmn @@ -1,7 +1,7 @@ { "name":"Bricks", "parameters":[ - { "name":"pattern", "label":"", "type":"enum", "values":[ + { "name":"pattern", "label":"", "type":"enum", "default":0, "values":[ { "name":"Running bond", "value":"rb" }, { "name":"Running bond (2)", "value":"rb2" }, { "name":"HerringBone", "value":"hb" }, diff --git a/addons/material_maker/nodes/generic.gd b/addons/material_maker/nodes/generic.gd index b86a653..cc5efd4 100644 --- a/addons/material_maker/nodes/generic.gd +++ b/addons/material_maker/nodes/generic.gd @@ -6,16 +6,16 @@ var controls = [] var uses_seed : bool = false -var parameters = {} -var model_data = {} - # Called when the node enters the scene tree for the first time. func _ready(): pass # Replace with function body. func set_generator(g): generator = g - update_node(g.model_data) + if g.get("shader_model") != null: + update_node(g.shader_model) + else: + update_node({}) func initialize_properties(): for o in controls: @@ -70,13 +70,9 @@ func _on_gradient_changed(new_gradient, variable): update_shaders() func update_node(data): - print("node_generic.update_node") if typeof(data) != TYPE_DICTIONARY: return - if !data.has("name"): - return # Clean node - parameters = {} var custom_node_buttons = null for c in get_children(): if c.name != "CustomNodeButtons": @@ -85,71 +81,69 @@ func update_node(data): else: custom_node_buttons = c # Rebuild node - title = data.name - model_data = data + title = generator.get_type_name() uses_seed = false - if model_data.has("instance") and model_data.instance.find("$(seed)"): + if data.has("instance") and data.instance.find("$(seed)"): uses_seed = true - if model_data.has("parameters") and typeof(model_data.parameters) == TYPE_ARRAY: - controls = [] - var sizer = null - for p in model_data.parameters: - if !p.has("name") or !p.has("type"): - continue - var control = null - if p.type == "float": - if p.has("widget") and p.widget == "spinbox": - control = SpinBox.new() - else: - control = HSlider.new() - control.min_value = p.min - control.max_value = p.max - control.step = 0 if !p.has("step") else p.step - if p.has("default"): - control.value = p.default - control.rect_min_size.x = 80 - parameters[p.name] = 0.5*(p.min+p.max) - elif p.type == "size": - control = OptionButton.new() - for i in range(p.first, p.last+1): - var s = pow(2, i) - control.add_item("%dx%d" % [ s, s ]) - control.selected = 0 if !p.has("default") else p.default-p.first - elif p.type == "enum": - control = OptionButton.new() - for i in range(p.values.size()): - var value = p.values[i] - control.add_item(value.name) - control.selected = 0 if !p.has("default") else p.default - elif p.type == "boolean": - control = CheckBox.new() - elif p.type == "color": - control = ColorPickerButton.new() - elif p.type == "gradient": - control = preload("res://addons/material_maker/widgets/gradient_editor.tscn").instance() - if control != null: - var label = p.name - control.name = label - controls.append(control) - if p.has("label"): - label = p.label - if sizer == null or label != "nonewline": - sizer = HBoxContainer.new() - sizer.size_flags_horizontal = SIZE_EXPAND | SIZE_FILL - add_child(sizer) - if label != "" && label != "nonewline": - var label_widget = Label.new() - label_widget.text = label - label_widget.size_flags_horizontal = SIZE_EXPAND | SIZE_FILL - sizer.add_child(label_widget) - control.size_flags_horizontal = SIZE_EXPAND | SIZE_FILL - sizer.add_child(control) - initialize_properties() - else: - model_data.parameters = [] - if model_data.has("inputs") and typeof(model_data.inputs) == TYPE_ARRAY: - for i in range(model_data.inputs.size()): - var input = model_data.inputs[i] + # Parameters + print("Parameters") + controls = [] + var sizer = null + for p in generator.get_parameter_defs(): + if !p.has("name") or !p.has("type"): + continue + print(p.name) + var control = null + if p.type == "float": + if p.has("widget") and p.widget == "spinbox": + control = SpinBox.new() + else: + control = HSlider.new() + control.min_value = p.min + control.max_value = p.max + control.step = 0 if !p.has("step") else p.step + if p.has("default"): + control.value = p.default + control.rect_min_size.x = 80 + elif p.type == "size": + control = OptionButton.new() + for i in range(p.first, p.last+1): + var s = pow(2, i) + control.add_item("%dx%d" % [ s, s ]) + control.selected = 0 if !p.has("default") else p.default-p.first + elif p.type == "enum": + control = OptionButton.new() + for i in range(p.values.size()): + var value = p.values[i] + control.add_item(value.name) + control.selected = 0 if !p.has("default") else p.default + elif p.type == "boolean": + control = CheckBox.new() + elif p.type == "color": + control = ColorPickerButton.new() + elif p.type == "gradient": + control = preload("res://addons/material_maker/widgets/gradient_editor.tscn").instance() + if control != null: + var label = p.name + control.name = label + controls.append(control) + if p.has("label"): + label = p.label + if sizer == null or label != "nonewline": + sizer = HBoxContainer.new() + sizer.size_flags_horizontal = SIZE_EXPAND | SIZE_FILL + add_child(sizer) + if label != "" && label != "nonewline": + var label_widget = Label.new() + label_widget.text = label + label_widget.size_flags_horizontal = SIZE_EXPAND | SIZE_FILL + sizer.add_child(label_widget) + control.size_flags_horizontal = SIZE_EXPAND | SIZE_FILL + sizer.add_child(control) + initialize_properties() + if data.has("inputs") and typeof(data.inputs) == TYPE_ARRAY: + for i in range(data.inputs.size()): + var input = data.inputs[i] var enable_left = false var color_left = Color(0.5, 0.5, 0.5) if typeof(input) == TYPE_DICTIONARY: @@ -162,11 +156,9 @@ func update_node(data): else: enable_left = true set_slot(i, enable_left, 0, color_left, false, 0, Color()) - else: - model_data.inputs = [] - if model_data.has("outputs") and typeof(model_data.outputs) == TYPE_ARRAY: - for i in range(model_data.outputs.size()): - var output = model_data.outputs[i] + if data.has("outputs") and typeof(data.outputs) == TYPE_ARRAY: + for i in range(data.outputs.size()): + var output = data.outputs[i] var enable_right = false var color_right = Color(0.5, 0.5, 0.5) if typeof(output) == TYPE_DICTIONARY: @@ -179,7 +171,5 @@ func update_node(data): elif output.has("f"): enable_right = true set_slot(i, is_slot_enabled_left(i), get_slot_type_left(i), get_slot_color_left(i), enable_right, 0, color_right) - else: - model_data.outputs = [] if custom_node_buttons != null: move_child(custom_node_buttons, get_child_count()-1) diff --git a/addons/material_maker/plugin.gd b/addons/material_maker/plugin.gd index 95c143e..467e3ed 100644 --- a/addons/material_maker/plugin.gd +++ b/addons/material_maker/plugin.gd @@ -51,4 +51,7 @@ func generate_material(ptex_filename: String) -> Material: var generator = loader.load_gen(ptex_filename) add_child(generator) var material = generator.get_node("Material") - return material.generate_material(renderer) + var return_value = material.generate_material(renderer) + while return_value is GDScriptFunctionState: + return_value = yield(return_value, "completed") + return return_value diff --git a/addons/material_maker/types/gradient.gd b/addons/material_maker/types/gradient.gd index 894e20e..f776898 100644 --- a/addons/material_maker/types/gradient.gd +++ b/addons/material_maker/types/gradient.gd @@ -8,9 +8,6 @@ class CustomSorter: var points = [ { v=0.0, c=Color(0.0, 0.0, 0.0, 0.0) }, { v=1.0, c=Color(1.0, 1.0, 1.0, 1.0) } ] var sorted = true -func _ready(): - pass - func to_string(): var rv = PoolStringArray() for p in points: @@ -39,17 +36,20 @@ func sort(): func get_color(x): sort() - if x < points[0].v: - return points[0].c - var s = points.size()-1 - for i in range(s): - if x < points[i+1].v: - var p0 = points[i].v - var c0 = points[i].c - var p1 = points[i+1].v - var c1 = points[i+1].c - return c0 + (c1-c0) * (x-p0) / (p1-p0) - return points[s].c + if points.size() >0: + if x < points[0].v: + return points[0].c + var s = points.size()-1 + for i in range(s): + if x < points[i+1].v: + var p0 = points[i].v + var c0 = points[i].c + var p1 = points[i+1].v + var c1 = points[i+1].c + return c0 + (c1-c0) * (x-p0) / (p1-p0) + return points[s].c + else: + return Color(0.0, 0.0, 0.0, 1.0) # get_color_in_shader func gcis(color): @@ -59,19 +59,22 @@ func get_shader(name): sort() var shader shader = "vec4 "+name+"(float x) {\n" - shader += " if (x < %.9f) {\n" % points[0].v - shader += " return "+gcis(points[0].c)+";\n" - var s = points.size()-1 - for i in range(s): - var p0 = points[i].v - var c0 = points[i].c - var p1mp0 = points[i+1].v-p0 - var c1mc0 = points[i+1].c-c0 - if p1mp0 > 0: - shader += " } else if (x < %.9f) {\n" % points[i+1].v - shader += " return %s+x*%s;\n" % [gcis(c0-c1mc0*(p0/p1mp0)), gcis(c1mc0/p1mp0)] - shader += " }\n" - shader += " return "+gcis(points[s].c)+";\n" + if points.size() > 0: + shader += " if (x < %.9f) {\n" % points[0].v + shader += " return "+gcis(points[0].c)+";\n" + var s = points.size()-1 + for i in range(s): + var p0 = points[i].v + var c0 = points[i].c + var p1mp0 = points[i+1].v-p0 + var c1mc0 = points[i+1].c-c0 + if p1mp0 > 0: + shader += " } else if (x < %.9f) {\n" % points[i+1].v + shader += " return %s+x*%s;\n" % [gcis(c0-c1mc0*(p0/p1mp0)), gcis(c1mc0/p1mp0)] + shader += " }\n" + shader += " return "+gcis(points[s].c)+";\n" + else: + shader += " return vec4(0.0, 0.0, 0.0, 1.0);\n" shader += "}\n" return shader @@ -89,7 +92,7 @@ func deserialize(v): for i in v: if !i.has("a"): i.a = 1.0 add_point(i.pos, Color(i.r, i.g, i.b, i.a)) - elif typeof(v) == TYPE_DICTIONARY && v.has("type") && v.type == "Gradient": + elif typeof(v) == TYPE_DICTIONARY and v.has("type") && v.type == "Gradient": for i in v.points: if !i.has("a"): i.a = 1.0 add_point(i.pos, Color(i.r, i.g, i.b, i.a)) diff --git a/test.png b/test.png new file mode 100644 index 0000000000000000000000000000000000000000..8571f28dd2b17aafddf23e36536263e2a60cd732 GIT binary patch literal 1096 zcmeAS@N?(olHy`uVBq!ia0y~yU;;9k7&zE~)R&4YzZe);_&r@5Ln`LHJ!r@X6g;%x rtA8$g{sJI#6pV(zXb6n35O`qD^nro#X8OktkjFh;{an^LB{Ts5V@4J+ literal 0 HcmV?d00001 diff --git a/test.ptex b/test.ptex index 3094556..b6fd2ef 100644 --- a/test.ptex +++ b/test.ptex @@ -1 +1,158 @@ -{"connections":[{"from":"bricks_0","from_port":0,"to":"custom_0","to_port":0},{"from":"custom_0","from_port":0,"to":"adjust_hsv_0","to_port":0},{"from":"adjust_hsv_0","from_port":0,"to":"Material","to_port":0}],"nodes":[{"name":"Material","node_position":{"x":143,"y":-210},"parameters":{"albedo_color":{"a":1,"b":1,"g":1,"r":1,"type":"Color"},"ao_light_affect":1,"depth_scale":1,"emission_energy":1,"metallic":1,"normal_scale":1,"resolution":1,"roughness":1},"type":"material"},{"model_data":{"global":"","inputs":[{"default":"0.0","label":"Input","name":"input","type":"f"}],"instance":"","name":"Colorize","outputs":[{"rgba":"$gradient($input($uv))"}],"parameters":[{"default":{"points":[{"a":1,"b":0,"g":0,"pos":0,"r":0},{"a":1,"b":1,"g":1,"pos":1,"r":1}],"type":"Gradient"},"label":"Gradient","name":"gradient","type":"gradient"}]},"name":"custom_0","node_position":{"x":-433,"y":-109.416656},"parameters":{"gradient":{"points":[{"a":1,"b":0,"g":0,"pos":0,"r":0},{"a":1,"b":0,"g":0,"pos":0.517045,"r":1},{"a":0,"b":1,"g":1,"pos":1,"r":1}],"type":"Gradient"}},"type":"custom"},{"name":"adjust_hsv_0","node_position":{"x":-135.541687,"y":-150.597229},"parameters":{"hue":0,"saturation":1,"value":1},"type":"adjust_hsv"},{"name":"bricks_0","node_position":{"x":-599,"y":-332},"parameters":{"bevel":0.209961,"columns":3,"mortar":0.116211,"pattern":0,"repeat":1,"row_offset":0.5,"rows":6},"type":"bricks"}]} \ No newline at end of file +{ + "connections": [ + { + "from": "bricks_0", + "from_port": 0, + "to": "custom_0", + "to_port": 0 + }, + { + "from": "custom_0", + "from_port": 0, + "to": "adjust_hsv_0", + "to_port": 0 + }, + { + "from": "adjust_hsv_0", + "from_port": 0, + "to": "Material", + "to_port": 0 + } + ], + "nodes": [ + { + "name": "Material", + "node_position": { + "x": 143, + "y": -210 + }, + "parameters": { + "albedo_color": { + "a": 1, + "b": 1, + "g": 1, + "r": 1, + "type": "Color" + }, + "ao_light_affect": 1, + "depth_scale": 1, + "emission_energy": 1, + "metallic": 1, + "normal_scale": 1, + "resolution": 1, + "roughness": 1 + }, + "type": "material" + }, + { + "shader_model": { + "global": "", + "inputs": [ + { + "default": "0.0", + "label": "Input", + "name": "input", + "type": "f" + } + ], + "instance": "", + "name": "Colorize", + "outputs": [ + { + "rgba": "$gradient($input($uv))" + } + ], + "parameters": [ + { + "default": { + "points": [ + { + "a": 1, + "b": 0, + "g": 0, + "pos": 0, + "r": 0 + }, + { + "a": 1, + "b": 1, + "g": 1, + "pos": 1, + "r": 1 + } + ], + "type": "Gradient" + }, + "label": "Gradient", + "name": "gradient", + "type": "gradient" + } + ] + }, + "name": "custom_0", + "node_position": { + "x": -433, + "y": -109.416656 + }, + "parameters": { + "gradient": { + "points": [ + { + "a": 1, + "b": 0, + "g": 0, + "pos": 0, + "r": 0 + }, + { + "a": 1, + "b": 0, + "g": 0, + "pos": 0.517045, + "r": 1 + }, + { + "a": 0, + "b": 1, + "g": 1, + "pos": 1, + "r": 1 + } + ], + "type": "Gradient" + } + }, + "type": "custom" + }, + { + "name": "adjust_hsv_0", + "node_position": { + "x": -135.541687, + "y": -150.597229 + }, + "parameters": { + "hue": 0, + "saturation": 1, + "value": 1 + }, + "type": "adjust_hsv" + }, + { + "name": "bricks_0", + "node_position": { + "x": -599, + "y": -332 + }, + "parameters": { + "bevel": 0.209961, + "columns": 3, + "mortar": 0.116211, + "pattern": 0, + "repeat": 1, + "row_offset": 0.5, + "rows": 6 + }, + "type": "bricks" + } + ] +} \ No newline at end of file From d8d9aaa9b4c5c9a5b79da9d4833b9d12e1a252a7 Mon Sep 17 00:00:00 2001 From: Rodolphe Suescun Date: Sun, 18 Aug 2019 16:28:50 +0200 Subject: [PATCH 010/133] More refactoring and added buffer generator --- addons/material_maker/engine/gen_base.gd | 15 ++--- addons/material_maker/engine/gen_buffer.gd | 27 +++++++- addons/material_maker/engine/gen_material.gd | 3 +- addons/material_maker/engine/gen_shader.gd | 43 ++++++++++--- addons/material_maker/engine/renderer.gd | 5 +- addons/material_maker/nodes/colorize.mmn | 2 +- addons/material_maker/nodes/generic.gd | 66 ++++++++++---------- 7 files changed, 105 insertions(+), 56 deletions(-) diff --git a/addons/material_maker/engine/gen_base.gd b/addons/material_maker/engine/gen_base.gd index 7ff6546..b2be44b 100644 --- a/addons/material_maker/engine/gen_base.gd +++ b/addons/material_maker/engine/gen_base.gd @@ -9,16 +9,7 @@ class OutputPort: func _init(g : MMGenBase, o : int): generator = g output_index = o - """ - func get_shader(): - return generator.get_shader(output_index) - func get_shader_code(uv): - return generator.get_shader_code(uv, output_index) - - func get_globals(): - return generator.get_globals() - """ func to_str(): return generator.name+"("+str(output_index)+")" @@ -81,16 +72,20 @@ func get_globals(): func render(output_index : int, renderer : MMGenRenderer, size : int): var context : MMGenContext = MMGenContext.new(renderer) var source = get_shader_code("UV", output_index, context) + while source is GDScriptFunctionState: + source = yield(source, "completed") if source == null: return false var shader : String = renderer.generate_shader(source) - var status = renderer.render_shader(shader, {}, 1024) + var status = renderer.render_shader(shader, source.textures, size) while status is GDScriptFunctionState: status = yield(status, "completed") return status func get_shader_code(uv : String, output_index : int, context : MMGenContext): var rv = _get_shader_code(uv, output_index, context) + while rv is GDScriptFunctionState: + rv = yield(rv, "completed") if rv != null: if !rv.has("f"): if rv.has("rgb"): diff --git a/addons/material_maker/engine/gen_buffer.gd b/addons/material_maker/engine/gen_buffer.gd index 0ba7296..58bcce8 100644 --- a/addons/material_maker/engine/gen_buffer.gd +++ b/addons/material_maker/engine/gen_buffer.gd @@ -2,6 +2,8 @@ tool extends MMGenBase class_name MMGenBuffer +var texture : ImageTexture = ImageTexture.new() + func _ready(): if !parameters.has("size"): parameters.size = 4 @@ -16,7 +18,28 @@ func get_parameter_defs(): return [ { name="size", type="size", first=4, last=11, default=4 } ] func get_input_defs(): - return [ ] + return [ { name="in", type="rgba" } ] func get_output_defs(): - return [ ] + return [ { rgba="" } ] + +func _get_shader_code(uv : String, output_index : int, context : MMGenContext): + var source = get_source(0) + if source != null: + print(parameters.size) + var status = source.generator.render(source.output_index, context.renderer, pow(2, 4+parameters.size)) + while status is GDScriptFunctionState: + status = yield(status, "completed") + if status: + var image : Image = context.renderer.get_texture().get_data() + texture.create_from_image(image) + texture.flags = 0 + var rv = { defs="" } + var variant_index = context.get_variant(self, uv) + if variant_index == -1: + variant_index = context.get_variant(self, uv) + var texture_name = name+"_tex" + rv.code = "vec4 %s_%d = texture(%s, %s);\n" % [ name, variant_index, texture_name, uv ] + rv.rgba = "%s_%d" % [ name, variant_index ] + rv.textures = { texture_name:texture } + return rv \ No newline at end of file diff --git a/addons/material_maker/engine/gen_material.gd b/addons/material_maker/engine/gen_material.gd index 7e208de..963568e 100644 --- a/addons/material_maker/engine/gen_material.gd +++ b/addons/material_maker/engine/gen_material.gd @@ -39,8 +39,7 @@ func _ready(): func generate_material(renderer : MMGenRenderer): var source = get_source(0) if source != null: - var shader : String = renderer.generate_shader(source) - var status = renderer.render_shader(shader, {}, 512) + var status = source.generator.render(source.output_index, renderer, 512) while status is GDScriptFunctionState: status = yield(status, "completed") print("Render status: "+str(status)) diff --git a/addons/material_maker/engine/gen_shader.gd b/addons/material_maker/engine/gen_shader.gd index 2800908..822d033 100644 --- a/addons/material_maker/engine/gen_shader.gd +++ b/addons/material_maker/engine/gen_shader.gd @@ -3,7 +3,6 @@ extends MMGenBase class_name MMGenShader var shader_model : Dictionary = {} -var generated_variants = [] func get_type(): return "shader" @@ -19,6 +18,18 @@ func get_parameter_defs(): else: return shader_model.parameters +func get_input_defs(): + if shader_model == null or !shader_model.has("inputs"): + return [] + else: + return shader_model.inputs + +func get_output_defs(): + if shader_model == null or !shader_model.has("outputs"): + return [] + else: + return shader_model.outputs + func set_shader_model(data: Dictionary): shader_model = data init_parameters() @@ -43,6 +54,7 @@ func find_keyword_call(string, keyword): func replace_input(string, context, input, type, src, default): var required_defs = "" var required_code = "" + var required_textures = {} while true: var uv = find_keyword_call(string, input) if uv == null: @@ -52,15 +64,17 @@ func replace_input(string, context, input, type, src, default): break var src_code if src == null: - src_code = subst(default, "(%s)" % uv) + src_code = subst(default, context, "(%s)" % uv) else: - print(src.to_str()) src_code = src.generator.get_shader_code(uv, src.output_index, context) + while src_code is GDScriptFunctionState: + src_code = yield(src_code, "completed") src_code.string = src_code[type] required_defs += src_code.defs required_code += src_code.code + required_textures = src_code.textures string = string.replace("$%s(%s)" % [ input, uv ], src_code.string) - return { string=string, defs=required_defs, code=required_code } + return { string=string, defs=required_defs, code=required_code, textures=required_textures } func is_word_letter(l): return "azertyuiopqsdfghjklmwxcvbnAZERTYUIOPQSDFGHJKLMWXCVBN1234567890_".find(l) != -1 @@ -86,6 +100,7 @@ func replace_variable(string, variable, value): func subst(string, context, uv = ""): var required_defs = "" var required_code = "" + var required_textures = {} string = replace_variable(string, "name", name) string = replace_variable(string, "seed", str(get_seed())) if uv != "": @@ -113,20 +128,29 @@ func subst(string, context, uv = ""): var input = shader_model.inputs[i] var source = get_source(i) var result = replace_input(string, context, input.name, input.type, source, input.default) + while result is GDScriptFunctionState: + result = yield(result, "completed") string = result.string required_defs += result.defs required_code += result.code - return { string=string, defs=required_defs, code=required_code } + for t in result.textures.keys(): + required_textures[t] = result.textures[t] + return { string=string, defs=required_defs, code=required_code, textures=required_textures } func _get_shader_code(uv : String, output_index : int, context : MMGenContext): var output_info = [ { field="rgba", type="vec4" }, { field="rgb", type="vec3" }, { field="f", type="float" } ] - var rv = { defs="", code="" } + var rv = { defs="", code="", textures={} } var variant_string = uv+","+str(output_index) if shader_model != null and shader_model.has("outputs") and shader_model.outputs.size() > output_index: var output = shader_model.outputs[output_index] rv.defs = "" if shader_model.has("instance") && !context.has_variant(self): - rv.defs += subst(shader_model.instance, context).string + var subst_output = subst(shader_model.instance, context, uv) + while subst_output is GDScriptFunctionState: + subst_output = yield(subst_output, "completed") + rv.defs += subst_output.string + for t in subst_output.textures.keys(): + rv.textures[t] = subst_output.textures[t] for p in shader_model.parameters: if p.type == "gradient": var g = parameters[p.name] @@ -137,13 +161,16 @@ func _get_shader_code(uv : String, output_index : int, context : MMGenContext): var variant_index = context.get_variant(self, variant_string) if variant_index == -1: variant_index = context.get_variant(self, variant_string) - generated_variants.append(variant_string) for t in output_info: if output.has(t.field): var subst_output = subst(output[t.field], context, uv) + while subst_output is GDScriptFunctionState: + subst_output = yield(subst_output, "completed") rv.defs += subst_output.defs rv.code += subst_output.code rv.code += "%s %s_%d_%d_%s = %s;\n" % [ t.type, name, output_index, variant_index, t.field, subst_output.string ] + for t in subst_output.textures.keys(): + rv.textures[t] = subst_output.textures[t] for t in output_info: if output.has(t.field): rv[t.field] = "%s_%d_%d_%s" % [ name, output_index, variant_index, t.field ] diff --git a/addons/material_maker/engine/renderer.gd b/addons/material_maker/engine/renderer.gd index 2662bd6..14d7420 100644 --- a/addons/material_maker/engine/renderer.gd +++ b/addons/material_maker/engine/renderer.gd @@ -18,6 +18,9 @@ static func generate_shader(src_code): file.open("res://addons/material_maker/common.shader", File.READ) code += file.get_as_text() code += "\n" + if src_code.has("textures"): + for t in src_code.textures.keys(): + code += "uniform sampler2D "+t+";\n" if src_code.has("globals"): for g in src_code.globals: code += g @@ -84,7 +87,7 @@ func render_shader(shader, textures, render_size): shader_material.shader.code = shader if textures != null: for k in textures.keys(): - shader_material.set_shader_param(k+"_tex", textures[k]) + shader_material.set_shader_param(k, textures[k]) render_target_update_mode = Viewport.UPDATE_ONCE update_worlds() yield(get_tree(), "idle_frame") diff --git a/addons/material_maker/nodes/colorize.mmn b/addons/material_maker/nodes/colorize.mmn index f2fd928..f1dcfc3 100644 --- a/addons/material_maker/nodes/colorize.mmn +++ b/addons/material_maker/nodes/colorize.mmn @@ -1 +1 @@ -{"global":"","inputs":[{"default":"0.0","label":"Input","name":"input","type":"f"}],"instance":"","name":"Colorize","outputs":[{"rgba":"$gradient($input($uv))"}],"parameters":[{"default":{"points":[{"a":1,"b":0,"g":0,"pos":0,"r":0},{"a":1,"b":1,"g":1,"pos":1,"r":1}],"type":"Gradient"},"label":"","name":"gradient","type":"gradient"}]} \ No newline at end of file +{"global":"","inputs":[{"default":"$uv.x","label":"Input","name":"input","type":"f"}],"instance":"","name":"Colorize","outputs":[{"rgba":"$gradient($input($uv))"}],"parameters":[{"default":{"points":[{"a":1,"b":0,"g":0,"pos":0,"r":0},{"a":1,"b":1,"g":1,"pos":1,"r":1}],"type":"Gradient"},"label":"","name":"gradient","type":"gradient"}]} \ No newline at end of file diff --git a/addons/material_maker/nodes/generic.gd b/addons/material_maker/nodes/generic.gd index cc5efd4..f515c8e 100644 --- a/addons/material_maker/nodes/generic.gd +++ b/addons/material_maker/nodes/generic.gd @@ -86,13 +86,11 @@ func update_node(data): if data.has("instance") and data.instance.find("$(seed)"): uses_seed = true # Parameters - print("Parameters") controls = [] var sizer = null for p in generator.get_parameter_defs(): if !p.has("name") or !p.has("type"): continue - print(p.name) var control = null if p.type == "float": if p.has("widget") and p.widget == "spinbox": @@ -141,35 +139,39 @@ func update_node(data): control.size_flags_horizontal = SIZE_EXPAND | SIZE_FILL sizer.add_child(control) initialize_properties() - if data.has("inputs") and typeof(data.inputs) == TYPE_ARRAY: - for i in range(data.inputs.size()): - var input = data.inputs[i] - var enable_left = false - var color_left = Color(0.5, 0.5, 0.5) - if typeof(input) == TYPE_DICTIONARY: - if input.type == "rgb": - enable_left = true - color_left = Color(0.5, 0.5, 1.0) - elif input.type == "rgba": - enable_left = true - color_left = Color(0.0, 0.5, 0.0, 0.5) - else: - enable_left = true - set_slot(i, enable_left, 0, color_left, false, 0, Color()) - if data.has("outputs") and typeof(data.outputs) == TYPE_ARRAY: - for i in range(data.outputs.size()): - var output = data.outputs[i] - var enable_right = false - var color_right = Color(0.5, 0.5, 0.5) - if typeof(output) == TYPE_DICTIONARY: - if output.has("rgb"): - enable_right = true - color_right = Color(0.5, 0.5, 1.0) - elif output.has("rgba"): - enable_right = true - color_right = Color(0.0, 0.5, 0.0, 0.5) - elif output.has("f"): - enable_right = true - set_slot(i, is_slot_enabled_left(i), get_slot_type_left(i), get_slot_color_left(i), enable_right, 0, color_right) + # Inputs + var inputs = generator.get_input_defs() + for i in range(inputs.size()): + var input = inputs[i] + print(input) + var enable_left = false + var color_left = Color(0.5, 0.5, 0.5) + if typeof(input) == TYPE_DICTIONARY: + if input.type == "rgb": + enable_left = true + color_left = Color(0.5, 0.5, 1.0) + elif input.type == "rgba": + enable_left = true + color_left = Color(0.0, 0.5, 0.0, 0.5) + else: + enable_left = true + set_slot(i, enable_left, 0, color_left, false, 0, Color()) + # Outputs + var outputs = generator.get_output_defs() + for i in range(outputs.size()): + var output = outputs[i] + print(output) + var enable_right = false + var color_right = Color(0.5, 0.5, 0.5) + if typeof(output) == TYPE_DICTIONARY: + if output.has("rgb"): + enable_right = true + color_right = Color(0.5, 0.5, 1.0) + elif output.has("rgba"): + enable_right = true + color_right = Color(0.0, 0.5, 0.0, 0.5) + elif output.has("f"): + enable_right = true + set_slot(i, is_slot_enabled_left(i), get_slot_type_left(i), get_slot_color_left(i), enable_right, 0, color_right) if custom_node_buttons != null: move_child(custom_node_buttons, get_child_count()-1) From 9d650c98a11ea2686987635b482fa41f7f982318 Mon Sep 17 00:00:00 2001 From: Rodolphe Suescun Date: Mon, 19 Aug 2019 16:37:17 +0200 Subject: [PATCH 011/133] Reimplemented node deletion --- addons/material_maker/engine/gen_graph.gd | 7 +++++++ addons/material_maker/graph_edit.gd | 2 +- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/addons/material_maker/engine/gen_graph.gd b/addons/material_maker/engine/gen_graph.gd index 25b78b5..988094f 100644 --- a/addons/material_maker/engine/gen_graph.gd +++ b/addons/material_maker/engine/gen_graph.gd @@ -15,6 +15,13 @@ func get_port_source(gen_name: String, input_index: int) -> OutputPort: return OutputPort.new(get_node(c.from), c.from_port) return null +func remove_generator(generator : MMGenBase): + var new_connections = [] + for c in connections: + if c.from != generator.name and c.to != generator.name: + new_connections.append(c) + connections = new_connections + func connect_children(from, from_port : int, to, to_port : int): # disconnect target while true: diff --git a/addons/material_maker/graph_edit.gd b/addons/material_maker/graph_edit.gd index 4dc11ef..2b5fca7 100644 --- a/addons/material_maker/graph_edit.gd +++ b/addons/material_maker/graph_edit.gd @@ -54,7 +54,7 @@ func disconnect_node(from, from_slot, to, to_slot): send_changed_signal(); func remove_node(node): - generator.remove_node(node.generator) + generator.remove_generator(node.generator) var node_name = node.name for c in get_connection_list(): if c.from == node_name or c.to == node_name: From 0bcdbb2204bd36797968309df29206636ec6e93c Mon Sep 17 00:00:00 2001 From: Rodolphe Suescun Date: Sun, 25 Aug 2019 23:27:07 +0200 Subject: [PATCH 012/133] More refactoring and added image "generator" --- addons/material_maker/engine/gen_base.gd | 8 +- addons/material_maker/engine/gen_buffer.gd | 23 +- addons/material_maker/engine/gen_image.gd | 21 ++ addons/material_maker/engine/gen_texture.gd | 23 ++ addons/material_maker/engine/loader.gd | 2 + addons/material_maker/graph_edit.tscn | 1 - addons/material_maker/nodes/generic.gd | 14 +- addons/material_maker/nodes/image.gd | 30 +++ .../nodes/{image => }/image.tscn | 5 +- addons/material_maker/nodes/image/image.gd | 53 ----- .../material_maker/nodes/switch/switch.tscn | 201 +++--------------- project.godot | 14 +- 12 files changed, 138 insertions(+), 257 deletions(-) create mode 100644 addons/material_maker/engine/gen_image.gd create mode 100644 addons/material_maker/engine/gen_texture.gd create mode 100644 addons/material_maker/nodes/image.gd rename addons/material_maker/nodes/{image => }/image.tscn (87%) delete mode 100644 addons/material_maker/nodes/image/image.gd diff --git a/addons/material_maker/engine/gen_base.gd b/addons/material_maker/engine/gen_base.gd index b2be44b..936ef64 100644 --- a/addons/material_maker/engine/gen_base.gd +++ b/addons/material_maker/engine/gen_base.gd @@ -2,6 +2,10 @@ tool extends Node class_name MMGenBase +""" +Base class for texture generators, that defines their API +""" + class OutputPort: var generator : MMGenBase = null var output_index : int = 0 @@ -21,7 +25,6 @@ func _ready(): func init_parameters(): for p in get_parameter_defs(): - print(p) if !parameters.has(p.name): if p.has("default"): parameters[p.name] = MMType.deserialize_value(p.default) @@ -40,6 +43,9 @@ func get_type_name(): func get_parameter_defs(): return [] +func set_parameter(n : String, v): + parameters[n] = v + func get_input_defs(): return [] diff --git a/addons/material_maker/engine/gen_buffer.gd b/addons/material_maker/engine/gen_buffer.gd index 58bcce8..92efdfa 100644 --- a/addons/material_maker/engine/gen_buffer.gd +++ b/addons/material_maker/engine/gen_buffer.gd @@ -1,8 +1,11 @@ tool -extends MMGenBase +extends MMGenTexture class_name MMGenBuffer -var texture : ImageTexture = ImageTexture.new() +""" +Texture generator buffers, that render their input in a specific resolution and provide the result as output. +This is useful when using generators that sample their inputs several times (such as convolutions) +""" func _ready(): if !parameters.has("size"): @@ -20,9 +23,6 @@ func get_parameter_defs(): func get_input_defs(): return [ { name="in", type="rgba" } ] -func get_output_defs(): - return [ { rgba="" } ] - func _get_shader_code(uv : String, output_index : int, context : MMGenContext): var source = get_source(0) if source != null: @@ -34,12 +34,7 @@ func _get_shader_code(uv : String, output_index : int, context : MMGenContext): var image : Image = context.renderer.get_texture().get_data() texture.create_from_image(image) texture.flags = 0 - var rv = { defs="" } - var variant_index = context.get_variant(self, uv) - if variant_index == -1: - variant_index = context.get_variant(self, uv) - var texture_name = name+"_tex" - rv.code = "vec4 %s_%d = texture(%s, %s);\n" % [ name, variant_index, texture_name, uv ] - rv.rgba = "%s_%d" % [ name, variant_index ] - rv.textures = { texture_name:texture } - return rv \ No newline at end of file + var rv = ._get_shader_code(uv, output_index, context) + while rv is GDScriptFunctionState: + rv = yield(rv, "completed") + return rv diff --git a/addons/material_maker/engine/gen_image.gd b/addons/material_maker/engine/gen_image.gd new file mode 100644 index 0000000..9d89b9e --- /dev/null +++ b/addons/material_maker/engine/gen_image.gd @@ -0,0 +1,21 @@ +tool +extends MMGenTexture +class_name MMGenImage + +""" +Texture generator from image +""" + +func get_type(): + return "image" + +func get_type_name(): + return "Image" + +func get_parameter_defs(): + return [ { name="image", type="path" } ] + +func set_parameter(n : String, v): + .set_parameter(n, v) + if n == "image": + texture.load(v) diff --git a/addons/material_maker/engine/gen_texture.gd b/addons/material_maker/engine/gen_texture.gd new file mode 100644 index 0000000..dafb901 --- /dev/null +++ b/addons/material_maker/engine/gen_texture.gd @@ -0,0 +1,23 @@ +tool +extends MMGenBase +class_name MMGenTexture + +""" +Base class for texture generators that provide a texture as output +""" + +var texture : ImageTexture = ImageTexture.new() + +func get_output_defs(): + return [ { rgba="" } ] + +func _get_shader_code(uv : String, output_index : int, context : MMGenContext): + var rv = { defs="" } + var variant_index = context.get_variant(self, uv) + if variant_index == -1: + variant_index = context.get_variant(self, uv) + var texture_name = name+"_tex" + rv.code = "vec4 %s_%d = texture(%s, %s);\n" % [ name, variant_index, texture_name, uv ] + rv.rgba = "%s_%d" % [ name, variant_index ] + rv.textures = { texture_name:texture } + return rv \ No newline at end of file diff --git a/addons/material_maker/engine/loader.gd b/addons/material_maker/engine/loader.gd index a225295..a4253dd 100644 --- a/addons/material_maker/engine/loader.gd +++ b/addons/material_maker/engine/loader.gd @@ -40,6 +40,8 @@ func create_gen(data) -> MMGenBase: generator = MMGenMaterial.new() elif data.type == "buffer": generator = MMGenBuffer.new() + elif data.type == "image": + generator = MMGenImage.new() else: var file = File.new() if file.open("res://addons/material_maker/library/"+data.type+".mml", File.READ) == OK: diff --git a/addons/material_maker/graph_edit.tscn b/addons/material_maker/graph_edit.tscn index 04a242f..2b611c3 100644 --- a/addons/material_maker/graph_edit.tscn +++ b/addons/material_maker/graph_edit.tscn @@ -7,7 +7,6 @@ self_modulate = Color( 1, 1, 1, 0 ) anchor_right = 1.0 anchor_bottom = 1.0 right_disconnects = true -scroll_offset = Vector2( -325, -250 ) use_snap = false script = ExtResource( 1 ) diff --git a/addons/material_maker/nodes/generic.gd b/addons/material_maker/nodes/generic.gd index f515c8e..cb8bfb8 100644 --- a/addons/material_maker/nodes/generic.gd +++ b/addons/material_maker/nodes/generic.gd @@ -4,18 +4,13 @@ var generator = null setget set_generator var controls = [] -var uses_seed : bool = false - # Called when the node enters the scene tree for the first time. func _ready(): pass # Replace with function body. func set_generator(g): generator = g - if g.get("shader_model") != null: - update_node(g.shader_model) - else: - update_node({}) + update_node() func initialize_properties(): for o in controls: @@ -69,9 +64,7 @@ func _on_gradient_changed(new_gradient, variable): generator.parameters[variable] = new_gradient update_shaders() -func update_node(data): - if typeof(data) != TYPE_DICTIONARY: - return +func update_node(): # Clean node var custom_node_buttons = null for c in get_children(): @@ -82,9 +75,6 @@ func update_node(data): custom_node_buttons = c # Rebuild node title = generator.get_type_name() - uses_seed = false - if data.has("instance") and data.instance.find("$(seed)"): - uses_seed = true # Parameters controls = [] var sizer = null diff --git a/addons/material_maker/nodes/image.gd b/addons/material_maker/nodes/image.gd new file mode 100644 index 0000000..45d1313 --- /dev/null +++ b/addons/material_maker/nodes/image.gd @@ -0,0 +1,30 @@ +tool +extends "res://addons/material_maker/node_base.gd" + +var generator = null + +func _ready(): + set_slot(0, false, 0, Color(0.5, 0.5, 1), true, 0, Color(0.5, 0.5, 1)) + +func set_texture(path): + if path == null: + return + if generator != null: + generator.set_parameter("image", path) + $TextureButton.texture_normal = generator.texture + +func get_textures(): + var list = {} + list[name] = $TextureButton.texture_normal + return list + +func _on_TextureButton_pressed(): + var dialog = FileDialog.new() + add_child(dialog) + dialog.rect_min_size = Vector2(500, 500) + dialog.access = FileDialog.ACCESS_FILESYSTEM + dialog.mode = FileDialog.MODE_OPEN_FILE + dialog.add_filter("*.png;PNG image") + dialog.add_filter("*.jpg;JPG image") + dialog.connect("file_selected", self, "set_texture") + dialog.popup_centered() diff --git a/addons/material_maker/nodes/image/image.tscn b/addons/material_maker/nodes/image.tscn similarity index 87% rename from addons/material_maker/nodes/image/image.tscn rename to addons/material_maker/nodes/image.tscn index 7eafbfb..ceea37f 100644 --- a/addons/material_maker/nodes/image/image.tscn +++ b/addons/material_maker/nodes/image.tscn @@ -1,6 +1,6 @@ [gd_scene load_steps=4 format=2] -[ext_resource path="res://addons/material_maker/nodes/image/image.gd" type="Script" id=1] +[ext_resource path="res://addons/material_maker/nodes/image.gd" type="Script" id=1] [ext_resource path="res://addons/material_maker/nodes/image/godot_logo.png" type="Texture" id=2] [sub_resource type="Theme" id=1] @@ -20,7 +20,7 @@ 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/0/right_color = Color( 0, 1, 0, 0.501961 ) script = ExtResource( 1 ) [node name="TextureButton" type="TextureButton" parent="."] @@ -33,5 +33,4 @@ rect_clip_content = true texture_normal = ExtResource( 2 ) expand = true stretch_mode = 5 - [connection signal="pressed" from="TextureButton" to="." method="_on_TextureButton_pressed"] diff --git a/addons/material_maker/nodes/image/image.gd b/addons/material_maker/nodes/image/image.gd deleted file mode 100644 index 746c75c..0000000 --- a/addons/material_maker/nodes/image/image.gd +++ /dev/null @@ -1,53 +0,0 @@ -tool -extends "res://addons/material_maker/node_base.gd" - -var file_path = null - -func _ready(): - set_slot(0, false, 0, Color(0.5, 0.5, 1), true, 0, Color(0.5, 0.5, 1)) - -func set_texture(path): - file_path = path - var texture = ImageTexture.new() - if path != null: - texture.load(path) - $TextureButton.texture_normal = texture - update_shaders() - -func get_textures(): - var list = {} - list[name] = $TextureButton.texture_normal - return list - -func _get_shader_code(uv, slot = 0): - var rv = { defs="", code="" } - if generated_variants.empty(): - rv.defs = "uniform sampler2D %s_tex;\n" % [ name ] - var variant_index = generated_variants.find(uv) - if variant_index == -1: - variant_index = generated_variants.size() - generated_variants.append(uv) - rv.code = "vec4 %s_%d_rgba = texture(%s_tex, %s);\n" % [ name, variant_index, name, uv ] - rv.rgba = "%s_%d_rgba" % [ name, variant_index ] - return rv - -func _on_TextureButton_pressed(): - var dialog = FileDialog.new() - add_child(dialog) - dialog.rect_min_size = Vector2(500, 500) - dialog.access = FileDialog.ACCESS_FILESYSTEM - dialog.mode = FileDialog.MODE_OPEN_FILE - dialog.add_filter("*.png;PNG image") - dialog.add_filter("*.jpg;JPG image") - dialog.connect("file_selected", self, "set_texture") - dialog.popup_centered() - -func serialize(): - var data = .serialize() - data.file_path = file_path - return data - -func deserialize(data): - if data.has("file_path"): - set_texture(data.file_path) - .deserialize(data) diff --git a/addons/material_maker/nodes/switch/switch.tscn b/addons/material_maker/nodes/switch/switch.tscn index c676ab2..34ed4a1 100644 --- a/addons/material_maker/nodes/switch/switch.tscn +++ b/addons/material_maker/nodes/switch/switch.tscn @@ -2,34 +2,17 @@ [ext_resource path="res://addons/material_maker/nodes/switch/switch.gd" type="Script" id=1] - [sub_resource type="Theme" id=1] - -[node name="Switch" type="GraphNode" index="0"] - -anchor_left = 0.0 -anchor_top = 0.0 -anchor_right = 0.0 -anchor_bottom = 0.0 +[node name="Switch" type="GraphNode"] margin_left = 1.0 margin_top = 1.0 -margin_right = 87.0 -margin_bottom = 89.0 -rect_pivot_offset = Vector2( 0, 0 ) -rect_clip_content = false +margin_right = 100.0 +margin_bottom = 110.0 mouse_filter = 1 -mouse_default_cursor_shape = 0 -size_flags_horizontal = 1 -size_flags_vertical = 1 theme = SubResource( 1 ) title = "Switch" -offset = Vector2( 0, 0 ) show_close = true -resizable = false -selected = false -comment = false -overlay = 0 slot/0/left_enabled = false slot/0/left_type = 0 slot/0/left_color = Color( 0.498039, 0.498039, 1, 1 ) @@ -61,190 +44,64 @@ slot/4/right_enabled = false slot/4/right_type = 0 slot/4/right_color = Color( 1, 0, 0, 1 ) script = ExtResource( 1 ) -_sections_unfolded = [ "Theme", "slot", "slot/0", "slot/1", "slot/2", "slot/3", "slot/4" ] -[node name="source" type="OptionButton" parent="." index="0"] - -anchor_left = 0.0 -anchor_top = 0.0 -anchor_right = 0.0 -anchor_bottom = 0.0 +[node name="source" type="OptionButton" parent="."] margin_left = 16.0 margin_top = 24.0 -margin_right = 70.0 +margin_right = 83.0 margin_bottom = 44.0 -rect_pivot_offset = Vector2( 0, 0 ) -rect_clip_content = false -focus_mode = 2 -mouse_filter = 0 -mouse_default_cursor_shape = 0 -size_flags_horizontal = 1 -size_flags_vertical = 1 -toggle_mode = false -action_mode = 0 -enabled_focus_mode = 2 -shortcut = null -group = null text = "1" -flat = false -align = 0 items = [ "1", null, false, 0, null, "2", null, false, 1, null ] selected = 0 -[node name="Label1" type="Label" parent="." index="1"] - -anchor_left = 0.0 -anchor_top = 0.0 -anchor_right = 0.0 -anchor_bottom = 0.0 +[node name="Label1" type="Label" parent="."] margin_left = 16.0 margin_top = 44.0 -margin_right = 70.0 +margin_right = 83.0 margin_bottom = 58.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 = "A1" -percent_visible = 1.0 -lines_skipped = 0 -max_lines_visible = -1 -[node name="HBoxContainer1" type="HBoxContainer" parent="." index="2"] - -anchor_left = 0.0 -anchor_top = 0.0 -anchor_right = 0.0 -anchor_bottom = 0.0 +[node name="HBoxContainer1" type="HBoxContainer" parent="."] margin_left = 16.0 margin_top = 59.0 -margin_right = 70.0 +margin_right = 83.0 margin_bottom = 73.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 -alignment = 0 -[node name="Label1" type="Label" parent="HBoxContainer1" index="0"] - -anchor_left = 0.0 -anchor_top = 0.0 -anchor_right = 0.0 -anchor_bottom = 0.0 -margin_right = 41.0 -margin_bottom = 14.0 -rect_pivot_offset = Vector2( 0, 0 ) -rect_clip_content = false -mouse_filter = 2 -mouse_default_cursor_shape = 0 -size_flags_horizontal = 3 -size_flags_vertical = 4 -text = "B1" -percent_visible = 1.0 -lines_skipped = 0 -max_lines_visible = -1 - -[node name="Label2" type="Label" parent="HBoxContainer1" index="1"] - -anchor_left = 0.0 -anchor_top = 0.0 -anchor_right = 0.0 -anchor_bottom = 0.0 -margin_left = 45.0 +[node name="Label1" type="Label" parent="HBoxContainer1"] margin_right = 54.0 margin_bottom = 14.0 -rect_pivot_offset = Vector2( 0, 0 ) -rect_clip_content = false -mouse_filter = 2 -mouse_default_cursor_shape = 0 +size_flags_horizontal = 3 +text = "B1" + +[node name="Label2" type="Label" parent="HBoxContainer1"] +margin_left = 58.0 +margin_right = 67.0 +margin_bottom = 14.0 size_flags_horizontal = 9 -size_flags_vertical = 4 text = "A" -percent_visible = 1.0 -lines_skipped = 0 -max_lines_visible = -1 -[node name="HBoxContainer2" type="HBoxContainer" parent="." index="3"] - -anchor_left = 0.0 -anchor_top = 0.0 -anchor_right = 0.0 -anchor_bottom = 0.0 +[node name="HBoxContainer2" type="HBoxContainer" parent="."] margin_left = 16.0 margin_top = 74.0 -margin_right = 70.0 +margin_right = 83.0 margin_bottom = 88.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 -alignment = 0 -[node name="Label1" type="Label" parent="HBoxContainer2" index="0"] - -anchor_left = 0.0 -anchor_top = 0.0 -anchor_right = 0.0 -anchor_bottom = 0.0 -margin_right = 41.0 -margin_bottom = 14.0 -rect_pivot_offset = Vector2( 0, 0 ) -rect_clip_content = false -mouse_filter = 2 -mouse_default_cursor_shape = 0 -size_flags_horizontal = 3 -size_flags_vertical = 4 -text = "A2" -percent_visible = 1.0 -lines_skipped = 0 -max_lines_visible = -1 - -[node name="Label2" type="Label" parent="HBoxContainer2" index="1"] - -anchor_left = 0.0 -anchor_top = 0.0 -anchor_right = 0.0 -anchor_bottom = 0.0 -margin_left = 45.0 +[node name="Label1" type="Label" parent="HBoxContainer2"] margin_right = 54.0 margin_bottom = 14.0 -rect_pivot_offset = Vector2( 0, 0 ) -rect_clip_content = false -mouse_filter = 2 -mouse_default_cursor_shape = 0 +size_flags_horizontal = 3 +text = "A2" + +[node name="Label2" type="Label" parent="HBoxContainer2"] +margin_left = 58.0 +margin_right = 67.0 +margin_bottom = 14.0 size_flags_horizontal = 9 -size_flags_vertical = 4 text = "B" -percent_visible = 1.0 -lines_skipped = 0 -max_lines_visible = -1 -[node name="Label2" type="Label" parent="." index="4"] - -anchor_left = 0.0 -anchor_top = 0.0 -anchor_right = 0.0 -anchor_bottom = 0.0 +[node name="Label2" type="Label" parent="."] margin_left = 16.0 margin_top = 89.0 -margin_right = 70.0 +margin_right = 83.0 margin_bottom = 103.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 = "B2" -percent_visible = 1.0 -lines_skipped = 0 -max_lines_visible = -1 - - diff --git a/project.godot b/project.godot index 42fc611..8442bec 100644 --- a/project.godot +++ b/project.godot @@ -14,7 +14,7 @@ _global_script_classes=[ { "language": "GDScript", "path": "res://addons/material_maker/engine/gen_base.gd" }, { -"base": "MMGenBase", +"base": "MMGenTexture", "class": "MMGenBuffer", "language": "GDScript", "path": "res://addons/material_maker/engine/gen_buffer.gd" @@ -34,6 +34,11 @@ _global_script_classes=[ { "language": "GDScript", "path": "res://addons/material_maker/engine/gen_graph.gd" }, { +"base": "MMGenTexture", +"class": "MMGenImage", +"language": "GDScript", +"path": "res://addons/material_maker/engine/gen_image.gd" +}, { "base": "Object", "class": "MMGenLoader", "language": "GDScript", @@ -54,6 +59,11 @@ _global_script_classes=[ { "language": "GDScript", "path": "res://addons/material_maker/engine/gen_shader.gd" }, { +"base": "MMGenBase", +"class": "MMGenTexture", +"language": "GDScript", +"path": "res://addons/material_maker/engine/gen_texture.gd" +}, { "base": "Object", "class": "MMGradient", "language": "GDScript", @@ -70,10 +80,12 @@ _global_script_class_icons={ "MMGenContext": "", "MMGenConvolution": "", "MMGenGraph": "", +"MMGenImage": "", "MMGenLoader": "", "MMGenMaterial": "", "MMGenRenderer": "", "MMGenShader": "", +"MMGenTexture": "", "MMGradient": "", "MMType": "" } From 27d5ddbe97c8041cf95824d7dd63fc2f1785f1d7 Mon Sep 17 00:00:00 2001 From: RodZill4 Date: Mon, 9 Sep 2019 22:00:18 +0200 Subject: [PATCH 013/133] Implemented save and shader generator editing... --- addons/material_maker/engine/gen_base.gd | 16 ++++ addons/material_maker/engine/gen_buffer.gd | 4 + addons/material_maker/engine/gen_graph.gd | 17 +++- addons/material_maker/engine/gen_material.gd | 4 + addons/material_maker/engine/gen_shader.gd | 8 +- addons/material_maker/engine/loader.gd | 19 +++-- addons/material_maker/graph_edit.gd | 14 +--- addons/material_maker/library/base.json | 3 +- addons/material_maker/main_window.gd | 29 +++++-- addons/material_maker/nodes/combine.mmg | 1 + addons/material_maker/nodes/edit_buttons.gd | 6 ++ addons/material_maker/nodes/edit_buttons.tscn | 31 +++++++ addons/material_maker/nodes/generic.gd | 82 ++++++++++++++++++- addons/material_maker/nodes/generic.tscn | 4 +- addons/material_maker/plugin.gd | 3 +- addons/material_maker/types/gradient.gd | 6 +- addons/material_maker/types/types.gd | 4 +- 17 files changed, 212 insertions(+), 39 deletions(-) create mode 100644 addons/material_maker/nodes/combine.mmg create mode 100644 addons/material_maker/nodes/edit_buttons.gd create mode 100644 addons/material_maker/nodes/edit_buttons.tscn diff --git a/addons/material_maker/engine/gen_base.gd b/addons/material_maker/engine/gen_base.gd index 936ef64..0ca3742 100644 --- a/addons/material_maker/engine/gen_base.gd +++ b/addons/material_maker/engine/gen_base.gd @@ -18,6 +18,7 @@ class OutputPort: return generator.name+"("+str(output_index)+")" var position : Vector2 = Vector2(0, 0) +var model = null var parameters = {} func _ready(): @@ -112,3 +113,18 @@ func get_shader_code(uv : String, output_index : int, context : MMGenContext): func _get_shader_code(uv : String, output_index : int, context : MMGenContext): return null + +func _serialize(data): + print("cannot save "+name) + return data + +func serialize(): + var rv = { name=name, parameters={}, node_position={ x=position.x, y=position.y } } + for p in parameters.keys(): + rv.parameters[p] = MMType.serialize_value(parameters[p]) + if model != null: + rv.type = model + else: + rv = _serialize(rv) + + return rv \ No newline at end of file diff --git a/addons/material_maker/engine/gen_buffer.gd b/addons/material_maker/engine/gen_buffer.gd index 92efdfa..4861a78 100644 --- a/addons/material_maker/engine/gen_buffer.gd +++ b/addons/material_maker/engine/gen_buffer.gd @@ -38,3 +38,7 @@ func _get_shader_code(uv : String, output_index : int, context : MMGenContext): while rv is GDScriptFunctionState: rv = yield(rv, "completed") return rv + +func _serialize(data): + data.type = "buffer" + return data diff --git a/addons/material_maker/engine/gen_graph.gd b/addons/material_maker/engine/gen_graph.gd index 988094f..6aa2844 100644 --- a/addons/material_maker/engine/gen_graph.gd +++ b/addons/material_maker/engine/gen_graph.gd @@ -21,6 +21,14 @@ func remove_generator(generator : MMGenBase): if c.from != generator.name and c.to != generator.name: new_connections.append(c) connections = new_connections + generator.queue_free() + +func replace_generator(old : MMGenBase, new : MMGenBase): + new.name = old.name + new.position = old.position + remove_child(old) + old.free() + add_child(new) func connect_children(from, from_port : int, to, to_port : int): # disconnect target @@ -47,4 +55,11 @@ func disconnect_children(from, from_port : int, to, to_port : int): if remove == -1: break connections.remove(remove) - return true \ No newline at end of file + return true + +func _serialize(data): + data.nodes = [] + for c in get_children(): + data.nodes.append(c.serialize()) + data.connections = connections + return data diff --git a/addons/material_maker/engine/gen_material.gd b/addons/material_maker/engine/gen_material.gd index 963568e..fad8969 100644 --- a/addons/material_maker/engine/gen_material.gd +++ b/addons/material_maker/engine/gen_material.gd @@ -129,3 +129,7 @@ func export_textures(prefix, size = null): update_spatial_material(new_material, prefix) ResourceSaver.save("%s.tres" % [ prefix ], new_material) resource_filesystem.scan() + +func _serialize(data): + data.type = "material" + return data diff --git a/addons/material_maker/engine/gen_shader.gd b/addons/material_maker/engine/gen_shader.gd index 822d033..82136fa 100644 --- a/addons/material_maker/engine/gen_shader.gd +++ b/addons/material_maker/engine/gen_shader.gd @@ -120,7 +120,7 @@ func subst(string, context, uv = ""): elif p.type == "color": value_string = "vec4(%.9f, %.9f, %.9f, %.9f)" % [ value.r, value.g, value.b, value.a ] elif p.type == "gradient": - value_string = p.name+"_gradient_fct" + value_string = name+"__"+p.name+"_gradient_fct" if value_string != null: string = replace_variable(string, p.name, value_string) if shader_model.has("inputs") and typeof(shader_model.inputs) == TYPE_ARRAY: @@ -157,7 +157,7 @@ func _get_shader_code(uv : String, output_index : int, context : MMGenContext): if !(g is MMGradient): g = MMGradient.new() g.deserialize(parameters[p.name]) - rv.defs += g.get_shader(p.name+"_gradient_fct") + rv.defs += g.get_shader(name+"__"+p.name+"_gradient_fct") var variant_index = context.get_variant(self, variant_string) if variant_index == -1: variant_index = context.get_variant(self, variant_string) @@ -181,3 +181,7 @@ func get_globals(): if typeof(shader_model) == TYPE_DICTIONARY and shader_model.has("global") and list.find(shader_model.global) == -1: list.append(shader_model.global) return list + +func _serialize(data): + data.shader_model = shader_model + return data diff --git a/addons/material_maker/engine/loader.gd b/addons/material_maker/engine/loader.gd index a4253dd..baf9cef 100644 --- a/addons/material_maker/engine/loader.gd +++ b/addons/material_maker/engine/loader.gd @@ -2,14 +2,14 @@ tool extends Object class_name MMGenLoader -func load_gen(filename: String) -> MMGenBase: +static func load_gen(filename: String) -> MMGenBase: var file = File.new() if file.open(filename, File.READ) == OK: var data = parse_json(file.get_as_text()) return create_gen(data) return null -func add_to_gen_graph(gen_graph, generators, connections): +static func add_to_gen_graph(gen_graph, generators, connections): var rv = { generators=[], connections=[] } for n in generators: var g = create_gen(n) @@ -27,7 +27,7 @@ func add_to_gen_graph(gen_graph, generators, connections): rv.connections.append(c) return rv -func create_gen(data) -> MMGenBase: +static func create_gen(data) -> MMGenBase: var generator = null if data.has("connections") and data.has("nodes"): generator = MMGenGraph.new() @@ -35,6 +35,9 @@ func create_gen(data) -> MMGenBase: elif data.has("shader_model"): generator = MMGenShader.new() generator.set_shader_model(data.shader_model) + elif data.has("model_data"): + generator = MMGenShader.new() + generator.set_shader_model(data.model_data) elif data.has("type"): if data.type == "material": generator = MMGenMaterial.new() @@ -44,13 +47,13 @@ func create_gen(data) -> MMGenBase: generator = MMGenImage.new() else: var file = File.new() - if file.open("res://addons/material_maker/library/"+data.type+".mml", File.READ) == OK: - print("loaded description "+data.type+".mml") + if file.open("res://addons/material_maker/nodes/"+data.type+".mmg", File.READ) == OK: generator = create_gen(parse_json(file.get_as_text())) + generator.model = data.type file.close() elif file.open("res://addons/material_maker/nodes/"+data.type+".mmn", File.READ) == OK: generator = MMGenShader.new() - print("loaded description "+data.type+".mmn") + generator.model = data.type generator.set_shader_model(parse_json(file.get_as_text())) file.close() else: @@ -58,7 +61,7 @@ func create_gen(data) -> MMGenBase: if generator != null: generator.name = data.type else: - print(data) + print("LOADER: data not supported:"+str(data)) if generator != null: if data.has("name"): generator.name = data.name @@ -67,5 +70,5 @@ func create_gen(data) -> MMGenBase: generator.position.y = data.node_position.y if data.has("parameters"): for p in data.parameters.keys(): - generator.parameters[p] = data.parameters[p] + generator.parameters[p] = MMType.deserialize_value(data.parameters[p]) return generator diff --git a/addons/material_maker/graph_edit.gd b/addons/material_maker/graph_edit.gd index 2b5fca7..d500632 100644 --- a/addons/material_maker/graph_edit.gd +++ b/addons/material_maker/graph_edit.gd @@ -134,16 +134,14 @@ func create_nodes(data, position : Vector2 = Vector2(0, 0)): if data.has("type"): data = { nodes=[data], connections=[] } if typeof(data.nodes) == TYPE_ARRAY and typeof(data.connections) == TYPE_ARRAY: - var loader = MMGenLoader.new() - var new_stuff = loader.add_to_gen_graph(generator, data.nodes, data.connections) + var new_stuff = MMGenLoader.add_to_gen_graph(generator, data.nodes, data.connections) for g in new_stuff.generators: g.position += position update_graph(new_stuff.generators, new_stuff.connections) func load_file(filename): clear_material() - var loader = MMGenLoader.new() - generator = loader.load_gen(filename) + generator = MMGenLoader.load_gen(filename) if generator != null: add_child(generator) update_graph(generator.get_children(), generator.connections) @@ -152,11 +150,7 @@ func load_file(filename): center_view() func save_file(filename): - var data = { nodes = [] } - for c in get_children(): - if c is GraphNode: - data.nodes.append(c.serialize()) - data.connections = get_connection_list() + var data = generator.serialize() var file = File.new() if file.open(filename, File.WRITE) == OK: file.store_string(to_json(data)) @@ -191,7 +185,7 @@ func serialize_selection(): center += n.offset+0.5*n.rect_size center /= nodes.size() for n in nodes: - var s = n.serialize() + var s = n.generator.serialize() var p = n.offset-center s.node_position = { x=p.x, y=p.y } data.nodes.append(s) diff --git a/addons/material_maker/library/base.json b/addons/material_maker/library/base.json index 7e16e24..08bd7b8 100644 --- a/addons/material_maker/library/base.json +++ b/addons/material_maker/library/base.json @@ -254,7 +254,8 @@ }, { "tree_item":"Miscellaneous/Custom", - "type":"custom" + "type":"custom", + "shader_model":{} }, { "tree_item":"Miscellaneous/Remote", diff --git a/addons/material_maker/main_window.gd b/addons/material_maker/main_window.gd index 138c227..125aea8 100644 --- a/addons/material_maker/main_window.gd +++ b/addons/material_maker/main_window.gd @@ -25,6 +25,7 @@ const MENU = [ { menu="Edit", command="edit_cut", shortcut="Control+X", description="Cut" }, { menu="Edit", command="edit_copy", shortcut="Control+C", description="Copy" }, { menu="Edit", command="edit_paste", shortcut="Control+V", description="Paste" }, + { menu="Tools", command="make_selected_nodes_editable", description="Make selected nodes editable" }, { menu="Tools", command="add_to_user_library", description="Add selected node to user library" }, { menu="Tools", command="save_user_library", description="Save user library" }, { menu="Help", command="show_doc", description="User manual" }, @@ -233,19 +234,33 @@ func edit_paste_is_disabled(): var data = parse_json(OS.clipboard) return data == null -func add_to_user_library(): +func get_selected_nodes(): var graph_edit = $VBoxContainer/HBoxContainer/Projects.get_current_tab_control() if graph_edit != null and graph_edit is GraphEdit: var selected_nodes = [] for n in graph_edit.get_children(): if n is GraphNode and n.selected: selected_nodes.append(n) - if !selected_nodes.empty(): - var dialog = preload("res://addons/material_maker/widgets/line_dialog.tscn").instance() - dialog.set_texts("New library element", "Select a name for the new library element") - add_child(dialog) - dialog.connect("ok", self, "do_add_to_user_library", [ selected_nodes ]) - dialog.popup_centered() + return selected_nodes + else: + return [] + +func make_selected_nodes_editable(): + var selected_nodes = get_selected_nodes() + if !selected_nodes.empty(): + for n in selected_nodes: + print(n.name) + n.generator.model = null + n.update_node() + +func add_to_user_library(): + var selected_nodes = get_selected_nodes() + if !selected_nodes.empty(): + var dialog = preload("res://addons/material_maker/widgets/line_dialog.tscn").instance() + dialog.set_texts("New library element", "Select a name for the new library element") + add_child(dialog) + dialog.connect("ok", self, "do_add_to_user_library", [ selected_nodes ]) + dialog.popup_centered() func do_add_to_user_library(name, nodes): var data diff --git a/addons/material_maker/nodes/combine.mmg b/addons/material_maker/nodes/combine.mmg new file mode 100644 index 0000000..f263c0c --- /dev/null +++ b/addons/material_maker/nodes/combine.mmg @@ -0,0 +1 @@ +{"name":"uniform","node_position":{"x":-130,"y":-66},"parameters":{"color":{"a":1,"b":1,"g":1,"r":1,"type":"Color"},"name":0},"shader_model":{"global":"","inputs":[{"default":"0.0","label":"R","name":"r","type":"f"},{"default":"0.0","label":"G","name":"g","type":"f"},{"default":"0.0","label":"B","name":"b","type":"f"},{"default":"1.0","label":"A","name":"a","type":"f"}],"instance":"","name":"Combine","outputs":[{"rgba":"vec4($r($uv), $g($uv), $b($uv), $a($uv))"}],"parameters":[]}} \ No newline at end of file diff --git a/addons/material_maker/nodes/edit_buttons.gd b/addons/material_maker/nodes/edit_buttons.gd new file mode 100644 index 0000000..c62bbd5 --- /dev/null +++ b/addons/material_maker/nodes/edit_buttons.gd @@ -0,0 +1,6 @@ +extends HBoxContainer + +func connect_buttons(object, edit_fct, load_fct, save_fct): + $Edit.connect("pressed", object, edit_fct) + $Load.connect("pressed", object, load_fct) + $Save.connect("pressed", object, save_fct) \ No newline at end of file diff --git a/addons/material_maker/nodes/edit_buttons.tscn b/addons/material_maker/nodes/edit_buttons.tscn new file mode 100644 index 0000000..ce6a0e7 --- /dev/null +++ b/addons/material_maker/nodes/edit_buttons.tscn @@ -0,0 +1,31 @@ +[gd_scene load_steps=5 format=2] + +[ext_resource path="res://addons/material_maker/nodes/edit_buttons.gd" type="Script" id=1] +[ext_resource path="res://addons/material_maker/icons/edit.png" type="Texture" id=2] +[ext_resource path="res://addons/material_maker/icons/load.png" type="Texture" id=3] +[ext_resource path="res://addons/material_maker/icons/save.png" type="Texture" id=4] + +[node name="NodeEditButtons" type="HBoxContainer"] +margin_right = 91.0 +margin_bottom = 22.0 +script = ExtResource( 1 ) + +[node name="Edit" type="Button" parent="."] +margin_right = 27.0 +margin_bottom = 22.0 +icon = ExtResource( 2 ) +flat = true + +[node name="Load" type="Button" parent="."] +margin_left = 31.0 +margin_right = 59.0 +margin_bottom = 22.0 +icon = ExtResource( 3 ) +flat = true + +[node name="Save" type="Button" parent="."] +margin_left = 63.0 +margin_right = 91.0 +margin_bottom = 22.0 +icon = ExtResource( 4 ) +flat = true diff --git a/addons/material_maker/nodes/generic.gd b/addons/material_maker/nodes/generic.gd index cb8bfb8..ad312ba 100644 --- a/addons/material_maker/nodes/generic.gd +++ b/addons/material_maker/nodes/generic.gd @@ -12,6 +12,13 @@ func set_generator(g): generator = g update_node() +func on_close_request(): + print("close") + generator.get_parent().remove_generator(generator) + +func on_offset_changed(): + generator.position = offset + func initialize_properties(): for o in controls: if o == null: @@ -73,6 +80,7 @@ func update_node(): c.queue_free() else: custom_node_buttons = c + rect_size = Vector2(0, 0) # Rebuild node title = generator.get_type_name() # Parameters @@ -133,7 +141,6 @@ func update_node(): var inputs = generator.get_input_defs() for i in range(inputs.size()): var input = inputs[i] - print(input) var enable_left = false var color_left = Color(0.5, 0.5, 0.5) if typeof(input) == TYPE_DICTIONARY: @@ -146,11 +153,14 @@ func update_node(): else: enable_left = true set_slot(i, enable_left, 0, color_left, false, 0, Color()) + if i >= get_child_count(): + var control = Control.new() + control.rect_min_size = Vector2(0, 16) + add_child(control) # Outputs var outputs = generator.get_output_defs() for i in range(outputs.size()): var output = outputs[i] - print(output) var enable_right = false var color_right = Color(0.5, 0.5, 0.5) if typeof(output) == TYPE_DICTIONARY: @@ -163,5 +173,69 @@ func update_node(): elif output.has("f"): enable_right = true set_slot(i, is_slot_enabled_left(i), get_slot_type_left(i), get_slot_color_left(i), enable_right, 0, color_right) - if custom_node_buttons != null: - move_child(custom_node_buttons, get_child_count()-1) + if i >= get_child_count(): + var control = Control.new() + control.rect_min_size = Vector2(0, 16) + add_child(control) + if generator.model == null: + var edit_buttons = preload("res://addons/material_maker/nodes/edit_buttons.tscn").instance() + add_child(edit_buttons) + edit_buttons.connect_buttons(self, "edit_generator", "load_generator", "save_generator") + +func edit_generator(): + var edit_window = load("res://addons/material_maker/widgets/node_editor/node_editor.tscn").instance() + get_parent().add_child(edit_window) + if generator.shader_model != null: + edit_window.set_model_data(generator.shader_model) + edit_window.connect("node_changed", self, "update_generator") + edit_window.popup_centered() + +func update_generator(shader_model): + generator.shader_model = shader_model + update_node() + +func load_generator(): + var dialog = FileDialog.new() + add_child(dialog) + dialog.rect_min_size = Vector2(500, 500) + dialog.access = FileDialog.ACCESS_FILESYSTEM + dialog.mode = FileDialog.MODE_OPEN_FILE + dialog.add_filter("*.mmg,*.mmn;Material Maker Generator") + dialog.connect("file_selected", self, "do_load_generator") + dialog.popup_centered() + +func do_load_generator(file_name : String): + print(file_name) + var new_generator = null + if file_name.ends_with(".mmn"): + var file = File.new() + if file.open(file_name, File.READ) == OK: + new_generator = MMGenShader.new() + new_generator.set_shader_model(parse_json(file.get_as_text())) + file.close() + else: + new_generator = MMGenLoader.load_gen(file_name) + if new_generator != null: + var parent_generator = generator.get_parent() + print("before: "+generator.name) + parent_generator.replace_generator(generator, new_generator) + generator = new_generator + print("after: "+generator.name) + update_node() + +func save_generator(): + var dialog = FileDialog.new() + add_child(dialog) + dialog.rect_min_size = Vector2(500, 500) + dialog.access = FileDialog.ACCESS_FILESYSTEM + dialog.mode = FileDialog.MODE_SAVE_FILE + dialog.add_filter("*.mmg;Material Maker Generator") + dialog.connect("file_selected", self, "do_save_generator") + dialog.popup_centered() + +func do_save_generator(file_name : String): + var data = generator.serialize() + var file = File.new() + if file.open(file_name, File.WRITE) == OK: + file.store_string(to_json(data)) + file.close() diff --git a/addons/material_maker/nodes/generic.tscn b/addons/material_maker/nodes/generic.tscn index 3bdc771..9bc13f2 100644 --- a/addons/material_maker/nodes/generic.tscn +++ b/addons/material_maker/nodes/generic.tscn @@ -3,8 +3,10 @@ [ext_resource path="res://addons/material_maker/nodes/generic.gd" type="Script" id=1] [node name="Generic" type="GraphNode"] -margin_right = 82.0 +margin_right = 95.0 margin_bottom = 29.0 title = "Generic" show_close = true script = ExtResource( 1 ) +[connection signal="close_request" from="." to="." method="on_close_request"] +[connection signal="offset_changed" from="." to="." method="on_offset_changed"] diff --git a/addons/material_maker/plugin.gd b/addons/material_maker/plugin.gd index 467e3ed..bcb1b25 100644 --- a/addons/material_maker/plugin.gd +++ b/addons/material_maker/plugin.gd @@ -47,8 +47,7 @@ func close_material_maker(): material_maker = null func generate_material(ptex_filename: String) -> Material: - var loader = MMGenLoader.new() - var generator = loader.load_gen(ptex_filename) + var generator = MMGenLoader.load_gen(ptex_filename) add_child(generator) var material = generator.get_node("Material") var return_value = material.generate_material(renderer) diff --git a/addons/material_maker/types/gradient.gd b/addons/material_maker/types/gradient.gd index f776898..c56a6d4 100644 --- a/addons/material_maker/types/gradient.gd +++ b/addons/material_maker/types/gradient.gd @@ -36,7 +36,7 @@ func sort(): func get_color(x): sort() - if points.size() >0: + if points.size() > 0: if x < points[0].v: return points[0].c var s = points.size()-1 @@ -96,3 +96,7 @@ func deserialize(v): for i in v.points: if !i.has("a"): i.a = 1.0 add_point(i.pos, Color(i.r, i.g, i.b, i.a)) + elif typeof(v) == TYPE_OBJECT and v.get_script() == get_script(): + clear() + for p in v.points: + add_point(p.v, p.c) diff --git a/addons/material_maker/types/types.gd b/addons/material_maker/types/types.gd index a8d135f..f20fcd6 100644 --- a/addons/material_maker/types/types.gd +++ b/addons/material_maker/types/types.gd @@ -5,8 +5,8 @@ const Gradient = preload("res://addons/material_maker/types/gradient.gd") static func serialize_value(value): if typeof(value) == TYPE_COLOR: - return { type= "Color", r=value.r, g=value.g, b=value.b, a=value.a } - elif typeof(value) == TYPE_OBJECT && value.has_method("serialize"): + return { type="Color", r=value.r, g=value.g, b=value.b, a=value.a } + elif typeof(value) == TYPE_OBJECT and value.has_method("serialize"): return value.serialize() return value From 34349c98ca9f08cf437a43acf510cd9baacad019 Mon Sep 17 00:00:00 2001 From: RodZill4 Date: Tue, 10 Sep 2019 21:01:08 +0200 Subject: [PATCH 014/133] Minor fixes and cleanup --- addons/material_maker/engine/gen_context.gd | 2 +- addons/material_maker/engine/gen_texture.gd | 6 +- addons/material_maker/graph_edit.gd | 1 - addons/material_maker/main_window.tscn | 4 +- addons/material_maker/nodes/combine.mmg | 2 +- addons/material_maker/nodes/decompose.mmg | 1 + addons/material_maker/nodes/generic.gd | 5 +- .../nodes/transform/transform.tscn | 330 ++---------------- 8 files changed, 31 insertions(+), 320 deletions(-) create mode 100644 addons/material_maker/nodes/decompose.mmg diff --git a/addons/material_maker/engine/gen_context.gd b/addons/material_maker/engine/gen_context.gd index 25e0a75..2845d75 100644 --- a/addons/material_maker/engine/gen_context.gd +++ b/addons/material_maker/engine/gen_context.gd @@ -16,7 +16,7 @@ func get_variant(generator, uv): if variants.has(generator): rv = variants[generator].find(uv) if rv == -1: - variants[generator].push(uv) + variants[generator].push_back(uv) else: variants[generator] = [uv] return rv diff --git a/addons/material_maker/engine/gen_texture.gd b/addons/material_maker/engine/gen_texture.gd index dafb901..a4a533a 100644 --- a/addons/material_maker/engine/gen_texture.gd +++ b/addons/material_maker/engine/gen_texture.gd @@ -12,12 +12,12 @@ func get_output_defs(): return [ { rgba="" } ] func _get_shader_code(uv : String, output_index : int, context : MMGenContext): - var rv = { defs="" } + var rv = { defs="", code="" } + var texture_name = name+"_tex" var variant_index = context.get_variant(self, uv) if variant_index == -1: variant_index = context.get_variant(self, uv) - var texture_name = name+"_tex" - rv.code = "vec4 %s_%d = texture(%s, %s);\n" % [ name, variant_index, texture_name, uv ] + rv.code = "vec4 %s_%d = texture(%s, %s);\n" % [ name, variant_index, texture_name, uv ] rv.rgba = "%s_%d" % [ name, variant_index ] rv.textures = { texture_name:texture } return rv \ No newline at end of file diff --git a/addons/material_maker/graph_edit.gd b/addons/material_maker/graph_edit.gd index d500632..880ab96 100644 --- a/addons/material_maker/graph_edit.gd +++ b/addons/material_maker/graph_edit.gd @@ -40,7 +40,6 @@ func add_node(node): node.connect("close_request", self, "remove_node", [ node ]) func connect_node(from, from_slot, to, to_slot): - print("Connecting "+str(from)+"("+str(from_slot)+") to "+str(to)+"("+str(to_slot)+")") if generator.connect_children(get_node(from).generator, from_slot, get_node(to).generator, to_slot): var disconnect = get_source(to, to_slot) if disconnect != null: diff --git a/addons/material_maker/main_window.tscn b/addons/material_maker/main_window.tscn index 1ee2d32..a964aaa 100644 --- a/addons/material_maker/main_window.tscn +++ b/addons/material_maker/main_window.tscn @@ -42,14 +42,14 @@ margin_left = 79.0 margin_right = 125.0 margin_bottom = 20.0 text = "Tools" -items = [ "Add selected node to user library", null, 0, false, false, 15, 0, null, "", false, "Save user library", null, 0, false, false, 16, 0, null, "", false ] +items = [ "Make selected nodes editable", null, 0, false, false, 15, 0, null, "", false, "Add selected node to user library", null, 0, false, false, 16, 0, null, "", false, "Save user library", null, 0, false, false, 17, 0, null, "", false ] [node name="Help" type="MenuButton" parent="VBoxContainer/Menu"] margin_left = 129.0 margin_right = 171.0 margin_bottom = 20.0 text = "Help" -items = [ "User manual", null, 0, false, false, 17, 0, null, "", false, "Report a bug", null, 0, false, false, 18, 0, null, "", false, "", null, 0, false, false, -1, 0, null, "", true, "About", null, 0, false, false, 20, 0, null, "", false ] +items = [ "User manual", null, 0, false, false, 18, 0, null, "", false, "Report a bug", null, 0, false, false, 19, 0, null, "", false, "", null, 0, false, false, -1, 0, null, "", true, "About", null, 0, false, false, 21, 0, null, "", false ] [node name="HBoxContainer" type="HSplitContainer" parent="VBoxContainer"] margin_top = 24.0 diff --git a/addons/material_maker/nodes/combine.mmg b/addons/material_maker/nodes/combine.mmg index f263c0c..4099686 100644 --- a/addons/material_maker/nodes/combine.mmg +++ b/addons/material_maker/nodes/combine.mmg @@ -1 +1 @@ -{"name":"uniform","node_position":{"x":-130,"y":-66},"parameters":{"color":{"a":1,"b":1,"g":1,"r":1,"type":"Color"},"name":0},"shader_model":{"global":"","inputs":[{"default":"0.0","label":"R","name":"r","type":"f"},{"default":"0.0","label":"G","name":"g","type":"f"},{"default":"0.0","label":"B","name":"b","type":"f"},{"default":"1.0","label":"A","name":"a","type":"f"}],"instance":"","name":"Combine","outputs":[{"rgba":"vec4($r($uv), $g($uv), $b($uv), $a($uv))"}],"parameters":[]}} \ No newline at end of file +{"name":"uniform","node_position":{"x":0,"y":0},"parameters":{"color":{"a":1,"b":1,"g":1,"r":1,"type":"Color"},"name":0},"shader_model":{"global":"","inputs":[{"default":"0.0","label":"R","name":"r","type":"f"},{"default":"0.0","label":"G","name":"g","type":"f"},{"default":"0.0","label":"B","name":"b","type":"f"},{"default":"1.0","label":"A","name":"a","type":"f"}],"instance":"","name":"Combine","outputs":[{"rgba":"vec4($r($uv), $g($uv), $b($uv), $a($uv))"}],"parameters":[]}} diff --git a/addons/material_maker/nodes/decompose.mmg b/addons/material_maker/nodes/decompose.mmg new file mode 100644 index 0000000..f7ca846 --- /dev/null +++ b/addons/material_maker/nodes/decompose.mmg @@ -0,0 +1 @@ +{"name":"decompose","node_position":{"x":0,"y":0},"parameters":{},"shader_model":{"global":"","inputs":[{"default":"vec4(1.0)","label":"","name":"i","type":"rgba"}],"instance":"","name":"Decompose","outputs":[{"f":"$i($uv).r"},{"f":"$i($uv).g"},{"f":"$i($uv).b"},{"f":"$i($uv).a"}],"parameters":[]}} diff --git a/addons/material_maker/nodes/generic.gd b/addons/material_maker/nodes/generic.gd index ad312ba..c02b9c1 100644 --- a/addons/material_maker/nodes/generic.gd +++ b/addons/material_maker/nodes/generic.gd @@ -13,7 +13,6 @@ func set_generator(g): update_node() func on_close_request(): - print("close") generator.get_parent().remove_generator(generator) func on_offset_changed(): @@ -205,7 +204,6 @@ func load_generator(): dialog.popup_centered() func do_load_generator(file_name : String): - print(file_name) var new_generator = null if file_name.ends_with(".mmn"): var file = File.new() @@ -217,10 +215,8 @@ func do_load_generator(file_name : String): new_generator = MMGenLoader.load_gen(file_name) if new_generator != null: var parent_generator = generator.get_parent() - print("before: "+generator.name) parent_generator.replace_generator(generator, new_generator) generator = new_generator - print("after: "+generator.name) update_node() func save_generator(): @@ -235,6 +231,7 @@ func save_generator(): func do_save_generator(file_name : String): var data = generator.serialize() + data.node_position = { x=0, y=0 } var file = File.new() if file.open(file_name, File.WRITE) == OK: file.store_string(to_json(data)) diff --git a/addons/material_maker/nodes/transform/transform.tscn b/addons/material_maker/nodes/transform/transform.tscn index 0d74e8e..5c0bd21 100644 --- a/addons/material_maker/nodes/transform/transform.tscn +++ b/addons/material_maker/nodes/transform/transform.tscn @@ -4,37 +4,21 @@ [sub_resource type="Theme" id=1] - -[node name="Transform" type="GraphNode" index="0"] - -anchor_left = 0.0 -anchor_top = 0.0 -anchor_right = 0.0 -anchor_bottom = 0.0 +[node name="Transform" type="GraphNode"] margin_left = 1.0 margin_top = 1.0 margin_right = 185.0 margin_bottom = 179.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 = "Transform" -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, 1, 0, 0.502784 ) +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, 1, 0, 0.501961 ) +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.760784, 0.760784, 0.760784, 1 ) @@ -72,422 +56,152 @@ slot/6/right_enabled = false slot/6/right_type = 0 slot/6/right_color = Color( 1, 1, 1, 1 ) script = ExtResource( 1 ) -_sections_unfolded = [ "Theme", "slot", "slot/0", "slot/1", "slot/2" ] -[node name="HBoxContainer0" type="HBoxContainer" parent="." index="0"] - -anchor_left = 0.0 -anchor_top = 0.0 -anchor_right = 0.0 -anchor_bottom = 0.0 +[node name="HBoxContainer0" type="HBoxContainer" parent="."] margin_left = 16.0 margin_top = 24.0 margin_right = 168.0 margin_bottom = 44.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 -alignment = 0 -[node name="Input" type="Label" parent="HBoxContainer0" index="0"] - -anchor_left = 0.0 -anchor_top = 0.0 -anchor_right = 0.0 -anchor_bottom = 0.0 +[node name="Input" type="Label" parent="HBoxContainer0"] margin_right = 74.0 margin_bottom = 20.0 rect_min_size = Vector2( 0, 20 ) -rect_pivot_offset = Vector2( 0, 0 ) -rect_clip_content = false -mouse_filter = 2 -mouse_default_cursor_shape = 0 size_flags_horizontal = 3 -size_flags_vertical = 4 text = "Input" valign = 1 -percent_visible = 1.0 -lines_skipped = 0 -max_lines_visible = -1 -[node name="Output" type="Label" parent="HBoxContainer0" index="1"] - -anchor_left = 0.0 -anchor_top = 0.0 -anchor_right = 0.0 -anchor_bottom = 0.0 +[node name="Output" type="Label" parent="HBoxContainer0"] margin_left = 78.0 margin_right = 152.0 margin_bottom = 20.0 rect_min_size = Vector2( 0, 20 ) -rect_pivot_offset = Vector2( 0, 0 ) -rect_clip_content = false -mouse_filter = 2 -mouse_default_cursor_shape = 0 size_flags_horizontal = 3 -size_flags_vertical = 4 text = "Output" align = 2 valign = 1 -percent_visible = 1.0 -lines_skipped = 0 -max_lines_visible = -1 -[node name="HBoxContainer1" type="HBoxContainer" parent="." index="1"] - -anchor_left = 0.0 -anchor_top = 0.0 -anchor_right = 0.0 -anchor_bottom = 0.0 +[node name="HBoxContainer1" type="HBoxContainer" parent="."] margin_left = 16.0 margin_top = 44.0 margin_right = 168.0 margin_bottom = 68.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 -alignment = 0 -[node name="Label" type="Label" parent="HBoxContainer1" index="0"] - -anchor_left = 0.0 -anchor_top = 0.0 -anchor_right = 0.0 -anchor_bottom = 0.0 +[node name="Label" type="Label" parent="HBoxContainer1"] margin_top = 5.0 margin_right = 74.0 margin_bottom = 19.0 -rect_pivot_offset = Vector2( 0, 0 ) -rect_clip_content = false -mouse_filter = 2 -mouse_default_cursor_shape = 0 size_flags_horizontal = 3 -size_flags_vertical = 4 text = "Translate X:" -percent_visible = 1.0 -lines_skipped = 0 -max_lines_visible = -1 -[node name="translate_x" type="SpinBox" parent="HBoxContainer1" index="1"] - -anchor_left = 0.0 -anchor_top = 0.0 -anchor_right = 0.0 -anchor_bottom = 0.0 +[node name="translate_x" type="SpinBox" parent="HBoxContainer1"] margin_left = 78.0 margin_right = 152.0 margin_bottom = 24.0 -rect_pivot_offset = Vector2( 0, 0 ) -rect_clip_content = false -mouse_filter = 0 -mouse_default_cursor_shape = 0 size_flags_horizontal = 0 size_flags_vertical = 4 min_value = -1.0 max_value = 1.0 step = 0.05 -page = 0.0 -value = 0.0 -exp_edit = false -rounded = false -editable = true -prefix = "" -suffix = "" -_sections_unfolded = [ "Caret", "Placeholder", "Rect" ] -[node name="HBoxContainer2" type="HBoxContainer" parent="." index="2"] - -anchor_left = 0.0 -anchor_top = 0.0 -anchor_right = 0.0 -anchor_bottom = 0.0 +[node name="HBoxContainer2" type="HBoxContainer" parent="."] margin_left = 16.0 margin_top = 69.0 margin_right = 168.0 margin_bottom = 93.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 -alignment = 0 -[node name="Label" type="Label" parent="HBoxContainer2" index="0"] - -anchor_left = 0.0 -anchor_top = 0.0 -anchor_right = 0.0 -anchor_bottom = 0.0 +[node name="Label" type="Label" parent="HBoxContainer2"] margin_top = 5.0 margin_right = 74.0 margin_bottom = 19.0 -rect_pivot_offset = Vector2( 0, 0 ) -rect_clip_content = false -mouse_filter = 2 -mouse_default_cursor_shape = 0 size_flags_horizontal = 3 -size_flags_vertical = 4 text = "Translate Y:" -percent_visible = 1.0 -lines_skipped = 0 -max_lines_visible = -1 -[node name="translate_y" type="SpinBox" parent="HBoxContainer2" index="1"] - -anchor_left = 0.0 -anchor_top = 0.0 -anchor_right = 0.0 -anchor_bottom = 0.0 +[node name="translate_y" type="SpinBox" parent="HBoxContainer2"] margin_left = 78.0 margin_right = 152.0 margin_bottom = 24.0 -rect_pivot_offset = Vector2( 0, 0 ) -rect_clip_content = false -mouse_filter = 0 -mouse_default_cursor_shape = 0 size_flags_horizontal = 0 size_flags_vertical = 4 min_value = -1.0 max_value = 1.0 step = 0.05 -page = 0.0 -value = 0.0 -exp_edit = false -rounded = false -editable = true -prefix = "" -suffix = "" -_sections_unfolded = [ "Caret", "Placeholder" ] -[node name="HBoxContainer3" type="HBoxContainer" parent="." index="3"] - -anchor_left = 0.0 -anchor_top = 0.0 -anchor_right = 0.0 -anchor_bottom = 0.0 +[node name="HBoxContainer3" type="HBoxContainer" parent="."] margin_left = 16.0 margin_top = 94.0 margin_right = 168.0 margin_bottom = 118.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 -alignment = 0 -[node name="Label" type="Label" parent="HBoxContainer3" index="0"] - -anchor_left = 0.0 -anchor_top = 0.0 -anchor_right = 0.0 -anchor_bottom = 0.0 +[node name="Label" type="Label" parent="HBoxContainer3"] margin_top = 5.0 margin_right = 74.0 margin_bottom = 19.0 -rect_pivot_offset = Vector2( 0, 0 ) -rect_clip_content = false -mouse_filter = 2 -mouse_default_cursor_shape = 0 size_flags_horizontal = 3 -size_flags_vertical = 4 text = "Rotate:" -percent_visible = 1.0 -lines_skipped = 0 -max_lines_visible = -1 -_sections_unfolded = [ "Size Flags" ] -[node name="rotate" type="SpinBox" parent="HBoxContainer3" index="1"] - -anchor_left = 0.0 -anchor_top = 0.0 -anchor_right = 0.0 -anchor_bottom = 0.0 +[node name="rotate" type="SpinBox" parent="HBoxContainer3"] margin_left = 78.0 margin_right = 152.0 margin_bottom = 24.0 -rect_pivot_offset = Vector2( 0, 0 ) -rect_clip_content = false -mouse_filter = 0 -mouse_default_cursor_shape = 0 size_flags_horizontal = 0 size_flags_vertical = 4 min_value = -720.0 max_value = 720.0 step = 5.0 -page = 0.0 -value = 0.0 -exp_edit = false -rounded = false -editable = true -prefix = "" -suffix = "" -_sections_unfolded = [ "Caret", "Placeholder", "Size Flags" ] -[node name="HBoxContainer4" type="HBoxContainer" parent="." index="4"] - -anchor_left = 0.0 -anchor_top = 0.0 -anchor_right = 0.0 -anchor_bottom = 0.0 +[node name="HBoxContainer4" type="HBoxContainer" parent="."] margin_left = 16.0 margin_top = 119.0 margin_right = 168.0 margin_bottom = 143.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 -alignment = 0 -[node name="Label" type="Label" parent="HBoxContainer4" index="0"] - -anchor_left = 0.0 -anchor_top = 0.0 -anchor_right = 0.0 -anchor_bottom = 0.0 +[node name="Label" type="Label" parent="HBoxContainer4"] margin_top = 5.0 margin_right = 74.0 margin_bottom = 19.0 -rect_pivot_offset = Vector2( 0, 0 ) -rect_clip_content = false -mouse_filter = 2 -mouse_default_cursor_shape = 0 size_flags_horizontal = 3 -size_flags_vertical = 4 text = "Scale X:" -percent_visible = 1.0 -lines_skipped = 0 -max_lines_visible = -1 -_sections_unfolded = [ "Size Flags" ] -[node name="scale_x" type="SpinBox" parent="HBoxContainer4" index="1"] - -anchor_left = 0.0 -anchor_top = 0.0 -anchor_right = 0.0 -anchor_bottom = 0.0 +[node name="scale_x" type="SpinBox" parent="HBoxContainer4"] margin_left = 78.0 margin_right = 152.0 margin_bottom = 24.0 -rect_pivot_offset = Vector2( 0, 0 ) -rect_clip_content = false -mouse_filter = 0 -mouse_default_cursor_shape = 0 size_flags_horizontal = 0 size_flags_vertical = 4 min_value = 0.05 max_value = 50.0 step = 0.05 -page = 0.0 value = 1.0 -exp_edit = false -rounded = false -editable = true -prefix = "" -suffix = "" -_sections_unfolded = [ "Caret", "Placeholder" ] -[node name="HBoxContainer5" type="HBoxContainer" parent="." index="5"] - -anchor_left = 0.0 -anchor_top = 0.0 -anchor_right = 0.0 -anchor_bottom = 0.0 +[node name="HBoxContainer5" type="HBoxContainer" parent="."] margin_left = 16.0 margin_top = 144.0 margin_right = 168.0 margin_bottom = 168.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 -alignment = 0 -[node name="Label" type="Label" parent="HBoxContainer5" index="0"] - -anchor_left = 0.0 -anchor_top = 0.0 -anchor_right = 0.0 -anchor_bottom = 0.0 +[node name="Label" type="Label" parent="HBoxContainer5"] margin_top = 5.0 margin_right = 74.0 margin_bottom = 19.0 -rect_pivot_offset = Vector2( 0, 0 ) -rect_clip_content = false -mouse_filter = 2 -mouse_default_cursor_shape = 0 size_flags_horizontal = 3 -size_flags_vertical = 4 text = "Scale Y:" -percent_visible = 1.0 -lines_skipped = 0 -max_lines_visible = -1 -_sections_unfolded = [ "Size Flags" ] -[node name="scale_y" type="SpinBox" parent="HBoxContainer5" index="1"] - -anchor_left = 0.0 -anchor_top = 0.0 -anchor_right = 0.0 -anchor_bottom = 0.0 +[node name="scale_y" type="SpinBox" parent="HBoxContainer5"] margin_left = 78.0 margin_right = 152.0 margin_bottom = 24.0 -rect_pivot_offset = Vector2( 0, 0 ) -rect_clip_content = false -mouse_filter = 0 -mouse_default_cursor_shape = 0 size_flags_horizontal = 0 size_flags_vertical = 4 min_value = 0.05 max_value = 50.0 step = 0.05 -page = 0.0 value = 1.0 -exp_edit = false -rounded = false -editable = true -prefix = "" -suffix = "" -_sections_unfolded = [ "Caret", "Placeholder" ] -[node name="repeat" type="CheckBox" parent="." index="6"] - -anchor_left = 0.0 -anchor_top = 0.0 -anchor_right = 0.0 -anchor_bottom = 0.0 +[node name="repeat" type="CheckBox" parent="."] margin_left = 16.0 margin_top = 169.0 margin_right = 168.0 margin_bottom = 193.0 -rect_pivot_offset = Vector2( 0, 0 ) -rect_clip_content = false -focus_mode = 2 -mouse_filter = 0 -mouse_default_cursor_shape = 0 -size_flags_horizontal = 1 -size_flags_vertical = 1 -toggle_mode = true pressed = true -enabled_focus_mode = 2 -shortcut = null -group = null text = "Repeat" -flat = false -align = 0 - - From bd8becaf758b5c387301f449c3fbde6003b527e5 Mon Sep 17 00:00:00 2001 From: RodZill4 Date: Tue, 10 Sep 2019 21:25:08 +0200 Subject: [PATCH 015/133] Removed old generator model file format --- addons/material_maker/engine/gen_buffer.gd | 1 - addons/material_maker/nodes/adjust_hsv.mmg | 1 + addons/material_maker/nodes/adjust_hsv.mmn | 1 - addons/material_maker/nodes/bricks.mmg | 1 + addons/material_maker/nodes/bricks.mmn | 122 --------------------- addons/material_maker/nodes/colorize.mmg | 1 + addons/material_maker/nodes/colorize.mmn | 1 - addons/material_maker/nodes/generic.gd | 1 + addons/material_maker/nodes/noise.mmg | 1 + addons/material_maker/nodes/noise.mmn | 1 - addons/material_maker/nodes/pattern.mmg | 1 + addons/material_maker/nodes/pattern.mmn | 1 - addons/material_maker/nodes/perlin.mmg | 1 + addons/material_maker/nodes/perlin.mmn | 1 - addons/material_maker/nodes/shape.mmg | 1 + addons/material_maker/nodes/shape.mmn | 1 - addons/material_maker/nodes/uniform.mmg | 1 + addons/material_maker/nodes/uniform.mmn | 1 - addons/material_maker/nodes/voronoi.mmg | 1 + addons/material_maker/nodes/voronoi.mmn | 1 - 20 files changed, 10 insertions(+), 131 deletions(-) create mode 100644 addons/material_maker/nodes/adjust_hsv.mmg delete mode 100644 addons/material_maker/nodes/adjust_hsv.mmn create mode 100644 addons/material_maker/nodes/bricks.mmg delete mode 100644 addons/material_maker/nodes/bricks.mmn create mode 100644 addons/material_maker/nodes/colorize.mmg delete mode 100644 addons/material_maker/nodes/colorize.mmn create mode 100644 addons/material_maker/nodes/noise.mmg delete mode 100644 addons/material_maker/nodes/noise.mmn create mode 100644 addons/material_maker/nodes/pattern.mmg delete mode 100644 addons/material_maker/nodes/pattern.mmn create mode 100644 addons/material_maker/nodes/perlin.mmg delete mode 100644 addons/material_maker/nodes/perlin.mmn create mode 100644 addons/material_maker/nodes/shape.mmg delete mode 100644 addons/material_maker/nodes/shape.mmn create mode 100644 addons/material_maker/nodes/uniform.mmg delete mode 100644 addons/material_maker/nodes/uniform.mmn create mode 100644 addons/material_maker/nodes/voronoi.mmg delete mode 100644 addons/material_maker/nodes/voronoi.mmn diff --git a/addons/material_maker/engine/gen_buffer.gd b/addons/material_maker/engine/gen_buffer.gd index 4861a78..79f498a 100644 --- a/addons/material_maker/engine/gen_buffer.gd +++ b/addons/material_maker/engine/gen_buffer.gd @@ -26,7 +26,6 @@ func get_input_defs(): func _get_shader_code(uv : String, output_index : int, context : MMGenContext): var source = get_source(0) if source != null: - print(parameters.size) var status = source.generator.render(source.output_index, context.renderer, pow(2, 4+parameters.size)) while status is GDScriptFunctionState: status = yield(status, "completed") diff --git a/addons/material_maker/nodes/adjust_hsv.mmg b/addons/material_maker/nodes/adjust_hsv.mmg new file mode 100644 index 0000000..c8bb5a2 --- /dev/null +++ b/addons/material_maker/nodes/adjust_hsv.mmg @@ -0,0 +1 @@ +{"name":"uniform","node_position":{"x":0,"y":0},"parameters":{"hue":0,"saturation":1,"value":1},"shader_model":{"global":"vec3 rgb_to_hsv(vec3 c) {\n\tvec4 K = vec4(0.0, -1.0 / 3.0, 2.0 / 3.0, -1.0);\n\tvec4 p = c.g < c.b ? vec4(c.bg, K.wz) : vec4(c.gb, K.xy);\n\tvec4 q = c.r < p.x ? vec4(p.xyw, c.r) : vec4(c.r, p.yzx);\n\n\tfloat d = q.x - min(q.w, q.y);\n\tfloat e = 1.0e-10;\n\treturn vec3(abs(q.z + (q.w - q.y) / (6.0 * d + e)), d / (q.x + e), q.x);\n}\n\nvec3 hsv_to_rgb(vec3 c) {\n\tvec4 K = vec4(1.0, 2.0 / 3.0, 1.0 / 3.0, 3.0);\n\tvec3 p = abs(fract(c.xxx + K.xyz) * 6.0 - K.www);\n\treturn c.z * mix(K.xxx, clamp(p - K.xxx, 0.0, 1.0), c.y);\n}\n","inputs":[{"default":"vec4($uv.x, $uv.y, 0.0, 1.0)","label":"","name":"in","type":"rgba"}],"instance":"vec4 $(name)_f(vec4 c) {\n\tvec3 hsv = rgb_to_hsv(c.rgb);\n\treturn vec4(hsv_to_rgb(vec3(fract(hsv.x+$(hue)), clamp(hsv.y*$(saturation), 0.0, 1.0), clamp(hsv.z*$(value), 0.0, 1.0))), c.a);\n}","name":"AdjustHSV","outputs":[{"rgba":"$(name)_f($in($(uv)))"}],"parameters":[{"default":0,"label":"Hue","max":0.5,"min":-0.5,"name":"hue","step":0,"type":"float"},{"default":1,"label":"Saturation","max":2,"min":0,"name":"saturation","step":0,"type":"float"},{"default":1,"label":"Value","max":2,"min":0,"name":"value","step":0,"type":"float"}]}} \ No newline at end of file diff --git a/addons/material_maker/nodes/adjust_hsv.mmn b/addons/material_maker/nodes/adjust_hsv.mmn deleted file mode 100644 index ecb72dd..0000000 --- a/addons/material_maker/nodes/adjust_hsv.mmn +++ /dev/null @@ -1 +0,0 @@ -{"global":"vec3 rgb_to_hsv(vec3 c) {\n\tvec4 K = vec4(0.0, -1.0 / 3.0, 2.0 / 3.0, -1.0);\n\tvec4 p = c.g < c.b ? vec4(c.bg, K.wz) : vec4(c.gb, K.xy);\n\tvec4 q = c.r < p.x ? vec4(p.xyw, c.r) : vec4(c.r, p.yzx);\n\n\tfloat d = q.x - min(q.w, q.y);\n\tfloat e = 1.0e-10;\n\treturn vec3(abs(q.z + (q.w - q.y) / (6.0 * d + e)), d / (q.x + e), q.x);\n}\n\nvec3 hsv_to_rgb(vec3 c) {\n\tvec4 K = vec4(1.0, 2.0 / 3.0, 1.0 / 3.0, 3.0);\n\tvec3 p = abs(fract(c.xxx + K.xyz) * 6.0 - K.www);\n\treturn c.z * mix(K.xxx, clamp(p - K.xxx, 0.0, 1.0), c.y);\n}\n","inputs":[{"default":"vec4($uv.x, $uv.y, 0.0, 1.0)","label":"","name":"in","type":"rgba"}],"instance":"vec4 $(name)_f(vec4 c) {\n\tvec3 hsv = rgb_to_hsv(c.rgb);\n\treturn vec4(hsv_to_rgb(vec3(fract(hsv.x+$(hue)), clamp(hsv.y*$(saturation), 0.0, 1.0), clamp(hsv.z*$(value), 0.0, 1.0))), c.a);\n}","name":"AdjustHSV","outputs":[{"rgba":"$(name)_f($in($(uv)))"}],"parameters":[{"default":0,"label":"Hue","max":0.5,"min":-0.5,"name":"hue","step":0,"type":"float"},{"default":1,"label":"Saturation","max":2,"min":0,"name":"saturation","step":0,"type":"float"},{"default":1,"label":"Value","max":2,"min":0,"name":"value","step":0,"type":"float"}]} \ No newline at end of file diff --git a/addons/material_maker/nodes/bricks.mmg b/addons/material_maker/nodes/bricks.mmg new file mode 100644 index 0000000..0af4fe3 --- /dev/null +++ b/addons/material_maker/nodes/bricks.mmg @@ -0,0 +1 @@ +{"name":"uniform","node_position":{"x":0,"y":0},"parameters":{"bevel":0.1,"columns":3,"mortar":0.1,"pattern":0,"repeat":1,"row_offset":0.5,"rows":6},"shader_model":{"global":"\n\t\tvec3 brick(vec2 uv, vec2 bmin, vec2 bmax, float mortar, float bevel) {\n\t\t\tfloat color = 0.5;\n\t\t\tvec2 c1 = (uv-bmin-vec2(mortar))/bevel;\n\t\t\tvec2 c2 = (bmax-uv-vec2(mortar))/bevel;\n\t\t\tvec2 c = min(c1, c2);\n\t\t\tcolor = clamp(min(c.x, c.y), 0.0, 1.0);\n\t\t\treturn vec3(color, mod(bmin, vec2(1.0, 1.0)));\n\t\t}\n\n\t\tvec3 bricks_rb(vec2 uv, vec2 count, float repeat, float offset, float mortar, float bevel) {\n\t\t\tcount *= repeat;\n\t\t\tmortar /= max(count.x, count.y);\n\t\t\tbevel /= max(count.x, count.y);\n\t\t\tfloat x_offset = offset*step(0.5, fract(uv.y*count.y*0.5));\n\t\t\tvec2 bmin = floor(vec2(uv.x*count.x-x_offset, uv.y*count.y));\n\t\t\tbmin.x += x_offset;\n\t\t\tbmin /= count;\n\t\t\treturn brick(uv, bmin, bmin+vec2(1.0)/count, mortar, bevel);\n\t\t}\n\n\t\tvec3 bricks_rb2(vec2 uv, vec2 count, float repeat, float offset, float mortar, float bevel) {\n\t\t\tcount *= repeat;\n\t\t\tmortar /= max(2.0*count.x, count.y);\n\t\t\tbevel /= max(2.0*count.x, count.y);\n\t\t\tfloat x_offset = offset*step(0.5, fract(uv.y*count.y*0.5));\n\t\t\tcount.x = count.x*(1.0+step(0.5, fract(uv.y*count.y*0.5)));\n\t\t\tvec2 bmin = floor(vec2(uv.x*count.x-x_offset, uv.y*count.y));\n\t\t\tbmin.x += x_offset;\n\t\t\tbmin /= count;\n\t\t\treturn brick(uv, bmin, bmin+vec2(1.0)/count, mortar, bevel);\n\t\t}\n\n\t\tvec3 bricks_hb(vec2 uv, vec2 count, float repeat, float offset, float mortar, float bevel) {\n\t\t\tfloat pc = count.x+count.y;\n\t\t\tfloat c = pc*repeat;\n\t\t\tmortar /= c;\n\t\t\tbevel /= c;\n\t\t\tvec2 corner = floor(uv*c);\n\t\t\tfloat cdiff = mod(corner.x-corner.y, pc);\n\t\t\tif (cdiff < count.x) {\n\t\t\t\treturn brick(uv, (corner-vec2(cdiff, 0.0))/c, (corner-vec2(cdiff, 0.0)+vec2(count.x, 1.0))/c, mortar, bevel);\n\t\t\t} else {\n\t\t\t\treturn brick(uv, (corner-vec2(0.0, pc-cdiff-1.0))/c, (corner-vec2(0.0, pc-cdiff-1.0)+vec2(1.0, count.y))/c, mortar, bevel);\n\t\t\t}\n\t\t}\n\n\t\tvec3 bricks_bw(vec2 uv, vec2 count, float repeat, float offset, float mortar, float bevel) {\n\t\t\tvec2 c = 2.0*count*repeat;\n\t\t\tfloat mc = max(c.x, c.y);\n\t\t\tmortar /= mc;\n\t\t\tbevel /= mc;\n\t\t\tvec2 corner1 = floor(uv*c);\n\t\t\tvec2 corner2 = count*floor(repeat*2.0*uv);\n\t\t\tfloat cdiff = mod(dot(floor(repeat*2.0*uv), vec2(1.0)), 2.0);\n\t\t\tvec2 corner;\n\t\t\tvec2 size;\n\t\t\tif (cdiff == 0.0) {\n\t\t\t\tcorner = vec2(corner1.x, corner2.y);\n\t\t\t\tsize = vec2(1.0, count.y);\n\t\t\t} else {\n\t\t\t\tcorner = vec2(corner2.x, corner1.y);\n\t\t\t\tsize = vec2(count.x, 1.0);\n\t\t\t}\n\t\t\treturn brick(uv, corner/c, (corner+size)/c, mortar, bevel);\n\t\t}\n\n\t\tvec3 bricks_sb(vec2 uv, vec2 count, float repeat, float offset, float mortar, float bevel) {\n\t\t\tvec2 c = (count+vec2(1.0))*repeat;\n\t\t\tfloat mc = max(c.x, c.y);\n\t\t\tmortar /= mc;\n\t\t\tbevel /= mc;\n\t\t\tvec2 corner1 = floor(uv*c);\n\t\t\tvec2 corner2 = (count+vec2(1.0))*floor(repeat*uv);\n\t\t\tvec2 rcorner = corner1 - corner2;\n\t\t\tvec2 corner;\n\t\t\tvec2 size;\n\t\t\tif (rcorner.x == 0.0 && rcorner.y < count.y) {\n\t\t\t\tcorner = corner2;\n\t\t\t\tsize = vec2(1.0, count.y);\n\t\t\t} else if (rcorner.y == 0.0) {\n\t\t\t\tcorner = corner2+vec2(1.0, 0.0);\n\t\t\t\tsize = vec2(count.x, 1.0);\n\t\t\t} else if (rcorner.x == count.x) {\n\t\t\t\tcorner = corner2+vec2(count.x, 1.0);\n\t\t\t\tsize = vec2(1.0, count.y);\n\t\t\t} else if (rcorner.y == count.y) {\n\t\t\t\tcorner = corner2+vec2(0.0, count.y);\n\t\t\t\tsize = vec2(count.x, 1.0);\n\t\t\t} else {\n\t\t\t\tcorner = corner2+vec2(1.0);\n\t\t\t\tsize = vec2(count.x-1.0, count.y-1.0);\n\t\t\t}\n\t\t\treturn brick(uv, corner/c, (corner+size)/c, mortar, bevel);\n\t\t}","include":["noise"],"instance":"\n\t\tvec3 $(name)_xyz(vec2 uv) {\n\t\t\treturn bricks_$(pattern)(uv, vec2($(columns), $(rows)), $(repeat), $(row_offset), $(mortar), max(0.001, $(bevel)));\n\t\t}","name":"Bricks","outputs":[{"f":"$(name)_xyz($(uv)).x"},{"rgb":"rand3($(name)_xyz($(uv)).yz+vec2($(seed)))"}],"parameters":[{"default":0,"label":"","name":"pattern","type":"enum","values":[{"name":"Running bond","value":"rb"},{"name":"Running bond (2)","value":"rb2"},{"name":"HerringBone","value":"hb"},{"name":"Basket weave","value":"bw"},{"name":"Spanish bond","value":"sb"}]},{"default":1,"label":"Repeat:","max":8,"min":1,"name":"repeat","step":1,"type":"float","widget":"spinbox"},{"default":6,"label":"Rows:","max":64,"min":1,"name":"rows","step":1,"type":"float","widget":"spinbox"},{"default":3,"label":"Columns:","max":64,"min":1,"name":"columns","step":1,"type":"float","widget":"spinbox"},{"default":0.5,"label":"Offset:","max":1,"min":0,"name":"row_offset","type":"float"},{"default":0.1,"label":"Mortar:","max":0.5,"min":0,"name":"mortar","type":"float"},{"default":0.1,"label":"Bevel:","max":0.5,"min":0,"name":"bevel","type":"float"}]}} \ No newline at end of file diff --git a/addons/material_maker/nodes/bricks.mmn b/addons/material_maker/nodes/bricks.mmn deleted file mode 100644 index 24bee6b..0000000 --- a/addons/material_maker/nodes/bricks.mmn +++ /dev/null @@ -1,122 +0,0 @@ -{ - "name":"Bricks", - "parameters":[ - { "name":"pattern", "label":"", "type":"enum", "default":0, "values":[ - { "name":"Running bond", "value":"rb" }, - { "name":"Running bond (2)", "value":"rb2" }, - { "name":"HerringBone", "value":"hb" }, - { "name":"Basket weave", "value":"bw" }, - { "name":"Spanish bond", "value":"sb" } - ] }, - { "name":"repeat", "label":"Repeat:", "type":"float", "min":1, "max":8, "step":1, "default":1, "widget":"spinbox" }, - { "name":"rows", "label":"Rows:", "type":"float", "min":1, "max":64, "step":1, "default":6, "widget":"spinbox" }, - { "name":"columns", "label":"Columns:", "type":"float", "min":1, "max":64, "step":1, "default":3, "widget":"spinbox" }, - { "name":"row_offset", "label":"Offset:", "type":"float", "min":0, "max":1, "default":0.5 }, - { "name":"mortar", "label":"Mortar:", "type":"float", "min":0, "max":0.5, "default":0.1 }, - { "name":"bevel", "label":"Bevel:", "type":"float", "min":0, "max":0.5, "default":0.1 } - ], - "include":[ "noise" ], - "global":" - vec3 brick(vec2 uv, vec2 bmin, vec2 bmax, float mortar, float bevel) { - float color = 0.5; - vec2 c1 = (uv-bmin-vec2(mortar))/bevel; - vec2 c2 = (bmax-uv-vec2(mortar))/bevel; - vec2 c = min(c1, c2); - color = clamp(min(c.x, c.y), 0.0, 1.0); - return vec3(color, mod(bmin, vec2(1.0, 1.0))); - } - - vec3 bricks_rb(vec2 uv, vec2 count, float repeat, float offset, float mortar, float bevel) { - count *= repeat; - mortar /= max(count.x, count.y); - bevel /= max(count.x, count.y); - float x_offset = offset*step(0.5, fract(uv.y*count.y*0.5)); - vec2 bmin = floor(vec2(uv.x*count.x-x_offset, uv.y*count.y)); - bmin.x += x_offset; - bmin /= count; - return brick(uv, bmin, bmin+vec2(1.0)/count, mortar, bevel); - } - - vec3 bricks_rb2(vec2 uv, vec2 count, float repeat, float offset, float mortar, float bevel) { - count *= repeat; - mortar /= max(2.0*count.x, count.y); - bevel /= max(2.0*count.x, count.y); - float x_offset = offset*step(0.5, fract(uv.y*count.y*0.5)); - count.x = count.x*(1.0+step(0.5, fract(uv.y*count.y*0.5))); - vec2 bmin = floor(vec2(uv.x*count.x-x_offset, uv.y*count.y)); - bmin.x += x_offset; - bmin /= count; - return brick(uv, bmin, bmin+vec2(1.0)/count, mortar, bevel); - } - - vec3 bricks_hb(vec2 uv, vec2 count, float repeat, float offset, float mortar, float bevel) { - float pc = count.x+count.y; - float c = pc*repeat; - mortar /= c; - bevel /= c; - vec2 corner = floor(uv*c); - float cdiff = mod(corner.x-corner.y, pc); - if (cdiff < count.x) { - return brick(uv, (corner-vec2(cdiff, 0.0))/c, (corner-vec2(cdiff, 0.0)+vec2(count.x, 1.0))/c, mortar, bevel); - } else { - return brick(uv, (corner-vec2(0.0, pc-cdiff-1.0))/c, (corner-vec2(0.0, pc-cdiff-1.0)+vec2(1.0, count.y))/c, mortar, bevel); - } - } - - vec3 bricks_bw(vec2 uv, vec2 count, float repeat, float offset, float mortar, float bevel) { - vec2 c = 2.0*count*repeat; - float mc = max(c.x, c.y); - mortar /= mc; - bevel /= mc; - vec2 corner1 = floor(uv*c); - vec2 corner2 = count*floor(repeat*2.0*uv); - float cdiff = mod(dot(floor(repeat*2.0*uv), vec2(1.0)), 2.0); - vec2 corner; - vec2 size; - if (cdiff == 0.0) { - corner = vec2(corner1.x, corner2.y); - size = vec2(1.0, count.y); - } else { - corner = vec2(corner2.x, corner1.y); - size = vec2(count.x, 1.0); - } - return brick(uv, corner/c, (corner+size)/c, mortar, bevel); - } - - vec3 bricks_sb(vec2 uv, vec2 count, float repeat, float offset, float mortar, float bevel) { - vec2 c = (count+vec2(1.0))*repeat; - float mc = max(c.x, c.y); - mortar /= mc; - bevel /= mc; - vec2 corner1 = floor(uv*c); - vec2 corner2 = (count+vec2(1.0))*floor(repeat*uv); - vec2 rcorner = corner1 - corner2; - vec2 corner; - vec2 size; - if (rcorner.x == 0.0 && rcorner.y < count.y) { - corner = corner2; - size = vec2(1.0, count.y); - } else if (rcorner.y == 0.0) { - corner = corner2+vec2(1.0, 0.0); - size = vec2(count.x, 1.0); - } else if (rcorner.x == count.x) { - corner = corner2+vec2(count.x, 1.0); - size = vec2(1.0, count.y); - } else if (rcorner.y == count.y) { - corner = corner2+vec2(0.0, count.y); - size = vec2(count.x, 1.0); - } else { - corner = corner2+vec2(1.0); - size = vec2(count.x-1.0, count.y-1.0); - } - return brick(uv, corner/c, (corner+size)/c, mortar, bevel); - }", - "instance":" - vec3 $(name)_xyz(vec2 uv) { - return bricks_$(pattern)(uv, vec2($(columns), $(rows)), $(repeat), $(row_offset), $(mortar), max(0.001, $(bevel))); - }", - "outputs":[ - { "f":"$(name)_xyz($(uv)).x" }, - { "rgb":"rand3($(name)_xyz($(uv)).yz+vec2($(seed)))" } - ] -} \ No newline at end of file diff --git a/addons/material_maker/nodes/colorize.mmg b/addons/material_maker/nodes/colorize.mmg new file mode 100644 index 0000000..0787e79 --- /dev/null +++ b/addons/material_maker/nodes/colorize.mmg @@ -0,0 +1 @@ +{"name":"uniform","node_position":{"x":0,"y":0},"parameters":{"gradient":{"points":[{"a":1,"b":0,"g":0,"pos":0,"r":0},{"a":1,"b":1,"g":1,"pos":1,"r":1}],"type":"Gradient"}},"shader_model":{"global":"","inputs":[{"default":"$uv.x","label":"Input","name":"input","type":"f"}],"instance":"","name":"Colorize","outputs":[{"rgba":"$gradient($input($uv))"}],"parameters":[{"default":{"points":[{"a":1,"b":0,"g":0,"pos":0,"r":0},{"a":1,"b":1,"g":1,"pos":1,"r":1}],"type":"Gradient"},"label":"","name":"gradient","type":"gradient"}]}} \ No newline at end of file diff --git a/addons/material_maker/nodes/colorize.mmn b/addons/material_maker/nodes/colorize.mmn deleted file mode 100644 index f1dcfc3..0000000 --- a/addons/material_maker/nodes/colorize.mmn +++ /dev/null @@ -1 +0,0 @@ -{"global":"","inputs":[{"default":"$uv.x","label":"Input","name":"input","type":"f"}],"instance":"","name":"Colorize","outputs":[{"rgba":"$gradient($input($uv))"}],"parameters":[{"default":{"points":[{"a":1,"b":0,"g":0,"pos":0,"r":0},{"a":1,"b":1,"g":1,"pos":1,"r":1}],"type":"Gradient"},"label":"","name":"gradient","type":"gradient"}]} \ No newline at end of file diff --git a/addons/material_maker/nodes/generic.gd b/addons/material_maker/nodes/generic.gd index c02b9c1..6d2a8d6 100644 --- a/addons/material_maker/nodes/generic.gd +++ b/addons/material_maker/nodes/generic.gd @@ -1,3 +1,4 @@ +tool extends GraphNode var generator = null setget set_generator diff --git a/addons/material_maker/nodes/noise.mmg b/addons/material_maker/nodes/noise.mmg new file mode 100644 index 0000000..645f2c6 --- /dev/null +++ b/addons/material_maker/nodes/noise.mmg @@ -0,0 +1 @@ +{"name":"uniform","node_position":{"x":0,"y":0},"parameters":{"density":0.5,"size":8},"shader_model":{"global":"float dots(vec2 uv, float size, float density, int seed) {\n\tvec2 seed2 = rand2(vec2(float(seed), 1.0-float(seed)));\n\tuv /= size;\n\tvec2 point_pos = floor(uv)+vec2(0.5);\n\tfloat color = step(rand(seed2+point_pos), density);\n return color;\n}","instance":"\n\t\tfloat $(name)_f(vec2 uv) {\n\t\t\treturn dots(uv, 1.0/$(size), $(density), $(seed));\n\t\t}","name":"Noise","outputs":[{"f":"$(name)_f($(uv))"}],"parameters":[{"default":8,"first":2,"label":"Grid Size:","last":8,"name":"size","type":"size"},{"default":0.5,"label":"Density:","max":1,"min":0,"name":"density","step":0,"type":"float"}]}} \ No newline at end of file diff --git a/addons/material_maker/nodes/noise.mmn b/addons/material_maker/nodes/noise.mmn deleted file mode 100644 index 85b1136..0000000 --- a/addons/material_maker/nodes/noise.mmn +++ /dev/null @@ -1 +0,0 @@ -{"global":"float dots(vec2 uv, float size, float density, int seed) {\n\tvec2 seed2 = rand2(vec2(float(seed), 1.0-float(seed)));\n\tuv /= size;\n\tvec2 point_pos = floor(uv)+vec2(0.5);\n\tfloat color = step(rand(seed2+point_pos), density);\n return color;\n}","instance":"\n\t\tfloat $(name)_f(vec2 uv) {\n\t\t\treturn dots(uv, 1.0/$(size), $(density), $(seed));\n\t\t}","name":"Noise","outputs":[{"f":"$(name)_f($(uv))"}],"parameters":[{"default":8,"first":2,"label":"Grid Size:","last":8,"name":"size","type":"size"},{"default":0.5,"label":"Density:","max":1,"min":0,"name":"density","step":0,"type":"float"}]} \ No newline at end of file diff --git a/addons/material_maker/nodes/pattern.mmg b/addons/material_maker/nodes/pattern.mmg new file mode 100644 index 0000000..f11e98b --- /dev/null +++ b/addons/material_maker/nodes/pattern.mmg @@ -0,0 +1 @@ +{"name":"uniform","node_position":{"x":0,"y":0},"parameters":{"mix":0,"x_scale":4,"x_wave":0,"y_scale":4,"y_wave":0},"shader_model":{"global":"float wave_constant(float x) {\n\treturn 1.0;\n}\n\nfloat wave_sine(float x) {\n\treturn 0.5-0.5*cos(3.14159265359*2.0*x);\n}\n\nfloat wave_triangle(float x) {\n\tx = fract(x);\n\treturn min(2.0*x, 2.0-2.0*x);\n}\n\nfloat wave_sawtooth(float x) {\n\treturn fract(x);\n}\n\nfloat wave_square(float x) {\n\treturn (fract(x) < 0.5) ? 0.0 : 1.0;\n}\n\nfloat mix_mul(float x, float y) {\n\treturn x*y;\n}\n\nfloat mix_add(float x, float y) {\n\treturn min(x+y, 1.0);\n}\n\nfloat mix_max(float x, float y) {\n\treturn max(x, y);\n}\n\nfloat mix_min(float x, float y) {\n\treturn min(x, y);\n}\n\nfloat mix_xor(float x, float y) {\n\treturn min(x+y, 2.0-x-y);\n}\n\nfloat mix_pow(float x, float y) {\n\treturn pow(x, y);\n}","instance":"float $(name)_fct(vec2 uv) {\n\treturn mix_$(mix)(wave_$(x_wave)($(x_scale)*uv.x), wave_$(y_wave)($(y_scale)*uv.y));\n}","name":"Pattern","outputs":[{"f":"$(name)_fct($(uv))"}],"parameters":[{"default":0,"label":"Combiner","name":"mix","type":"enum","values":[{"name":"Multiply","value":"mul"},{"name":"Add","value":"add"},{"name":"Max","value":"max"},{"name":"Min","value":"min"},{"name":"Xor","value":"xor"},{"name":"Pow","value":"pow"}]},{"default":0,"label":"X","name":"x_wave","type":"enum","values":[{"name":"Sine","value":"sine"},{"name":"Triangle","value":"triangle"},{"name":"Square","value":"square"},{"name":"Sawtooth","value":"sawtooth"},{"name":"Constant","value":"constant"}]},{"default":4,"label":"nonewline","max":32,"min":0,"name":"x_scale","step":1,"type":"float","widget":"spinbox"},{"default":0,"label":"Y","name":"y_wave","type":"enum","values":[{"name":"Sine","value":"sine"},{"name":"Triangle","value":"triangle"},{"name":"Square","value":"square"},{"name":"Sawtooth","value":"sawtooth"},{"name":"Constant","value":"constant"}]},{"default":4,"label":"nonewline","max":32,"min":0,"name":"y_scale","step":1,"type":"float","widget":"spinbox"}]}} \ No newline at end of file diff --git a/addons/material_maker/nodes/pattern.mmn b/addons/material_maker/nodes/pattern.mmn deleted file mode 100644 index 6f1bfb4..0000000 --- a/addons/material_maker/nodes/pattern.mmn +++ /dev/null @@ -1 +0,0 @@ -{"global":"float wave_constant(float x) {\n\treturn 1.0;\n}\n\nfloat wave_sine(float x) {\n\treturn 0.5-0.5*cos(3.14159265359*2.0*x);\n}\n\nfloat wave_triangle(float x) {\n\tx = fract(x);\n\treturn min(2.0*x, 2.0-2.0*x);\n}\n\nfloat wave_sawtooth(float x) {\n\treturn fract(x);\n}\n\nfloat wave_square(float x) {\n\treturn (fract(x) < 0.5) ? 0.0 : 1.0;\n}\n\nfloat mix_mul(float x, float y) {\n\treturn x*y;\n}\n\nfloat mix_add(float x, float y) {\n\treturn min(x+y, 1.0);\n}\n\nfloat mix_max(float x, float y) {\n\treturn max(x, y);\n}\n\nfloat mix_min(float x, float y) {\n\treturn min(x, y);\n}\n\nfloat mix_xor(float x, float y) {\n\treturn min(x+y, 2.0-x-y);\n}\n\nfloat mix_pow(float x, float y) {\n\treturn pow(x, y);\n}","instance":"float $(name)_fct(vec2 uv) {\n\treturn mix_$(mix)(wave_$(x_wave)($(x_scale)*uv.x), wave_$(y_wave)($(y_scale)*uv.y));\n}","name":"Pattern","outputs":[{"f":"$(name)_fct($(uv))"}],"parameters":[{"default":0,"label":"Combiner","name":"mix","type":"enum","values":[{"name":"Multiply","value":"mul"},{"name":"Add","value":"add"},{"name":"Max","value":"max"},{"name":"Min","value":"min"},{"name":"Xor","value":"xor"},{"name":"Pow","value":"pow"}]},{"default":0,"label":"X","name":"x_wave","type":"enum","values":[{"name":"Sine","value":"sine"},{"name":"Triangle","value":"triangle"},{"name":"Square","value":"square"},{"name":"Sawtooth","value":"sawtooth"},{"name":"Constant","value":"constant"}]},{"default":4,"label":"nonewline","max":32,"min":0,"name":"x_scale","step":1,"type":"float","widget":"spinbox"},{"default":0,"label":"Y","name":"y_wave","type":"enum","values":[{"name":"Sine","value":"sine"},{"name":"Triangle","value":"triangle"},{"name":"Square","value":"square"},{"name":"Sawtooth","value":"sawtooth"},{"name":"Constant","value":"constant"}]},{"default":4,"label":"nonewline","max":32,"min":0,"name":"y_scale","step":1,"type":"float","widget":"spinbox"}]} \ No newline at end of file diff --git a/addons/material_maker/nodes/perlin.mmg b/addons/material_maker/nodes/perlin.mmg new file mode 100644 index 0000000..1fce24b --- /dev/null +++ b/addons/material_maker/nodes/perlin.mmg @@ -0,0 +1 @@ +{"name":"uniform","node_position":{"x":0,"y":0},"parameters":{"iterations":3,"persistence":0.5,"scale_x":4,"scale_y":4},"shader_model":{"global":"float perlin(vec2 uv, vec2 size, int iterations, float persistence, int seed) {\n\tvec2 seed2 = rand2(vec2(float(seed), 1.0-float(seed)));\n float rv = 0.0;\n float coef = 1.0;\n float acc = 0.0;\n for (int i = 0; i < iterations; ++i) {\n \tvec2 step = vec2(1.0)/size;\n\t\tvec2 xy = floor(uv*size);\n float f0 = rand(seed2+mod(xy, size));\n float f1 = rand(seed2+mod(xy+vec2(1.0, 0.0), size));\n float f2 = rand(seed2+mod(xy+vec2(0.0, 1.0), size));\n float f3 = rand(seed2+mod(xy+vec2(1.0, 1.0), size));\n vec2 mixval = smoothstep(0.0, 1.0, fract(uv*size));\n rv += coef * mix(mix(f0, f1, mixval.x), mix(f2, f3, mixval.x), mixval.y);\n acc += coef;\n size *= 2.0;\n coef *= persistence;\n }\n \n return rv / acc;\n}\n","instance":"","name":"Perlin","outputs":[{"f":"perlin($(uv), vec2($(scale_x), $(scale_y)), int($(iterations)), $(persistence), $(seed))"}],"parameters":[{"default":4,"label":"Scale X","max":32,"min":1,"name":"scale_x","step":1,"type":"float","widget":"spinbox"},{"default":4,"label":"Scale Y","max":32,"min":1,"name":"scale_y","step":1,"type":"float","widget":"spinbox"},{"default":3,"label":"Iterations","max":10,"min":1,"name":"iterations","step":1,"type":"float","widget":"spinbox"},{"default":0.5,"label":"Persistance","max":1,"min":0,"name":"persistence","step":0.05,"type":"float","widget":"spinbox"}]}} \ No newline at end of file diff --git a/addons/material_maker/nodes/perlin.mmn b/addons/material_maker/nodes/perlin.mmn deleted file mode 100644 index c26eaee..0000000 --- a/addons/material_maker/nodes/perlin.mmn +++ /dev/null @@ -1 +0,0 @@ -{"global":"float perlin(vec2 uv, vec2 size, int iterations, float persistence, int seed) {\n\tvec2 seed2 = rand2(vec2(float(seed), 1.0-float(seed)));\n float rv = 0.0;\n float coef = 1.0;\n float acc = 0.0;\n for (int i = 0; i < iterations; ++i) {\n \tvec2 step = vec2(1.0)/size;\n\t\tvec2 xy = floor(uv*size);\n float f0 = rand(seed2+mod(xy, size));\n float f1 = rand(seed2+mod(xy+vec2(1.0, 0.0), size));\n float f2 = rand(seed2+mod(xy+vec2(0.0, 1.0), size));\n float f3 = rand(seed2+mod(xy+vec2(1.0, 1.0), size));\n vec2 mixval = smoothstep(0.0, 1.0, fract(uv*size));\n rv += coef * mix(mix(f0, f1, mixval.x), mix(f2, f3, mixval.x), mixval.y);\n acc += coef;\n size *= 2.0;\n coef *= persistence;\n }\n \n return rv / acc;\n}\n","instance":"","name":"Perlin","outputs":[{"f":"perlin($(uv), vec2($(scale_x), $(scale_y)), int($(iterations)), $(persistence), $(seed))"}],"parameters":[{"default":4,"label":"Scale X","max":32,"min":1,"name":"scale_x","step":1,"type":"float","widget":"spinbox"},{"default":4,"label":"Scale Y","max":32,"min":1,"name":"scale_y","step":1,"type":"float","widget":"spinbox"},{"default":3,"label":"Iterations","max":10,"min":1,"name":"iterations","step":1,"type":"float","widget":"spinbox"},{"default":0.5,"label":"Persistance","max":1,"min":0,"name":"persistence","step":0.05,"type":"float","widget":"spinbox"}]} \ No newline at end of file diff --git a/addons/material_maker/nodes/shape.mmg b/addons/material_maker/nodes/shape.mmg new file mode 100644 index 0000000..178386c --- /dev/null +++ b/addons/material_maker/nodes/shape.mmg @@ -0,0 +1 @@ +{"name":"uniform","node_position":{"x":0,"y":0},"parameters":{"edge":0.2,"radius":1,"shape":0,"sides":3},"shader_model":{"global":"float shape_circle(vec2 uv, float sides, float size, float edge) {\n uv = 2.0*uv-1.0;\n\tedge = max(edge, 1.0e-8);\n float distance = length(uv);\n return clamp((1.0-distance/size)/edge, 0.0, 1.0);\n}\n\nfloat shape_polygon(vec2 uv, float sides, float size, float edge) {\n uv = 2.0*uv-1.0;\n\tedge = max(edge, 1.0e-8);\n float angle = atan(uv.x, uv.y)+3.14159265359;\n float slice = 6.28318530718/sides;\n return clamp((size-cos(floor(0.5+angle/slice)*slice-angle)*length(uv))/(edge*size), 0.0, 1.0);\n}\n\nfloat shape_star(vec2 uv, float sides, float size, float edge) {\n uv = 2.0*uv-1.0;\n\tedge = max(edge, 1.0e-8);\n float angle = atan(uv.x, uv.y);\n float slice = 6.28318530718/sides;\n return clamp((size-cos(floor(1.5+angle/slice-2.0*step(0.5*slice, mod(angle, slice)))*slice-angle)*length(uv))/(edge*size), 0.0, 1.0);\n}\n\nfloat shape_curved_star(vec2 uv, float sides, float size, float edge) {\n uv = 2.0*uv-1.0;\n\tedge = max(edge, 1.0e-8);\n float angle = 2.0*(atan(uv.x, uv.y)+3.14159265359);\n float slice = 6.28318530718/sides;\n return clamp((size-cos(floor(0.5+0.5*angle/slice)*2.0*slice-angle)*length(uv))/(edge*size), 0.0, 1.0);\n}\n\nfloat shape_rays(vec2 uv, float sides, float size, float edge) {\n uv = 2.0*uv-1.0;\n\tedge = 0.5*max(edge, 1.0e-8)*size;\n\tfloat slice = 6.28318530718/sides;\n float angle = mod(atan(uv.x, uv.y)+3.14159265359, slice)/slice;\n return clamp(min((size-angle)/edge, angle/edge), 0.0, 1.0);\n}\n\n","instance":"","name":"Shape","outputs":[{"f":"shape_$(shape)($(uv), $(sides), $(radius), $(edge))"}],"parameters":[{"default":0,"label":"","name":"shape","type":"enum","values":[{"name":"Circle","value":"circle"},{"name":"Polygon","value":"polygon"},{"name":"Star","value":"star"},{"name":"Curved star","value":"curved_star"},{"name":"Rays","value":"rays"}]},{"default":3,"label":"","max":32,"min":2,"name":"sides","step":1,"type":"float"},{"default":1,"label":"","max":1,"min":0,"name":"radius","step":0,"type":"float"},{"default":0.2,"label":"","max":1,"min":0,"name":"edge","step":0,"type":"float"}]}} \ No newline at end of file diff --git a/addons/material_maker/nodes/shape.mmn b/addons/material_maker/nodes/shape.mmn deleted file mode 100644 index c6fb9bc..0000000 --- a/addons/material_maker/nodes/shape.mmn +++ /dev/null @@ -1 +0,0 @@ -{"global":"float shape_circle(vec2 uv, float sides, float size, float edge) {\n uv = 2.0*uv-1.0;\n\tedge = max(edge, 1.0e-8);\n float distance = length(uv);\n return clamp((1.0-distance/size)/edge, 0.0, 1.0);\n}\n\nfloat shape_polygon(vec2 uv, float sides, float size, float edge) {\n uv = 2.0*uv-1.0;\n\tedge = max(edge, 1.0e-8);\n float angle = atan(uv.x, uv.y)+3.14159265359;\n float slice = 6.28318530718/sides;\n return clamp((size-cos(floor(0.5+angle/slice)*slice-angle)*length(uv))/(edge*size), 0.0, 1.0);\n}\n\nfloat shape_star(vec2 uv, float sides, float size, float edge) {\n uv = 2.0*uv-1.0;\n\tedge = max(edge, 1.0e-8);\n float angle = atan(uv.x, uv.y);\n float slice = 6.28318530718/sides;\n return clamp((size-cos(floor(1.5+angle/slice-2.0*step(0.5*slice, mod(angle, slice)))*slice-angle)*length(uv))/(edge*size), 0.0, 1.0);\n}\n\nfloat shape_curved_star(vec2 uv, float sides, float size, float edge) {\n uv = 2.0*uv-1.0;\n\tedge = max(edge, 1.0e-8);\n float angle = 2.0*(atan(uv.x, uv.y)+3.14159265359);\n float slice = 6.28318530718/sides;\n return clamp((size-cos(floor(0.5+0.5*angle/slice)*2.0*slice-angle)*length(uv))/(edge*size), 0.0, 1.0);\n}\n\nfloat shape_rays(vec2 uv, float sides, float size, float edge) {\n uv = 2.0*uv-1.0;\n\tedge = 0.5*max(edge, 1.0e-8)*size;\n\tfloat slice = 6.28318530718/sides;\n float angle = mod(atan(uv.x, uv.y)+3.14159265359, slice)/slice;\n return clamp(min((size-angle)/edge, angle/edge), 0.0, 1.0);\n}\n\n","instance":"","name":"Shape","outputs":[{"f":"shape_$(shape)($(uv), $(sides), $(radius), $(edge))"}],"parameters":[{"default":0,"label":"","name":"shape","type":"enum","values":[{"name":"Circle","value":"circle"},{"name":"Polygon","value":"polygon"},{"name":"Star","value":"star"},{"name":"Curved star","value":"curved_star"},{"name":"Rays","value":"rays"}]},{"default":3,"label":"","max":32,"min":2,"name":"sides","step":1,"type":"float"},{"default":1,"label":"","max":1,"min":0,"name":"radius","step":0,"type":"float"},{"default":0.2,"label":"","max":1,"min":0,"name":"edge","step":0,"type":"float"}]} \ No newline at end of file diff --git a/addons/material_maker/nodes/uniform.mmg b/addons/material_maker/nodes/uniform.mmg new file mode 100644 index 0000000..23ccdca --- /dev/null +++ b/addons/material_maker/nodes/uniform.mmg @@ -0,0 +1 @@ +{"name":"uniform","node_position":{"x":0,"y":0},"parameters":{"color":{"a":1,"b":1,"g":1,"r":1,"type":"Color"}},"shader_model":{"global":"","instance":"","name":"Uniform","outputs":[{"rgba":"$(color)"}],"parameters":[{"default":{"a":1,"b":1,"g":1,"r":1},"label":"","name":"color","type":"color"}]}} \ No newline at end of file diff --git a/addons/material_maker/nodes/uniform.mmn b/addons/material_maker/nodes/uniform.mmn deleted file mode 100644 index 2a652e3..0000000 --- a/addons/material_maker/nodes/uniform.mmn +++ /dev/null @@ -1 +0,0 @@ -{"global":"","instance":"","name":"Uniform","outputs":[{"rgba":"$(color)"}],"parameters":[{"default":{"a":1,"b":1,"g":1,"r":1},"label":"","name":"color","type":"color"}]} \ No newline at end of file diff --git a/addons/material_maker/nodes/voronoi.mmg b/addons/material_maker/nodes/voronoi.mmg new file mode 100644 index 0000000..4fbabbf --- /dev/null +++ b/addons/material_maker/nodes/voronoi.mmg @@ -0,0 +1 @@ +{"name":"uniform","node_position":{"x":0,"y":0},"parameters":{"intensity":0.5,"scale_x":4,"scale_y":4},"shader_model":{"global":"vec4 voronoi(vec2 uv, vec2 size, float intensity, int seed) {\n\tvec2 seed2 = rand2(vec2(float(seed), 1.0-float(seed)));\n uv *= size;\n float best_distance0 = 1.0;\n float best_distance1 = 1.0;\n vec2 point0;\n vec2 point1;\n vec2 p0 = floor(uv);\n for (int dx = -1; dx < 2; ++dx) {\n \tfor (int dy = -1; dy < 2; ++dy) {\n vec2 d = vec2(float(dx), float(dy));\n vec2 p = p0+d;\n p += rand2(seed2+mod(p, size));\n float distance = length((uv - p) / size);\n if (best_distance0 > distance) {\n \tbest_distance1 = best_distance0;\n \tbest_distance0 = distance;\n point1 = point0;\n point0 = p;\n } else if (best_distance1 > distance) {\n \tbest_distance1 = distance;\n point1 = p;\n }\n }\n }\n float edge_distance = dot(uv - 0.5*(point0+point1), normalize(point0-point1));\n \n return vec4(point0, best_distance0*length(size)*intensity, edge_distance);\n}\n","instance":"","name":"Voronoi","outputs":[{"f":"voronoi($(uv), vec2($(scale_x), $(scale_y)), $(intensity), $(seed)).z"},{"f":"voronoi($(uv), vec2($(scale_x), $(scale_y)), $(intensity), $(seed)).w"},{"rgb":"rand3(fract(voronoi($(uv), vec2($(scale_x), $(scale_y)), $(intensity), $(seed)).xy))"}],"parameters":[{"default":4,"label":"Scale X","max":32,"min":1,"name":"scale_x","step":1,"type":"float","widget":"spinbox"},{"default":4,"label":"Scale Y","max":32,"min":1,"name":"scale_y","step":1,"type":"float","widget":"spinbox"},{"default":0.5,"label":"Intensity","max":1,"min":0,"name":"intensity","step":0.05,"type":"float","widget":"spinbox"}]}} \ No newline at end of file diff --git a/addons/material_maker/nodes/voronoi.mmn b/addons/material_maker/nodes/voronoi.mmn deleted file mode 100644 index 06e1ca4..0000000 --- a/addons/material_maker/nodes/voronoi.mmn +++ /dev/null @@ -1 +0,0 @@ -{"global":"vec4 voronoi(vec2 uv, vec2 size, float intensity, int seed) {\n\tvec2 seed2 = rand2(vec2(float(seed), 1.0-float(seed)));\n uv *= size;\n float best_distance0 = 1.0;\n float best_distance1 = 1.0;\n vec2 point0;\n vec2 point1;\n vec2 p0 = floor(uv);\n for (int dx = -1; dx < 2; ++dx) {\n \tfor (int dy = -1; dy < 2; ++dy) {\n vec2 d = vec2(float(dx), float(dy));\n vec2 p = p0+d;\n p += rand2(seed2+mod(p, size));\n float distance = length((uv - p) / size);\n if (best_distance0 > distance) {\n \tbest_distance1 = best_distance0;\n \tbest_distance0 = distance;\n point1 = point0;\n point0 = p;\n } else if (best_distance1 > distance) {\n \tbest_distance1 = distance;\n point1 = p;\n }\n }\n }\n float edge_distance = dot(uv - 0.5*(point0+point1), normalize(point0-point1));\n \n return vec4(point0, best_distance0*length(size)*intensity, edge_distance);\n}\n","instance":"","name":"Voronoi","outputs":[{"f":"voronoi($(uv), vec2($(scale_x), $(scale_y)), $(intensity), $(seed)).z"},{"f":"voronoi($(uv), vec2($(scale_x), $(scale_y)), $(intensity), $(seed)).w"},{"rgb":"rand3(fract(voronoi($(uv), vec2($(scale_x), $(scale_y)), $(intensity), $(seed)).xy))"}],"parameters":[{"default":4,"label":"Scale X","max":32,"min":1,"name":"scale_x","step":1,"type":"float","widget":"spinbox"},{"default":4,"label":"Scale Y","max":32,"min":1,"name":"scale_y","step":1,"type":"float","widget":"spinbox"},{"default":0.5,"label":"Intensity","max":1,"min":0,"name":"intensity","step":0.05,"type":"float","widget":"spinbox"}]} \ No newline at end of file From be2e7f6e5980a2ca1e6dff864c76be73429f5cd5 Mon Sep 17 00:00:00 2001 From: RodZill4 Date: Tue, 10 Sep 2019 22:51:49 +0200 Subject: [PATCH 016/133] Updated generic node layout (added input names) and all .mmg files --- addons/material_maker/engine/gen_switch.gd | 22 ++++++ addons/material_maker/engine/renderer.tscn | 1 + addons/material_maker/nodes/adjust_hsv.mmg | 2 +- addons/material_maker/nodes/bricks.mmg | 2 +- addons/material_maker/nodes/colorize.mmg | 2 +- addons/material_maker/nodes/combine.mmg | 2 +- addons/material_maker/nodes/decompose.mmg | 2 +- addons/material_maker/nodes/generic.gd | 80 ++++++++++++++-------- addons/material_maker/nodes/noise.mmg | 2 +- addons/material_maker/nodes/pattern.mmg | 2 +- addons/material_maker/nodes/perlin.mmg | 2 +- addons/material_maker/nodes/shape.mmg | 2 +- addons/material_maker/nodes/voronoi.mmg | 2 +- 13 files changed, 83 insertions(+), 40 deletions(-) create mode 100644 addons/material_maker/engine/gen_switch.gd diff --git a/addons/material_maker/engine/gen_switch.gd b/addons/material_maker/engine/gen_switch.gd new file mode 100644 index 0000000..d67bddb --- /dev/null +++ b/addons/material_maker/engine/gen_switch.gd @@ -0,0 +1,22 @@ +tool +extends MMGenBase +class_name MMGenSwitch + +""" +Texture generator switch +""" + +func get_type(): + return "switch" + +func get_type_name(): + return "Switch" + +func get_parameter_defs(): + return [ { name="outputs", label="Outputs", type="float", min=1, max=5, step=1, default=2 }, + { name="choices", label="Choices", type="float", min=2, max=5, step=1, default=2 }, + { name="source", label="Source", type="float", min=1, max=2, step=1 } ] + +func set_parameter(n : String, v): + .set_parameter(n, v) + # Force redraw if outputs or choices is modified \ No newline at end of file diff --git a/addons/material_maker/engine/renderer.tscn b/addons/material_maker/engine/renderer.tscn index ab81c35..bbbdd44 100644 --- a/addons/material_maker/engine/renderer.tscn +++ b/addons/material_maker/engine/renderer.tscn @@ -17,6 +17,7 @@ shader = SubResource( 1 ) own_world = true transparent_bg = true hdr = false +keep_3d_linear = true usage = 0 render_target_v_flip = true render_target_update_mode = 1 diff --git a/addons/material_maker/nodes/adjust_hsv.mmg b/addons/material_maker/nodes/adjust_hsv.mmg index c8bb5a2..dda785d 100644 --- a/addons/material_maker/nodes/adjust_hsv.mmg +++ b/addons/material_maker/nodes/adjust_hsv.mmg @@ -1 +1 @@ -{"name":"uniform","node_position":{"x":0,"y":0},"parameters":{"hue":0,"saturation":1,"value":1},"shader_model":{"global":"vec3 rgb_to_hsv(vec3 c) {\n\tvec4 K = vec4(0.0, -1.0 / 3.0, 2.0 / 3.0, -1.0);\n\tvec4 p = c.g < c.b ? vec4(c.bg, K.wz) : vec4(c.gb, K.xy);\n\tvec4 q = c.r < p.x ? vec4(p.xyw, c.r) : vec4(c.r, p.yzx);\n\n\tfloat d = q.x - min(q.w, q.y);\n\tfloat e = 1.0e-10;\n\treturn vec3(abs(q.z + (q.w - q.y) / (6.0 * d + e)), d / (q.x + e), q.x);\n}\n\nvec3 hsv_to_rgb(vec3 c) {\n\tvec4 K = vec4(1.0, 2.0 / 3.0, 1.0 / 3.0, 3.0);\n\tvec3 p = abs(fract(c.xxx + K.xyz) * 6.0 - K.www);\n\treturn c.z * mix(K.xxx, clamp(p - K.xxx, 0.0, 1.0), c.y);\n}\n","inputs":[{"default":"vec4($uv.x, $uv.y, 0.0, 1.0)","label":"","name":"in","type":"rgba"}],"instance":"vec4 $(name)_f(vec4 c) {\n\tvec3 hsv = rgb_to_hsv(c.rgb);\n\treturn vec4(hsv_to_rgb(vec3(fract(hsv.x+$(hue)), clamp(hsv.y*$(saturation), 0.0, 1.0), clamp(hsv.z*$(value), 0.0, 1.0))), c.a);\n}","name":"AdjustHSV","outputs":[{"rgba":"$(name)_f($in($(uv)))"}],"parameters":[{"default":0,"label":"Hue","max":0.5,"min":-0.5,"name":"hue","step":0,"type":"float"},{"default":1,"label":"Saturation","max":2,"min":0,"name":"saturation","step":0,"type":"float"},{"default":1,"label":"Value","max":2,"min":0,"name":"value","step":0,"type":"float"}]}} \ No newline at end of file +{"name":"adjust_hsv","node_position":{"x":0,"y":0},"parameters":{"hue":0,"saturation":1,"value":1},"shader_model":{"global":"vec3 rgb_to_hsv(vec3 c) {\n\tvec4 K = vec4(0.0, -1.0 / 3.0, 2.0 / 3.0, -1.0);\n\tvec4 p = c.g < c.b ? vec4(c.bg, K.wz) : vec4(c.gb, K.xy);\n\tvec4 q = c.r < p.x ? vec4(p.xyw, c.r) : vec4(c.r, p.yzx);\n\n\tfloat d = q.x - min(q.w, q.y);\n\tfloat e = 1.0e-10;\n\treturn vec3(abs(q.z + (q.w - q.y) / (6.0 * d + e)), d / (q.x + e), q.x);\n}\n\nvec3 hsv_to_rgb(vec3 c) {\n\tvec4 K = vec4(1.0, 2.0 / 3.0, 1.0 / 3.0, 3.0);\n\tvec3 p = abs(fract(c.xxx + K.xyz) * 6.0 - K.www);\n\treturn c.z * mix(K.xxx, clamp(p - K.xxx, 0.0, 1.0), c.y);\n}\n","inputs":[{"default":"vec4($uv.x, $uv.y, 0.0, 1.0)","label":"","name":"in","type":"rgba"}],"instance":"vec4 $(name)_f(vec4 c) {\n\tvec3 hsv = rgb_to_hsv(c.rgb);\n\treturn vec4(hsv_to_rgb(vec3(fract(hsv.x+$(hue)), clamp(hsv.y*$(saturation), 0.0, 1.0), clamp(hsv.z*$(value), 0.0, 1.0))), c.a);\n}","name":"AdjustHSV","outputs":[{"rgba":"$(name)_f($in($(uv)))"}],"parameters":[{"default":0,"label":"Hue","max":0.5,"min":-0.5,"name":"hue","step":0,"type":"float"},{"default":1,"label":"Saturation","max":2,"min":0,"name":"saturation","step":0,"type":"float"},{"default":1,"label":"Value","max":2,"min":0,"name":"value","step":0,"type":"float"}]}} \ No newline at end of file diff --git a/addons/material_maker/nodes/bricks.mmg b/addons/material_maker/nodes/bricks.mmg index 0af4fe3..c007f04 100644 --- a/addons/material_maker/nodes/bricks.mmg +++ b/addons/material_maker/nodes/bricks.mmg @@ -1 +1 @@ -{"name":"uniform","node_position":{"x":0,"y":0},"parameters":{"bevel":0.1,"columns":3,"mortar":0.1,"pattern":0,"repeat":1,"row_offset":0.5,"rows":6},"shader_model":{"global":"\n\t\tvec3 brick(vec2 uv, vec2 bmin, vec2 bmax, float mortar, float bevel) {\n\t\t\tfloat color = 0.5;\n\t\t\tvec2 c1 = (uv-bmin-vec2(mortar))/bevel;\n\t\t\tvec2 c2 = (bmax-uv-vec2(mortar))/bevel;\n\t\t\tvec2 c = min(c1, c2);\n\t\t\tcolor = clamp(min(c.x, c.y), 0.0, 1.0);\n\t\t\treturn vec3(color, mod(bmin, vec2(1.0, 1.0)));\n\t\t}\n\n\t\tvec3 bricks_rb(vec2 uv, vec2 count, float repeat, float offset, float mortar, float bevel) {\n\t\t\tcount *= repeat;\n\t\t\tmortar /= max(count.x, count.y);\n\t\t\tbevel /= max(count.x, count.y);\n\t\t\tfloat x_offset = offset*step(0.5, fract(uv.y*count.y*0.5));\n\t\t\tvec2 bmin = floor(vec2(uv.x*count.x-x_offset, uv.y*count.y));\n\t\t\tbmin.x += x_offset;\n\t\t\tbmin /= count;\n\t\t\treturn brick(uv, bmin, bmin+vec2(1.0)/count, mortar, bevel);\n\t\t}\n\n\t\tvec3 bricks_rb2(vec2 uv, vec2 count, float repeat, float offset, float mortar, float bevel) {\n\t\t\tcount *= repeat;\n\t\t\tmortar /= max(2.0*count.x, count.y);\n\t\t\tbevel /= max(2.0*count.x, count.y);\n\t\t\tfloat x_offset = offset*step(0.5, fract(uv.y*count.y*0.5));\n\t\t\tcount.x = count.x*(1.0+step(0.5, fract(uv.y*count.y*0.5)));\n\t\t\tvec2 bmin = floor(vec2(uv.x*count.x-x_offset, uv.y*count.y));\n\t\t\tbmin.x += x_offset;\n\t\t\tbmin /= count;\n\t\t\treturn brick(uv, bmin, bmin+vec2(1.0)/count, mortar, bevel);\n\t\t}\n\n\t\tvec3 bricks_hb(vec2 uv, vec2 count, float repeat, float offset, float mortar, float bevel) {\n\t\t\tfloat pc = count.x+count.y;\n\t\t\tfloat c = pc*repeat;\n\t\t\tmortar /= c;\n\t\t\tbevel /= c;\n\t\t\tvec2 corner = floor(uv*c);\n\t\t\tfloat cdiff = mod(corner.x-corner.y, pc);\n\t\t\tif (cdiff < count.x) {\n\t\t\t\treturn brick(uv, (corner-vec2(cdiff, 0.0))/c, (corner-vec2(cdiff, 0.0)+vec2(count.x, 1.0))/c, mortar, bevel);\n\t\t\t} else {\n\t\t\t\treturn brick(uv, (corner-vec2(0.0, pc-cdiff-1.0))/c, (corner-vec2(0.0, pc-cdiff-1.0)+vec2(1.0, count.y))/c, mortar, bevel);\n\t\t\t}\n\t\t}\n\n\t\tvec3 bricks_bw(vec2 uv, vec2 count, float repeat, float offset, float mortar, float bevel) {\n\t\t\tvec2 c = 2.0*count*repeat;\n\t\t\tfloat mc = max(c.x, c.y);\n\t\t\tmortar /= mc;\n\t\t\tbevel /= mc;\n\t\t\tvec2 corner1 = floor(uv*c);\n\t\t\tvec2 corner2 = count*floor(repeat*2.0*uv);\n\t\t\tfloat cdiff = mod(dot(floor(repeat*2.0*uv), vec2(1.0)), 2.0);\n\t\t\tvec2 corner;\n\t\t\tvec2 size;\n\t\t\tif (cdiff == 0.0) {\n\t\t\t\tcorner = vec2(corner1.x, corner2.y);\n\t\t\t\tsize = vec2(1.0, count.y);\n\t\t\t} else {\n\t\t\t\tcorner = vec2(corner2.x, corner1.y);\n\t\t\t\tsize = vec2(count.x, 1.0);\n\t\t\t}\n\t\t\treturn brick(uv, corner/c, (corner+size)/c, mortar, bevel);\n\t\t}\n\n\t\tvec3 bricks_sb(vec2 uv, vec2 count, float repeat, float offset, float mortar, float bevel) {\n\t\t\tvec2 c = (count+vec2(1.0))*repeat;\n\t\t\tfloat mc = max(c.x, c.y);\n\t\t\tmortar /= mc;\n\t\t\tbevel /= mc;\n\t\t\tvec2 corner1 = floor(uv*c);\n\t\t\tvec2 corner2 = (count+vec2(1.0))*floor(repeat*uv);\n\t\t\tvec2 rcorner = corner1 - corner2;\n\t\t\tvec2 corner;\n\t\t\tvec2 size;\n\t\t\tif (rcorner.x == 0.0 && rcorner.y < count.y) {\n\t\t\t\tcorner = corner2;\n\t\t\t\tsize = vec2(1.0, count.y);\n\t\t\t} else if (rcorner.y == 0.0) {\n\t\t\t\tcorner = corner2+vec2(1.0, 0.0);\n\t\t\t\tsize = vec2(count.x, 1.0);\n\t\t\t} else if (rcorner.x == count.x) {\n\t\t\t\tcorner = corner2+vec2(count.x, 1.0);\n\t\t\t\tsize = vec2(1.0, count.y);\n\t\t\t} else if (rcorner.y == count.y) {\n\t\t\t\tcorner = corner2+vec2(0.0, count.y);\n\t\t\t\tsize = vec2(count.x, 1.0);\n\t\t\t} else {\n\t\t\t\tcorner = corner2+vec2(1.0);\n\t\t\t\tsize = vec2(count.x-1.0, count.y-1.0);\n\t\t\t}\n\t\t\treturn brick(uv, corner/c, (corner+size)/c, mortar, bevel);\n\t\t}","include":["noise"],"instance":"\n\t\tvec3 $(name)_xyz(vec2 uv) {\n\t\t\treturn bricks_$(pattern)(uv, vec2($(columns), $(rows)), $(repeat), $(row_offset), $(mortar), max(0.001, $(bevel)));\n\t\t}","name":"Bricks","outputs":[{"f":"$(name)_xyz($(uv)).x"},{"rgb":"rand3($(name)_xyz($(uv)).yz+vec2($(seed)))"}],"parameters":[{"default":0,"label":"","name":"pattern","type":"enum","values":[{"name":"Running bond","value":"rb"},{"name":"Running bond (2)","value":"rb2"},{"name":"HerringBone","value":"hb"},{"name":"Basket weave","value":"bw"},{"name":"Spanish bond","value":"sb"}]},{"default":1,"label":"Repeat:","max":8,"min":1,"name":"repeat","step":1,"type":"float","widget":"spinbox"},{"default":6,"label":"Rows:","max":64,"min":1,"name":"rows","step":1,"type":"float","widget":"spinbox"},{"default":3,"label":"Columns:","max":64,"min":1,"name":"columns","step":1,"type":"float","widget":"spinbox"},{"default":0.5,"label":"Offset:","max":1,"min":0,"name":"row_offset","type":"float"},{"default":0.1,"label":"Mortar:","max":0.5,"min":0,"name":"mortar","type":"float"},{"default":0.1,"label":"Bevel:","max":0.5,"min":0,"name":"bevel","type":"float"}]}} \ No newline at end of file +{"name":"bricks","node_position":{"x":0,"y":0},"parameters":{"bevel":0.1,"columns":3,"mortar":0.1,"pattern":0,"repeat":1,"row_offset":0.5,"rows":6},"shader_model":{"global":"\n\t\tvec3 brick(vec2 uv, vec2 bmin, vec2 bmax, float mortar, float bevel) {\n\t\t\tfloat color = 0.5;\n\t\t\tvec2 c1 = (uv-bmin-vec2(mortar))/bevel;\n\t\t\tvec2 c2 = (bmax-uv-vec2(mortar))/bevel;\n\t\t\tvec2 c = min(c1, c2);\n\t\t\tcolor = clamp(min(c.x, c.y), 0.0, 1.0);\n\t\t\treturn vec3(color, mod(bmin, vec2(1.0, 1.0)));\n\t\t}\n\n\t\tvec3 bricks_rb(vec2 uv, vec2 count, float repeat, float offset, float mortar, float bevel) {\n\t\t\tcount *= repeat;\n\t\t\tmortar /= max(count.x, count.y);\n\t\t\tbevel /= max(count.x, count.y);\n\t\t\tfloat x_offset = offset*step(0.5, fract(uv.y*count.y*0.5));\n\t\t\tvec2 bmin = floor(vec2(uv.x*count.x-x_offset, uv.y*count.y));\n\t\t\tbmin.x += x_offset;\n\t\t\tbmin /= count;\n\t\t\treturn brick(uv, bmin, bmin+vec2(1.0)/count, mortar, bevel);\n\t\t}\n\n\t\tvec3 bricks_rb2(vec2 uv, vec2 count, float repeat, float offset, float mortar, float bevel) {\n\t\t\tcount *= repeat;\n\t\t\tmortar /= max(2.0*count.x, count.y);\n\t\t\tbevel /= max(2.0*count.x, count.y);\n\t\t\tfloat x_offset = offset*step(0.5, fract(uv.y*count.y*0.5));\n\t\t\tcount.x = count.x*(1.0+step(0.5, fract(uv.y*count.y*0.5)));\n\t\t\tvec2 bmin = floor(vec2(uv.x*count.x-x_offset, uv.y*count.y));\n\t\t\tbmin.x += x_offset;\n\t\t\tbmin /= count;\n\t\t\treturn brick(uv, bmin, bmin+vec2(1.0)/count, mortar, bevel);\n\t\t}\n\n\t\tvec3 bricks_hb(vec2 uv, vec2 count, float repeat, float offset, float mortar, float bevel) {\n\t\t\tfloat pc = count.x+count.y;\n\t\t\tfloat c = pc*repeat;\n\t\t\tmortar /= c;\n\t\t\tbevel /= c;\n\t\t\tvec2 corner = floor(uv*c);\n\t\t\tfloat cdiff = mod(corner.x-corner.y, pc);\n\t\t\tif (cdiff < count.x) {\n\t\t\t\treturn brick(uv, (corner-vec2(cdiff, 0.0))/c, (corner-vec2(cdiff, 0.0)+vec2(count.x, 1.0))/c, mortar, bevel);\n\t\t\t} else {\n\t\t\t\treturn brick(uv, (corner-vec2(0.0, pc-cdiff-1.0))/c, (corner-vec2(0.0, pc-cdiff-1.0)+vec2(1.0, count.y))/c, mortar, bevel);\n\t\t\t}\n\t\t}\n\n\t\tvec3 bricks_bw(vec2 uv, vec2 count, float repeat, float offset, float mortar, float bevel) {\n\t\t\tvec2 c = 2.0*count*repeat;\n\t\t\tfloat mc = max(c.x, c.y);\n\t\t\tmortar /= mc;\n\t\t\tbevel /= mc;\n\t\t\tvec2 corner1 = floor(uv*c);\n\t\t\tvec2 corner2 = count*floor(repeat*2.0*uv);\n\t\t\tfloat cdiff = mod(dot(floor(repeat*2.0*uv), vec2(1.0)), 2.0);\n\t\t\tvec2 corner;\n\t\t\tvec2 size;\n\t\t\tif (cdiff == 0.0) {\n\t\t\t\tcorner = vec2(corner1.x, corner2.y);\n\t\t\t\tsize = vec2(1.0, count.y);\n\t\t\t} else {\n\t\t\t\tcorner = vec2(corner2.x, corner1.y);\n\t\t\t\tsize = vec2(count.x, 1.0);\n\t\t\t}\n\t\t\treturn brick(uv, corner/c, (corner+size)/c, mortar, bevel);\n\t\t}\n\n\t\tvec3 bricks_sb(vec2 uv, vec2 count, float repeat, float offset, float mortar, float bevel) {\n\t\t\tvec2 c = (count+vec2(1.0))*repeat;\n\t\t\tfloat mc = max(c.x, c.y);\n\t\t\tmortar /= mc;\n\t\t\tbevel /= mc;\n\t\t\tvec2 corner1 = floor(uv*c);\n\t\t\tvec2 corner2 = (count+vec2(1.0))*floor(repeat*uv);\n\t\t\tvec2 rcorner = corner1 - corner2;\n\t\t\tvec2 corner;\n\t\t\tvec2 size;\n\t\t\tif (rcorner.x == 0.0 && rcorner.y < count.y) {\n\t\t\t\tcorner = corner2;\n\t\t\t\tsize = vec2(1.0, count.y);\n\t\t\t} else if (rcorner.y == 0.0) {\n\t\t\t\tcorner = corner2+vec2(1.0, 0.0);\n\t\t\t\tsize = vec2(count.x, 1.0);\n\t\t\t} else if (rcorner.x == count.x) {\n\t\t\t\tcorner = corner2+vec2(count.x, 1.0);\n\t\t\t\tsize = vec2(1.0, count.y);\n\t\t\t} else if (rcorner.y == count.y) {\n\t\t\t\tcorner = corner2+vec2(0.0, count.y);\n\t\t\t\tsize = vec2(count.x, 1.0);\n\t\t\t} else {\n\t\t\t\tcorner = corner2+vec2(1.0);\n\t\t\t\tsize = vec2(count.x-1.0, count.y-1.0);\n\t\t\t}\n\t\t\treturn brick(uv, corner/c, (corner+size)/c, mortar, bevel);\n\t\t}","include":["noise"],"instance":"\n\t\tvec3 $(name)_xyz(vec2 uv) {\n\t\t\treturn bricks_$(pattern)(uv, vec2($(columns), $(rows)), $(repeat), $(row_offset), $(mortar), max(0.001, $(bevel)));\n\t\t}","name":"Bricks","outputs":[{"f":"$(name)_xyz($(uv)).x"},{"rgb":"rand3($(name)_xyz($(uv)).yz+vec2($(seed)))"}],"parameters":[{"default":0,"label":"","name":"pattern","type":"enum","values":[{"name":"Running bond","value":"rb"},{"name":"Running bond (2)","value":"rb2"},{"name":"HerringBone","value":"hb"},{"name":"Basket weave","value":"bw"},{"name":"Spanish bond","value":"sb"}]},{"default":1,"label":"Repeat:","max":8,"min":1,"name":"repeat","step":1,"type":"float","widget":"spinbox"},{"default":6,"label":"Rows:","max":64,"min":1,"name":"rows","step":1,"type":"float","widget":"spinbox"},{"default":3,"label":"Columns:","max":64,"min":1,"name":"columns","step":1,"type":"float","widget":"spinbox"},{"default":0.5,"label":"Offset:","max":1,"min":0,"name":"row_offset","type":"float"},{"default":0.1,"label":"Mortar:","max":0.5,"min":0,"name":"mortar","type":"float"},{"default":0.1,"label":"Bevel:","max":0.5,"min":0,"name":"bevel","type":"float"}]}} \ No newline at end of file diff --git a/addons/material_maker/nodes/colorize.mmg b/addons/material_maker/nodes/colorize.mmg index 0787e79..1255dbe 100644 --- a/addons/material_maker/nodes/colorize.mmg +++ b/addons/material_maker/nodes/colorize.mmg @@ -1 +1 @@ -{"name":"uniform","node_position":{"x":0,"y":0},"parameters":{"gradient":{"points":[{"a":1,"b":0,"g":0,"pos":0,"r":0},{"a":1,"b":1,"g":1,"pos":1,"r":1}],"type":"Gradient"}},"shader_model":{"global":"","inputs":[{"default":"$uv.x","label":"Input","name":"input","type":"f"}],"instance":"","name":"Colorize","outputs":[{"rgba":"$gradient($input($uv))"}],"parameters":[{"default":{"points":[{"a":1,"b":0,"g":0,"pos":0,"r":0},{"a":1,"b":1,"g":1,"pos":1,"r":1}],"type":"Gradient"},"label":"","name":"gradient","type":"gradient"}]}} \ No newline at end of file +{"name":"colorize","node_position":{"x":0,"y":0},"parameters":{"gradient":{"points":[{"a":1,"b":0,"g":0,"pos":0,"r":0},{"a":1,"b":1,"g":1,"pos":1,"r":1}],"type":"Gradient"}},"shader_model":{"global":"","inputs":[{"default":"$uv.x","label":"","name":"input","type":"f"}],"instance":"","name":"Colorize","outputs":[{"rgba":"$gradient($input($uv))"}],"parameters":[{"default":{"points":[{"a":1,"b":0,"g":0,"pos":0,"r":0},{"a":1,"b":1,"g":1,"pos":1,"r":1}],"type":"Gradient"},"label":"","name":"gradient","type":"gradient"}]}} \ No newline at end of file diff --git a/addons/material_maker/nodes/combine.mmg b/addons/material_maker/nodes/combine.mmg index 4099686..2250750 100644 --- a/addons/material_maker/nodes/combine.mmg +++ b/addons/material_maker/nodes/combine.mmg @@ -1 +1 @@ -{"name":"uniform","node_position":{"x":0,"y":0},"parameters":{"color":{"a":1,"b":1,"g":1,"r":1,"type":"Color"},"name":0},"shader_model":{"global":"","inputs":[{"default":"0.0","label":"R","name":"r","type":"f"},{"default":"0.0","label":"G","name":"g","type":"f"},{"default":"0.0","label":"B","name":"b","type":"f"},{"default":"1.0","label":"A","name":"a","type":"f"}],"instance":"","name":"Combine","outputs":[{"rgba":"vec4($r($uv), $g($uv), $b($uv), $a($uv))"}],"parameters":[]}} +{"name":"combine","node_position":{"x":0,"y":0},"parameters":{"color":{"a":1,"b":1,"g":1,"r":1,"type":"Color"},"name":0},"shader_model":{"global":"","inputs":[{"default":"0.0","label":"R","name":"r","type":"f"},{"default":"0.0","label":"G","name":"g","type":"f"},{"default":"0.0","label":"B","name":"b","type":"f"},{"default":"1.0","label":"A","name":"a","type":"f"}],"instance":"","name":"Combine","outputs":[{"rgba":"vec4($r($uv), $g($uv), $b($uv), $a($uv))"}],"parameters":[]}} \ No newline at end of file diff --git a/addons/material_maker/nodes/decompose.mmg b/addons/material_maker/nodes/decompose.mmg index f7ca846..67c0cc6 100644 --- a/addons/material_maker/nodes/decompose.mmg +++ b/addons/material_maker/nodes/decompose.mmg @@ -1 +1 @@ -{"name":"decompose","node_position":{"x":0,"y":0},"parameters":{},"shader_model":{"global":"","inputs":[{"default":"vec4(1.0)","label":"","name":"i","type":"rgba"}],"instance":"","name":"Decompose","outputs":[{"f":"$i($uv).r"},{"f":"$i($uv).g"},{"f":"$i($uv).b"},{"f":"$i($uv).a"}],"parameters":[]}} +{"name":"decompose","node_position":{"x":0,"y":0},"parameters":{},"shader_model":{"global":"","inputs":[{"default":"vec4(1.0)","label":"","name":"i","type":"rgba"}],"instance":"","name":"Decompose","outputs":[{"f":"$i($uv).r"},{"f":"$i($uv).g"},{"f":"$i($uv).b"},{"f":"$i($uv).a"}],"parameters":[]}} \ No newline at end of file diff --git a/addons/material_maker/nodes/generic.gd b/addons/material_maker/nodes/generic.gd index 6d2a8d6..1c39db4 100644 --- a/addons/material_maker/nodes/generic.gd +++ b/addons/material_maker/nodes/generic.gd @@ -83,9 +83,40 @@ func update_node(): rect_size = Vector2(0, 0) # Rebuild node title = generator.get_type_name() + # Inputs + var inputs = generator.get_input_defs() + for i in range(inputs.size()): + var input = inputs[i] + var enable_left = false + var color_left = Color(0.5, 0.5, 0.5) + if typeof(input) == TYPE_DICTIONARY: + if input.type == "rgb": + enable_left = true + color_left = Color(0.5, 0.5, 1.0) + elif input.type == "rgba": + enable_left = true + color_left = Color(0.0, 0.5, 0.0, 0.5) + else: + enable_left = true + set_slot(i, enable_left, 0, color_left, false, 0, Color()) + var hsizer : HBoxContainer = HBoxContainer.new() + hsizer.size_flags_horizontal = SIZE_EXPAND | SIZE_FILL + var label : Label = Label.new() + label.text = input.label if input.has("label") else "" + hsizer.add_child(label) + add_child(hsizer) + var input_names_width : int = 0 + for c in get_children(): + var width = c.get_child(0).rect_size.x + if width > input_names_width: + input_names_width = width + if input_names_width > 0: + input_names_width += 3 + for c in get_children(): + c.get_child(0).rect_min_size.x = input_names_width # Parameters controls = [] - var sizer = null + var index = -1 for p in generator.get_parameter_defs(): if !p.has("name") or !p.has("type"): continue @@ -125,38 +156,26 @@ func update_node(): controls.append(control) if p.has("label"): label = p.label - if sizer == null or label != "nonewline": - sizer = HBoxContainer.new() - sizer.size_flags_horizontal = SIZE_EXPAND | SIZE_FILL - add_child(sizer) - if label != "" && label != "nonewline": + if index == -1 or label != "nonewline": + index += 1 + var hsizer : HBoxContainer + if index >= get_child_count(): + hsizer = HBoxContainer.new() + hsizer.size_flags_horizontal = SIZE_EXPAND | SIZE_FILL + var empty_control : Control = Control.new() + empty_control.rect_min_size.x = input_names_width + hsizer.add_child(empty_control) + add_child(hsizer) + else: + hsizer = get_child(index) + if label != "" and label != "nonewline": var label_widget = Label.new() label_widget.text = label label_widget.size_flags_horizontal = SIZE_EXPAND | SIZE_FILL - sizer.add_child(label_widget) + hsizer.add_child(label_widget) control.size_flags_horizontal = SIZE_EXPAND | SIZE_FILL - sizer.add_child(control) + hsizer.add_child(control) initialize_properties() - # Inputs - var inputs = generator.get_input_defs() - for i in range(inputs.size()): - var input = inputs[i] - var enable_left = false - var color_left = Color(0.5, 0.5, 0.5) - if typeof(input) == TYPE_DICTIONARY: - if input.type == "rgb": - enable_left = true - color_left = Color(0.5, 0.5, 1.0) - elif input.type == "rgba": - enable_left = true - color_left = Color(0.0, 0.5, 0.0, 0.5) - else: - enable_left = true - set_slot(i, enable_left, 0, color_left, false, 0, Color()) - if i >= get_child_count(): - var control = Control.new() - control.rect_min_size = Vector2(0, 16) - add_child(control) # Outputs var outputs = generator.get_output_defs() for i in range(outputs.size()): @@ -231,9 +250,10 @@ func save_generator(): dialog.popup_centered() func do_save_generator(file_name : String): - var data = generator.serialize() - data.node_position = { x=0, y=0 } var file = File.new() if file.open(file_name, File.WRITE) == OK: + var data = generator.serialize() + data.name = file_name.get_file().get_basename() + data.node_position = { x=0, y=0 } file.store_string(to_json(data)) file.close() diff --git a/addons/material_maker/nodes/noise.mmg b/addons/material_maker/nodes/noise.mmg index 645f2c6..403f6f4 100644 --- a/addons/material_maker/nodes/noise.mmg +++ b/addons/material_maker/nodes/noise.mmg @@ -1 +1 @@ -{"name":"uniform","node_position":{"x":0,"y":0},"parameters":{"density":0.5,"size":8},"shader_model":{"global":"float dots(vec2 uv, float size, float density, int seed) {\n\tvec2 seed2 = rand2(vec2(float(seed), 1.0-float(seed)));\n\tuv /= size;\n\tvec2 point_pos = floor(uv)+vec2(0.5);\n\tfloat color = step(rand(seed2+point_pos), density);\n return color;\n}","instance":"\n\t\tfloat $(name)_f(vec2 uv) {\n\t\t\treturn dots(uv, 1.0/$(size), $(density), $(seed));\n\t\t}","name":"Noise","outputs":[{"f":"$(name)_f($(uv))"}],"parameters":[{"default":8,"first":2,"label":"Grid Size:","last":8,"name":"size","type":"size"},{"default":0.5,"label":"Density:","max":1,"min":0,"name":"density","step":0,"type":"float"}]}} \ No newline at end of file +{"name":"noise","node_position":{"x":0,"y":0},"parameters":{"density":0.5,"size":8},"shader_model":{"global":"float dots(vec2 uv, float size, float density, int seed) {\n\tvec2 seed2 = rand2(vec2(float(seed), 1.0-float(seed)));\n\tuv /= size;\n\tvec2 point_pos = floor(uv)+vec2(0.5);\n\tfloat color = step(rand(seed2+point_pos), density);\n return color;\n}","instance":"\n\t\tfloat $(name)_f(vec2 uv) {\n\t\t\treturn dots(uv, 1.0/$(size), $(density), $(seed));\n\t\t}","name":"Noise","outputs":[{"f":"$(name)_f($(uv))"}],"parameters":[{"default":8,"first":2,"label":"Grid Size:","last":8,"name":"size","type":"size"},{"default":0.5,"label":"Density:","max":1,"min":0,"name":"density","step":0,"type":"float"}]}} \ No newline at end of file diff --git a/addons/material_maker/nodes/pattern.mmg b/addons/material_maker/nodes/pattern.mmg index f11e98b..4a5cf7d 100644 --- a/addons/material_maker/nodes/pattern.mmg +++ b/addons/material_maker/nodes/pattern.mmg @@ -1 +1 @@ -{"name":"uniform","node_position":{"x":0,"y":0},"parameters":{"mix":0,"x_scale":4,"x_wave":0,"y_scale":4,"y_wave":0},"shader_model":{"global":"float wave_constant(float x) {\n\treturn 1.0;\n}\n\nfloat wave_sine(float x) {\n\treturn 0.5-0.5*cos(3.14159265359*2.0*x);\n}\n\nfloat wave_triangle(float x) {\n\tx = fract(x);\n\treturn min(2.0*x, 2.0-2.0*x);\n}\n\nfloat wave_sawtooth(float x) {\n\treturn fract(x);\n}\n\nfloat wave_square(float x) {\n\treturn (fract(x) < 0.5) ? 0.0 : 1.0;\n}\n\nfloat mix_mul(float x, float y) {\n\treturn x*y;\n}\n\nfloat mix_add(float x, float y) {\n\treturn min(x+y, 1.0);\n}\n\nfloat mix_max(float x, float y) {\n\treturn max(x, y);\n}\n\nfloat mix_min(float x, float y) {\n\treturn min(x, y);\n}\n\nfloat mix_xor(float x, float y) {\n\treturn min(x+y, 2.0-x-y);\n}\n\nfloat mix_pow(float x, float y) {\n\treturn pow(x, y);\n}","instance":"float $(name)_fct(vec2 uv) {\n\treturn mix_$(mix)(wave_$(x_wave)($(x_scale)*uv.x), wave_$(y_wave)($(y_scale)*uv.y));\n}","name":"Pattern","outputs":[{"f":"$(name)_fct($(uv))"}],"parameters":[{"default":0,"label":"Combiner","name":"mix","type":"enum","values":[{"name":"Multiply","value":"mul"},{"name":"Add","value":"add"},{"name":"Max","value":"max"},{"name":"Min","value":"min"},{"name":"Xor","value":"xor"},{"name":"Pow","value":"pow"}]},{"default":0,"label":"X","name":"x_wave","type":"enum","values":[{"name":"Sine","value":"sine"},{"name":"Triangle","value":"triangle"},{"name":"Square","value":"square"},{"name":"Sawtooth","value":"sawtooth"},{"name":"Constant","value":"constant"}]},{"default":4,"label":"nonewline","max":32,"min":0,"name":"x_scale","step":1,"type":"float","widget":"spinbox"},{"default":0,"label":"Y","name":"y_wave","type":"enum","values":[{"name":"Sine","value":"sine"},{"name":"Triangle","value":"triangle"},{"name":"Square","value":"square"},{"name":"Sawtooth","value":"sawtooth"},{"name":"Constant","value":"constant"}]},{"default":4,"label":"nonewline","max":32,"min":0,"name":"y_scale","step":1,"type":"float","widget":"spinbox"}]}} \ No newline at end of file +{"name":"pattern","node_position":{"x":0,"y":0},"parameters":{"mix":0,"x_scale":4,"x_wave":0,"y_scale":4,"y_wave":0},"shader_model":{"global":"float wave_constant(float x) {\n\treturn 1.0;\n}\n\nfloat wave_sine(float x) {\n\treturn 0.5-0.5*cos(3.14159265359*2.0*x);\n}\n\nfloat wave_triangle(float x) {\n\tx = fract(x);\n\treturn min(2.0*x, 2.0-2.0*x);\n}\n\nfloat wave_sawtooth(float x) {\n\treturn fract(x);\n}\n\nfloat wave_square(float x) {\n\treturn (fract(x) < 0.5) ? 0.0 : 1.0;\n}\n\nfloat mix_mul(float x, float y) {\n\treturn x*y;\n}\n\nfloat mix_add(float x, float y) {\n\treturn min(x+y, 1.0);\n}\n\nfloat mix_max(float x, float y) {\n\treturn max(x, y);\n}\n\nfloat mix_min(float x, float y) {\n\treturn min(x, y);\n}\n\nfloat mix_xor(float x, float y) {\n\treturn min(x+y, 2.0-x-y);\n}\n\nfloat mix_pow(float x, float y) {\n\treturn pow(x, y);\n}","instance":"float $(name)_fct(vec2 uv) {\n\treturn mix_$(mix)(wave_$(x_wave)($(x_scale)*uv.x), wave_$(y_wave)($(y_scale)*uv.y));\n}","name":"Pattern","outputs":[{"f":"$(name)_fct($(uv))"}],"parameters":[{"default":0,"label":"Combiner","name":"mix","type":"enum","values":[{"name":"Multiply","value":"mul"},{"name":"Add","value":"add"},{"name":"Max","value":"max"},{"name":"Min","value":"min"},{"name":"Xor","value":"xor"},{"name":"Pow","value":"pow"}]},{"default":0,"label":"X","name":"x_wave","type":"enum","values":[{"name":"Sine","value":"sine"},{"name":"Triangle","value":"triangle"},{"name":"Square","value":"square"},{"name":"Sawtooth","value":"sawtooth"},{"name":"Constant","value":"constant"}]},{"default":4,"label":"nonewline","max":32,"min":0,"name":"x_scale","step":1,"type":"float","widget":"spinbox"},{"default":0,"label":"Y","name":"y_wave","type":"enum","values":[{"name":"Sine","value":"sine"},{"name":"Triangle","value":"triangle"},{"name":"Square","value":"square"},{"name":"Sawtooth","value":"sawtooth"},{"name":"Constant","value":"constant"}]},{"default":4,"label":"nonewline","max":32,"min":0,"name":"y_scale","step":1,"type":"float","widget":"spinbox"}]}} \ No newline at end of file diff --git a/addons/material_maker/nodes/perlin.mmg b/addons/material_maker/nodes/perlin.mmg index 1fce24b..0974ecc 100644 --- a/addons/material_maker/nodes/perlin.mmg +++ b/addons/material_maker/nodes/perlin.mmg @@ -1 +1 @@ -{"name":"uniform","node_position":{"x":0,"y":0},"parameters":{"iterations":3,"persistence":0.5,"scale_x":4,"scale_y":4},"shader_model":{"global":"float perlin(vec2 uv, vec2 size, int iterations, float persistence, int seed) {\n\tvec2 seed2 = rand2(vec2(float(seed), 1.0-float(seed)));\n float rv = 0.0;\n float coef = 1.0;\n float acc = 0.0;\n for (int i = 0; i < iterations; ++i) {\n \tvec2 step = vec2(1.0)/size;\n\t\tvec2 xy = floor(uv*size);\n float f0 = rand(seed2+mod(xy, size));\n float f1 = rand(seed2+mod(xy+vec2(1.0, 0.0), size));\n float f2 = rand(seed2+mod(xy+vec2(0.0, 1.0), size));\n float f3 = rand(seed2+mod(xy+vec2(1.0, 1.0), size));\n vec2 mixval = smoothstep(0.0, 1.0, fract(uv*size));\n rv += coef * mix(mix(f0, f1, mixval.x), mix(f2, f3, mixval.x), mixval.y);\n acc += coef;\n size *= 2.0;\n coef *= persistence;\n }\n \n return rv / acc;\n}\n","instance":"","name":"Perlin","outputs":[{"f":"perlin($(uv), vec2($(scale_x), $(scale_y)), int($(iterations)), $(persistence), $(seed))"}],"parameters":[{"default":4,"label":"Scale X","max":32,"min":1,"name":"scale_x","step":1,"type":"float","widget":"spinbox"},{"default":4,"label":"Scale Y","max":32,"min":1,"name":"scale_y","step":1,"type":"float","widget":"spinbox"},{"default":3,"label":"Iterations","max":10,"min":1,"name":"iterations","step":1,"type":"float","widget":"spinbox"},{"default":0.5,"label":"Persistance","max":1,"min":0,"name":"persistence","step":0.05,"type":"float","widget":"spinbox"}]}} \ No newline at end of file +{"name":"perlin","node_position":{"x":0,"y":0},"parameters":{"iterations":3,"persistence":0.5,"scale_x":4,"scale_y":4},"shader_model":{"global":"float perlin(vec2 uv, vec2 size, int iterations, float persistence, int seed) {\n\tvec2 seed2 = rand2(vec2(float(seed), 1.0-float(seed)));\n float rv = 0.0;\n float coef = 1.0;\n float acc = 0.0;\n for (int i = 0; i < iterations; ++i) {\n \tvec2 step = vec2(1.0)/size;\n\t\tvec2 xy = floor(uv*size);\n float f0 = rand(seed2+mod(xy, size));\n float f1 = rand(seed2+mod(xy+vec2(1.0, 0.0), size));\n float f2 = rand(seed2+mod(xy+vec2(0.0, 1.0), size));\n float f3 = rand(seed2+mod(xy+vec2(1.0, 1.0), size));\n vec2 mixval = smoothstep(0.0, 1.0, fract(uv*size));\n rv += coef * mix(mix(f0, f1, mixval.x), mix(f2, f3, mixval.x), mixval.y);\n acc += coef;\n size *= 2.0;\n coef *= persistence;\n }\n \n return rv / acc;\n}\n","instance":"","name":"Perlin","outputs":[{"f":"perlin($(uv), vec2($(scale_x), $(scale_y)), int($(iterations)), $(persistence), $(seed))"}],"parameters":[{"default":4,"label":"Scale X","max":32,"min":1,"name":"scale_x","step":1,"type":"float","widget":"spinbox"},{"default":4,"label":"Scale Y","max":32,"min":1,"name":"scale_y","step":1,"type":"float","widget":"spinbox"},{"default":3,"label":"Iterations","max":10,"min":1,"name":"iterations","step":1,"type":"float","widget":"spinbox"},{"default":0.5,"label":"Persistance","max":1,"min":0,"name":"persistence","step":0.05,"type":"float","widget":"spinbox"}]}} \ No newline at end of file diff --git a/addons/material_maker/nodes/shape.mmg b/addons/material_maker/nodes/shape.mmg index 178386c..64f18d3 100644 --- a/addons/material_maker/nodes/shape.mmg +++ b/addons/material_maker/nodes/shape.mmg @@ -1 +1 @@ -{"name":"uniform","node_position":{"x":0,"y":0},"parameters":{"edge":0.2,"radius":1,"shape":0,"sides":3},"shader_model":{"global":"float shape_circle(vec2 uv, float sides, float size, float edge) {\n uv = 2.0*uv-1.0;\n\tedge = max(edge, 1.0e-8);\n float distance = length(uv);\n return clamp((1.0-distance/size)/edge, 0.0, 1.0);\n}\n\nfloat shape_polygon(vec2 uv, float sides, float size, float edge) {\n uv = 2.0*uv-1.0;\n\tedge = max(edge, 1.0e-8);\n float angle = atan(uv.x, uv.y)+3.14159265359;\n float slice = 6.28318530718/sides;\n return clamp((size-cos(floor(0.5+angle/slice)*slice-angle)*length(uv))/(edge*size), 0.0, 1.0);\n}\n\nfloat shape_star(vec2 uv, float sides, float size, float edge) {\n uv = 2.0*uv-1.0;\n\tedge = max(edge, 1.0e-8);\n float angle = atan(uv.x, uv.y);\n float slice = 6.28318530718/sides;\n return clamp((size-cos(floor(1.5+angle/slice-2.0*step(0.5*slice, mod(angle, slice)))*slice-angle)*length(uv))/(edge*size), 0.0, 1.0);\n}\n\nfloat shape_curved_star(vec2 uv, float sides, float size, float edge) {\n uv = 2.0*uv-1.0;\n\tedge = max(edge, 1.0e-8);\n float angle = 2.0*(atan(uv.x, uv.y)+3.14159265359);\n float slice = 6.28318530718/sides;\n return clamp((size-cos(floor(0.5+0.5*angle/slice)*2.0*slice-angle)*length(uv))/(edge*size), 0.0, 1.0);\n}\n\nfloat shape_rays(vec2 uv, float sides, float size, float edge) {\n uv = 2.0*uv-1.0;\n\tedge = 0.5*max(edge, 1.0e-8)*size;\n\tfloat slice = 6.28318530718/sides;\n float angle = mod(atan(uv.x, uv.y)+3.14159265359, slice)/slice;\n return clamp(min((size-angle)/edge, angle/edge), 0.0, 1.0);\n}\n\n","instance":"","name":"Shape","outputs":[{"f":"shape_$(shape)($(uv), $(sides), $(radius), $(edge))"}],"parameters":[{"default":0,"label":"","name":"shape","type":"enum","values":[{"name":"Circle","value":"circle"},{"name":"Polygon","value":"polygon"},{"name":"Star","value":"star"},{"name":"Curved star","value":"curved_star"},{"name":"Rays","value":"rays"}]},{"default":3,"label":"","max":32,"min":2,"name":"sides","step":1,"type":"float"},{"default":1,"label":"","max":1,"min":0,"name":"radius","step":0,"type":"float"},{"default":0.2,"label":"","max":1,"min":0,"name":"edge","step":0,"type":"float"}]}} \ No newline at end of file +{"name":"shape","node_position":{"x":0,"y":0},"parameters":{"edge":0.2,"radius":1,"shape":0,"sides":3},"shader_model":{"global":"float shape_circle(vec2 uv, float sides, float size, float edge) {\n uv = 2.0*uv-1.0;\n\tedge = max(edge, 1.0e-8);\n float distance = length(uv);\n return clamp((1.0-distance/size)/edge, 0.0, 1.0);\n}\n\nfloat shape_polygon(vec2 uv, float sides, float size, float edge) {\n uv = 2.0*uv-1.0;\n\tedge = max(edge, 1.0e-8);\n float angle = atan(uv.x, uv.y)+3.14159265359;\n float slice = 6.28318530718/sides;\n return clamp((size-cos(floor(0.5+angle/slice)*slice-angle)*length(uv))/(edge*size), 0.0, 1.0);\n}\n\nfloat shape_star(vec2 uv, float sides, float size, float edge) {\n uv = 2.0*uv-1.0;\n\tedge = max(edge, 1.0e-8);\n float angle = atan(uv.x, uv.y);\n float slice = 6.28318530718/sides;\n return clamp((size-cos(floor(1.5+angle/slice-2.0*step(0.5*slice, mod(angle, slice)))*slice-angle)*length(uv))/(edge*size), 0.0, 1.0);\n}\n\nfloat shape_curved_star(vec2 uv, float sides, float size, float edge) {\n uv = 2.0*uv-1.0;\n\tedge = max(edge, 1.0e-8);\n float angle = 2.0*(atan(uv.x, uv.y)+3.14159265359);\n float slice = 6.28318530718/sides;\n return clamp((size-cos(floor(0.5+0.5*angle/slice)*2.0*slice-angle)*length(uv))/(edge*size), 0.0, 1.0);\n}\n\nfloat shape_rays(vec2 uv, float sides, float size, float edge) {\n uv = 2.0*uv-1.0;\n\tedge = 0.5*max(edge, 1.0e-8)*size;\n\tfloat slice = 6.28318530718/sides;\n float angle = mod(atan(uv.x, uv.y)+3.14159265359, slice)/slice;\n return clamp(min((size-angle)/edge, angle/edge), 0.0, 1.0);\n}\n\n","instance":"","name":"Shape","outputs":[{"f":"shape_$(shape)($(uv), $(sides), $(radius), $(edge))"}],"parameters":[{"default":0,"label":"","name":"shape","type":"enum","values":[{"name":"Circle","value":"circle"},{"name":"Polygon","value":"polygon"},{"name":"Star","value":"star"},{"name":"Curved star","value":"curved_star"},{"name":"Rays","value":"rays"}]},{"default":3,"label":"","max":32,"min":2,"name":"sides","step":1,"type":"float"},{"default":1,"label":"","max":1,"min":0,"name":"radius","step":0,"type":"float"},{"default":0.2,"label":"","max":1,"min":0,"name":"edge","step":0,"type":"float"}]}} \ No newline at end of file diff --git a/addons/material_maker/nodes/voronoi.mmg b/addons/material_maker/nodes/voronoi.mmg index 4fbabbf..1e14136 100644 --- a/addons/material_maker/nodes/voronoi.mmg +++ b/addons/material_maker/nodes/voronoi.mmg @@ -1 +1 @@ -{"name":"uniform","node_position":{"x":0,"y":0},"parameters":{"intensity":0.5,"scale_x":4,"scale_y":4},"shader_model":{"global":"vec4 voronoi(vec2 uv, vec2 size, float intensity, int seed) {\n\tvec2 seed2 = rand2(vec2(float(seed), 1.0-float(seed)));\n uv *= size;\n float best_distance0 = 1.0;\n float best_distance1 = 1.0;\n vec2 point0;\n vec2 point1;\n vec2 p0 = floor(uv);\n for (int dx = -1; dx < 2; ++dx) {\n \tfor (int dy = -1; dy < 2; ++dy) {\n vec2 d = vec2(float(dx), float(dy));\n vec2 p = p0+d;\n p += rand2(seed2+mod(p, size));\n float distance = length((uv - p) / size);\n if (best_distance0 > distance) {\n \tbest_distance1 = best_distance0;\n \tbest_distance0 = distance;\n point1 = point0;\n point0 = p;\n } else if (best_distance1 > distance) {\n \tbest_distance1 = distance;\n point1 = p;\n }\n }\n }\n float edge_distance = dot(uv - 0.5*(point0+point1), normalize(point0-point1));\n \n return vec4(point0, best_distance0*length(size)*intensity, edge_distance);\n}\n","instance":"","name":"Voronoi","outputs":[{"f":"voronoi($(uv), vec2($(scale_x), $(scale_y)), $(intensity), $(seed)).z"},{"f":"voronoi($(uv), vec2($(scale_x), $(scale_y)), $(intensity), $(seed)).w"},{"rgb":"rand3(fract(voronoi($(uv), vec2($(scale_x), $(scale_y)), $(intensity), $(seed)).xy))"}],"parameters":[{"default":4,"label":"Scale X","max":32,"min":1,"name":"scale_x","step":1,"type":"float","widget":"spinbox"},{"default":4,"label":"Scale Y","max":32,"min":1,"name":"scale_y","step":1,"type":"float","widget":"spinbox"},{"default":0.5,"label":"Intensity","max":1,"min":0,"name":"intensity","step":0.05,"type":"float","widget":"spinbox"}]}} \ No newline at end of file +{"name":"voronoi","node_position":{"x":0,"y":0},"parameters":{"intensity":0.5,"scale_x":4,"scale_y":4},"shader_model":{"global":"vec4 voronoi(vec2 uv, vec2 size, float intensity, int seed) {\n\tvec2 seed2 = rand2(vec2(float(seed), 1.0-float(seed)));\n uv *= size;\n float best_distance0 = 1.0;\n float best_distance1 = 1.0;\n vec2 point0;\n vec2 point1;\n vec2 p0 = floor(uv);\n for (int dx = -1; dx < 2; ++dx) {\n \tfor (int dy = -1; dy < 2; ++dy) {\n vec2 d = vec2(float(dx), float(dy));\n vec2 p = p0+d;\n p += rand2(seed2+mod(p, size));\n float distance = length((uv - p) / size);\n if (best_distance0 > distance) {\n \tbest_distance1 = best_distance0;\n \tbest_distance0 = distance;\n point1 = point0;\n point0 = p;\n } else if (best_distance1 > distance) {\n \tbest_distance1 = distance;\n point1 = p;\n }\n }\n }\n float edge_distance = dot(uv - 0.5*(point0+point1), normalize(point0-point1));\n \n return vec4(point0, best_distance0*length(size)*intensity, edge_distance);\n}\n","instance":"","name":"Voronoi","outputs":[{"f":"voronoi($(uv), vec2($(scale_x), $(scale_y)), $(intensity), $(seed)).z"},{"f":"voronoi($(uv), vec2($(scale_x), $(scale_y)), $(intensity), $(seed)).w"},{"rgb":"rand3(fract(voronoi($(uv), vec2($(scale_x), $(scale_y)), $(intensity), $(seed)).xy))"}],"parameters":[{"default":4,"label":"Scale X","max":32,"min":1,"name":"scale_x","step":1,"type":"float","widget":"spinbox"},{"default":4,"label":"Scale Y","max":32,"min":1,"name":"scale_y","step":1,"type":"float","widget":"spinbox"},{"default":0.5,"label":"Intensity","max":1,"min":0,"name":"intensity","step":0.05,"type":"float","widget":"spinbox"}]}} \ No newline at end of file From 82f83ca482e1e1ef0c6ce99dd1dc0ac2950a3093 Mon Sep 17 00:00:00 2001 From: RodZill4 Date: Wed, 11 Sep 2019 07:53:06 +0200 Subject: [PATCH 017/133] More fixes and cleanup --- addons/material_maker/engine/gen_buffer.gd | 3 + addons/material_maker/engine/gen_shader.gd | 9 +++ addons/material_maker/graph_edit.gd | 4 +- addons/material_maker/nodes/generic.gd | 17 ++--- addons/material_maker/nodes/warp/warp.tscn | 75 +------------------ .../material_maker/widgets/gradient_editor.gd | 1 - 6 files changed, 26 insertions(+), 83 deletions(-) diff --git a/addons/material_maker/engine/gen_buffer.gd b/addons/material_maker/engine/gen_buffer.gd index 79f498a..b7f0f90 100644 --- a/addons/material_maker/engine/gen_buffer.gd +++ b/addons/material_maker/engine/gen_buffer.gd @@ -22,6 +22,9 @@ func get_parameter_defs(): func get_input_defs(): return [ { name="in", type="rgba" } ] + +func get_output_defs(): + return [ { type="rgba" } ] func _get_shader_code(uv : String, output_index : int, context : MMGenContext): var source = get_source(0) diff --git a/addons/material_maker/engine/gen_shader.gd b/addons/material_maker/engine/gen_shader.gd index 82136fa..2e98e53 100644 --- a/addons/material_maker/engine/gen_shader.gd +++ b/addons/material_maker/engine/gen_shader.gd @@ -33,6 +33,15 @@ func get_output_defs(): func set_shader_model(data: Dictionary): shader_model = data init_parameters() + if shader_model.has("outputs"): + for i in range(shader_model.outputs.size()): + var output = shader_model.outputs[i] + if output.has("rgba"): + shader_model.outputs[i].type = "rgba" + elif output.has("rgb"): + shader_model.outputs[i].type = "rgb" + else: + shader_model.outputs[i].type = "f" func find_keyword_call(string, keyword): var search_string = "$%s(" % keyword diff --git a/addons/material_maker/graph_edit.gd b/addons/material_maker/graph_edit.gd index 880ab96..c29dd6e 100644 --- a/addons/material_maker/graph_edit.gd +++ b/addons/material_maker/graph_edit.gd @@ -64,7 +64,9 @@ func remove_node(node): # Global operations on graph func update_tab_title(): + print("update_tab_title") if !get_parent().has_method("set_tab_title"): + print("no set_tab_title method") return var title = "[unnamed]" if save_path != null: @@ -115,7 +117,7 @@ func new_material(): if generator != null: add_child(generator) update_graph(generator.get_children(), generator.connections) - set_save_path(filename) + set_save_path(null) set_need_save(false) center_view() diff --git a/addons/material_maker/nodes/generic.gd b/addons/material_maker/nodes/generic.gd index 1c39db4..457c8ff 100644 --- a/addons/material_maker/nodes/generic.gd +++ b/addons/material_maker/nodes/generic.gd @@ -180,17 +180,14 @@ func update_node(): var outputs = generator.get_output_defs() for i in range(outputs.size()): var output = outputs[i] - var enable_right = false + var enable_right = true var color_right = Color(0.5, 0.5, 0.5) - if typeof(output) == TYPE_DICTIONARY: - if output.has("rgb"): - enable_right = true - color_right = Color(0.5, 0.5, 1.0) - elif output.has("rgba"): - enable_right = true - color_right = Color(0.0, 0.5, 0.0, 0.5) - elif output.has("f"): - enable_right = true + assert(typeof(output) == TYPE_DICTIONARY) + assert(output.has("type")) + enable_right = true + match output.type: + "rgb": color_right = Color(0.5, 0.5, 1.0) + "rgba": color_right = Color(0.0, 0.5, 0.0, 0.5) set_slot(i, is_slot_enabled_left(i), get_slot_type_left(i), get_slot_color_left(i), enable_right, 0, color_right) if i >= get_child_count(): var control = Control.new() diff --git a/addons/material_maker/nodes/warp/warp.tscn b/addons/material_maker/nodes/warp/warp.tscn index 00decbf..9c01860 100644 --- a/addons/material_maker/nodes/warp/warp.tscn +++ b/addons/material_maker/nodes/warp/warp.tscn @@ -4,31 +4,15 @@ [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 +[node name="Warp" type="GraphNode"] 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 ) @@ -48,78 +32,27 @@ 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", "slot", "slot/1" ] -[node name="Label1" type="Label" parent="." index="0"] - -anchor_left = 0.0 -anchor_top = 0.0 -anchor_right = 0.0 -anchor_bottom = 0.0 +[node name="Label1" type="Label" parent="."] margin_left = 16.0 margin_top = 24.0 margin_right = 90.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 +[node name="Label2" type="Label" parent="."] margin_left = 16.0 margin_top = 38.0 margin_right = 90.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="SpinBox" parent="." index="2"] - -anchor_left = 0.0 -anchor_top = 0.0 -anchor_right = 0.0 -anchor_bottom = 0.0 +[node name="amount" type="SpinBox" parent="."] margin_left = 16.0 margin_top = 53.0 margin_right = 90.0 margin_bottom = 77.0 -rect_pivot_offset = Vector2( 0, 0 ) -rect_clip_content = false -mouse_filter = 0 -mouse_default_cursor_shape = 0 -size_flags_horizontal = 1 -size_flags_vertical = 1 -min_value = 0.0 max_value = 1.0 step = 0.05 -page = 0.0 value = 0.5 -exp_edit = false -rounded = false -editable = true -prefix = "" -suffix = "" -_sections_unfolded = [ "Caret", "Placeholder" ] - [connection signal="close_request" from="." to="." method="queue_free"] - - diff --git a/addons/material_maker/widgets/gradient_editor.gd b/addons/material_maker/widgets/gradient_editor.gd index 9c209fc..e79453a 100644 --- a/addons/material_maker/widgets/gradient_editor.gd +++ b/addons/material_maker/widgets/gradient_editor.gd @@ -56,7 +56,6 @@ func set_value(v): remove_child(c) c.free() for p in value.points: - print(p) add_cursor(p.v*(rect_size.x-GradientCursor.WIDTH), p.c) update_shader() From 59dced1c09d251646d93edf3fa4d10e4c53ef638 Mon Sep 17 00:00:00 2001 From: RodZill4 Date: Wed, 11 Sep 2019 23:13:10 +0200 Subject: [PATCH 018/133] Updated generic layout and implemented blend generator Preview is now resized with a single click. --- addons/material_maker/common.shader | 68 ------------------------- addons/material_maker/nodes/blend.mmg | 1 + addons/material_maker/nodes/generic.gd | 17 ++++--- addons/material_maker/nodes/pattern.mmg | 2 +- addons/material_maker/preview.gd | 4 +- addons/material_maker/preview.tscn | 2 +- 6 files changed, 16 insertions(+), 78 deletions(-) create mode 100644 addons/material_maker/nodes/blend.mmg diff --git a/addons/material_maker/common.shader b/addons/material_maker/common.shader index e86954a..6cc468d 100644 --- a/addons/material_maker/common.shader +++ b/addons/material_maker/common.shader @@ -13,74 +13,6 @@ vec3 rand3(vec2 x) { dot(x, vec2(13.254, 5.867)))) * 43758.5453); } -vec3 blend_normal(vec2 uv, vec3 c1, vec3 c2, float opacity) { - return opacity*c1 + (1.0-opacity)*c2; -} - -vec3 blend_dissolve(vec2 uv, vec3 c1, vec3 c2, float opacity) { - if (rand(uv) < opacity) { - return c1; - } else { - return c2; - } -} - -vec3 blend_multiply(vec2 uv, vec3 c1, vec3 c2, float opacity) { - return opacity*c1*c2 + (1.0-opacity)*c2; -} - -vec3 blend_screen(vec2 uv, vec3 c1, vec3 c2, float opacity) { - return opacity*(1.0-(1.0-c1)*(1.0-c2)) + (1.0-opacity)*c2; -} - -float blend_overlay_f(float c1, float c2) { - return (c1 < 0.5) ? (2.0*c1*c2) : (1.0-2.0*(1.0-c1)*(1.0-c2)); -} - -vec3 blend_overlay(vec2 uv, vec3 c1, vec3 c2, float opacity) { - return opacity*vec3(blend_overlay_f(c1.x, c2.x), blend_overlay_f(c1.y, c2.y), blend_overlay_f(c1.z, c2.z)) + (1.0-opacity)*c2; -} - -vec3 blend_hard_light(vec2 uv, vec3 c1, vec3 c2, float opacity) { - return opacity*0.5*(c1*c2+blend_overlay(uv, c1, c2, 1.0)) + (1.0-opacity)*c2; -} - -float blend_soft_light_f(float c1, float c2) { - return (c2 < 0.5) ? (2.0*c1*c2+c1*c1*(1.0-2.0*c2)) : 2.0*c1*(1.0-c2)+sqrt(c1)*(2.0*c2-1.0); -} - -vec3 blend_soft_light(vec2 uv, vec3 c1, vec3 c2, float opacity) { - return opacity*vec3(blend_soft_light_f(c1.x, c2.x), blend_soft_light_f(c1.y, c2.y), blend_soft_light_f(c1.z, c2.z)) + (1.0-opacity)*c2; -} - -float blend_burn_f(float c1, float c2) { - return (c1==0.0)?c1:max((1.0-((1.0-c2)/c1)),0.0); -} - -vec3 blend_burn(vec2 uv, vec3 c1, vec3 c2, float opacity) { - return opacity*vec3(blend_burn_f(c1.x, c2.x), blend_burn_f(c1.y, c2.y), blend_burn_f(c1.z, c2.z)) + (1.0-opacity)*c2; -} - -float blend_dodge_f(float c1, float c2) { - return (c1==1.0)?c1:min(c2/(1.0-c1),1.0); -} - -vec3 blend_dodge(vec2 uv, vec3 c1, vec3 c2, float opacity) { - return opacity*vec3(blend_dodge_f(c1.x, c2.x), blend_dodge_f(c1.y, c2.y), blend_dodge_f(c1.z, c2.z)) + (1.0-opacity)*c2; -} - -vec3 blend_lighten(vec2 uv, vec3 c1, vec3 c2, float opacity) { - return opacity*max(c1, c2) + (1.0-opacity)*c2; -} - -vec3 blend_darken(vec2 uv, vec3 c1, vec3 c2, float opacity) { - return opacity*min(c1, c2) + (1.0-opacity)*c2; -} - -vec3 blend_difference(vec2 uv, vec3 c1, vec3 c2, float opacity) { - return opacity*clamp(c2-c1, vec3(0.0), vec3(1.0)) + (1.0-opacity)*c2; -} - vec2 transform(vec2 uv, vec2 translate, float rotate, vec2 scale) { vec2 rv; uv -= vec2(0.5); diff --git a/addons/material_maker/nodes/blend.mmg b/addons/material_maker/nodes/blend.mmg new file mode 100644 index 0000000..25f6372 --- /dev/null +++ b/addons/material_maker/nodes/blend.mmg @@ -0,0 +1 @@ +{"name":"blend","node_position":{"x":0,"y":0},"parameters":{"amount":1,"blend_type":6},"shader_model":{"global":"vec3 blend_normal(vec2 uv, vec3 c1, vec3 c2, float opacity) {\n\treturn opacity*c1 + (1.0-opacity)*c2;\n}\n\nvec3 blend_dissolve(vec2 uv, vec3 c1, vec3 c2, float opacity) {\n\tif (rand(uv) < opacity) {\n\t\treturn c1;\n\t} else {\n\t\treturn c2;\n\t}\n}\n\nvec3 blend_multiply(vec2 uv, vec3 c1, vec3 c2, float opacity) {\n\treturn opacity*c1*c2 + (1.0-opacity)*c2;\n}\n\nvec3 blend_screen(vec2 uv, vec3 c1, vec3 c2, float opacity) {\n\treturn opacity*(1.0-(1.0-c1)*(1.0-c2)) + (1.0-opacity)*c2;\n}\n\nfloat blend_overlay_f(float c1, float c2) {\n\treturn (c1 < 0.5) ? (2.0*c1*c2) : (1.0-2.0*(1.0-c1)*(1.0-c2));\n}\n\nvec3 blend_overlay(vec2 uv, vec3 c1, vec3 c2, float opacity) {\n\treturn opacity*vec3(blend_overlay_f(c1.x, c2.x), blend_overlay_f(c1.y, c2.y), blend_overlay_f(c1.z, c2.z)) + (1.0-opacity)*c2;\n}\n\nvec3 blend_hard_light(vec2 uv, vec3 c1, vec3 c2, float opacity) {\n\treturn opacity*0.5*(c1*c2+blend_overlay(uv, c1, c2, 1.0)) + (1.0-opacity)*c2;\n}\n\nfloat blend_soft_light_f(float c1, float c2) {\n\treturn (c2 < 0.5) ? (2.0*c1*c2+c1*c1*(1.0-2.0*c2)) : 2.0*c1*(1.0-c2)+sqrt(c1)*(2.0*c2-1.0);\n}\n\nvec3 blend_soft_light(vec2 uv, vec3 c1, vec3 c2, float opacity) {\n\treturn opacity*vec3(blend_soft_light_f(c1.x, c2.x), blend_soft_light_f(c1.y, c2.y), blend_soft_light_f(c1.z, c2.z)) + (1.0-opacity)*c2;\n}\n\nfloat blend_burn_f(float c1, float c2) {\n\treturn (c1==0.0)?c1:max((1.0-((1.0-c2)/c1)),0.0);\n}\n\nvec3 blend_burn(vec2 uv, vec3 c1, vec3 c2, float opacity) {\n\treturn opacity*vec3(blend_burn_f(c1.x, c2.x), blend_burn_f(c1.y, c2.y), blend_burn_f(c1.z, c2.z)) + (1.0-opacity)*c2;\n}\n\nfloat blend_dodge_f(float c1, float c2) {\n\treturn (c1==1.0)?c1:min(c2/(1.0-c1),1.0);\n}\n\nvec3 blend_dodge(vec2 uv, vec3 c1, vec3 c2, float opacity) {\n\treturn opacity*vec3(blend_dodge_f(c1.x, c2.x), blend_dodge_f(c1.y, c2.y), blend_dodge_f(c1.z, c2.z)) + (1.0-opacity)*c2;\n}\n\nvec3 blend_lighten(vec2 uv, vec3 c1, vec3 c2, float opacity) {\n\treturn opacity*max(c1, c2) + (1.0-opacity)*c2;\n}\n\nvec3 blend_darken(vec2 uv, vec3 c1, vec3 c2, float opacity) {\n\treturn opacity*min(c1, c2) + (1.0-opacity)*c2;\n}\n\nvec3 blend_difference(vec2 uv, vec3 c1, vec3 c2, float opacity) {\n\treturn opacity*clamp(c2-c1, vec3(0.0), vec3(1.0)) + (1.0-opacity)*c2;\n}\n","inputs":[{"default":"vec4($uv.x, 1.0, 1.0, 1.0)","label":"Source1","name":"s1","type":"rgba"},{"default":"vec4(1.0, $uv.y, 1.0, 1.0)","label":"Source2","name":"s2","type":"rgba"},{"default":"$amount","label":"Opacity","name":"a","type":"f"}],"instance":"","name":"Blend","outputs":[{"rgba":"vec4(blend_$blend_type($uv, $s1($uv).rgb, $s2($uv).rgb, $a($uv)*$s1($uv).a), min(1.0, $s2($uv).a+$a($uv)*$s1($uv).a))","type":"rgba"}],"parameters":[{"default":0,"label":"","name":"blend_type","type":"enum","values":[{"name":"Normal","value":"normal"},{"name":"Dissolve","value":"dissolve"},{"name":"Multiply","value":"multiply"},{"name":"Screen","value":"screen"},{"name":"Overlay","value":"overlay"},{"name":"Hard Light","value":"hard_light"},{"name":"Soft Light","value":"soft_light"},{"name":"Burn","value":"burn"},{"name":"Dodge","value":"dodge"},{"name":"Lighten","value":"lighten"},{"name":"Darken","value":"darken"},{"name":"Difference","value":"difference"}]},{"default":0.5,"label":"3:","max":1,"min":0,"name":"amount","step":0,"type":"float"}]}} \ No newline at end of file diff --git a/addons/material_maker/nodes/generic.gd b/addons/material_maker/nodes/generic.gd index 457c8ff..4bac6aa 100644 --- a/addons/material_maker/nodes/generic.gd +++ b/addons/material_maker/nodes/generic.gd @@ -117,6 +117,8 @@ func update_node(): # Parameters controls = [] var index = -1 + var regex = RegEx.new() + regex.compile("^(\\d+):(.*)") for p in generator.get_parameter_defs(): if !p.has("name") or !p.has("type"): continue @@ -156,19 +158,22 @@ func update_node(): controls.append(control) if p.has("label"): label = p.label - if index == -1 or label != "nonewline": + var result = regex.search(label) + if result: + index = result.get_string(1).to_int()-1 + label = result.get_string(2) + else: index += 1 var hsizer : HBoxContainer - if index >= get_child_count(): + while index >= get_child_count(): hsizer = HBoxContainer.new() hsizer.size_flags_horizontal = SIZE_EXPAND | SIZE_FILL var empty_control : Control = Control.new() empty_control.rect_min_size.x = input_names_width hsizer.add_child(empty_control) add_child(hsizer) - else: - hsizer = get_child(index) - if label != "" and label != "nonewline": + hsizer = get_child(index) + if label != "": var label_widget = Label.new() label_widget.text = label label_widget.size_flags_horizontal = SIZE_EXPAND | SIZE_FILL @@ -207,7 +212,7 @@ func edit_generator(): edit_window.popup_centered() func update_generator(shader_model): - generator.shader_model = shader_model + generator.set_shader_model(shader_model) update_node() func load_generator(): diff --git a/addons/material_maker/nodes/pattern.mmg b/addons/material_maker/nodes/pattern.mmg index 4a5cf7d..3f9a027 100644 --- a/addons/material_maker/nodes/pattern.mmg +++ b/addons/material_maker/nodes/pattern.mmg @@ -1 +1 @@ -{"name":"pattern","node_position":{"x":0,"y":0},"parameters":{"mix":0,"x_scale":4,"x_wave":0,"y_scale":4,"y_wave":0},"shader_model":{"global":"float wave_constant(float x) {\n\treturn 1.0;\n}\n\nfloat wave_sine(float x) {\n\treturn 0.5-0.5*cos(3.14159265359*2.0*x);\n}\n\nfloat wave_triangle(float x) {\n\tx = fract(x);\n\treturn min(2.0*x, 2.0-2.0*x);\n}\n\nfloat wave_sawtooth(float x) {\n\treturn fract(x);\n}\n\nfloat wave_square(float x) {\n\treturn (fract(x) < 0.5) ? 0.0 : 1.0;\n}\n\nfloat mix_mul(float x, float y) {\n\treturn x*y;\n}\n\nfloat mix_add(float x, float y) {\n\treturn min(x+y, 1.0);\n}\n\nfloat mix_max(float x, float y) {\n\treturn max(x, y);\n}\n\nfloat mix_min(float x, float y) {\n\treturn min(x, y);\n}\n\nfloat mix_xor(float x, float y) {\n\treturn min(x+y, 2.0-x-y);\n}\n\nfloat mix_pow(float x, float y) {\n\treturn pow(x, y);\n}","instance":"float $(name)_fct(vec2 uv) {\n\treturn mix_$(mix)(wave_$(x_wave)($(x_scale)*uv.x), wave_$(y_wave)($(y_scale)*uv.y));\n}","name":"Pattern","outputs":[{"f":"$(name)_fct($(uv))"}],"parameters":[{"default":0,"label":"Combiner","name":"mix","type":"enum","values":[{"name":"Multiply","value":"mul"},{"name":"Add","value":"add"},{"name":"Max","value":"max"},{"name":"Min","value":"min"},{"name":"Xor","value":"xor"},{"name":"Pow","value":"pow"}]},{"default":0,"label":"X","name":"x_wave","type":"enum","values":[{"name":"Sine","value":"sine"},{"name":"Triangle","value":"triangle"},{"name":"Square","value":"square"},{"name":"Sawtooth","value":"sawtooth"},{"name":"Constant","value":"constant"}]},{"default":4,"label":"nonewline","max":32,"min":0,"name":"x_scale","step":1,"type":"float","widget":"spinbox"},{"default":0,"label":"Y","name":"y_wave","type":"enum","values":[{"name":"Sine","value":"sine"},{"name":"Triangle","value":"triangle"},{"name":"Square","value":"square"},{"name":"Sawtooth","value":"sawtooth"},{"name":"Constant","value":"constant"}]},{"default":4,"label":"nonewline","max":32,"min":0,"name":"y_scale","step":1,"type":"float","widget":"spinbox"}]}} \ No newline at end of file +{"name":"pattern","node_position":{"x":0,"y":0},"parameters":{"mix":0,"x_scale":4,"x_wave":0,"y_scale":4,"y_wave":0},"shader_model":{"global":"float wave_constant(float x) {\n\treturn 1.0;\n}\n\nfloat wave_sine(float x) {\n\treturn 0.5-0.5*cos(3.14159265359*2.0*x);\n}\n\nfloat wave_triangle(float x) {\n\tx = fract(x);\n\treturn min(2.0*x, 2.0-2.0*x);\n}\n\nfloat wave_sawtooth(float x) {\n\treturn fract(x);\n}\n\nfloat wave_square(float x) {\n\treturn (fract(x) < 0.5) ? 0.0 : 1.0;\n}\n\nfloat mix_mul(float x, float y) {\n\treturn x*y;\n}\n\nfloat mix_add(float x, float y) {\n\treturn min(x+y, 1.0);\n}\n\nfloat mix_max(float x, float y) {\n\treturn max(x, y);\n}\n\nfloat mix_min(float x, float y) {\n\treturn min(x, y);\n}\n\nfloat mix_xor(float x, float y) {\n\treturn min(x+y, 2.0-x-y);\n}\n\nfloat mix_pow(float x, float y) {\n\treturn pow(x, y);\n}","inputs":[],"instance":"float $(name)_fct(vec2 uv) {\n\treturn mix_$(mix)(wave_$(x_wave)($(x_scale)*uv.x), wave_$(y_wave)($(y_scale)*uv.y));\n}","name":"Pattern","outputs":[{"f":"$(name)_fct($(uv))","type":"f"}],"parameters":[{"default":0,"label":"Combiner","name":"mix","type":"enum","values":[{"name":"Multiply","value":"mul"},{"name":"Add","value":"add"},{"name":"Max","value":"max"},{"name":"Min","value":"min"},{"name":"Xor","value":"xor"},{"name":"Pow","value":"pow"}]},{"default":0,"label":"X","name":"x_wave","type":"enum","values":[{"name":"Sine","value":"sine"},{"name":"Triangle","value":"triangle"},{"name":"Square","value":"square"},{"name":"Sawtooth","value":"sawtooth"},{"name":"Constant","value":"constant"}]},{"default":4,"label":"2:","max":32,"min":0,"name":"x_scale","step":1,"type":"float","widget":"spinbox"},{"default":0,"label":"Y","name":"y_wave","type":"enum","values":[{"name":"Sine","value":"sine"},{"name":"Triangle","value":"triangle"},{"name":"Square","value":"square"},{"name":"Sawtooth","value":"sawtooth"},{"name":"Constant","value":"constant"}]},{"default":4,"label":"3:","max":32,"min":0,"name":"y_scale","step":1,"type":"float","widget":"spinbox"}]}} \ No newline at end of file diff --git a/addons/material_maker/preview.gd b/addons/material_maker/preview.gd index 8d23fd3..c3aa276 100644 --- a/addons/material_maker/preview.gd +++ b/addons/material_maker/preview.gd @@ -42,8 +42,8 @@ func _on_Preview_resized(): $Preview2D.rect_position = Vector2(0, rect_size.y-64) $Preview2D.rect_size = Vector2(64, 64) -func _on_Preview2D_gui_input(ev): - if ev is InputEventMouseButton && ev.button_index == 1 && ev.doubleclick: +func _on_Preview2D_gui_input(ev : InputEvent): + if ev is InputEventMouseButton && ev.button_index == 1 && ev.pressed: preview_maximized = !preview_maximized _on_Preview_resized() diff --git a/addons/material_maker/preview.tscn b/addons/material_maker/preview.tscn index 3b8d8f6..1474b4a 100644 --- a/addons/material_maker/preview.tscn +++ b/addons/material_maker/preview.tscn @@ -127,7 +127,7 @@ render_target_clear_mode = 1 render_target_update_mode = 3 [node name="Objects" type="Spatial" parent="MaterialPreview"] -transform = Transform( 0.979431, 0, -0.201756, 0, 1, 0, 0.201756, 0, 0.979431, 0, 0, 0 ) +transform = Transform( -0.482492, 0, 0.875895, 0, 1, 0, -0.875895, 0, -0.482492, 0, 0, 0 ) [node name="Cube" type="MeshInstance" parent="MaterialPreview/Objects"] mesh = SubResource( 2 ) From 9834571c4a0f64d050d2c935f5246a8ccc60414e Mon Sep 17 00:00:00 2001 From: RodZill4 Date: Thu, 12 Sep 2019 21:16:07 +0200 Subject: [PATCH 019/133] Fixed shader generation and added transform, mirror and skew Fixed shader generation with nested usage of inputs (process code until no further input substitution is possible) --- addons/material_maker/common.shader | 19 -- addons/material_maker/engine/gen_shader.gd | 41 ++-- addons/material_maker/nodes/blend.mmg | 2 +- addons/material_maker/nodes/generic.gd | 4 +- addons/material_maker/nodes/mirror.mmg | 1 + addons/material_maker/nodes/skew.mmg | 1 + addons/material_maker/nodes/transform.mmg | 1 + .../widgets/node_editor/parameter_float.tscn | 203 +++--------------- 8 files changed, 60 insertions(+), 212 deletions(-) create mode 100644 addons/material_maker/nodes/mirror.mmg create mode 100644 addons/material_maker/nodes/skew.mmg create mode 100644 addons/material_maker/nodes/transform.mmg diff --git a/addons/material_maker/common.shader b/addons/material_maker/common.shader index 6cc468d..953318d 100644 --- a/addons/material_maker/common.shader +++ b/addons/material_maker/common.shader @@ -13,25 +13,6 @@ vec3 rand3(vec2 x) { dot(x, vec2(13.254, 5.867)))) * 43758.5453); } -vec2 transform(vec2 uv, vec2 translate, float rotate, vec2 scale) { - vec2 rv; - uv -= vec2(0.5); - rv.x = cos(rotate)*uv.x + sin(rotate)*uv.y; - rv.y = -sin(rotate)*uv.x + cos(rotate)*uv.y; - rv /= scale; - rv += vec2(0.5); - rv -= translate; - return rv; -} - -vec2 transform_repeat(vec2 uv, vec2 translate, float rotate, vec2 scale) { - return fract(transform(uv, translate, rotate, scale)); -} - -vec2 transform_norepeat(vec2 uv, vec2 translate, float rotate, vec2 scale) { - return clamp(transform(uv, translate, rotate, scale), vec2(0.0), vec2(1.0)); -} - // From http://lolengine.net/blog/2013/07/27/rgb-to-hsv-in-glsl vec3 rgb2hsv(vec3 c) { vec4 K = vec4(0.0, -1.0 / 3.0, 2.0 / 3.0, -1.0); diff --git a/addons/material_maker/engine/gen_shader.gd b/addons/material_maker/engine/gen_shader.gd index 2e98e53..39ee44d 100644 --- a/addons/material_maker/engine/gen_shader.gd +++ b/addons/material_maker/engine/gen_shader.gd @@ -64,6 +64,7 @@ func replace_input(string, context, input, type, src, default): var required_defs = "" var required_code = "" var required_textures = {} + var new_pass_required = false while true: var uv = find_keyword_call(string, input) if uv == null: @@ -71,6 +72,9 @@ func replace_input(string, context, input, type, src, default): elif uv == "": print("syntax error") break + elif uv.find("$") != -1: + new_pass_required = true + break var src_code if src == null: src_code = subst(default, context, "(%s)" % uv) @@ -83,7 +87,7 @@ func replace_input(string, context, input, type, src, default): required_code += src_code.code required_textures = src_code.textures string = string.replace("$%s(%s)" % [ input, uv ], src_code.string) - return { string=string, defs=required_defs, code=required_code, textures=required_textures } + return { string=string, defs=required_defs, code=required_code, textures=required_textures, new_pass_required=new_pass_required } func is_word_letter(l): return "azertyuiopqsdfghjklmwxcvbnAZERTYUIOPQSDFGHJKLMWXCVBN1234567890_".find(l) != -1 @@ -130,20 +134,33 @@ func subst(string, context, uv = ""): value_string = "vec4(%.9f, %.9f, %.9f, %.9f)" % [ value.r, value.g, value.b, value.a ] elif p.type == "gradient": value_string = name+"__"+p.name+"_gradient_fct" + elif p.type == "boolean": + value_string = "true" if value else "false" + else: + print("Cannot replace parameter of type "+p.type) if value_string != null: string = replace_variable(string, p.name, value_string) if shader_model.has("inputs") and typeof(shader_model.inputs) == TYPE_ARRAY: - for i in range(shader_model.inputs.size()): - var input = shader_model.inputs[i] - var source = get_source(i) - var result = replace_input(string, context, input.name, input.type, source, input.default) - while result is GDScriptFunctionState: - result = yield(result, "completed") - string = result.string - required_defs += result.defs - required_code += result.code - for t in result.textures.keys(): - required_textures[t] = result.textures[t] + var cont = true + while cont: + var changed = false + var new_pass_required = false + for i in range(shader_model.inputs.size()): + var input = shader_model.inputs[i] + var source = get_source(i) + var result = replace_input(string, context, input.name, input.type, source, input.default) + while result is GDScriptFunctionState: + result = yield(result, "completed") + if string != result.string: + changed = true + if result.new_pass_required: + new_pass_required = true + string = result.string + required_defs += result.defs + required_code += result.code + for t in result.textures.keys(): + required_textures[t] = result.textures[t] + cont = changed and new_pass_required return { string=string, defs=required_defs, code=required_code, textures=required_textures } func _get_shader_code(uv : String, output_index : int, context : MMGenContext): diff --git a/addons/material_maker/nodes/blend.mmg b/addons/material_maker/nodes/blend.mmg index 25f6372..b6e05e6 100644 --- a/addons/material_maker/nodes/blend.mmg +++ b/addons/material_maker/nodes/blend.mmg @@ -1 +1 @@ -{"name":"blend","node_position":{"x":0,"y":0},"parameters":{"amount":1,"blend_type":6},"shader_model":{"global":"vec3 blend_normal(vec2 uv, vec3 c1, vec3 c2, float opacity) {\n\treturn opacity*c1 + (1.0-opacity)*c2;\n}\n\nvec3 blend_dissolve(vec2 uv, vec3 c1, vec3 c2, float opacity) {\n\tif (rand(uv) < opacity) {\n\t\treturn c1;\n\t} else {\n\t\treturn c2;\n\t}\n}\n\nvec3 blend_multiply(vec2 uv, vec3 c1, vec3 c2, float opacity) {\n\treturn opacity*c1*c2 + (1.0-opacity)*c2;\n}\n\nvec3 blend_screen(vec2 uv, vec3 c1, vec3 c2, float opacity) {\n\treturn opacity*(1.0-(1.0-c1)*(1.0-c2)) + (1.0-opacity)*c2;\n}\n\nfloat blend_overlay_f(float c1, float c2) {\n\treturn (c1 < 0.5) ? (2.0*c1*c2) : (1.0-2.0*(1.0-c1)*(1.0-c2));\n}\n\nvec3 blend_overlay(vec2 uv, vec3 c1, vec3 c2, float opacity) {\n\treturn opacity*vec3(blend_overlay_f(c1.x, c2.x), blend_overlay_f(c1.y, c2.y), blend_overlay_f(c1.z, c2.z)) + (1.0-opacity)*c2;\n}\n\nvec3 blend_hard_light(vec2 uv, vec3 c1, vec3 c2, float opacity) {\n\treturn opacity*0.5*(c1*c2+blend_overlay(uv, c1, c2, 1.0)) + (1.0-opacity)*c2;\n}\n\nfloat blend_soft_light_f(float c1, float c2) {\n\treturn (c2 < 0.5) ? (2.0*c1*c2+c1*c1*(1.0-2.0*c2)) : 2.0*c1*(1.0-c2)+sqrt(c1)*(2.0*c2-1.0);\n}\n\nvec3 blend_soft_light(vec2 uv, vec3 c1, vec3 c2, float opacity) {\n\treturn opacity*vec3(blend_soft_light_f(c1.x, c2.x), blend_soft_light_f(c1.y, c2.y), blend_soft_light_f(c1.z, c2.z)) + (1.0-opacity)*c2;\n}\n\nfloat blend_burn_f(float c1, float c2) {\n\treturn (c1==0.0)?c1:max((1.0-((1.0-c2)/c1)),0.0);\n}\n\nvec3 blend_burn(vec2 uv, vec3 c1, vec3 c2, float opacity) {\n\treturn opacity*vec3(blend_burn_f(c1.x, c2.x), blend_burn_f(c1.y, c2.y), blend_burn_f(c1.z, c2.z)) + (1.0-opacity)*c2;\n}\n\nfloat blend_dodge_f(float c1, float c2) {\n\treturn (c1==1.0)?c1:min(c2/(1.0-c1),1.0);\n}\n\nvec3 blend_dodge(vec2 uv, vec3 c1, vec3 c2, float opacity) {\n\treturn opacity*vec3(blend_dodge_f(c1.x, c2.x), blend_dodge_f(c1.y, c2.y), blend_dodge_f(c1.z, c2.z)) + (1.0-opacity)*c2;\n}\n\nvec3 blend_lighten(vec2 uv, vec3 c1, vec3 c2, float opacity) {\n\treturn opacity*max(c1, c2) + (1.0-opacity)*c2;\n}\n\nvec3 blend_darken(vec2 uv, vec3 c1, vec3 c2, float opacity) {\n\treturn opacity*min(c1, c2) + (1.0-opacity)*c2;\n}\n\nvec3 blend_difference(vec2 uv, vec3 c1, vec3 c2, float opacity) {\n\treturn opacity*clamp(c2-c1, vec3(0.0), vec3(1.0)) + (1.0-opacity)*c2;\n}\n","inputs":[{"default":"vec4($uv.x, 1.0, 1.0, 1.0)","label":"Source1","name":"s1","type":"rgba"},{"default":"vec4(1.0, $uv.y, 1.0, 1.0)","label":"Source2","name":"s2","type":"rgba"},{"default":"$amount","label":"Opacity","name":"a","type":"f"}],"instance":"","name":"Blend","outputs":[{"rgba":"vec4(blend_$blend_type($uv, $s1($uv).rgb, $s2($uv).rgb, $a($uv)*$s1($uv).a), min(1.0, $s2($uv).a+$a($uv)*$s1($uv).a))","type":"rgba"}],"parameters":[{"default":0,"label":"","name":"blend_type","type":"enum","values":[{"name":"Normal","value":"normal"},{"name":"Dissolve","value":"dissolve"},{"name":"Multiply","value":"multiply"},{"name":"Screen","value":"screen"},{"name":"Overlay","value":"overlay"},{"name":"Hard Light","value":"hard_light"},{"name":"Soft Light","value":"soft_light"},{"name":"Burn","value":"burn"},{"name":"Dodge","value":"dodge"},{"name":"Lighten","value":"lighten"},{"name":"Darken","value":"darken"},{"name":"Difference","value":"difference"}]},{"default":0.5,"label":"3:","max":1,"min":0,"name":"amount","step":0,"type":"float"}]}} \ No newline at end of file +{"name":"blend","node_position":{"x":0,"y":0},"parameters":{"amount":0.935642,"blend_type":0},"shader_model":{"global":"vec3 blend_normal(vec2 uv, vec3 c1, vec3 c2, float opacity) {\n\treturn opacity*c1 + (1.0-opacity)*c2;\n}\n\nvec3 blend_dissolve(vec2 uv, vec3 c1, vec3 c2, float opacity) {\n\tif (rand(uv) < opacity) {\n\t\treturn c1;\n\t} else {\n\t\treturn c2;\n\t}\n}\n\nvec3 blend_multiply(vec2 uv, vec3 c1, vec3 c2, float opacity) {\n\treturn opacity*c1*c2 + (1.0-opacity)*c2;\n}\n\nvec3 blend_screen(vec2 uv, vec3 c1, vec3 c2, float opacity) {\n\treturn opacity*(1.0-(1.0-c1)*(1.0-c2)) + (1.0-opacity)*c2;\n}\n\nfloat blend_overlay_f(float c1, float c2) {\n\treturn (c1 < 0.5) ? (2.0*c1*c2) : (1.0-2.0*(1.0-c1)*(1.0-c2));\n}\n\nvec3 blend_overlay(vec2 uv, vec3 c1, vec3 c2, float opacity) {\n\treturn opacity*vec3(blend_overlay_f(c1.x, c2.x), blend_overlay_f(c1.y, c2.y), blend_overlay_f(c1.z, c2.z)) + (1.0-opacity)*c2;\n}\n\nvec3 blend_hard_light(vec2 uv, vec3 c1, vec3 c2, float opacity) {\n\treturn opacity*0.5*(c1*c2+blend_overlay(uv, c1, c2, 1.0)) + (1.0-opacity)*c2;\n}\n\nfloat blend_soft_light_f(float c1, float c2) {\n\treturn (c2 < 0.5) ? (2.0*c1*c2+c1*c1*(1.0-2.0*c2)) : 2.0*c1*(1.0-c2)+sqrt(c1)*(2.0*c2-1.0);\n}\n\nvec3 blend_soft_light(vec2 uv, vec3 c1, vec3 c2, float opacity) {\n\treturn opacity*vec3(blend_soft_light_f(c1.x, c2.x), blend_soft_light_f(c1.y, c2.y), blend_soft_light_f(c1.z, c2.z)) + (1.0-opacity)*c2;\n}\n\nfloat blend_burn_f(float c1, float c2) {\n\treturn (c1==0.0)?c1:max((1.0-((1.0-c2)/c1)),0.0);\n}\n\nvec3 blend_burn(vec2 uv, vec3 c1, vec3 c2, float opacity) {\n\treturn opacity*vec3(blend_burn_f(c1.x, c2.x), blend_burn_f(c1.y, c2.y), blend_burn_f(c1.z, c2.z)) + (1.0-opacity)*c2;\n}\n\nfloat blend_dodge_f(float c1, float c2) {\n\treturn (c1==1.0)?c1:min(c2/(1.0-c1),1.0);\n}\n\nvec3 blend_dodge(vec2 uv, vec3 c1, vec3 c2, float opacity) {\n\treturn opacity*vec3(blend_dodge_f(c1.x, c2.x), blend_dodge_f(c1.y, c2.y), blend_dodge_f(c1.z, c2.z)) + (1.0-opacity)*c2;\n}\n\nvec3 blend_lighten(vec2 uv, vec3 c1, vec3 c2, float opacity) {\n\treturn opacity*max(c1, c2) + (1.0-opacity)*c2;\n}\n\nvec3 blend_darken(vec2 uv, vec3 c1, vec3 c2, float opacity) {\n\treturn opacity*min(c1, c2) + (1.0-opacity)*c2;\n}\n\nvec3 blend_difference(vec2 uv, vec3 c1, vec3 c2, float opacity) {\n\treturn opacity*clamp(c2-c1, vec3(0.0), vec3(1.0)) + (1.0-opacity)*c2;\n}\n","inputs":[{"default":"vec4($uv.x, 1.0, 1.0, 1.0)","label":"Source1","name":"s1","type":"rgba"},{"default":"vec4(1.0, $uv.y, 1.0, 1.0)","label":"Source2","name":"s2","type":"rgba"},{"default":"1.0","label":"Opacity","name":"a","type":"f"}],"instance":"","name":"Blend","outputs":[{"rgba":"vec4(blend_$blend_type($uv, $s1($uv).rgb, $s2($uv).rgb, $amount*$a($uv)*$s1($uv).a), min(1.0, $s2($uv).a+$amount*$a($uv)*$s1($uv).a))","type":"rgba"}],"parameters":[{"default":0,"label":"","name":"blend_type","type":"enum","values":[{"name":"Normal","value":"normal"},{"name":"Dissolve","value":"dissolve"},{"name":"Multiply","value":"multiply"},{"name":"Screen","value":"screen"},{"name":"Overlay","value":"overlay"},{"name":"Hard Light","value":"hard_light"},{"name":"Soft Light","value":"soft_light"},{"name":"Burn","value":"burn"},{"name":"Dodge","value":"dodge"},{"name":"Lighten","value":"lighten"},{"name":"Darken","value":"darken"},{"name":"Difference","value":"difference"}]},{"default":0.5,"label":"3:","max":1,"min":0,"name":"amount","step":0,"type":"float"}]}} \ No newline at end of file diff --git a/addons/material_maker/nodes/generic.gd b/addons/material_maker/nodes/generic.gd index 4bac6aa..7f435b9 100644 --- a/addons/material_maker/nodes/generic.gd +++ b/addons/material_maker/nodes/generic.gd @@ -130,7 +130,9 @@ func update_node(): control = HSlider.new() control.min_value = p.min control.max_value = p.max - control.step = 0 if !p.has("step") else p.step + control.step = 0.005 if !p.has("step") else p.step + control.allow_greater = true + control.allow_lesser = true if p.has("default"): control.value = p.default control.rect_min_size.x = 80 diff --git a/addons/material_maker/nodes/mirror.mmg b/addons/material_maker/nodes/mirror.mmg new file mode 100644 index 0000000..60a6250 --- /dev/null +++ b/addons/material_maker/nodes/mirror.mmg @@ -0,0 +1 @@ +{"name":"mirror","node_position":{"x":0,"y":0},"parameters":{"direction":0,"offset":0.605},"shader_model":{"global":"vec2 uvmirror_h(vec2 uv, float offset) {\n\treturn vec2(max(0, abs(uv.x-0.5)-0.5*offset)+0.5, uv.y);\n}\nvec2 uvmirror_v(vec2 uv, float offset) {\n\treturn vec2(uv.x, max(0, abs(uv.y-0.5)-0.5*offset)+0.5);\n}","inputs":[{"default":"vec4($uv, 0, 1)","label":"","name":"i","type":"rgba"}],"instance":"","name":"Mirror","outputs":[{"rgba":"$i(uvmirror_$direction($uv, $offset))","type":"rgba"}],"parameters":[{"default":0,"label":"","name":"direction","type":"enum","values":[{"name":"Horizontal","value":"h"},{"name":"Vertical","value":"v"}]},{"default":0,"label":"","max":1,"min":0,"name":"offset","step":0.005,"type":"float","widget":"spinbox"}]}} \ No newline at end of file diff --git a/addons/material_maker/nodes/skew.mmg b/addons/material_maker/nodes/skew.mmg new file mode 100644 index 0000000..5f9ce5c --- /dev/null +++ b/addons/material_maker/nodes/skew.mmg @@ -0,0 +1 @@ +{"name":"skew","node_position":{"x":0,"y":0},"parameters":{"amount":-0.175,"amout":0,"direction":0,"offset":0.730769},"shader_model":{"global":"vec2 uvskew_h(vec2 uv, float amount) {\n\treturn vec2(uv.x+amount*(uv.y-0.5), uv.y);\n}\nvec2 uvskew_v(vec2 uv, float amount) {\n\treturn vec2(uv.x, uv.y+amount*(uv.x-0.5));\n}","inputs":[{"default":"vec4($uv, 0, 1)","label":"","name":"i","type":"rgba"}],"instance":"","name":"Skew","outputs":[{"rgba":"$i(uvskew_$direction($uv, $amount))","type":"rgba"}],"parameters":[{"default":0,"label":"","name":"direction","type":"enum","values":[{"name":"Horizontal","value":"h"},{"name":"Vertical","value":"v"}]},{"default":0,"label":"","max":3,"min":-3,"name":"amount","step":0.005,"type":"float","widget":"spinbox"}]}} \ No newline at end of file diff --git a/addons/material_maker/nodes/transform.mmg b/addons/material_maker/nodes/transform.mmg new file mode 100644 index 0000000..2897272 --- /dev/null +++ b/addons/material_maker/nodes/transform.mmg @@ -0,0 +1 @@ +{"name":"transform","node_position":{"x":0,"y":0},"parameters":{"repeat":false,"rotate":0,"scale_x":1,"scale_y":1,"translate_x":0.33,"translate_y":0.095},"shader_model":{"global":"vec2 transform(vec2 uv, vec2 translate, float rotate, vec2 scale, bool repeat) {\n \tvec2 rv;\n\tuv -= vec2(0.5);\n\trv.x = cos(rotate)*uv.x + sin(rotate)*uv.y;\n\trv.y = -sin(rotate)*uv.x + cos(rotate)*uv.y;\n\trv /= scale;\n\trv += vec2(0.5);\n\trv -= translate;\n if (repeat) {\n\t\treturn fract(rv);\n\t} else {\n\t\treturn clamp(rv, vec2(0.0), vec2(1.0));\n\t}\t\n}","inputs":[{"default":"vec4($uv, 0.0, 1.0)","label":"","name":"i","type":"rgba"},{"default":"1.0","label":"","name":"tx","type":"f"},{"default":"1.0","label":"","name":"ty","type":"f"},{"default":"1.0","label":"","name":"r","type":"f"},{"default":"1.0","label":"","name":"sx","type":"f"},{"default":"1.0","label":"","name":"sy","type":"f"}],"instance":"","name":"Transform","outputs":[{"rgba":"$i(transform($uv, vec2($translate_x*(2.0*$tx($uv)-1.0), $translate_y*(2.0*$ty($uv)-1.0)), $rotate*(2.0*$r($uv)-1.0), vec2($scale_x*(2.0*$sx($uv)-1.0), $scale_y*(2.0*$sy($uv)-1.0)), $repeat))","type":"rgba"}],"parameters":[{"default":0,"label":"2:Translate X:","max":1,"min":-1,"name":"translate_x","step":0.005,"type":"float","widget":"spinbox"},{"default":0,"label":"Translate Y:","max":1,"min":-1,"name":"translate_y","step":0.005,"type":"float","widget":"spinbox"},{"default":0,"label":"Rotate:","max":720,"min":-720,"name":"rotate","step":0.005,"type":"float","widget":"spinbox"},{"default":1,"label":"Scale X:","max":50,"min":0,"name":"scale_x","step":0.005,"type":"float","widget":"spinbox"},{"default":1,"label":"Scale Y:","max":50,"min":0,"name":"scale_y","step":0.005,"type":"float","widget":"spinbox"},{"default":false,"label":"Repeat:","name":"repeat","type":"boolean"}]}} \ No newline at end of file diff --git a/addons/material_maker/widgets/node_editor/parameter_float.tscn b/addons/material_maker/widgets/node_editor/parameter_float.tscn index 9857edc..7e6ba3e 100644 --- a/addons/material_maker/widgets/node_editor/parameter_float.tscn +++ b/addons/material_maker/widgets/node_editor/parameter_float.tscn @@ -3,232 +3,77 @@ [ext_resource path="res://addons/material_maker/widgets/node_editor/parameter_float.gd" type="Script" id=1] [node name="float" type="HBoxContainer"] - -anchor_left = 0.0 -anchor_top = 0.0 -anchor_right = 0.0 -anchor_bottom = 0.0 margin_right = 547.0 margin_bottom = 24.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 -alignment = 0 script = ExtResource( 1 ) -_sections_unfolded = [ "Visibility" ] -[node name="LabelMin" type="Label" parent="." index="0"] - -anchor_left = 0.0 -anchor_top = 0.0 -anchor_right = 0.0 -anchor_bottom = 0.0 +[node name="LabelMin" type="Label" parent="."] margin_top = 5.0 margin_right = 28.0 margin_bottom = 19.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 = "Min:" -percent_visible = 1.0 -lines_skipped = 0 -max_lines_visible = -1 -[node name="Min" type="SpinBox" parent="." index="1"] - -anchor_left = 0.0 -anchor_top = 0.0 -anchor_right = 0.0 -anchor_bottom = 0.0 +[node name="Min" type="SpinBox" parent="."] margin_left = 32.0 margin_right = 106.0 margin_bottom = 24.0 -rect_pivot_offset = Vector2( 0, 0 ) -rect_clip_content = false -mouse_filter = 0 -mouse_default_cursor_shape = 0 -size_flags_horizontal = 1 -size_flags_vertical = 1 min_value = -65536.0 -max_value = 65535.0 -step = 0.0 -page = 0.0 -value = 0.0 -exp_edit = false -rounded = false -editable = true -prefix = "" -suffix = "" +max_value = 65536.0 +step = 0.005 +allow_greater = true +allow_lesser = true -[node name="LabelMax" type="Label" parent="." index="2"] - -anchor_left = 0.0 -anchor_top = 0.0 -anchor_right = 0.0 -anchor_bottom = 0.0 +[node name="LabelMax" type="Label" parent="."] margin_left = 110.0 margin_top = 5.0 margin_right = 140.0 margin_bottom = 19.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 = "Max:" -percent_visible = 1.0 -lines_skipped = 0 -max_lines_visible = -1 -[node name="Max" type="SpinBox" parent="." index="3"] - -anchor_left = 0.0 -anchor_top = 0.0 -anchor_right = 0.0 -anchor_bottom = 0.0 +[node name="Max" type="SpinBox" parent="."] margin_left = 144.0 margin_right = 218.0 margin_bottom = 24.0 -rect_pivot_offset = Vector2( 0, 0 ) -rect_clip_content = false -mouse_filter = 0 -mouse_default_cursor_shape = 0 -size_flags_horizontal = 1 -size_flags_vertical = 1 min_value = -65536.0 -max_value = 65535.0 -step = 0.0 -page = 0.0 -value = 0.0 -exp_edit = false -rounded = false -editable = true -prefix = "" -suffix = "" +max_value = 65536.0 +step = 0.005 +allow_greater = true +allow_lesser = true -[node name="LabelStep" type="Label" parent="." index="4"] - -anchor_left = 0.0 -anchor_top = 0.0 -anchor_right = 0.0 -anchor_bottom = 0.0 +[node name="LabelStep" type="Label" parent="."] margin_left = 222.0 margin_top = 5.0 margin_right = 254.0 margin_bottom = 19.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 = "Step:" -percent_visible = 1.0 -lines_skipped = 0 -max_lines_visible = -1 -[node name="Step" type="SpinBox" parent="." index="5"] - -anchor_left = 0.0 -anchor_top = 0.0 -anchor_right = 0.0 -anchor_bottom = 0.0 +[node name="Step" type="SpinBox" parent="."] margin_left = 258.0 margin_right = 332.0 margin_bottom = 24.0 -rect_pivot_offset = Vector2( 0, 0 ) -rect_clip_content = false -mouse_filter = 0 -mouse_default_cursor_shape = 0 -size_flags_horizontal = 1 -size_flags_vertical = 1 -min_value = 0.0 -max_value = 65535.0 -step = 0.0 -page = 0.0 -value = 0.0 -exp_edit = false -rounded = false -editable = true -prefix = "" -suffix = "" +step = 0.005 +allow_greater = true +allow_lesser = true -[node name="LabelDefault" type="Label" parent="." index="6"] - -anchor_left = 0.0 -anchor_top = 0.0 -anchor_right = 0.0 -anchor_bottom = 0.0 +[node name="LabelDefault" type="Label" parent="."] margin_left = 336.0 margin_top = 5.0 margin_right = 386.0 margin_bottom = 19.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 = "Default:" -percent_visible = 1.0 -lines_skipped = 0 -max_lines_visible = -1 -[node name="Default" type="SpinBox" parent="." index="7"] - -anchor_left = 0.0 -anchor_top = 0.0 -anchor_right = 0.0 -anchor_bottom = 0.0 +[node name="Default" type="SpinBox" parent="."] margin_left = 390.0 margin_right = 464.0 margin_bottom = 24.0 -rect_pivot_offset = Vector2( 0, 0 ) -rect_clip_content = false -mouse_filter = 0 -mouse_default_cursor_shape = 0 -size_flags_horizontal = 1 -size_flags_vertical = 1 -min_value = 0.0 -max_value = 65535.0 +min_value = -65536.0 +max_value = 65536.0 step = 0.0 -page = 0.0 -value = 0.0 -exp_edit = false -rounded = false -editable = true -prefix = "" -suffix = "" +allow_greater = true +allow_lesser = true -[node name="SpinBox" type="CheckBox" parent="." index="8"] - -anchor_left = 0.0 -anchor_top = 0.0 -anchor_right = 0.0 -anchor_bottom = 0.0 +[node name="SpinBox" type="CheckBox" parent="."] margin_left = 468.0 margin_right = 547.0 margin_bottom = 24.0 -rect_pivot_offset = Vector2( 0, 0 ) -rect_clip_content = false -focus_mode = 2 -mouse_filter = 0 -mouse_default_cursor_shape = 0 -size_flags_horizontal = 1 -size_flags_vertical = 1 -toggle_mode = true -enabled_focus_mode = 2 -shortcut = null -group = null text = "SpinBox" -flat = false -align = 0 - - From d643cecebbe4e7b825714871fba60a2531446557 Mon Sep 17 00:00:00 2001 From: RodZill4 Date: Fri, 13 Sep 2019 08:07:46 +0200 Subject: [PATCH 020/133] Fixed 3d preview and added warp generator --- addons/material_maker/engine/gen_material.gd | 37 +- addons/material_maker/main_window.gd | 7 +- addons/material_maker/nodes/material.tscn | 374 ++---------------- .../nodes/transform/transform.tscn | 15 +- addons/material_maker/nodes/warp.mmg | 1 + addons/material_maker/preview.gd | 2 +- 6 files changed, 66 insertions(+), 370 deletions(-) create mode 100644 addons/material_maker/nodes/warp.mmg diff --git a/addons/material_maker/engine/gen_material.gd b/addons/material_maker/engine/gen_material.gd index fad8969..a7b02ae 100644 --- a/addons/material_maker/engine/gen_material.gd +++ b/addons/material_maker/engine/gen_material.gd @@ -33,7 +33,7 @@ func _ready(): if Engine.editor_hint: texture_list = ADDON_TEXTURE_LIST for t in texture_list: - generated_textures[t.texture] = { shader=null, source=null, texture=null } + generated_textures[t.texture] = null material = SpatialMaterial.new() func generate_material(renderer : MMGenRenderer): @@ -42,14 +42,25 @@ func generate_material(renderer : MMGenRenderer): var status = source.generator.render(source.output_index, renderer, 512) while status is GDScriptFunctionState: status = yield(status, "completed") - print("Render status: "+str(status)) renderer.get_texture().get_data().save_png("res://test.png") material.albedo_texture = load("res://test.png") return material -func initialize(data: Dictionary): - if data.has("name"): - name = data.name +func render_textures(renderer : MMGenRenderer): + for t in texture_list: + var source = get_source(t.port) + var texture = null + if source != null: + var status = source.generator.render(source.output_index, renderer, 512) + while status is GDScriptFunctionState: + status = yield(status, "completed") + texture = ImageTexture.new() + texture.create_from_image(renderer.get_texture().get_data()) + generated_textures[t.texture] = texture + +func update_materials(material_list): + for m in material_list: + update_spatial_material(m) func get_generated_texture(slot, file_prefix = null): if file_prefix != null: @@ -59,14 +70,14 @@ func get_generated_texture(slot, file_prefix = null): else: return null else: - return generated_textures[slot].texture + return generated_textures[slot] func update_spatial_material(m, file_prefix = null): var texture - m.albedo_color = parameters.albedo_color + m.albedo_color = Color(1, 1, 1)#parameters.albedo_color m.albedo_texture = get_generated_texture("albedo", file_prefix) - m.metallic = parameters.metallic - m.roughness = parameters.roughness + m.metallic = 1#parameters.metallic + m.roughness = 1#parameters.roughness if Engine.editor_hint: texture = get_generated_texture("mrao", file_prefix) m.metallic_texture = texture @@ -79,7 +90,7 @@ func update_spatial_material(m, file_prefix = null): texture = get_generated_texture("emission", file_prefix) if texture != null: m.emission_enabled = true - m.emission_energy = parameters.emission_energy + #m.emission_energy = parameters.emission_energy m.emission_texture = texture else: m.emission_enabled = false @@ -92,7 +103,7 @@ func update_spatial_material(m, file_prefix = null): if Engine.editor_hint: if (generated_textures.mrao.mask & (1 << 2)) != 0: m.ao_enabled = true - m.ao_light_affect = parameters.ao_light_affect + #m.ao_light_affect = parameters.ao_light_affect m.ao_texture = m.metallic_texture m.ao_texture_channel = SpatialMaterial.TEXTURE_CHANNEL_BLUE else: @@ -101,14 +112,14 @@ func update_spatial_material(m, file_prefix = null): texture = get_generated_texture("ambient_occlusion", file_prefix) if texture != null: m.ao_enabled = true - m.ao_light_affect = parameters.ao_light_affect + #m.ao_light_affect = parameters.ao_light_affect m.ao_texture = texture else: m.ao_enabled = false texture = get_generated_texture("depth_map", file_prefix) if texture != null: m.depth_enabled = true - m.depth_scale = parameters.depth_scale + #m.depth_scale = parameters.depth_scale m.depth_texture = texture else: m.depth_enabled = false diff --git a/addons/material_maker/main_window.gd b/addons/material_maker/main_window.gd index 125aea8..4aba213 100644 --- a/addons/material_maker/main_window.gd +++ b/addons/material_maker/main_window.gd @@ -312,9 +312,12 @@ func _on_LoadRecent_id_pressed(id): # Preview func update_preview(): - var material_node = $VBoxContainer/HBoxContainer/Projects.get_current_tab_control().get_node("Material") + var material_node = $VBoxContainer/HBoxContainer/Projects.get_current_tab_control().get_node("node_Material") if material_node != null: - material_node.update_materials($VBoxContainer/HBoxContainer/VBoxContainer/Preview.get_materials()) + var status = material_node.generator.render_textures(renderer) + while status is GDScriptFunctionState: + status = yield(status, "completed") + material_node.generator.update_materials($VBoxContainer/HBoxContainer/VBoxContainer/Preview.get_materials()) update_preview_2d() func update_preview_2d(node = null): diff --git a/addons/material_maker/nodes/material.tscn b/addons/material_maker/nodes/material.tscn index 3f4b924..5b0582b 100644 --- a/addons/material_maker/nodes/material.tscn +++ b/addons/material_maker/nodes/material.tscn @@ -4,27 +4,12 @@ [sub_resource type="Theme" id=1] -[node name="Material" type="GraphNode" index="0"] -anchor_left = 0.0 -anchor_top = 0.0 -anchor_right = 0.0 -anchor_bottom = 0.0 +[node name="Material" type="GraphNode"] margin_right = 230.0 margin_bottom = 199.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 = "Material" -offset = Vector2( 0, 0 ) -show_close = false -resizable = false -selected = false -comment = false -overlay = 0 slot/0/left_enabled = false slot/0/left_type = 0 slot/0/left_color = Color( 0.411765, 1, 0.388235, 0.352941 ) @@ -74,478 +59,165 @@ slot/7/right_enabled = false slot/7/right_type = 0 slot/7/right_color = Color( 0.494118, 0.494118, 1, 1 ) script = ExtResource( 1 ) -_sections_unfolded = [ "Theme", "slot", "slot/0", "slot/1", "slot/2", "slot/5", "slot/7" ] -[node name="resolution" type="OptionButton" parent="." index="0"] -anchor_left = 0.0 -anchor_top = 0.0 -anchor_right = 0.0 -anchor_bottom = 0.0 +[node name="resolution" type="OptionButton" parent="."] margin_left = 16.0 margin_top = 24.0 margin_right = 214.0 margin_bottom = 44.0 -rect_pivot_offset = Vector2( 0, 0 ) -rect_clip_content = false -focus_mode = 2 -mouse_filter = 0 -mouse_default_cursor_shape = 0 -size_flags_horizontal = 1 -size_flags_vertical = 1 -toggle_mode = false -action_mode = 0 -enabled_focus_mode = 2 -shortcut = null -group = null text = "512x512" -flat = false -align = 0 items = [ "256x256", null, false, 0, null, "512x512", null, false, 1, null, "1024x1024", null, false, 2, null, "2048x2048", null, false, -1, null ] selected = 1 -[node name="Albedo" type="HBoxContainer" parent="." index="1"] -anchor_left = 0.0 -anchor_top = 0.0 -anchor_right = 0.0 -anchor_bottom = 0.0 +[node name="Albedo" type="HBoxContainer" parent="."] margin_left = 16.0 margin_top = 44.0 margin_right = 214.0 margin_bottom = 64.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 -alignment = 0 -[node name="Label" type="Label" parent="Albedo" index="0"] -anchor_left = 0.0 -anchor_top = 0.0 -anchor_right = 0.0 -anchor_bottom = 0.0 +[node name="Label" type="Label" parent="Albedo"] margin_top = 3.0 margin_right = 114.0 margin_bottom = 17.0 -rect_pivot_offset = Vector2( 0, 0 ) -rect_clip_content = false -mouse_filter = 2 -mouse_default_cursor_shape = 0 size_flags_horizontal = 3 -size_flags_vertical = 4 text = "Albedo" -percent_visible = 1.0 -lines_skipped = 0 -max_lines_visible = -1 -_sections_unfolded = [ "Size Flags" ] -[node name="albedo_color" type="ColorPickerButton" parent="Albedo" index="1"] -anchor_left = 0.0 -anchor_top = 0.0 -anchor_right = 0.0 -anchor_bottom = 0.0 +[node name="albedo_color" type="ColorPickerButton" parent="Albedo"] margin_left = 118.0 margin_right = 198.0 margin_bottom = 20.0 rect_min_size = Vector2( 80, 0 ) -rect_pivot_offset = Vector2( 0, 0 ) -rect_clip_content = false -focus_mode = 2 -mouse_filter = 0 -mouse_default_cursor_shape = 0 -size_flags_horizontal = 1 -size_flags_vertical = 1 -toggle_mode = false -enabled_focus_mode = 2 -shortcut = null -group = null -flat = false -align = 1 color = Color( 1, 1, 1, 1 ) edit_alpha = false -_sections_unfolded = [ "Rect", "Size Flags" ] -[node name="Metallic" type="HBoxContainer" parent="." index="2"] +[node name="Metallic" type="HBoxContainer" parent="."] editor/display_folded = true -anchor_left = 0.0 -anchor_top = 0.0 -anchor_right = 0.0 -anchor_bottom = 0.0 margin_left = 16.0 margin_top = 65.0 margin_right = 214.0 margin_bottom = 89.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 -alignment = 0 -[node name="Label" type="Label" parent="Metallic" index="0"] -anchor_left = 0.0 -anchor_top = 0.0 -anchor_right = 0.0 -anchor_bottom = 0.0 +[node name="Label" type="Label" parent="Metallic"] margin_top = 5.0 margin_right = 120.0 margin_bottom = 19.0 -rect_pivot_offset = Vector2( 0, 0 ) -rect_clip_content = false -mouse_filter = 2 -mouse_default_cursor_shape = 0 size_flags_horizontal = 3 -size_flags_vertical = 4 text = "Metallic" -percent_visible = 1.0 -lines_skipped = 0 -max_lines_visible = -1 -_sections_unfolded = [ "Size Flags" ] -[node name="metallic" type="SpinBox" parent="Metallic" index="1"] -anchor_left = 0.0 -anchor_top = 0.0 -anchor_right = 0.0 -anchor_bottom = 0.0 +[node name="metallic" type="SpinBox" parent="Metallic"] margin_left = 124.0 margin_right = 198.0 margin_bottom = 24.0 -rect_pivot_offset = Vector2( 0, 0 ) -rect_clip_content = false -mouse_filter = 0 -mouse_default_cursor_shape = 0 -size_flags_horizontal = 1 -size_flags_vertical = 1 -min_value = 0.0 max_value = 1.0 step = 0.05 -page = 0.0 value = 1.0 -exp_edit = false -rounded = false -editable = true -prefix = "" -suffix = "" -_sections_unfolded = [ "Rect" ] -[node name="Roughness" type="HBoxContainer" parent="." index="3"] +[node name="Roughness" type="HBoxContainer" parent="."] editor/display_folded = true -anchor_left = 0.0 -anchor_top = 0.0 -anchor_right = 0.0 -anchor_bottom = 0.0 margin_left = 16.0 margin_top = 90.0 margin_right = 214.0 margin_bottom = 114.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 -alignment = 0 -[node name="Label" type="Label" parent="Roughness" index="0"] -anchor_left = 0.0 -anchor_top = 0.0 -anchor_right = 0.0 -anchor_bottom = 0.0 +[node name="Label" type="Label" parent="Roughness"] margin_top = 5.0 margin_right = 120.0 margin_bottom = 19.0 -rect_pivot_offset = Vector2( 0, 0 ) -rect_clip_content = false -mouse_filter = 2 -mouse_default_cursor_shape = 0 size_flags_horizontal = 3 -size_flags_vertical = 4 text = "Roughness" -percent_visible = 1.0 -lines_skipped = 0 -max_lines_visible = -1 -_sections_unfolded = [ "Size Flags" ] -[node name="roughness" type="SpinBox" parent="Roughness" index="1"] -anchor_left = 0.0 -anchor_top = 0.0 -anchor_right = 0.0 -anchor_bottom = 0.0 +[node name="roughness" type="SpinBox" parent="Roughness"] margin_left = 124.0 margin_right = 198.0 margin_bottom = 24.0 -rect_pivot_offset = Vector2( 0, 0 ) -rect_clip_content = false -mouse_filter = 0 -mouse_default_cursor_shape = 0 -size_flags_horizontal = 1 -size_flags_vertical = 1 -min_value = 0.0 max_value = 1.0 step = 0.05 -page = 0.0 value = 1.0 -exp_edit = false -rounded = false -editable = true -prefix = "" -suffix = "" -_sections_unfolded = [ "Rect" ] -[node name="Emission" type="HBoxContainer" parent="." index="4"] +[node name="Emission" type="HBoxContainer" parent="."] editor/display_folded = true -anchor_left = 0.0 -anchor_top = 0.0 -anchor_right = 0.0 -anchor_bottom = 0.0 margin_left = 16.0 margin_top = 115.0 margin_right = 214.0 margin_bottom = 139.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 -alignment = 0 -[node name="Label" type="Label" parent="Emission" index="0"] -anchor_left = 0.0 -anchor_top = 0.0 -anchor_right = 0.0 -anchor_bottom = 0.0 +[node name="Label" type="Label" parent="Emission"] margin_top = 5.0 margin_right = 120.0 margin_bottom = 19.0 -rect_pivot_offset = Vector2( 0, 0 ) -rect_clip_content = false -mouse_filter = 2 -mouse_default_cursor_shape = 0 size_flags_horizontal = 3 -size_flags_vertical = 4 text = "Emission" -percent_visible = 1.0 -lines_skipped = 0 -max_lines_visible = -1 -_sections_unfolded = [ "Size Flags" ] -[node name="emission_energy" type="SpinBox" parent="Emission" index="1"] -anchor_left = 0.0 -anchor_top = 0.0 -anchor_right = 0.0 -anchor_bottom = 0.0 +[node name="emission_energy" type="SpinBox" parent="Emission"] margin_left = 124.0 margin_right = 198.0 margin_bottom = 24.0 -rect_pivot_offset = Vector2( 0, 0 ) -rect_clip_content = false -mouse_filter = 0 -mouse_default_cursor_shape = 0 -size_flags_horizontal = 1 -size_flags_vertical = 1 -min_value = 0.0 max_value = 5.0 step = 0.05 -page = 0.0 value = 1.0 -exp_edit = false -rounded = false -editable = true -prefix = "" -suffix = "" -_sections_unfolded = [ "Rect" ] -[node name="NormalMap" type="HBoxContainer" parent="." index="5"] +[node name="NormalMap" type="HBoxContainer" parent="."] editor/display_folded = true -anchor_left = 0.0 -anchor_top = 0.0 -anchor_right = 0.0 -anchor_bottom = 0.0 margin_left = 16.0 margin_top = 140.0 margin_right = 214.0 margin_bottom = 164.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 -alignment = 0 -[node name="Label" type="Label" parent="NormalMap" index="0"] -anchor_left = 0.0 -anchor_top = 0.0 -anchor_right = 0.0 -anchor_bottom = 0.0 +[node name="Label" type="Label" parent="NormalMap"] margin_top = 5.0 margin_right = 120.0 margin_bottom = 19.0 -rect_pivot_offset = Vector2( 0, 0 ) -rect_clip_content = false -mouse_filter = 2 -mouse_default_cursor_shape = 0 size_flags_horizontal = 3 -size_flags_vertical = 4 text = "Normal map" -percent_visible = 1.0 -lines_skipped = 0 -max_lines_visible = -1 -_sections_unfolded = [ "Size Flags" ] -[node name="normal_scale" type="SpinBox" parent="NormalMap" index="1"] -anchor_left = 0.0 -anchor_top = 0.0 -anchor_right = 0.0 -anchor_bottom = 0.0 +[node name="normal_scale" type="SpinBox" parent="NormalMap"] margin_left = 124.0 margin_right = 198.0 margin_bottom = 24.0 -rect_pivot_offset = Vector2( 0, 0 ) -rect_clip_content = false -mouse_filter = 0 -mouse_default_cursor_shape = 0 -size_flags_horizontal = 1 -size_flags_vertical = 1 -min_value = 0.0 max_value = 5.0 step = 0.05 -page = 0.0 value = 1.0 -exp_edit = false -rounded = false -editable = true -prefix = "" -suffix = "" -_sections_unfolded = [ "Rect" ] -[node name="AmbientOcclusion" type="HBoxContainer" parent="." index="6"] +[node name="AmbientOcclusion" type="HBoxContainer" parent="."] editor/display_folded = true -anchor_left = 0.0 -anchor_top = 0.0 -anchor_right = 0.0 -anchor_bottom = 0.0 margin_left = 16.0 margin_top = 165.0 margin_right = 214.0 margin_bottom = 189.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 -alignment = 0 -[node name="Label" type="Label" parent="AmbientOcclusion" index="0"] -anchor_left = 0.0 -anchor_top = 0.0 -anchor_right = 0.0 -anchor_bottom = 0.0 +[node name="Label" type="Label" parent="AmbientOcclusion"] margin_top = 5.0 margin_right = 120.0 margin_bottom = 19.0 -rect_pivot_offset = Vector2( 0, 0 ) -rect_clip_content = false -mouse_filter = 2 -mouse_default_cursor_shape = 0 size_flags_horizontal = 3 -size_flags_vertical = 4 text = "Ambient occlusion" -percent_visible = 1.0 -lines_skipped = 0 -max_lines_visible = -1 -_sections_unfolded = [ "Size Flags" ] -[node name="ao_light_affect" type="SpinBox" parent="AmbientOcclusion" index="1"] -anchor_left = 0.0 -anchor_top = 0.0 -anchor_right = 0.0 -anchor_bottom = 0.0 +[node name="ao_light_affect" type="SpinBox" parent="AmbientOcclusion"] margin_left = 124.0 margin_right = 198.0 margin_bottom = 24.0 -rect_pivot_offset = Vector2( 0, 0 ) -rect_clip_content = false -mouse_filter = 0 -mouse_default_cursor_shape = 0 -size_flags_horizontal = 1 -size_flags_vertical = 1 -min_value = 0.0 max_value = 5.0 step = 0.05 -page = 0.0 value = 1.0 -exp_edit = false -rounded = false -editable = true -prefix = "" -suffix = "" -_sections_unfolded = [ "Rect" ] -[node name="DepthMap" type="HBoxContainer" parent="." index="7"] +[node name="DepthMap" type="HBoxContainer" parent="."] editor/display_folded = true -anchor_left = 0.0 -anchor_top = 0.0 -anchor_right = 0.0 -anchor_bottom = 0.0 margin_left = 16.0 margin_top = 190.0 margin_right = 214.0 margin_bottom = 214.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 -alignment = 0 -[node name="Label" type="Label" parent="DepthMap" index="0"] -anchor_left = 0.0 -anchor_top = 0.0 -anchor_right = 0.0 -anchor_bottom = 0.0 +[node name="Label" type="Label" parent="DepthMap"] margin_top = 5.0 margin_right = 120.0 margin_bottom = 19.0 -rect_pivot_offset = Vector2( 0, 0 ) -rect_clip_content = false -mouse_filter = 2 -mouse_default_cursor_shape = 0 size_flags_horizontal = 3 -size_flags_vertical = 4 text = "Depth map" -percent_visible = 1.0 -lines_skipped = 0 -max_lines_visible = -1 -_sections_unfolded = [ "Size Flags" ] -[node name="depth_scale" type="SpinBox" parent="DepthMap" index="1"] -anchor_left = 0.0 -anchor_top = 0.0 -anchor_right = 0.0 -anchor_bottom = 0.0 +[node name="depth_scale" type="SpinBox" parent="DepthMap"] margin_left = 124.0 margin_right = 198.0 margin_bottom = 24.0 -rect_pivot_offset = Vector2( 0, 0 ) -rect_clip_content = false -mouse_filter = 0 -mouse_default_cursor_shape = 0 -size_flags_horizontal = 1 -size_flags_vertical = 1 -min_value = 0.0 max_value = 5.0 step = 0.05 -page = 0.0 value = 1.0 -exp_edit = false -rounded = false -editable = true -prefix = "" -suffix = "" -_sections_unfolded = [ "Rect" ] diff --git a/addons/material_maker/nodes/transform/transform.tscn b/addons/material_maker/nodes/transform/transform.tscn index 5c0bd21..b4aa0cd 100644 --- a/addons/material_maker/nodes/transform/transform.tscn +++ b/addons/material_maker/nodes/transform/transform.tscn @@ -1,8 +1,14 @@ -[gd_scene load_steps=3 format=2] +[gd_scene load_steps=6 format=2] [ext_resource path="res://addons/material_maker/nodes/transform/transform.gd" type="Script" id=1] -[sub_resource type="Theme" id=1] +[sub_resource type="StyleBoxEmpty" id=1] + +[sub_resource type="StyleBoxEmpty" id=2] + +[sub_resource type="StyleBoxEmpty" id=3] + +[sub_resource type="StyleBoxEmpty" id=4] [node name="Transform" type="GraphNode"] margin_left = 1.0 @@ -10,7 +16,10 @@ margin_top = 1.0 margin_right = 185.0 margin_bottom = 179.0 mouse_filter = 1 -theme = SubResource( 1 ) +custom_styles/position = SubResource( 1 ) +custom_styles/defaultfocus = SubResource( 2 ) +custom_styles/breakpoint = SubResource( 3 ) +custom_styles/defaultframe = SubResource( 4 ) title = "Transform" show_close = true slot/0/left_enabled = true diff --git a/addons/material_maker/nodes/warp.mmg b/addons/material_maker/nodes/warp.mmg new file mode 100644 index 0000000..ae92e0c --- /dev/null +++ b/addons/material_maker/nodes/warp.mmg @@ -0,0 +1 @@ +{"name":"warp","node_position":{"x":0,"y":0},"parameters":{"amount":0.2,"eps":0.045,"epsilon":0},"shader_model":{"global":"","inputs":[{"default":"vec4(sin($uv.x*20.0)*0.5+0.5, sin($uv.y*20.0)*0.5+0.5, 0, 1)","label":"","name":"in","type":"rgba"},{"default":"0.0","label":"","name":"d","type":"f"}],"instance":"","name":"Warp","outputs":[{"rgba":"$in($uv+$amount*vec2($d(fract($uv+vec2($eps, 0.0)))-$d(fract($uv-vec2($eps, 0.0))), $d(fract($uv+vec2(0.0, $eps)))-$d(fract($uv-vec2(0.0, $eps)))))","type":"rgba"}],"parameters":[{"default":0,"label":"","max":1,"min":0,"name":"amount","step":0.005,"type":"float","widget":"spinbox"},{"default":0,"label":"","max":0.2,"min":0.005,"name":"eps","step":0.005,"type":"float","widget":"spinbox"}]}} \ No newline at end of file diff --git a/addons/material_maker/preview.gd b/addons/material_maker/preview.gd index c3aa276..bd97705 100644 --- a/addons/material_maker/preview.gd +++ b/addons/material_maker/preview.gd @@ -43,7 +43,7 @@ func _on_Preview_resized(): $Preview2D.rect_size = Vector2(64, 64) func _on_Preview2D_gui_input(ev : InputEvent): - if ev is InputEventMouseButton && ev.button_index == 1 && ev.pressed: + if ev is InputEventMouseButton and ev.button_index == 1 and ev.pressed: preview_maximized = !preview_maximized _on_Preview_resized() From f2807f4eff13dcdd29710d33807c47a20b00e784 Mon Sep 17 00:00:00 2001 From: RodZill4 Date: Sat, 14 Sep 2019 09:14:27 +0200 Subject: [PATCH 021/133] Implemented lazy buffers update and started refactoring material node. --- addons/material_maker/engine/gen_base.gd | 23 ++++++++++++++++- addons/material_maker/engine/gen_buffer.gd | 8 +++++- addons/material_maker/engine/gen_graph.gd | 10 +++++++- addons/material_maker/engine/gen_material.gd | 25 ++++++++++++++++--- addons/material_maker/graph_edit.gd | 1 - addons/material_maker/nodes/generic.gd | 8 +++--- .../{material.tscn => material_old.tscn} | 0 7 files changed, 63 insertions(+), 12 deletions(-) rename addons/material_maker/nodes/{material.tscn => material_old.tscn} (100%) diff --git a/addons/material_maker/engine/gen_base.gd b/addons/material_maker/engine/gen_base.gd index 0ca3742..4aa13ce 100644 --- a/addons/material_maker/engine/gen_base.gd +++ b/addons/material_maker/engine/gen_base.gd @@ -6,6 +6,17 @@ class_name MMGenBase Base class for texture generators, that defines their API """ +class InputPort: + var generator : MMGenBase = null + var input_index : int = 0 + + func _init(g : MMGenBase, i : int): + generator = g + input_index = i + + func to_str(): + return generator.name+".in("+str(input_index)+")" + class OutputPort: var generator : MMGenBase = null var output_index : int = 0 @@ -15,7 +26,7 @@ class OutputPort: output_index = o func to_str(): - return generator.name+"("+str(output_index)+")" + return generator.name+".out("+str(output_index)+")" var position : Vector2 = Vector2(0, 0) var model = null @@ -46,6 +57,13 @@ func get_parameter_defs(): func set_parameter(n : String, v): parameters[n] = v + source_changed(0) + +func source_changed(input_index : int): + for i in range(get_output_defs().size()): + var target = get_target(i) + if target != null: + target.generator.source_changed(target.input_index) func get_input_defs(): return [] @@ -55,6 +73,9 @@ func get_output_defs(): func get_source(input_index : int): return get_parent().get_port_source(name, input_index) + +func get_target(output_index : int): + return get_parent().get_port_target(name, output_index) func get_input_shader(input_index : int): var source = get_source(input_index) diff --git a/addons/material_maker/engine/gen_buffer.gd b/addons/material_maker/engine/gen_buffer.gd index b7f0f90..d19e207 100644 --- a/addons/material_maker/engine/gen_buffer.gd +++ b/addons/material_maker/engine/gen_buffer.gd @@ -7,6 +7,8 @@ Texture generator buffers, that render their input in a specific resolution and This is useful when using generators that sample their inputs several times (such as convolutions) """ +var updated : bool = false + func _ready(): if !parameters.has("size"): parameters.size = 4 @@ -26,9 +28,12 @@ func get_input_defs(): func get_output_defs(): return [ { type="rgba" } ] +func source_changed(input_port_index): + updated = false + func _get_shader_code(uv : String, output_index : int, context : MMGenContext): var source = get_source(0) - if source != null: + if source != null and !updated: var status = source.generator.render(source.output_index, context.renderer, pow(2, 4+parameters.size)) while status is GDScriptFunctionState: status = yield(status, "completed") @@ -36,6 +41,7 @@ func _get_shader_code(uv : String, output_index : int, context : MMGenContext): var image : Image = context.renderer.get_texture().get_data() texture.create_from_image(image) texture.flags = 0 + updated = true var rv = ._get_shader_code(uv, output_index, context) while rv is GDScriptFunctionState: rv = yield(rv, "completed") diff --git a/addons/material_maker/engine/gen_graph.gd b/addons/material_maker/engine/gen_graph.gd index 6aa2844..6ed6299 100644 --- a/addons/material_maker/engine/gen_graph.gd +++ b/addons/material_maker/engine/gen_graph.gd @@ -12,7 +12,15 @@ func get_port_source(gen_name: String, input_index: int) -> OutputPort: if c.to == gen_name and c.to_port == input_index: var src_gen = get_node(c.from) if src_gen != null: - return OutputPort.new(get_node(c.from), c.from_port) + return OutputPort.new(src_gen, c.from_port) + return null + +func get_port_target(gen_name: String, input_index: int) -> InputPort: + for c in connections: + if c.from == gen_name and c.from_port == input_index: + var tgt_gen = get_node(c.to) + if tgt_gen != null: + return InputPort.new(tgt_gen, c.to_port) return null func remove_generator(generator : MMGenBase): diff --git a/addons/material_maker/engine/gen_material.gd b/addons/material_maker/engine/gen_material.gd index a7b02ae..77d6f5d 100644 --- a/addons/material_maker/engine/gen_material.gd +++ b/addons/material_maker/engine/gen_material.gd @@ -28,6 +28,22 @@ const ADDON_TEXTURE_LIST = [ func get_type(): return "material" +func get_parameter_defs(): + return [ + { name="albedo_color", label="Albedo", type="color", default={ r=1.0, g=1.0, b=1.0, a=1.0} }, + { name="metallic", label="Metallic", type="float", min=0.0, max=1.0, default=1.0 }, + { name="roughness", label="Roughness", type="float", min=0.0, max=1.0, default=1.0 }, + { name="emission_energy", label="Emission", type="float", min=0.0, max=8.0, default=1.0 } + ] + +func get_input_defs(): + return [ + { name="albedo_texture", label="", type="rgb" }, + { name="metallic_texture", label="", type="f" }, + { name="roughness_texture", label="", type="f" }, + { name="emission_texture", label="", type="rgb" } + ] + func _ready(): texture_list = TEXTURE_LIST if Engine.editor_hint: @@ -35,6 +51,7 @@ func _ready(): for t in texture_list: generated_textures[t.texture] = null material = SpatialMaterial.new() + model = material func generate_material(renderer : MMGenRenderer): var source = get_source(0) @@ -74,10 +91,10 @@ func get_generated_texture(slot, file_prefix = null): func update_spatial_material(m, file_prefix = null): var texture - m.albedo_color = Color(1, 1, 1)#parameters.albedo_color + m.albedo_color = parameters.albedo_color m.albedo_texture = get_generated_texture("albedo", file_prefix) - m.metallic = 1#parameters.metallic - m.roughness = 1#parameters.roughness + m.metallic = parameters.metallic + m.roughness = parameters.roughness if Engine.editor_hint: texture = get_generated_texture("mrao", file_prefix) m.metallic_texture = texture @@ -90,7 +107,7 @@ func update_spatial_material(m, file_prefix = null): texture = get_generated_texture("emission", file_prefix) if texture != null: m.emission_enabled = true - #m.emission_energy = parameters.emission_energy + m.emission_energy = parameters.emission_energy m.emission_texture = texture else: m.emission_enabled = false diff --git a/addons/material_maker/graph_edit.gd b/addons/material_maker/graph_edit.gd index c29dd6e..e8efb4a 100644 --- a/addons/material_maker/graph_edit.gd +++ b/addons/material_maker/graph_edit.gd @@ -64,7 +64,6 @@ func remove_node(node): # Global operations on graph func update_tab_title(): - print("update_tab_title") if !get_parent().has_method("set_tab_title"): print("no set_tab_title method") return diff --git a/addons/material_maker/nodes/generic.gd b/addons/material_maker/nodes/generic.gd index 7f435b9..fc83735 100644 --- a/addons/material_maker/nodes/generic.gd +++ b/addons/material_maker/nodes/generic.gd @@ -56,19 +56,19 @@ func update_shaders(): get_parent().send_changed_signal() func _on_text_changed(new_text, variable): - generator.parameters[variable] = float(new_text) + generator.set_parameter(variable, float(new_text)) update_shaders() func _on_value_changed(new_value, variable): - generator.parameters[variable] = new_value + generator.set_parameter(variable, new_value) update_shaders() func _on_color_changed(new_color, variable): - generator.parameters[variable] = new_color + generator.set_parameter(variable, new_color) update_shaders() func _on_gradient_changed(new_gradient, variable): - generator.parameters[variable] = new_gradient + generator.set_parameter(variable, new_gradient) update_shaders() func update_node(): diff --git a/addons/material_maker/nodes/material.tscn b/addons/material_maker/nodes/material_old.tscn similarity index 100% rename from addons/material_maker/nodes/material.tscn rename to addons/material_maker/nodes/material_old.tscn From caf682de8834f2ad4d2f073faa8608561f0e9ad5 Mon Sep 17 00:00:00 2001 From: RodZill4 Date: Mon, 16 Sep 2019 20:45:47 +0200 Subject: [PATCH 022/133] updated generator naming in shaders and added basic convolutions --- addons/material_maker/engine/gen_base.gd | 3 +- .../material_maker/engine/gen_convolution.gd | 60 +++++++++++++++++++ addons/material_maker/engine/gen_material.gd | 21 ++++--- addons/material_maker/engine/gen_shader.gd | 12 ++-- addons/material_maker/engine/gen_texture.gd | 7 ++- addons/material_maker/engine/loader.gd | 3 + addons/material_maker/main_window.tscn | 2 + 7 files changed, 89 insertions(+), 19 deletions(-) diff --git a/addons/material_maker/engine/gen_base.gd b/addons/material_maker/engine/gen_base.gd index 4aa13ce..7d0db5e 100644 --- a/addons/material_maker/engine/gen_base.gd +++ b/addons/material_maker/engine/gen_base.gd @@ -140,12 +140,11 @@ func _serialize(data): return data func serialize(): - var rv = { name=name, parameters={}, node_position={ x=position.x, y=position.y } } + var rv = { name=name, type=get_type(), parameters={}, node_position={ x=position.x, y=position.y } } for p in parameters.keys(): rv.parameters[p] = MMType.serialize_value(parameters[p]) if model != null: rv.type = model else: rv = _serialize(rv) - return rv \ No newline at end of file diff --git a/addons/material_maker/engine/gen_convolution.gd b/addons/material_maker/engine/gen_convolution.gd index aae09ef..59e1e5d 100644 --- a/addons/material_maker/engine/gen_convolution.gd +++ b/addons/material_maker/engine/gen_convolution.gd @@ -1,3 +1,63 @@ tool extends MMGenBase class_name MMGenConvolution + +var convolution_params : Dictionary = {} + +func get_type(): + return "shader" + +func get_type_name(): + if convolution_params.has("name"): + return convolution_params.name + return .get_type_name() + +func get_parameter_defs(): + return [ { name="size", type="size", first=4, last=11, default=4 } ] + +func get_input_defs(): + return [ { name="in", type=convolution_params.input_type } ] + +func get_output_defs(): + return [ { type=convolution_params.output_type } ] + +func set_convolution_params(data: Dictionary): + convolution_params = data + +func _get_shader_code(uv : String, output_index : int, context : MMGenContext): + var genname = "o"+str(get_instance_id()) + var epsilon = 1.0/pow(2, 4+parameters.size) + var types = { "rgba": { type="vec4", init="vec4(0.0)" }, "rgb": { type="vec3", init="vec3(0.0)" }, "f": { type="float", init="0.0" } } + var rv = { defs="", code="", textures={} } + var source = get_source(0) + if source == null: + return rv + var variant_index = context.get_variant(self, uv) + if variant_index == -1: + variant_index = context.get_variant(self, uv) + rv.code += "%s %s_%d = %s;\n" % [ types[convolution_params.output_type].type, genname, variant_index, types[convolution_params.output_type].init ] + for dy in range(-convolution_params.y, convolution_params.y+1): + for dx in range(-convolution_params.x, convolution_params.x+1): + var coef = convolution_params.matrix[dy+convolution_params.y][dx+convolution_params.x] + if typeof(coef) == TYPE_INT: + coef = float(coef) + if typeof(coef) == TYPE_REAL: + coef = Vector3(coef, coef, coef) + if typeof(coef) == TYPE_ARRAY: + coef = Vector3(coef[0], coef[1], coef[2]) + var coef_str = "vec3(%.9f,%.9f,%.9f)" % [ coef.x, coef.y, coef.z ] + var uv_str = "((%s)+vec2(%.9f,%.9f))" % [ uv, dx*epsilon, dy*epsilon ] + var src_code = source.generator.get_shader_code(uv_str, source.output_index, context) + while src_code is GDScriptFunctionState: + src_code = yield(src_code, "completed") + rv.defs += src_code.defs + rv.code += src_code.code + rv.code += "%s_%d += %s*%s;\n" % [ genname, variant_index, coef_str, src_code[convolution_params.input_type] ] + for t in src_code.textures.keys(): + rv.textures[t] = src_code.textures[t] + rv.rgb = "%s_%d" % [ genname, variant_index ] + return rv + +func _serialize(data): + data.convolution_params = convolution_params + return data diff --git a/addons/material_maker/engine/gen_material.gd b/addons/material_maker/engine/gen_material.gd index 77d6f5d..abd407f 100644 --- a/addons/material_maker/engine/gen_material.gd +++ b/addons/material_maker/engine/gen_material.gd @@ -12,22 +12,25 @@ const TEXTURE_LIST = [ { port=1, texture="metallic" }, { port=2, texture="roughness" }, { port=3, texture="emission" }, - { port=4, texture="normal_map" }, + { port=4, texture="normal_texture" }, { port=5, texture="ambient_occlusion" }, - { port=6, texture="depth_map" } + { port=6, texture="depth_texture" } ] const ADDON_TEXTURE_LIST = [ { port=0, texture="albedo" }, { port=3, texture="emission" }, - { port=4, texture="normal_map" }, + { port=4, texture="normal_texture" }, { ports=[1, 2, 5], default_values=["0.0", "1.0", "1.0"], texture="mrao" }, - { port=6, texture="depth_map" } + { port=6, texture="depth_texture" } ] func get_type(): return "material" +func get_type_name(): + return "Material" + func get_parameter_defs(): return [ { name="albedo_color", label="Albedo", type="color", default={ r=1.0, g=1.0, b=1.0, a=1.0} }, @@ -41,7 +44,9 @@ func get_input_defs(): { name="albedo_texture", label="", type="rgb" }, { name="metallic_texture", label="", type="f" }, { name="roughness_texture", label="", type="f" }, - { name="emission_texture", label="", type="rgb" } + { name="emission_texture", label="", type="rgb" }, + { name="normal_texture", label="", type="rgb" }, + { name="depth_texture", label="", type="f" } ] func _ready(): @@ -51,7 +56,6 @@ func _ready(): for t in texture_list: generated_textures[t.texture] = null material = SpatialMaterial.new() - model = material func generate_material(renderer : MMGenRenderer): var source = get_source(0) @@ -111,7 +115,7 @@ func update_spatial_material(m, file_prefix = null): m.emission_texture = texture else: m.emission_enabled = false - texture = get_generated_texture("normal_map", file_prefix) + texture = get_generated_texture("normal_texture", file_prefix) if texture != null: m.normal_enabled = true m.normal_texture = texture @@ -133,7 +137,7 @@ func update_spatial_material(m, file_prefix = null): m.ao_texture = texture else: m.ao_enabled = false - texture = get_generated_texture("depth_map", file_prefix) + texture = get_generated_texture("depth_texture", file_prefix) if texture != null: m.depth_enabled = true #m.depth_scale = parameters.depth_scale @@ -159,5 +163,4 @@ func export_textures(prefix, size = null): resource_filesystem.scan() func _serialize(data): - data.type = "material" return data diff --git a/addons/material_maker/engine/gen_shader.gd b/addons/material_maker/engine/gen_shader.gd index 39ee44d..4fe0902 100644 --- a/addons/material_maker/engine/gen_shader.gd +++ b/addons/material_maker/engine/gen_shader.gd @@ -111,10 +111,11 @@ func replace_variable(string, variable, value): return new_string func subst(string, context, uv = ""): + var genname = "o"+str(get_instance_id()) var required_defs = "" var required_code = "" var required_textures = {} - string = replace_variable(string, "name", name) + string = replace_variable(string, "name", genname) string = replace_variable(string, "seed", str(get_seed())) if uv != "": string = replace_variable(string, "uv", "("+uv+")") @@ -133,7 +134,7 @@ func subst(string, context, uv = ""): elif p.type == "color": value_string = "vec4(%.9f, %.9f, %.9f, %.9f)" % [ value.r, value.g, value.b, value.a ] elif p.type == "gradient": - value_string = name+"__"+p.name+"_gradient_fct" + value_string = genname+"__"+p.name+"_gradient_fct" elif p.type == "boolean": value_string = "true" if value else "false" else: @@ -164,6 +165,7 @@ func subst(string, context, uv = ""): return { string=string, defs=required_defs, code=required_code, textures=required_textures } func _get_shader_code(uv : String, output_index : int, context : MMGenContext): + var genname = "o"+str(get_instance_id()) var output_info = [ { field="rgba", type="vec4" }, { field="rgb", type="vec3" }, { field="f", type="float" } ] var rv = { defs="", code="", textures={} } var variant_string = uv+","+str(output_index) @@ -183,7 +185,7 @@ func _get_shader_code(uv : String, output_index : int, context : MMGenContext): if !(g is MMGradient): g = MMGradient.new() g.deserialize(parameters[p.name]) - rv.defs += g.get_shader(name+"__"+p.name+"_gradient_fct") + rv.defs += g.get_shader(genname+"__"+p.name+"_gradient_fct") var variant_index = context.get_variant(self, variant_string) if variant_index == -1: variant_index = context.get_variant(self, variant_string) @@ -194,12 +196,12 @@ func _get_shader_code(uv : String, output_index : int, context : MMGenContext): subst_output = yield(subst_output, "completed") rv.defs += subst_output.defs rv.code += subst_output.code - rv.code += "%s %s_%d_%d_%s = %s;\n" % [ t.type, name, output_index, variant_index, t.field, subst_output.string ] + rv.code += "%s %s_%d_%d_%s = %s;\n" % [ t.type, genname, output_index, variant_index, t.field, subst_output.string ] for t in subst_output.textures.keys(): rv.textures[t] = subst_output.textures[t] for t in output_info: if output.has(t.field): - rv[t.field] = "%s_%d_%d_%s" % [ name, output_index, variant_index, t.field ] + rv[t.field] = "%s_%d_%d_%s" % [ genname, output_index, variant_index, t.field ] return rv func get_globals(): diff --git a/addons/material_maker/engine/gen_texture.gd b/addons/material_maker/engine/gen_texture.gd index a4a533a..ec8d6f2 100644 --- a/addons/material_maker/engine/gen_texture.gd +++ b/addons/material_maker/engine/gen_texture.gd @@ -12,12 +12,13 @@ func get_output_defs(): return [ { rgba="" } ] func _get_shader_code(uv : String, output_index : int, context : MMGenContext): + var genname = "o"+str(get_instance_id()) var rv = { defs="", code="" } - var texture_name = name+"_tex" + var texture_name = genname+"_tex" var variant_index = context.get_variant(self, uv) if variant_index == -1: variant_index = context.get_variant(self, uv) - rv.code = "vec4 %s_%d = texture(%s, %s);\n" % [ name, variant_index, texture_name, uv ] - rv.rgba = "%s_%d" % [ name, variant_index ] + rv.code = "vec4 %s_%d = texture(%s, %s);\n" % [ genname, variant_index, texture_name, uv ] + rv.rgba = "%s_%d" % [ genname, variant_index ] rv.textures = { texture_name:texture } return rv \ No newline at end of file diff --git a/addons/material_maker/engine/loader.gd b/addons/material_maker/engine/loader.gd index baf9cef..efcf467 100644 --- a/addons/material_maker/engine/loader.gd +++ b/addons/material_maker/engine/loader.gd @@ -35,6 +35,9 @@ static func create_gen(data) -> MMGenBase: elif data.has("shader_model"): generator = MMGenShader.new() generator.set_shader_model(data.shader_model) + elif data.has("convolution_params"): + generator = MMGenConvolution.new() + generator.set_convolution_params(data.convolution_params) elif data.has("model_data"): generator = MMGenShader.new() generator.set_shader_model(data.model_data) diff --git a/addons/material_maker/main_window.tscn b/addons/material_maker/main_window.tscn index a964aaa..fb86ec5 100644 --- a/addons/material_maker/main_window.tscn +++ b/addons/material_maker/main_window.tscn @@ -104,6 +104,8 @@ script = ExtResource( 6 ) [connection signal="tab_changed" from="VBoxContainer/HBoxContainer/Projects" to="." method="_on_Projects_tab_changed"] [connection signal="connection_request" from="VBoxContainer/HBoxContainer/Projects/GraphEdit" to="VBoxContainer/HBoxContainer/Projects/GraphEdit" method="connect_node"] [connection signal="disconnection_request" from="VBoxContainer/HBoxContainer/Projects/GraphEdit" to="VBoxContainer/HBoxContainer/Projects/GraphEdit" method="disconnect_node"] +[connection signal="close_request" from="VBoxContainer/HBoxContainer/Projects/GraphEdit/node_Material" to="VBoxContainer/HBoxContainer/Projects/GraphEdit/node_Material" method="on_close_request"] +[connection signal="offset_changed" from="VBoxContainer/HBoxContainer/Projects/GraphEdit/node_Material" to="VBoxContainer/HBoxContainer/Projects/GraphEdit/node_Material" method="on_offset_changed"] [connection signal="reposition_active_tab_request" from="VBoxContainer/HBoxContainer/Projects/Tabs" to="VBoxContainer/HBoxContainer/Projects" method="move_active_tab_to"] [connection signal="tab_changed" from="VBoxContainer/HBoxContainer/Projects/Tabs" to="VBoxContainer/HBoxContainer/Projects" method="set_current_tab"] [connection signal="tab_close" from="VBoxContainer/HBoxContainer/Projects/Tabs" to="VBoxContainer/HBoxContainer/Projects" method="close_tab"] From 07273fdd046abf2ee0fc18a9b63aae6be667ae8a Mon Sep 17 00:00:00 2001 From: RodZill4 Date: Tue, 17 Sep 2019 08:12:53 +0200 Subject: [PATCH 023/133] fixed rotation in transform, started implementing hierrachy --- addons/material_maker/engine/gen_graph.gd | 48 ++++++++++++++++++--- addons/material_maker/engine/gen_ios.gd | 50 ++++++++++++++++++++++ addons/material_maker/engine/loader.gd | 15 ++++++- addons/material_maker/graph_edit.gd | 15 +++++-- addons/material_maker/nodes/normal_map.mmg | 1 + addons/material_maker/nodes/transform.mmg | 2 +- 6 files changed, 118 insertions(+), 13 deletions(-) create mode 100644 addons/material_maker/engine/gen_ios.gd create mode 100644 addons/material_maker/nodes/normal_map.mmg diff --git a/addons/material_maker/engine/gen_graph.gd b/addons/material_maker/engine/gen_graph.gd index 6ed6299..8fb9859 100644 --- a/addons/material_maker/engine/gen_graph.gd +++ b/addons/material_maker/engine/gen_graph.gd @@ -2,22 +2,48 @@ tool extends MMGenBase class_name MMGenGraph +var label : String = "Graph" var connections = [] func get_type(): return "graph" +func get_type_name(): + return label + +func get_parameter_defs(): + return [] + +func get_input_defs(): + var inputs = get_node("gen_inputs") + if inputs != null: + return inputs.get_input_defs() + return [] + +func get_output_defs(): + var outputs = get_node("gen_outputs") + if outputs != null: + return outputs.get_output_defs() + return [] + func get_port_source(gen_name: String, input_index: int) -> OutputPort: - for c in connections: - if c.to == gen_name and c.to_port == input_index: - var src_gen = get_node(c.from) - if src_gen != null: - return OutputPort.new(src_gen, c.from_port) + if gen_name == "gen_inputs": + var parent = get_parent() + if parent != null and parent.get_type() == "graph": + return parent.get_port_source(name, input_index) + else: + for c in connections: + if c.to == gen_name and c.to_port == input_index: + var src_gen = get_node(c.from) + if src_gen != null: + if src_gen.get_type() == "graph": + return src_gen.get_port_source("gen_outputs", c.from_port) + return OutputPort.new(src_gen, c.from_port) return null -func get_port_target(gen_name: String, input_index: int) -> InputPort: +func get_port_target(gen_name: String, output_index: int) -> InputPort: for c in connections: - if c.from == gen_name and c.from_port == input_index: + if c.from == gen_name and c.from_port == output_index: var tgt_gen = get_node(c.to) if tgt_gen != null: return InputPort.new(tgt_gen, c.to_port) @@ -65,7 +91,15 @@ func disconnect_children(from, from_port : int, to, to_port : int): connections.remove(remove) return true +func _get_shader_code(uv : String, output_index : int, context : MMGenContext): + print("Getting shader code from graph") + var outputs = get_node("gen_outputs") + if outputs != null: + outputs._get_shader_code(uv, output_index, context) + return { defs="", code="", textures={} } + func _serialize(data): + data.label = label data.nodes = [] for c in get_children(): data.nodes.append(c.serialize()) diff --git a/addons/material_maker/engine/gen_ios.gd b/addons/material_maker/engine/gen_ios.gd new file mode 100644 index 0000000..38ee958 --- /dev/null +++ b/addons/material_maker/engine/gen_ios.gd @@ -0,0 +1,50 @@ +tool +extends MMGenBase +class_name MMGenIOs + +""" +IOs just forward their inputs to their outputs and are used to specify graph interfaces +""" + +var mask : int = 3 +var ports : Array = [] + +func _ready(): + if !parameters.has("size"): + parameters.size = 4 + +func get_type(): + return "buffer" + +func get_type_name(): + match mask: + 1: return "Inputs" + 2: return "Output" + _: return "IOs" + return "Buffer" + +func get_input_defs(): + var rv : Array = [] + if mask != 2: + for p in ports: + rv.push_back({ name=p.name, type="rgba" }) + return rv + +func get_output_defs(): + var rv : Array = [] + if mask != 2: + for p in ports: + rv.push_back({ name=p.name, type="rgba" }) + return rv + +func _get_shader_code(uv : String, output_index : int, context : MMGenContext): + print("Getting shader code from ios") + if mask != 2: + var source = get_source(output_index) + if source != null: + return source.generator._get_shader_code(uv, source.output_index, context) + return { defs="", code="", textures={} } + +func _serialize(data): + data.type = "buffer" + return data diff --git a/addons/material_maker/engine/loader.gd b/addons/material_maker/engine/loader.gd index efcf467..e4b41fe 100644 --- a/addons/material_maker/engine/loader.gd +++ b/addons/material_maker/engine/loader.gd @@ -11,9 +11,11 @@ static func load_gen(filename: String) -> MMGenBase: static func add_to_gen_graph(gen_graph, generators, connections): var rv = { generators=[], connections=[] } + var gennames = {} for n in generators: var g = create_gen(n) if g != null: + var orig_name = g.name var name = g.name var index = 1 while gen_graph.has_node(name): @@ -22,15 +24,21 @@ static func add_to_gen_graph(gen_graph, generators, connections): g.name = name gen_graph.add_child(g) rv.generators.append(g) + gennames[orig_name] = name for c in connections: - gen_graph.connections.append(c) - rv.connections.append(c) + if gennames.has(c.from) and gennames.has(c.to): + c.from = gennames[c.from] + c.to = gennames[c.to] + gen_graph.connections.append(c) + rv.connections.append(c) return rv static func create_gen(data) -> MMGenBase: var generator = null if data.has("connections") and data.has("nodes"): generator = MMGenGraph.new() + if data.has("label"): + generator.label = data.label add_to_gen_graph(generator, data.nodes, data.connections) elif data.has("shader_model"): generator = MMGenShader.new() @@ -48,6 +56,9 @@ static func create_gen(data) -> MMGenBase: generator = MMGenBuffer.new() elif data.type == "image": generator = MMGenImage.new() + elif data.type == "ios": + generator = MMGenIOs.new() + generator.ports = data.ports else: var file = File.new() if file.open("res://addons/material_maker/nodes/"+data.type+".mmg", File.READ) == OK: diff --git a/addons/material_maker/graph_edit.gd b/addons/material_maker/graph_edit.gd index e8efb4a..89b2cc8 100644 --- a/addons/material_maker/graph_edit.gd +++ b/addons/material_maker/graph_edit.gd @@ -99,6 +99,7 @@ func clear_material(): send_changed_signal() func update_graph(generators, connections): + var rv = [] for g in generators: var node = node_factory.create_node(g.get_type()) if node != null: @@ -106,8 +107,10 @@ func update_graph(generators, connections): add_node(node) node.generator = g node.offset = g.position + rv.push_back(node) for c in connections: .connect_node("node_"+c.from, c.from_port, "node_"+c.to, c.to_port) + return rv func new_material(): clear_material() @@ -137,7 +140,8 @@ func create_nodes(data, position : Vector2 = Vector2(0, 0)): var new_stuff = MMGenLoader.add_to_gen_graph(generator, data.nodes, data.connections) for g in new_stuff.generators: g.position += position - update_graph(new_stuff.generators, new_stuff.connections) + return update_graph(new_stuff.generators, new_stuff.connections) + return [] func load_file(filename): clear_material() @@ -172,6 +176,7 @@ func remove_selection(): if c is GraphNode and c.selected and c.name != "Material": remove_node(c) +# Maybe move this to gen_graph... func serialize_selection(): var data = { nodes = [], connections = [] } var nodes = [] @@ -193,7 +198,10 @@ func serialize_selection(): var from = get_node(c.from) var to = get_node(c.to) if from != null and from.selected and to != null and to.selected: - data.connections.append(c) + var connection = c.duplicate(true) + connection.from = from.generator.name + connection.to = to.generator.name + data.connections.append(connection) return data func can_copy(): @@ -214,7 +222,8 @@ func paste(pos = Vector2(0, 0)): if c is GraphNode: c.selected = false var data = parse_json(OS.clipboard) - create_nodes(data, scroll_offset+0.5*rect_size) + for c in create_nodes(data, scroll_offset+0.5*rect_size): + c.selected = true # Center view diff --git a/addons/material_maker/nodes/normal_map.mmg b/addons/material_maker/nodes/normal_map.mmg new file mode 100644 index 0000000..9ddeea0 --- /dev/null +++ b/addons/material_maker/nodes/normal_map.mmg @@ -0,0 +1 @@ +{"label":"Normal Map","connections":[{"from":"nm_convolution","from_port":0,"to":"nm_postprocess","to_port":0},{"from":"nm_postprocess","from_port":0,"to":"gen_outputs","to_port":0},{"from":"gen_inputs","from_port":0,"to":"nm_convolution","to_port":0}],"nodes":[{"name":"gen_inputs","type":"ios","ports":[{"name":""}],"node_position":{"x":-89.25,"y":-73.75}},{"name":"gen_outputs","type":"ios","ports":[{"name":""}],"node_position":{"x":-89.25,"y":-73.75}},{"convolution_params":{"input_type":"f","matrix":[[[-1,-1,0],[0,-2,0],[1,-1,0]],[[-2,0,0],0,[2,0,0]],[[-1,1,0],[0,2,0],[1,1,0]]],"output_type":"rgb","x":1,"y":1},"name":"nm_convolution","node_position":{"x":-89.25,"y":-73.75},"parameters":{"size":7},"type":"shader"},{"name":"nm_postprocess","node_position":{"x":-98.25,"y":-6.75},"parameters":{"amount":0.995,"size":7},"shader_model":{"global":"","inputs":[{"default":"vec3(0.0)","label":"","name":"in","type":"rgb"}],"instance":"","name":"NormalMapPostProcess","outputs":[{"rgb":"0.5*normalize($in($uv)*$amount*$size/128.0-vec3(0.0, 0.0, 1.0))+vec3(0.5)","type":"rgb"}],"parameters":[{"default":8,"first":4,"label":"","last":11,"name":"size","type":"size"},{"default":1,"label":"","max":2,"min":0,"name":"amount","step":0.005,"type":"float"}]},"type":"shader"}]} \ No newline at end of file diff --git a/addons/material_maker/nodes/transform.mmg b/addons/material_maker/nodes/transform.mmg index 2897272..620c91d 100644 --- a/addons/material_maker/nodes/transform.mmg +++ b/addons/material_maker/nodes/transform.mmg @@ -1 +1 @@ -{"name":"transform","node_position":{"x":0,"y":0},"parameters":{"repeat":false,"rotate":0,"scale_x":1,"scale_y":1,"translate_x":0.33,"translate_y":0.095},"shader_model":{"global":"vec2 transform(vec2 uv, vec2 translate, float rotate, vec2 scale, bool repeat) {\n \tvec2 rv;\n\tuv -= vec2(0.5);\n\trv.x = cos(rotate)*uv.x + sin(rotate)*uv.y;\n\trv.y = -sin(rotate)*uv.x + cos(rotate)*uv.y;\n\trv /= scale;\n\trv += vec2(0.5);\n\trv -= translate;\n if (repeat) {\n\t\treturn fract(rv);\n\t} else {\n\t\treturn clamp(rv, vec2(0.0), vec2(1.0));\n\t}\t\n}","inputs":[{"default":"vec4($uv, 0.0, 1.0)","label":"","name":"i","type":"rgba"},{"default":"1.0","label":"","name":"tx","type":"f"},{"default":"1.0","label":"","name":"ty","type":"f"},{"default":"1.0","label":"","name":"r","type":"f"},{"default":"1.0","label":"","name":"sx","type":"f"},{"default":"1.0","label":"","name":"sy","type":"f"}],"instance":"","name":"Transform","outputs":[{"rgba":"$i(transform($uv, vec2($translate_x*(2.0*$tx($uv)-1.0), $translate_y*(2.0*$ty($uv)-1.0)), $rotate*(2.0*$r($uv)-1.0), vec2($scale_x*(2.0*$sx($uv)-1.0), $scale_y*(2.0*$sy($uv)-1.0)), $repeat))","type":"rgba"}],"parameters":[{"default":0,"label":"2:Translate X:","max":1,"min":-1,"name":"translate_x","step":0.005,"type":"float","widget":"spinbox"},{"default":0,"label":"Translate Y:","max":1,"min":-1,"name":"translate_y","step":0.005,"type":"float","widget":"spinbox"},{"default":0,"label":"Rotate:","max":720,"min":-720,"name":"rotate","step":0.005,"type":"float","widget":"spinbox"},{"default":1,"label":"Scale X:","max":50,"min":0,"name":"scale_x","step":0.005,"type":"float","widget":"spinbox"},{"default":1,"label":"Scale Y:","max":50,"min":0,"name":"scale_y","step":0.005,"type":"float","widget":"spinbox"},{"default":false,"label":"Repeat:","name":"repeat","type":"boolean"}]}} \ No newline at end of file +{"name":"transform","node_position":{"x":0,"y":0},"parameters":{"repeat":false,"rotate":120,"scale_x":1,"scale_y":1,"translate_x":0,"translate_y":0},"shader_model":{"global":"vec2 transform(vec2 uv, vec2 translate, float rotate, vec2 scale, bool repeat) {\n \tvec2 rv;\n\tuv -= vec2(0.5);\n\trv.x = cos(rotate)*uv.x + sin(rotate)*uv.y;\n\trv.y = -sin(rotate)*uv.x + cos(rotate)*uv.y;\n\trv /= scale;\n\trv += vec2(0.5);\n\trv -= translate;\n if (repeat) {\n\t\treturn fract(rv);\n\t} else {\n\t\treturn clamp(rv, vec2(0.0), vec2(1.0));\n\t}\t\n}","inputs":[{"default":"vec4($uv, 0.0, 1.0)","label":"","name":"i","type":"rgba"},{"default":"1.0","label":"","name":"tx","type":"f"},{"default":"1.0","label":"","name":"ty","type":"f"},{"default":"1.0","label":"","name":"r","type":"f"},{"default":"1.0","label":"","name":"sx","type":"f"},{"default":"1.0","label":"","name":"sy","type":"f"}],"instance":"","name":"Transform","outputs":[{"rgba":"$i(transform($uv, vec2($translate_x*(2.0*$tx($uv)-1.0), $translate_y*(2.0*$ty($uv)-1.0)), $rotate*0.01745329251*(2.0*$r($uv)-1.0), vec2($scale_x*(2.0*$sx($uv)-1.0), $scale_y*(2.0*$sy($uv)-1.0)), $repeat))","type":"rgba"}],"parameters":[{"default":0,"label":"2:Translate X:","max":1,"min":-1,"name":"translate_x","step":0.005,"type":"float","widget":"spinbox"},{"default":0,"label":"Translate Y:","max":1,"min":-1,"name":"translate_y","step":0.005,"type":"float","widget":"spinbox"},{"default":0,"label":"Rotate:","max":720,"min":-720,"name":"rotate","step":0.005,"type":"float","widget":"spinbox"},{"default":1,"label":"Scale X:","max":50,"min":0,"name":"scale_x","step":0.005,"type":"float","widget":"spinbox"},{"default":1,"label":"Scale Y:","max":50,"min":0,"name":"scale_y","step":0.005,"type":"float","widget":"spinbox"},{"default":false,"label":"Repeat:","name":"repeat","type":"boolean"}]},"type":"shader"} \ No newline at end of file From ac4a5c39b6928333faeff8d0eff90d086d7fb407 Mon Sep 17 00:00:00 2001 From: RodZill4 Date: Thu, 19 Sep 2019 07:56:32 +0200 Subject: [PATCH 024/133] Added support for hierrachical navigation --- addons/material_maker/engine/gen_graph.gd | 3 ++ addons/material_maker/engine/gen_shader.gd | 8 +++++ addons/material_maker/graph_edit.gd | 40 +++++++++++++++------- addons/material_maker/graph_edit.tscn | 10 ++++++ addons/material_maker/nodes/generic.gd | 8 ++--- 5 files changed, 50 insertions(+), 19 deletions(-) diff --git a/addons/material_maker/engine/gen_graph.gd b/addons/material_maker/engine/gen_graph.gd index 8fb9859..e036c5f 100644 --- a/addons/material_maker/engine/gen_graph.gd +++ b/addons/material_maker/engine/gen_graph.gd @@ -105,3 +105,6 @@ func _serialize(data): data.nodes.append(c.serialize()) data.connections = connections return data + +func edit(node): + node.get_parent().call_deferred("update_view", self) \ No newline at end of file diff --git a/addons/material_maker/engine/gen_shader.gd b/addons/material_maker/engine/gen_shader.gd index 4fe0902..a50a2d4 100644 --- a/addons/material_maker/engine/gen_shader.gd +++ b/addons/material_maker/engine/gen_shader.gd @@ -213,3 +213,11 @@ func get_globals(): func _serialize(data): data.shader_model = shader_model return data + +func edit(node): + if shader_model != null: + var edit_window = load("res://addons/material_maker/widgets/node_editor/node_editor.tscn").instance() + node.get_parent().add_child(edit_window) + edit_window.set_model_data(shader_model) + edit_window.connect("node_changed", node, "update_generator") + edit_window.popup_centered() diff --git a/addons/material_maker/graph_edit.gd b/addons/material_maker/graph_edit.gd index 89b2cc8..72d93c1 100644 --- a/addons/material_maker/graph_edit.gd +++ b/addons/material_maker/graph_edit.gd @@ -8,6 +8,7 @@ var renderer = null var save_path = null setget set_save_path var need_save = false +var top_generator = null var generator = null signal save_path_changed @@ -86,15 +87,24 @@ func set_save_path(path): update_tab_title() emit_signal("save_path_changed", self, path) -func clear_material(): +func clear_view(): clear_connections() for c in get_children(): if c is GraphNode: remove_child(c) c.free() - if generator != null: - remove_child(generator) - generator.free() + +func update_view(g): + clear_view() + generator = g + update_graph(generator.get_children(), generator.connections) + $ButtonUp.visible = generator != top_generator + +func clear_material(): + if top_generator != null: + remove_child(top_generator) + top_generator.free() + top_generator = null generator = null send_changed_signal() @@ -115,10 +125,10 @@ func update_graph(generators, connections): func new_material(): clear_material() var loader = MMGenLoader.new() - generator = loader.create_gen({nodes=[{name="Material", type="material"}], connections=[]}) - if generator != null: - add_child(generator) - update_graph(generator.get_children(), generator.connections) + top_generator = loader.create_gen({nodes=[{name="Material", type="material"}], connections=[]}) + if top_generator != null: + add_child(top_generator) + update_view(top_generator) set_save_path(null) set_need_save(false) center_view() @@ -145,16 +155,16 @@ func create_nodes(data, position : Vector2 = Vector2(0, 0)): func load_file(filename): clear_material() - generator = MMGenLoader.load_gen(filename) - if generator != null: - add_child(generator) - update_graph(generator.get_children(), generator.connections) + top_generator = MMGenLoader.load_gen(filename) + if top_generator != null: + add_child(top_generator) + update_view(top_generator) set_save_path(filename) set_need_save(false) center_view() func save_file(filename): - var data = generator.serialize() + var data = top_generator.serialize() var file = File.new() if file.open(filename, File.WRITE) == OK: file.store_string(to_json(data)) @@ -258,3 +268,7 @@ func drop_data(position, data): Input.set_mouse_mode(Input.MOUSE_MODE_VISIBLE) create_nodes(data, offset_from_global_position(get_global_transform().xform(position))) return true + +func on_ButtonUp_pressed(): + if generator != top_generator && generator.get_parent() is MMGenGraph: + call_deferred("update_view", generator.get_parent()) diff --git a/addons/material_maker/graph_edit.tscn b/addons/material_maker/graph_edit.tscn index 2b611c3..ad08ee3 100644 --- a/addons/material_maker/graph_edit.tscn +++ b/addons/material_maker/graph_edit.tscn @@ -13,6 +13,16 @@ script = ExtResource( 1 ) [node name="Timer" type="Timer" parent="."] wait_time = 0.2 one_shot = true + +[node name="ButtonUp" type="Button" parent="."] +anchor_left = 1.0 +anchor_right = 1.0 +margin_left = -44.0 +margin_top = 4.0 +margin_right = -14.0 +margin_bottom = 24.0 +text = "Up" [connection signal="connection_request" from="." to="." method="connect_node"] [connection signal="disconnection_request" from="." to="." method="disconnect_node"] [connection signal="timeout" from="Timer" to="." method="do_send_changed_signal"] +[connection signal="pressed" from="ButtonUp" to="." method="on_ButtonUp_pressed"] diff --git a/addons/material_maker/nodes/generic.gd b/addons/material_maker/nodes/generic.gd index fc83735..c16c2b9 100644 --- a/addons/material_maker/nodes/generic.gd +++ b/addons/material_maker/nodes/generic.gd @@ -206,12 +206,8 @@ func update_node(): edit_buttons.connect_buttons(self, "edit_generator", "load_generator", "save_generator") func edit_generator(): - var edit_window = load("res://addons/material_maker/widgets/node_editor/node_editor.tscn").instance() - get_parent().add_child(edit_window) - if generator.shader_model != null: - edit_window.set_model_data(generator.shader_model) - edit_window.connect("node_changed", self, "update_generator") - edit_window.popup_centered() + if generator.has_method("edit"): + generator.edit(self) func update_generator(shader_model): generator.set_shader_model(shader_model) From afb84a85cf88afe6e15612ed1d9f6819d7238c1b Mon Sep 17 00:00:00 2001 From: Rodolphe Suescun Date: Fri, 20 Sep 2019 20:43:57 +0200 Subject: [PATCH 025/133] Started implementing remote node --- addons/material_maker/engine/gen_ios.gd | 1 - addons/material_maker/engine/gen_remote.gd | 23 +++ addons/material_maker/engine/loader.gd | 3 + addons/material_maker/main_window.tscn | 4 - addons/material_maker/nodes/generic.gd | 4 - .../nodes/{remote => }/remote.gd | 43 +++--- addons/material_maker/nodes/remote.tscn | 57 +++++++ .../material_maker/nodes/remote/remote.tscn | 140 ------------------ .../widgets/linked_widgets/config_control.gd | 5 +- .../widgets/linked_widgets/linked_control.gd | 5 +- .../linked_widgets/linked_control_base.gd | 4 +- project.godot | 18 +++ 12 files changed, 127 insertions(+), 180 deletions(-) create mode 100644 addons/material_maker/engine/gen_remote.gd rename addons/material_maker/nodes/{remote => }/remote.gd (66%) create mode 100644 addons/material_maker/nodes/remote.tscn delete mode 100644 addons/material_maker/nodes/remote/remote.tscn diff --git a/addons/material_maker/engine/gen_ios.gd b/addons/material_maker/engine/gen_ios.gd index 38ee958..75f8c2f 100644 --- a/addons/material_maker/engine/gen_ios.gd +++ b/addons/material_maker/engine/gen_ios.gd @@ -38,7 +38,6 @@ func get_output_defs(): return rv func _get_shader_code(uv : String, output_index : int, context : MMGenContext): - print("Getting shader code from ios") if mask != 2: var source = get_source(output_index) if source != null: diff --git a/addons/material_maker/engine/gen_remote.gd b/addons/material_maker/engine/gen_remote.gd new file mode 100644 index 0000000..bbb2a26 --- /dev/null +++ b/addons/material_maker/engine/gen_remote.gd @@ -0,0 +1,23 @@ +tool +extends MMGenBase +class_name MMGenRemote + +""" +Remote can be used to control parameters from several generators in the same graph +""" + +var widgets = null + +func set_widgets(w): + widgets = w + +func get_type(): + return "remote" + +func get_type_name(): + return "Remote" + +func _serialize(data): + data.type = "remote" + data.widgets = widgets + return data diff --git a/addons/material_maker/engine/loader.gd b/addons/material_maker/engine/loader.gd index e4b41fe..d223e02 100644 --- a/addons/material_maker/engine/loader.gd +++ b/addons/material_maker/engine/loader.gd @@ -49,6 +49,9 @@ static func create_gen(data) -> MMGenBase: elif data.has("model_data"): generator = MMGenShader.new() generator.set_shader_model(data.model_data) + elif data.has("widgets"): + generator = MMGenRemote.new() + generator.set_widgets(data.widgets) elif data.has("type"): if data.type == "material": generator = MMGenMaterial.new() diff --git a/addons/material_maker/main_window.tscn b/addons/material_maker/main_window.tscn index fb86ec5..ac61f02 100644 --- a/addons/material_maker/main_window.tscn +++ b/addons/material_maker/main_window.tscn @@ -102,10 +102,6 @@ script = ExtResource( 6 ) [connection signal="no_more_tabs" from="VBoxContainer/HBoxContainer/Projects" to="." method="new_material"] [connection signal="resized" from="VBoxContainer/HBoxContainer/Projects" to="VBoxContainer/HBoxContainer/Projects" method="_on_Projects_resized"] [connection signal="tab_changed" from="VBoxContainer/HBoxContainer/Projects" to="." method="_on_Projects_tab_changed"] -[connection signal="connection_request" from="VBoxContainer/HBoxContainer/Projects/GraphEdit" to="VBoxContainer/HBoxContainer/Projects/GraphEdit" method="connect_node"] -[connection signal="disconnection_request" from="VBoxContainer/HBoxContainer/Projects/GraphEdit" to="VBoxContainer/HBoxContainer/Projects/GraphEdit" method="disconnect_node"] -[connection signal="close_request" from="VBoxContainer/HBoxContainer/Projects/GraphEdit/node_Material" to="VBoxContainer/HBoxContainer/Projects/GraphEdit/node_Material" method="on_close_request"] -[connection signal="offset_changed" from="VBoxContainer/HBoxContainer/Projects/GraphEdit/node_Material" to="VBoxContainer/HBoxContainer/Projects/GraphEdit/node_Material" method="on_offset_changed"] [connection signal="reposition_active_tab_request" from="VBoxContainer/HBoxContainer/Projects/Tabs" to="VBoxContainer/HBoxContainer/Projects" method="move_active_tab_to"] [connection signal="tab_changed" from="VBoxContainer/HBoxContainer/Projects/Tabs" to="VBoxContainer/HBoxContainer/Projects" method="set_current_tab"] [connection signal="tab_close" from="VBoxContainer/HBoxContainer/Projects/Tabs" to="VBoxContainer/HBoxContainer/Projects" method="close_tab"] diff --git a/addons/material_maker/nodes/generic.gd b/addons/material_maker/nodes/generic.gd index c16c2b9..5ce03ae 100644 --- a/addons/material_maker/nodes/generic.gd +++ b/addons/material_maker/nodes/generic.gd @@ -5,10 +5,6 @@ var generator = null setget set_generator var controls = [] -# Called when the node enters the scene tree for the first time. -func _ready(): - pass # Replace with function body. - func set_generator(g): generator = g update_node() diff --git a/addons/material_maker/nodes/remote/remote.gd b/addons/material_maker/nodes/remote.gd similarity index 66% rename from addons/material_maker/nodes/remote/remote.gd rename to addons/material_maker/nodes/remote.gd index f9007e6..2f9d393 100644 --- a/addons/material_maker/nodes/remote/remote.gd +++ b/addons/material_maker/nodes/remote.gd @@ -4,13 +4,24 @@ extends "res://addons/material_maker/node_base.gd" const LinkedControl = preload("res://addons/material_maker/widgets/linked_widgets/linked_control.tscn") const ConfigControl = preload("res://addons/material_maker/widgets/linked_widgets/config_control.tscn") -func _ready(): - pass +var generator = null setget set_generator -func _get_shader_code(uv, slot = 0): - var rv = { defs="", code="" } - rv.rgb = "vec3(1.0)" - return rv +func set_generator(g): + generator = g + call_deferred("update_node") + + +func update_node(): + for w in generator.widgets: + var widget + if w.type == "linked_control": + widget = LinkedControl.instance() + elif w.type == "config_control": + widget = ConfigControl.instance() + else: + continue + add_control(widget) + widget.deserialize(w) func add_control(widget): var controls = widget.get_associated_controls() @@ -18,7 +29,6 @@ func add_control(widget): $Controls.add_child(widget) $Controls.add_child(controls.buttons) - func _on_AddLink_pressed(): var widget = LinkedControl.instance() add_control(widget) @@ -42,22 +52,3 @@ func serialize(): widgets.append($Controls.get_child(i).serialize()) var data = { type="remote", node_position={x=offset.x,y=offset.y}, editable=true, widgets=widgets } return data - -func deserialize(data): - if data.has("node_position"): - offset.x = data.node_position.x - offset.y = data.node_position.y - call_deferred("do_deserialize", data) - -func do_deserialize(data): - if data.has("widgets"): - for w in data.widgets: - var widget - if w.type == "linked_control": - widget = LinkedControl.instance() - elif w.type == "config_control": - widget = ConfigControl.instance() - else: - continue - add_control(widget) - widget.deserialize(w) diff --git a/addons/material_maker/nodes/remote.tscn b/addons/material_maker/nodes/remote.tscn new file mode 100644 index 0000000..1c19a2e --- /dev/null +++ b/addons/material_maker/nodes/remote.tscn @@ -0,0 +1,57 @@ +[gd_scene load_steps=5 format=2] + +[ext_resource path="res://addons/material_maker/nodes/remote.gd" type="Script" id=1] +[ext_resource path="res://addons/material_maker/icons/link.png" type="Texture" id=2] +[ext_resource path="res://addons/material_maker/icons/config.png" type="Texture" id=3] + +[sub_resource type="Theme" id=1] + +[node name="Remote" type="GraphNode"] +margin_right = 95.0 +margin_bottom = 55.0 +mouse_filter = 1 +theme = SubResource( 1 ) +title = "Remote" +show_close = true +slot/0/left_enabled = false +slot/0/left_type = 0 +slot/0/left_color = Color( 0.5, 0.5, 1, 1 ) +slot/0/right_enabled = false +slot/0/right_type = 0 +slot/0/right_color = Color( 0.5, 0.5, 1, 1 ) +slot/1/left_enabled = false +slot/1/left_type = 0 +slot/1/left_color = Color( 1, 1, 1, 1 ) +slot/1/right_enabled = false +slot/1/right_type = 0 +slot/1/right_color = Color( 1, 1, 1, 1 ) +script = ExtResource( 1 ) + +[node name="Controls" type="GridContainer" parent="."] +margin_left = 16.0 +margin_top = 24.0 +margin_right = 79.0 +margin_bottom = 24.0 +columns = 3 + +[node name="HBoxContainer" type="HBoxContainer" parent="."] +margin_left = 16.0 +margin_top = 24.0 +margin_right = 79.0 +margin_bottom = 46.0 + +[node name="AddLink" type="Button" parent="HBoxContainer"] +margin_right = 28.0 +margin_bottom = 22.0 +hint_tooltip = "Add linked control" +size_flags_horizontal = 0 +icon = ExtResource( 2 ) + +[node name="AddConfig" type="Button" parent="HBoxContainer"] +margin_left = 32.0 +margin_right = 60.0 +margin_bottom = 22.0 +hint_tooltip = "Add configurations" +icon = ExtResource( 3 ) +[connection signal="pressed" from="HBoxContainer/AddLink" to="." method="_on_AddLink_pressed"] +[connection signal="pressed" from="HBoxContainer/AddConfig" to="." method="_on_AddConfig_pressed"] diff --git a/addons/material_maker/nodes/remote/remote.tscn b/addons/material_maker/nodes/remote/remote.tscn deleted file mode 100644 index 335af33..0000000 --- a/addons/material_maker/nodes/remote/remote.tscn +++ /dev/null @@ -1,140 +0,0 @@ -[gd_scene load_steps=5 format=2] - -[ext_resource path="res://addons/material_maker/nodes/remote/remote.gd" type="Script" id=1] -[ext_resource path="res://addons/material_maker/icons/link.png" type="Texture" id=2] -[ext_resource path="res://addons/material_maker/icons/config.png" type="Texture" id=3] - - -[sub_resource type="Theme" id=1] - - -[node name="Remote" type="GraphNode"] - -anchor_left = 0.0 -anchor_top = 0.0 -anchor_right = 0.0 -anchor_bottom = 0.0 -margin_right = 95.0 -margin_bottom = 55.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 = "Remote" -offset = Vector2( 0, 0 ) -show_close = true -resizable = false -selected = false -comment = false -overlay = 0 -slot/0/left_enabled = false -slot/0/left_type = 0 -slot/0/left_color = Color( 0.5, 0.5, 1, 1 ) -slot/0/right_enabled = false -slot/0/right_type = 0 -slot/0/right_color = Color( 0.5, 0.5, 1, 1 ) -slot/1/left_enabled = false -slot/1/left_type = 0 -slot/1/left_color = Color( 1, 1, 1, 1 ) -slot/1/right_enabled = false -slot/1/right_type = 0 -slot/1/right_color = Color( 1, 1, 1, 1 ) -script = ExtResource( 1 ) -_sections_unfolded = [ "Theme", "slot" ] - -[node name="Controls" type="GridContainer" 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 = 79.0 -margin_bottom = 24.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 -columns = 3 -_sections_unfolded = [ "Hint" ] - -[node name="HBoxContainer" type="HBoxContainer" 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 = 24.0 -margin_right = 79.0 -margin_bottom = 46.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 -alignment = 0 - -[node name="AddLink" type="Button" parent="HBoxContainer" index="0"] - -anchor_left = 0.0 -anchor_top = 0.0 -anchor_right = 0.0 -anchor_bottom = 0.0 -margin_right = 28.0 -margin_bottom = 22.0 -rect_pivot_offset = Vector2( 0, 0 ) -rect_clip_content = false -hint_tooltip = "Add linked control" -focus_mode = 2 -mouse_filter = 0 -mouse_default_cursor_shape = 0 -size_flags_horizontal = 0 -size_flags_vertical = 1 -toggle_mode = false -enabled_focus_mode = 2 -shortcut = null -group = null -icon = ExtResource( 2 ) -flat = false -align = 1 -_sections_unfolded = [ "Hint", "Rect", "Size Flags" ] - -[node name="AddConfig" type="Button" parent="HBoxContainer" index="1"] - -anchor_left = 0.0 -anchor_top = 0.0 -anchor_right = 0.0 -anchor_bottom = 0.0 -margin_left = 32.0 -margin_right = 60.0 -margin_bottom = 22.0 -rect_pivot_offset = Vector2( 0, 0 ) -rect_clip_content = false -hint_tooltip = "Add configurations" -focus_mode = 2 -mouse_filter = 0 -mouse_default_cursor_shape = 0 -size_flags_horizontal = 1 -size_flags_vertical = 1 -toggle_mode = false -enabled_focus_mode = 2 -shortcut = null -group = null -icon = ExtResource( 3 ) -flat = false -align = 1 -_sections_unfolded = [ "Hint" ] - -[connection signal="pressed" from="HBoxContainer/AddLink" to="." method="_on_AddLink_pressed"] - -[connection signal="pressed" from="HBoxContainer/AddConfig" to="." method="_on_AddConfig_pressed"] - - diff --git a/addons/material_maker/widgets/linked_widgets/config_control.gd b/addons/material_maker/widgets/linked_widgets/config_control.gd index 96fbde1..a437f02 100644 --- a/addons/material_maker/widgets/linked_widgets/config_control.gd +++ b/addons/material_maker/widgets/linked_widgets/config_control.gd @@ -115,9 +115,10 @@ func deserialize(data): var c = data.configurations[k] var configuration = [] for e in c: - var node = graph_edit.get_node(e.node) + var node = graph_edit.get_node("node_"+e.node) + print(e.widget) var widget = null - for w in node.property_widgets: + for w in node.controls: if w.name == e.widget: widget = w break diff --git a/addons/material_maker/widgets/linked_widgets/linked_control.gd b/addons/material_maker/widgets/linked_widgets/linked_control.gd index 1d42a6d..5f24ccd 100644 --- a/addons/material_maker/widgets/linked_widgets/linked_control.gd +++ b/addons/material_maker/widgets/linked_widgets/linked_control.gd @@ -68,7 +68,10 @@ func update_shaders(): func _on_value_changed(v): for l in linked_widgets: l.widget.value = v - l.node.parameters[l.widget.name] = v + var parent = l.widget.get_parent() + while !(parent is GraphNode): + parent = parent.get_parent() + parent.generator.set_parameter(l.widget.name, v) update_shaders() func _on_color_changed(c): diff --git a/addons/material_maker/widgets/linked_widgets/linked_control_base.gd b/addons/material_maker/widgets/linked_widgets/linked_control_base.gd index 962d00c..19a3612 100644 --- a/addons/material_maker/widgets/linked_widgets/linked_control_base.gd +++ b/addons/material_maker/widgets/linked_widgets/linked_control_base.gd @@ -88,8 +88,8 @@ func get_graph_edit(): func find_control(gp): for c in graph_edit.get_children(): if c is GraphNode: - if c.get("property_widgets") != null: - for w in c.property_widgets: + if c.get("controls") != null: + for w in c.controls: if Rect2(w.rect_global_position, w.rect_size*w.get_global_transform().get_scale()).has_point(gp): return { node=c, widget=w } return null diff --git a/project.godot b/project.godot index 8442bec..b80c364 100644 --- a/project.godot +++ b/project.godot @@ -34,6 +34,11 @@ _global_script_classes=[ { "language": "GDScript", "path": "res://addons/material_maker/engine/gen_graph.gd" }, { +"base": "MMGenBase", +"class": "MMGenIOs", +"language": "GDScript", +"path": "res://addons/material_maker/engine/gen_ios.gd" +}, { "base": "MMGenTexture", "class": "MMGenImage", "language": "GDScript", @@ -49,6 +54,11 @@ _global_script_classes=[ { "language": "GDScript", "path": "res://addons/material_maker/engine/gen_material.gd" }, { +"base": "MMGenBase", +"class": "MMGenRemote", +"language": "GDScript", +"path": "res://addons/material_maker/engine/gen_remote.gd" +}, { "base": "Viewport", "class": "MMGenRenderer", "language": "GDScript", @@ -60,6 +70,11 @@ _global_script_classes=[ { "path": "res://addons/material_maker/engine/gen_shader.gd" }, { "base": "MMGenBase", +"class": "MMGenSwitch", +"language": "GDScript", +"path": "res://addons/material_maker/engine/gen_switch.gd" +}, { +"base": "MMGenBase", "class": "MMGenTexture", "language": "GDScript", "path": "res://addons/material_maker/engine/gen_texture.gd" @@ -80,11 +95,14 @@ _global_script_class_icons={ "MMGenContext": "", "MMGenConvolution": "", "MMGenGraph": "", +"MMGenIOs": "", "MMGenImage": "", "MMGenLoader": "", "MMGenMaterial": "", +"MMGenRemote": "", "MMGenRenderer": "", "MMGenShader": "", +"MMGenSwitch": "", "MMGenTexture": "", "MMGradient": "", "MMType": "" From 8af2c04f918cf4be0474cd03577a0ab0a48c4cd3 Mon Sep 17 00:00:00 2001 From: RodZill4 Date: Sun, 22 Sep 2019 22:17:26 +0200 Subject: [PATCH 026/133] Mmore progree on remotes and hierarchy --- addons/material_maker/engine/gen_base.gd | 16 ++++-- addons/material_maker/engine/gen_buffer.gd | 3 +- addons/material_maker/engine/gen_graph.gd | 18 +++++-- addons/material_maker/engine/gen_ios.gd | 15 +++++- addons/material_maker/engine/gen_remote.gd | 49 ++++++++++++++++++- addons/material_maker/engine/gen_switch.gd | 29 +++++++++-- addons/material_maker/engine/loader.gd | 4 ++ addons/material_maker/main_window.tscn | 4 ++ addons/material_maker/nodes/generic.gd | 49 ++++++++++++------- addons/material_maker/nodes/normal_map.mmg | 2 +- .../widgets/linked_widgets/config_control.gd | 2 +- 11 files changed, 155 insertions(+), 36 deletions(-) diff --git a/addons/material_maker/engine/gen_base.gd b/addons/material_maker/engine/gen_base.gd index 7d0db5e..748b93f 100644 --- a/addons/material_maker/engine/gen_base.gd +++ b/addons/material_maker/engine/gen_base.gd @@ -6,6 +6,8 @@ class_name MMGenBase Base class for texture generators, that defines their API """ +signal parameter_changed + class InputPort: var generator : MMGenBase = null var input_index : int = 0 @@ -58,12 +60,16 @@ func get_parameter_defs(): func set_parameter(n : String, v): parameters[n] = v source_changed(0) + emit_signal("parameter_changed", n, v) + +func notify_output_change(output_index : int): + var targets = get_targets(output_index) + for target in targets: + target.generator.source_changed(target.input_index) func source_changed(input_index : int): for i in range(get_output_defs().size()): - var target = get_target(i) - if target != null: - target.generator.source_changed(target.input_index) + notify_output_change(i) func get_input_defs(): return [] @@ -74,8 +80,8 @@ func get_output_defs(): func get_source(input_index : int): return get_parent().get_port_source(name, input_index) -func get_target(output_index : int): - return get_parent().get_port_target(name, output_index) +func get_targets(output_index : int): + return get_parent().get_port_targets(name, output_index) func get_input_shader(input_index : int): var source = get_source(input_index) diff --git a/addons/material_maker/engine/gen_buffer.gd b/addons/material_maker/engine/gen_buffer.gd index d19e207..9b677c5 100644 --- a/addons/material_maker/engine/gen_buffer.gd +++ b/addons/material_maker/engine/gen_buffer.gd @@ -28,8 +28,9 @@ func get_input_defs(): func get_output_defs(): return [ { type="rgba" } ] -func source_changed(input_port_index): +func source_changed(input_port_index : int): updated = false + .source_changed(input_port_index) func _get_shader_code(uv : String, output_index : int, context : MMGenContext): var source = get_source(0) diff --git a/addons/material_maker/engine/gen_graph.gd b/addons/material_maker/engine/gen_graph.gd index e036c5f..ad0b7ba 100644 --- a/addons/material_maker/engine/gen_graph.gd +++ b/addons/material_maker/engine/gen_graph.gd @@ -26,6 +26,11 @@ func get_output_defs(): return outputs.get_output_defs() return [] +func source_changed(input_index : int): + var generator = get_node("gen_inputs") + if generator != null: + generator.source_changed(input_index) + func get_port_source(gen_name: String, input_index: int) -> OutputPort: if gen_name == "gen_inputs": var parent = get_parent() @@ -41,13 +46,14 @@ func get_port_source(gen_name: String, input_index: int) -> OutputPort: return OutputPort.new(src_gen, c.from_port) return null -func get_port_target(gen_name: String, output_index: int) -> InputPort: +func get_port_targets(gen_name: String, output_index: int) -> InputPort: + var rv = [] for c in connections: if c.from == gen_name and c.from_port == output_index: var tgt_gen = get_node(c.to) if tgt_gen != null: - return InputPort.new(tgt_gen, c.to_port) - return null + rv.push_back(InputPort.new(tgt_gen, c.to_port)) + return rv func remove_generator(generator : MMGenBase): var new_connections = [] @@ -95,7 +101,11 @@ func _get_shader_code(uv : String, output_index : int, context : MMGenContext): print("Getting shader code from graph") var outputs = get_node("gen_outputs") if outputs != null: - outputs._get_shader_code(uv, output_index, context) + print("found!") + var rv = outputs._get_shader_code(uv, output_index, context) + while rv is GDScriptFunctionState: + rv = yield(rv, "completed") + return rv return { defs="", code="", textures={} } func _serialize(data): diff --git a/addons/material_maker/engine/gen_ios.gd b/addons/material_maker/engine/gen_ios.gd index 75f8c2f..99ae0b3 100644 --- a/addons/material_maker/engine/gen_ios.gd +++ b/addons/material_maker/engine/gen_ios.gd @@ -37,13 +37,24 @@ func get_output_defs(): rv.push_back({ name=p.name, type="rgba" }) return rv +func source_changed(input_index : int): + if name == "gen_outputs": + get_parent().notify_output_change(input_index) + else: + notify_output_change(input_index) + func _get_shader_code(uv : String, output_index : int, context : MMGenContext): if mask != 2: var source = get_source(output_index) if source != null: - return source.generator._get_shader_code(uv, source.output_index, context) + var rv = source.generator._get_shader_code(uv, source.output_index, context) + while rv is GDScriptFunctionState: + rv = yield(rv, "completed") + return rv return { defs="", code="", textures={} } func _serialize(data): - data.type = "buffer" + data.type = "ios" + data.mask = mask + data.ports = ports return data diff --git a/addons/material_maker/engine/gen_remote.gd b/addons/material_maker/engine/gen_remote.gd index bbb2a26..e0d5976 100644 --- a/addons/material_maker/engine/gen_remote.gd +++ b/addons/material_maker/engine/gen_remote.gd @@ -10,13 +10,60 @@ var widgets = null func set_widgets(w): widgets = w + var i = 0 + for w in widgets: + var param_name = "param"+str(i) + if !parameters.has(param_name): + parameters["param"+str(i)] = 0 + i += 1 func get_type(): - return "remote" + return "remot" func get_type_name(): return "Remote" +func get_parameter_defs(): + var rv = [] + var i = 0 + for w in widgets: + match w.type: + "config_control": + var p = { name="param"+str(i), label=w.label, type="enum", values=[] } + for c in w.configurations: + p.values.push_back({ name=c, value=c }) + rv.append(p) + i += 1 + "linked_control": + var linked = w.linked_widgets[0] + var gen = get_parent().get_node(linked.node) + if gen != null: + var gen_params = gen.get_parameter_defs() + for pd in gen_params: + if pd.name == linked.widget: + var p = pd.duplicate(true) + p.name = "param"+str(i) + p.label = w.label + rv.append(p) + break + i += 1 + _: + print(w.type) + return rv + +func set_parameter(p, v): + .set_parameter(p, v) + var parent = get_parent() + var param_index = p.trim_prefix("param").to_int() + var widget = widgets[param_index] + match widget.type: + "linked_control": + for w in widget.linked_widgets: + parent.get_node(w.node).set_parameter(w.widget, v) + "config_control": + for w in widget.configurations[widget.configurations.keys()[v]]: + parent.get_node(w.node).set_parameter(w.widget, w.value) + func _serialize(data): data.type = "remote" data.widgets = widgets diff --git a/addons/material_maker/engine/gen_switch.gd b/addons/material_maker/engine/gen_switch.gd index d67bddb..f8f72a8 100644 --- a/addons/material_maker/engine/gen_switch.gd +++ b/addons/material_maker/engine/gen_switch.gd @@ -15,8 +15,29 @@ func get_type_name(): func get_parameter_defs(): return [ { name="outputs", label="Outputs", type="float", min=1, max=5, step=1, default=2 }, { name="choices", label="Choices", type="float", min=2, max=5, step=1, default=2 }, - { name="source", label="Source", type="float", min=1, max=2, step=1 } ] + { name="source", label="Source", type="float", min=0, max=1, step=1, default=0 } ] -func set_parameter(n : String, v): - .set_parameter(n, v) - # Force redraw if outputs or choices is modified \ No newline at end of file +func get_input_defs(): + var rv : Array = [] + for c in range(parameters.choices): + for o in range(parameters.outputs): + rv.push_back({ name=PoolByteArray([64+o]).get_string_from_ascii()+str(c), type="rgba" }) + return rv + +func get_output_defs(): + var rv : Array = [] + for o in range(parameters.outputs): + rv.push_back({ name=PoolByteArray([64+o]).get_string_from_ascii(), type="rgba" }) + return rv + +func source_changed(input_index : int): + notify_output_change(input_index % parameters.outputs) + +func _get_shader_code(uv : String, output_index : int, context : MMGenContext): + var source = get_source(output_index+parameters.source*parameters.outputs) + if source != null: + var rv = source.generator._get_shader_code(uv, source.output_index, context) + while rv is GDScriptFunctionState: + rv = yield(rv, "completed") + return rv + return { defs="", code="", textures={} } diff --git a/addons/material_maker/engine/loader.gd b/addons/material_maker/engine/loader.gd index d223e02..d5aa8f2 100644 --- a/addons/material_maker/engine/loader.gd +++ b/addons/material_maker/engine/loader.gd @@ -61,7 +61,11 @@ static func create_gen(data) -> MMGenBase: generator = MMGenImage.new() elif data.type == "ios": generator = MMGenIOs.new() + if data.has("mask"): + generator.mask = data.mask generator.ports = data.ports + elif data.type == "switch": + generator = MMGenSwitch.new() else: var file = File.new() if file.open("res://addons/material_maker/nodes/"+data.type+".mmg", File.READ) == OK: diff --git a/addons/material_maker/main_window.tscn b/addons/material_maker/main_window.tscn index ac61f02..fb86ec5 100644 --- a/addons/material_maker/main_window.tscn +++ b/addons/material_maker/main_window.tscn @@ -102,6 +102,10 @@ script = ExtResource( 6 ) [connection signal="no_more_tabs" from="VBoxContainer/HBoxContainer/Projects" to="." method="new_material"] [connection signal="resized" from="VBoxContainer/HBoxContainer/Projects" to="VBoxContainer/HBoxContainer/Projects" method="_on_Projects_resized"] [connection signal="tab_changed" from="VBoxContainer/HBoxContainer/Projects" to="." method="_on_Projects_tab_changed"] +[connection signal="connection_request" from="VBoxContainer/HBoxContainer/Projects/GraphEdit" to="VBoxContainer/HBoxContainer/Projects/GraphEdit" method="connect_node"] +[connection signal="disconnection_request" from="VBoxContainer/HBoxContainer/Projects/GraphEdit" to="VBoxContainer/HBoxContainer/Projects/GraphEdit" method="disconnect_node"] +[connection signal="close_request" from="VBoxContainer/HBoxContainer/Projects/GraphEdit/node_Material" to="VBoxContainer/HBoxContainer/Projects/GraphEdit/node_Material" method="on_close_request"] +[connection signal="offset_changed" from="VBoxContainer/HBoxContainer/Projects/GraphEdit/node_Material" to="VBoxContainer/HBoxContainer/Projects/GraphEdit/node_Material" method="on_offset_changed"] [connection signal="reposition_active_tab_request" from="VBoxContainer/HBoxContainer/Projects/Tabs" to="VBoxContainer/HBoxContainer/Projects" method="move_active_tab_to"] [connection signal="tab_changed" from="VBoxContainer/HBoxContainer/Projects/Tabs" to="VBoxContainer/HBoxContainer/Projects" method="set_current_tab"] [connection signal="tab_close" from="VBoxContainer/HBoxContainer/Projects/Tabs" to="VBoxContainer/HBoxContainer/Projects" method="close_tab"] diff --git a/addons/material_maker/nodes/generic.gd b/addons/material_maker/nodes/generic.gd index 5ce03ae..cd8883b 100644 --- a/addons/material_maker/nodes/generic.gd +++ b/addons/material_maker/nodes/generic.gd @@ -3,10 +3,11 @@ extends GraphNode var generator = null setget set_generator -var controls = [] +var controls = {} func set_generator(g): generator = g + generator.connect("parameter_changed", self, "on_parameter_changed") update_node() func on_close_request(): @@ -15,35 +16,49 @@ func on_close_request(): func on_offset_changed(): generator.position = offset +func on_parameter_changed(p, v): + var o = controls[p] + if o is LineEdit: + o.text = str(v) + elif o is SpinBox: + o.value = v + elif o is HSlider: + o.value = v + elif o is OptionButton: + o.selected = v + elif o is CheckBox: + o.pressed = v + elif o is ColorPickerButton: + o.color = MMType.deserialize_value(v) + elif o is Control and o.filename == "res://addons/material_maker/widgets/gradient_editor.tscn": + var gradient : MMGradient = MMGradient.new() + gradient.deserialize(v) + o.value = gradient + else: + print("unsupported widget "+str(o)) + func initialize_properties(): - for o in controls: - if o == null: - print("error in node "+name) - continue - if !generator.parameters.has(o.name): + var parameter_names = [] + for p in generator.get_parameter_defs(): + parameter_names.push_back(p.name) + for c in controls: + if parameter_names.find(c) == -1: continue + var o = controls[c] + on_parameter_changed(c, generator.parameters[c]) if o is LineEdit: - o.text = str(generator.parameters[o.name]) o.connect("text_changed", self, "_on_text_changed", [ o.name ]) elif o is SpinBox: - o.value = generator.parameters[o.name] o.connect("value_changed", self, "_on_value_changed", [ o.name ]) elif o is HSlider: - o.value = generator.parameters[o.name] o.connect("value_changed", self, "_on_value_changed", [ o.name ]) elif o is OptionButton: - o.selected = generator.parameters[o.name] o.connect("item_selected", self, "_on_value_changed", [ o.name ]) elif o is CheckBox: - o.pressed = generator.parameters[o.name] o.connect("toggled", self, "_on_value_changed", [ o.name ]) elif o is ColorPickerButton: - o.color = MMType.deserialize_value(generator.parameters[o.name]) o.connect("color_changed", self, "_on_color_changed", [ o.name ]) elif o is Control and o.filename == "res://addons/material_maker/widgets/gradient_editor.tscn": - var gradient : MMGradient = MMGradient.new() - gradient.deserialize(generator.parameters[o.name]) - o.value = gradient o.connect("updated", self, "_on_gradient_changed", [ o.name ]) else: print("unsupported widget "+str(o)) @@ -111,7 +126,7 @@ func update_node(): for c in get_children(): c.get_child(0).rect_min_size.x = input_names_width # Parameters - controls = [] + controls = {} var index = -1 var regex = RegEx.new() regex.compile("^(\\d+):(.*)") @@ -153,7 +168,7 @@ func update_node(): if control != null: var label = p.name control.name = label - controls.append(control) + controls[control.name] = control if p.has("label"): label = p.label var result = regex.search(label) diff --git a/addons/material_maker/nodes/normal_map.mmg b/addons/material_maker/nodes/normal_map.mmg index 9ddeea0..2d37a31 100644 --- a/addons/material_maker/nodes/normal_map.mmg +++ b/addons/material_maker/nodes/normal_map.mmg @@ -1 +1 @@ -{"label":"Normal Map","connections":[{"from":"nm_convolution","from_port":0,"to":"nm_postprocess","to_port":0},{"from":"nm_postprocess","from_port":0,"to":"gen_outputs","to_port":0},{"from":"gen_inputs","from_port":0,"to":"nm_convolution","to_port":0}],"nodes":[{"name":"gen_inputs","type":"ios","ports":[{"name":""}],"node_position":{"x":-89.25,"y":-73.75}},{"name":"gen_outputs","type":"ios","ports":[{"name":""}],"node_position":{"x":-89.25,"y":-73.75}},{"convolution_params":{"input_type":"f","matrix":[[[-1,-1,0],[0,-2,0],[1,-1,0]],[[-2,0,0],0,[2,0,0]],[[-1,1,0],[0,2,0],[1,1,0]]],"output_type":"rgb","x":1,"y":1},"name":"nm_convolution","node_position":{"x":-89.25,"y":-73.75},"parameters":{"size":7},"type":"shader"},{"name":"nm_postprocess","node_position":{"x":-98.25,"y":-6.75},"parameters":{"amount":0.995,"size":7},"shader_model":{"global":"","inputs":[{"default":"vec3(0.0)","label":"","name":"in","type":"rgb"}],"instance":"","name":"NormalMapPostProcess","outputs":[{"rgb":"0.5*normalize($in($uv)*$amount*$size/128.0-vec3(0.0, 0.0, 1.0))+vec3(0.5)","type":"rgb"}],"parameters":[{"default":8,"first":4,"label":"","last":11,"name":"size","type":"size"},{"default":1,"label":"","max":2,"min":0,"name":"amount","step":0.005,"type":"float"}]},"type":"shader"}]} \ No newline at end of file +{"connections":[{"from":"nm_convolution","from_port":0,"to":"nm_postprocess","to_port":0},{"from":"nm_postprocess","from_port":0,"to":"gen_outputs","to_port":0},{"from":"gen_inputs","from_port":0,"to":"buffer","to_port":0},{"from":"buffer","from_port":0,"to":"nm_convolution","to_port":0}],"label":"Normal Map","name":"normal_map","node_position":{"x":0,"y":0},"nodes":[{"name":"gen_inputs","node_position":{"x":-259.25,"y":-144.75},"type":"ios","ports":[{"name":"in","type":"rgba"}]},{"name":"gen_outputs","node_position":{"x":145.75,"y":-3.75},"type":"ios","ports":[{"name":"in","type":"rgba"}]},{"convolution_params":{"input_type":"f","matrix":[[[-1,-1,0],[0,-2,0],[1,-1,0]],[[-2,0,0],0,[2,0,0]],[[-1,1,0],[0,2,0],[1,1,0]]],"output_type":"rgb","x":1,"y":1},"name":"nm_convolution","node_position":{"x":-89.25,"y":-76.75},"parameters":{"size":5},"type":"shader"},{"name":"nm_postprocess","node_position":{"x":-98.25,"y":-6.75},"parameters":{"amount":0.995,"size":5},"shader_model":{"global":"","inputs":[{"default":"vec3(0.0)","label":"","name":"in","type":"rgb"}],"instance":"","name":"NormalMapPostProcess","outputs":[{"rgb":"0.5*normalize($in($uv)*$amount*$size/128.0-vec3(0.0, 0.0, 1.0))+vec3(0.5)","type":"rgb"}],"parameters":[{"default":8,"first":4,"label":"","last":11,"name":"size","type":"size"},{"default":1,"label":"","max":2,"min":0,"name":"amount","step":0.005,"type":"float"}]},"type":"shader"},{"name":"buffer","node_position":{"x":-89.663818,"y":-147.39386},"parameters":{"size":5},"type":"buffer"}],"parameters":{"amount":0.35,"size":4},"type":"graph"} \ No newline at end of file diff --git a/addons/material_maker/widgets/linked_widgets/config_control.gd b/addons/material_maker/widgets/linked_widgets/config_control.gd index a437f02..5672a38 100644 --- a/addons/material_maker/widgets/linked_widgets/config_control.gd +++ b/addons/material_maker/widgets/linked_widgets/config_control.gd @@ -52,7 +52,7 @@ func apply_configuration(c): for w in configurations[c]: var value = duplicate_value(w.value) w.widget.set(WIDGETS[get_widget_type(w.widget)].value_attr, value) - w.node.parameters[w.widget.name] = value + w.node.generator.set_parameter(w.widget.name, value) var graph_node = get_parent() while !(graph_node is GraphNode): graph_node = graph_node.get_parent() From 201f911f75f04b694609e3d1312777ddf01e685d Mon Sep 17 00:00:00 2001 From: RodZill4 Date: Tue, 24 Sep 2019 22:25:46 +0200 Subject: [PATCH 027/133] More progress on remote and various fixes --- addons/material_maker/engine/gen_material.gd | 21 +++-- addons/material_maker/engine/gen_remote.gd | 29 ++++++- addons/material_maker/engine/gen_switch.gd | 2 +- addons/material_maker/engine/renderer.gd | 11 +-- addons/material_maker/engine/renderer.tscn | 1 - addons/material_maker/main_window.tscn | 1 + addons/material_maker/nodes/generic.gd | 83 +++++++++++-------- addons/material_maker/nodes/remote.gd | 82 ++++++++++-------- addons/material_maker/nodes/remote.tscn | 8 +- .../widgets/linked_widgets/config_control.gd | 16 +--- .../widgets/linked_widgets/link.gd | 79 ++++++++++++++---- .../widgets/linked_widgets/linked_control.gd | 15 +++- .../linked_widgets/linked_control_base.gd | 13 ++- .../linked_control_buttons.tscn | 60 +------------- project.godot | 18 ++++ 15 files changed, 257 insertions(+), 182 deletions(-) diff --git a/addons/material_maker/engine/gen_material.gd b/addons/material_maker/engine/gen_material.gd index abd407f..ac4439b 100644 --- a/addons/material_maker/engine/gen_material.gd +++ b/addons/material_maker/engine/gen_material.gd @@ -13,7 +13,7 @@ const TEXTURE_LIST = [ { port=2, texture="roughness" }, { port=3, texture="emission" }, { port=4, texture="normal_texture" }, - { port=5, texture="ambient_occlusion" }, + { port=5, texture="ao_texture" }, { port=6, texture="depth_texture" } ] @@ -34,9 +34,12 @@ func get_type_name(): func get_parameter_defs(): return [ { name="albedo_color", label="Albedo", type="color", default={ r=1.0, g=1.0, b=1.0, a=1.0} }, - { name="metallic", label="Metallic", type="float", min=0.0, max=1.0, default=1.0 }, - { name="roughness", label="Roughness", type="float", min=0.0, max=1.0, default=1.0 }, - { name="emission_energy", label="Emission", type="float", min=0.0, max=8.0, default=1.0 } + { name="metallic", label="Metallic", type="float", min=0.0, max=1.0, step=0.05, default=1.0 }, + { name="roughness", label="Roughness", type="float", min=0.0, max=1.0, step=0.05, default=1.0 }, + { name="emission_energy", label="Emission", type="float", min=0.0, max=8.0, step=0.05, default=1.0 }, + { name="normal_scale", label="Normal", type="float", min=0.0, max=8.0, step=0.05, default=1.0 }, + { name="ao_light_affect", label="Ambient occlusion", type="float", min=0.0, max=1.0, step=0.05, default=1.0 }, + { name="depth_scale", label="Depth", type="float", min=0.0, max=1.0, step=0.05, default=1.0 } ] func get_input_defs(): @@ -46,6 +49,7 @@ func get_input_defs(): { name="roughness_texture", label="", type="f" }, { name="emission_texture", label="", type="rgb" }, { name="normal_texture", label="", type="rgb" }, + { name="ao_texture", label="", type="f" }, { name="depth_texture", label="", type="f" } ] @@ -124,23 +128,24 @@ func update_spatial_material(m, file_prefix = null): if Engine.editor_hint: if (generated_textures.mrao.mask & (1 << 2)) != 0: m.ao_enabled = true - #m.ao_light_affect = parameters.ao_light_affect + m.ao_light_affect = parameters.ao_light_affect m.ao_texture = m.metallic_texture m.ao_texture_channel = SpatialMaterial.TEXTURE_CHANNEL_BLUE else: m.ao_enabled = false else: - texture = get_generated_texture("ambient_occlusion", file_prefix) + texture = get_generated_texture("ao_texture", file_prefix) if texture != null: m.ao_enabled = true - #m.ao_light_affect = parameters.ao_light_affect + m.ao_light_affect = parameters.ao_light_affect m.ao_texture = texture else: m.ao_enabled = false texture = get_generated_texture("depth_texture", file_prefix) if texture != null: m.depth_enabled = true - #m.depth_scale = parameters.depth_scale + m.depth_deep_parallax = true + m.depth_scale = parameters.depth_scale m.depth_texture = texture else: m.depth_enabled = false diff --git a/addons/material_maker/engine/gen_remote.gd b/addons/material_maker/engine/gen_remote.gd index e0d5976..954c533 100644 --- a/addons/material_maker/engine/gen_remote.gd +++ b/addons/material_maker/engine/gen_remote.gd @@ -18,7 +18,7 @@ func set_widgets(w): i += 1 func get_type(): - return "remot" + return "remote" func get_type_name(): return "Remote" @@ -68,3 +68,30 @@ func _serialize(data): data.type = "remote" data.widgets = widgets return data + +func create_linked_control(label): + var index = widgets.size() + widgets.push_back({ label=label, type="linked_control", linked_widgets=[] }) + return index + +func create_config_control(label): + var index = widgets.size() + widgets.push_back({ label=label, type="config_control", linked_widgets=[], configurations=[] }) + return index + +func can_link_parameter(index, generator, param): + return true + +func link_parameter(index, generator, param): + if !can_link_parameter(index, generator, param): + return + widgets[index].linked_widgets.push_back({ node=generator.name, widget=param }) + if widgets[index].linked_widgets.size() == 1: + parameters["param"+str(index)] = generator.parameters[param] + emit_signal("parameter_changed", "", null) + +func remove_parameter(index): + for i in range(index, widgets.size()-2): + parameters["param"+str(i)] = parameters["param"+str(i+1)] + widgets.remove(index) + emit_signal("parameter_changed", "", null) \ No newline at end of file diff --git a/addons/material_maker/engine/gen_switch.gd b/addons/material_maker/engine/gen_switch.gd index f8f72a8..6ed0a96 100644 --- a/addons/material_maker/engine/gen_switch.gd +++ b/addons/material_maker/engine/gen_switch.gd @@ -31,7 +31,7 @@ func get_output_defs(): return rv func source_changed(input_index : int): - notify_output_change(input_index % parameters.outputs) + notify_output_change(input_index % int(parameters.outputs)) func _get_shader_code(uv : String, output_index : int, context : MMGenContext): var source = get_source(output_index+parameters.source*parameters.outputs) diff --git a/addons/material_maker/engine/renderer.gd b/addons/material_maker/engine/renderer.gd index 14d7420..ea28b29 100644 --- a/addons/material_maker/engine/renderer.gd +++ b/addons/material_maker/engine/renderer.gd @@ -6,6 +6,7 @@ export(String) var debug_path = null var debug_file_index : int = 0 var rendering : bool = false +signal done func _ready(): $ColorRect.material = $ColorRect.material.duplicate(true) @@ -70,9 +71,8 @@ func setup_material(shader_material, textures, shader_code): shader_material.shader.code = shader_code func render_shader(shader, textures, render_size): - if rendering: - print("Already rendering...") - return false + while rendering: + yield(self, "done") rendering = true if debug_path != null and debug_path != "": var f = File.new() @@ -91,6 +91,7 @@ func render_shader(shader, textures, render_size): render_target_update_mode = Viewport.UPDATE_ONCE update_worlds() yield(get_tree(), "idle_frame") - yield(get_tree(), "idle_frame") + #yield(get_tree(), "idle_frame") rendering = false - return true \ No newline at end of file + return true + emit_signal("done") diff --git a/addons/material_maker/engine/renderer.tscn b/addons/material_maker/engine/renderer.tscn index bbbdd44..e87b3b7 100644 --- a/addons/material_maker/engine/renderer.tscn +++ b/addons/material_maker/engine/renderer.tscn @@ -23,7 +23,6 @@ render_target_v_flip = true render_target_update_mode = 1 gui_disable_input = true script = ExtResource( 1 ) -debug_path = null [node name="ColorRect" type="ColorRect" parent="."] material = SubResource( 2 ) diff --git a/addons/material_maker/main_window.tscn b/addons/material_maker/main_window.tscn index fb86ec5..dd905c3 100644 --- a/addons/material_maker/main_window.tscn +++ b/addons/material_maker/main_window.tscn @@ -96,6 +96,7 @@ tab_align = 0 tab_close_display_policy = 1 [node name="Renderer" parent="." instance=ExtResource( 5 )] +debug_path = "" [node name="NodeFactory" type="Node" parent="."] script = ExtResource( 6 ) diff --git a/addons/material_maker/nodes/generic.gd b/addons/material_maker/nodes/generic.gd index cd8883b..1b4481b 100644 --- a/addons/material_maker/nodes/generic.gd +++ b/addons/material_maker/nodes/generic.gd @@ -1,14 +1,16 @@ tool extends GraphNode +class_name MMGraphNodeGeneric var generator = null setget set_generator var controls = {} +var ignore_parameter_change = false func set_generator(g): generator = g generator.connect("parameter_changed", self, "on_parameter_changed") - update_node() + call_deferred("update_node") func on_close_request(): generator.get_parent().remove_generator(generator) @@ -17,6 +19,8 @@ func on_offset_changed(): generator.position = offset func on_parameter_changed(p, v): + if ignore_parameter_change: + return var o = controls[p] if o is LineEdit: o.text = str(v) @@ -36,6 +40,7 @@ func on_parameter_changed(p, v): o.value = gradient else: print("unsupported widget "+str(o)) + update_shaders() func initialize_properties(): var parameter_names = [] @@ -67,21 +72,64 @@ func update_shaders(): get_parent().send_changed_signal() func _on_text_changed(new_text, variable): + ignore_parameter_change = true generator.set_parameter(variable, float(new_text)) + ignore_parameter_change = false update_shaders() func _on_value_changed(new_value, variable): + ignore_parameter_change = true generator.set_parameter(variable, new_value) + ignore_parameter_change = false update_shaders() func _on_color_changed(new_color, variable): + ignore_parameter_change = true generator.set_parameter(variable, new_color) + ignore_parameter_change = false update_shaders() func _on_gradient_changed(new_gradient, variable): + ignore_parameter_change = true generator.set_parameter(variable, new_gradient) + ignore_parameter_change = false update_shaders() +func create_parameter_control(p : Dictionary): + var control = null + if p.type == "float": + if p.has("widget") and p.widget == "spinbox": + control = SpinBox.new() + else: + control = HSlider.new() + control.min_value = p.min + control.max_value = p.max + control.step = 0.005 if !p.has("step") else p.step + control.allow_greater = true + control.allow_lesser = true + if p.has("default"): + control.value = p.default + control.rect_min_size.x = 80 + elif p.type == "size": + control = OptionButton.new() + for i in range(p.first, p.last+1): + var s = pow(2, i) + control.add_item("%dx%d" % [ s, s ]) + control.selected = 0 if !p.has("default") else p.default-p.first + elif p.type == "enum": + control = OptionButton.new() + for i in range(p.values.size()): + var value = p.values[i] + control.add_item(value.name) + control.selected = 0 if !p.has("default") else p.default + elif p.type == "boolean": + control = CheckBox.new() + elif p.type == "color": + control = ColorPickerButton.new() + elif p.type == "gradient": + control = preload("res://addons/material_maker/widgets/gradient_editor.tscn").instance() + return control + func update_node(): # Clean node var custom_node_buttons = null @@ -133,38 +181,7 @@ func update_node(): for p in generator.get_parameter_defs(): if !p.has("name") or !p.has("type"): continue - var control = null - if p.type == "float": - if p.has("widget") and p.widget == "spinbox": - control = SpinBox.new() - else: - control = HSlider.new() - control.min_value = p.min - control.max_value = p.max - control.step = 0.005 if !p.has("step") else p.step - control.allow_greater = true - control.allow_lesser = true - if p.has("default"): - control.value = p.default - control.rect_min_size.x = 80 - elif p.type == "size": - control = OptionButton.new() - for i in range(p.first, p.last+1): - var s = pow(2, i) - control.add_item("%dx%d" % [ s, s ]) - control.selected = 0 if !p.has("default") else p.default-p.first - elif p.type == "enum": - control = OptionButton.new() - for i in range(p.values.size()): - var value = p.values[i] - control.add_item(value.name) - control.selected = 0 if !p.has("default") else p.default - elif p.type == "boolean": - control = CheckBox.new() - elif p.type == "color": - control = ColorPickerButton.new() - elif p.type == "gradient": - control = preload("res://addons/material_maker/widgets/gradient_editor.tscn").instance() + var control = create_parameter_control(p) if control != null: var label = p.name control.name = label diff --git a/addons/material_maker/nodes/remote.gd b/addons/material_maker/nodes/remote.gd index 2f9d393..feb3d34 100644 --- a/addons/material_maker/nodes/remote.gd +++ b/addons/material_maker/nodes/remote.gd @@ -1,43 +1,56 @@ tool -extends "res://addons/material_maker/node_base.gd" +extends MMGraphNodeGeneric +class_name MMGraphNodeRemote const LinkedControl = preload("res://addons/material_maker/widgets/linked_widgets/linked_control.tscn") const ConfigControl = preload("res://addons/material_maker/widgets/linked_widgets/config_control.tscn") -var generator = null setget set_generator - -func set_generator(g): - generator = g - call_deferred("update_node") - +func add_control(text, control): + var index = $Controls.get_child_count() / 4 + var label = preload("res://addons/material_maker/widgets/linked_widgets/editable_label.tscn").instance() + label.set_text(text) + $Controls.add_child(label) + $Controls.add_child(control) + var button = Button.new() + button.icon = preload("res://addons/material_maker/icons/link.png") + $Controls.add_child(button) + button.connect("pressed", self, "_on_Link_pressed", [ index ]) + button = Button.new() + button.icon = preload("res://addons/material_maker/icons/remove.png") + $Controls.add_child(button) + button.connect("pressed", generator, "remove_parameter", [ index ]) func update_node(): - for w in generator.widgets: - var widget - if w.type == "linked_control": - widget = LinkedControl.instance() - elif w.type == "config_control": - widget = ConfigControl.instance() - else: - continue - add_control(widget) - widget.deserialize(w) - -func add_control(widget): - var controls = widget.get_associated_controls() - $Controls.add_child(controls.label) - $Controls.add_child(widget) - $Controls.add_child(controls.buttons) + var i : int = 0 + for c in $Controls.get_children(): + c.queue_free() + yield(get_tree(), "idle_frame") + controls = {} + for p in generator.get_parameter_defs(): + var control = create_parameter_control(p) + if control != null: + control.name = p.name + controls[control.name] = control + add_control(generator.widgets[i].label, control) + i += 1 + rect_size = Vector2(0, 0) + initialize_properties() func _on_AddLink_pressed(): - var widget = LinkedControl.instance() - add_control(widget) - widget.pick_linked() + var widget = Control.new() + add_control("Unnamed", widget) + var link = MMNodeLink.new(get_parent()) + link.pick(widget, generator, generator.create_linked_control("Unnamed"), true) func _on_AddConfig_pressed(): - var widget = ConfigControl.instance() - add_control(widget) - widget.pick_linked() + var widget = Control.new() + add_control("Unnamed", widget) + var link = MMNodeLink.new(get_parent()) + link.pick(widget, generator, generator.create_config_control("Unnamed"), true) + +func _on_Link_pressed(index): + var link = MMNodeLink.new(get_parent()) + link.pick($Controls.get_child(index*4+1), generator, index) func _on_Remote_resize_request(new_minsize): print("_on_Remote_resize_request") @@ -46,9 +59,8 @@ func _on_Remote_resize_request(new_minsize): func _on_HBoxContainer_minimum_size_changed(): print("_on_HBoxContainer_minimum_size_changed "+str($HBoxContainer.rect_min_size)) -func serialize(): - var widgets = [] - for i in range(1, $Controls.get_child_count(), 3): - widgets.append($Controls.get_child(i).serialize()) - var data = { type="remote", node_position={x=offset.x,y=offset.y}, editable=true, widgets=widgets } - return data +func on_parameter_changed(p, v): + if p == "": + update_node() + else: + .on_parameter_changed(p, v) \ No newline at end of file diff --git a/addons/material_maker/nodes/remote.tscn b/addons/material_maker/nodes/remote.tscn index 1c19a2e..941f019 100644 --- a/addons/material_maker/nodes/remote.tscn +++ b/addons/material_maker/nodes/remote.tscn @@ -1,14 +1,14 @@ [gd_scene load_steps=5 format=2] [ext_resource path="res://addons/material_maker/nodes/remote.gd" type="Script" id=1] -[ext_resource path="res://addons/material_maker/icons/link.png" type="Texture" id=2] -[ext_resource path="res://addons/material_maker/icons/config.png" type="Texture" id=3] +[ext_resource path="res://addons/material_maker/icons/add_link.png" type="Texture" id=2] +[ext_resource path="res://addons/material_maker/icons/add_config.png" type="Texture" id=3] [sub_resource type="Theme" id=1] [node name="Remote" type="GraphNode"] margin_right = 95.0 -margin_bottom = 55.0 +margin_bottom = 52.0 mouse_filter = 1 theme = SubResource( 1 ) title = "Remote" @@ -32,7 +32,7 @@ margin_left = 16.0 margin_top = 24.0 margin_right = 79.0 margin_bottom = 24.0 -columns = 3 +columns = 4 [node name="HBoxContainer" type="HBoxContainer" parent="."] margin_left = 16.0 diff --git a/addons/material_maker/widgets/linked_widgets/config_control.gd b/addons/material_maker/widgets/linked_widgets/config_control.gd index 5672a38..8100501 100644 --- a/addons/material_maker/widgets/linked_widgets/config_control.gd +++ b/addons/material_maker/widgets/linked_widgets/config_control.gd @@ -48,15 +48,8 @@ func duplicate_value(value): value = value.duplicate() return value -func apply_configuration(c): - for w in configurations[c]: - var value = duplicate_value(w.value) - w.widget.set(WIDGETS[get_widget_type(w.widget)].value_attr, value) - w.node.generator.set_parameter(w.widget.name, value) - var graph_node = get_parent() - while !(graph_node is GraphNode): - graph_node = graph_node.get_parent() - graph_node.update_shaders() +func apply_configuration(i): + get_parent().get_parent().generator.set_parameter("param"+str(get_index()%4-1), i) func do_update_configuration(name): var configuration = [] @@ -78,7 +71,7 @@ func _on_item_selected(ID): if ID >= 0 && ID < count: current = button.get_item_text(ID) update_options() - apply_configuration(current) + apply_configuration(ID) elif ID == count+1: button.selected = 0 update_configuration() @@ -116,10 +109,9 @@ func deserialize(data): var configuration = [] for e in c: var node = graph_edit.get_node("node_"+e.node) - print(e.widget) var widget = null for w in node.controls: - if w.name == e.widget: + if w == e.widget: widget = w break configuration.append({ node=node, widget=widget, value=Types.deserialize_value(e.value) }) diff --git a/addons/material_maker/widgets/linked_widgets/link.gd b/addons/material_maker/widgets/linked_widgets/link.gd index 368bb0b..7d3df28 100644 --- a/addons/material_maker/widgets/linked_widgets/link.gd +++ b/addons/material_maker/widgets/linked_widgets/link.gd @@ -1,33 +1,84 @@ +tool extends Control +class_name MMNodeLink -var clip_pos = Vector2(0, 0) -var clip_size = Vector2(0, 0) var end var source = null var target = null -func _ready(): - mouse_filter = Control.MOUSE_FILTER_IGNORE +var generator = null +var param_index = 0 +var creating = false -func clip(p, s): - clip_pos = p - rect_global_position = Vector2(0, 0) - rect_size = s +func _init(parent): + size_flags_horizontal = SIZE_EXPAND_FILL + size_flags_vertical = SIZE_EXPAND_FILL + rect_size = parent.rect_size rect_clip_content = true + parent.add_child(self) + +func pick(s, g, i, c = false): + source = s + end = get_global_transform().xform_inv(source.get_global_transform().xform(0.5*source.rect_size)) + generator = g + param_index = i + creating = c + set_process_input(true) + +func show_link(s, t): + set_process_input(false) + mouse_filter = Control.MOUSE_FILTER_IGNORE + source = s + target = t + update() func closest(rect, point): return Vector2(max(rect.position.x, min(rect.end.x, point.x)), max(rect.position.y, min(rect.end.y, point.y))) +func find_control(gp): + for c in get_parent().get_children(): + if c is GraphNode: + if c.get("controls") != null: + for w in c.controls: + var widget = c.controls[w] + if Rect2(widget.rect_global_position, widget.rect_size*widget.get_global_transform().get_scale()).has_point(gp): + return { node=c, widget=widget } + return null + func _draw(): - var start = source.rect_global_position+0.5*source.rect_size*source.get_global_transform().get_scale() + draw_rect(Rect2(rect_position, rect_size), Color(1.0, 0.0, 0.0, 0.2)) + draw_rect(Rect2(rect_position, rect_size), Color(1.0, 1.0, 0.0), false) + var start = get_global_transform().xform_inv(source.get_global_transform().xform(0.5*source.rect_size)) var color = Color(1, 0.5, 0.5, 0.5) var rect if target != null: color = Color(0.5, 1, 0.5, 0.5) - rect = Rect2(target.rect_global_position, target.rect_size*target.get_global_transform().get_scale()) - draw_rect(Rect2(rect.position-clip_pos, rect.size), color, false) + rect = get_global_transform().xform_inv(target.get_global_transform().xform(Rect2(Vector2(0, 0), target.rect_size))) + draw_rect(rect, color, false) end = closest(rect, start) - rect = Rect2(source.rect_global_position, source.rect_size*source.get_global_transform().get_scale()) - draw_rect(Rect2(rect.position-clip_pos, rect.size), color, false) + rect = get_global_transform().xform_inv(source.get_global_transform().xform(Rect2(Vector2(0, 0), source.rect_size))) + draw_rect(rect, color, false) start = closest(rect, end) - draw_line(start-clip_pos, end-clip_pos, color, 1, true) + draw_line(start, end, color, 1, true) + +func _input(event): + if event is InputEventKey: + if event.scancode == KEY_ESCAPE: + set_process_input(false) + queue_free() + elif event is InputEventMouseMotion: + var control = find_control(event.global_position) + end = get_global_transform().xform_inv(event.global_position) + target = control.widget if control != null and generator.can_link_parameter(param_index, control.node.generator, control.widget.name) else null + update() + elif event is InputEventMouseButton: + if event.pressed: + if event.button_index == BUTTON_LEFT: + var control = find_control(event.global_position) + if control != null: + generator.link_parameter(param_index, control.node.generator, control.widget.name) + elif creating: + generator.remove_parameter(param_index) + set_process_input(false) + queue_free() + get_tree().set_input_as_handled() diff --git a/addons/material_maker/widgets/linked_widgets/linked_control.gd b/addons/material_maker/widgets/linked_widgets/linked_control.gd index 5f24ccd..82ebee5 100644 --- a/addons/material_maker/widgets/linked_widgets/linked_control.gd +++ b/addons/material_maker/widgets/linked_widgets/linked_control.gd @@ -77,19 +77,28 @@ func _on_value_changed(v): func _on_color_changed(c): for l in linked_widgets: l.widget.color = c - l.node.parameters[l.widget.name] = c + var parent = l.widget.get_parent() + while !(parent is GraphNode): + parent = parent.get_parent() + parent.generator.set_parameter(l.widget.name, c) update_shaders() func _on_item_selected(i): for l in linked_widgets: l.widget.selected = i - l.node.parameters[l.widget.name] = i + var parent = l.widget.get_parent() + while !(parent is GraphNode): + parent = parent.get_parent() + parent.generator.set_parameter(l.widget.name, i) update_shaders() func _on_gradient_updated(g): for l in linked_widgets: l.widget.value = g - l.node.parameters[l.widget.name] = g + var parent = l.widget.get_parent() + while !(parent is GraphNode): + parent = parent.get_parent() + parent.generator.set_parameter(l.widget.name, g) update_shaders() func serialize(): diff --git a/addons/material_maker/widgets/linked_widgets/linked_control_base.gd b/addons/material_maker/widgets/linked_widgets/linked_control_base.gd index 19a3612..0952958 100644 --- a/addons/material_maker/widgets/linked_widgets/linked_control_base.gd +++ b/addons/material_maker/widgets/linked_widgets/linked_control_base.gd @@ -61,11 +61,9 @@ func _on_mouse_entered(): links = [] var viewport = get_viewport() for w in linked_widgets: - var link = Link.new() - link.clip(graph_edit.rect_global_position, graph_edit.rect_size) + var link = Link.new(graph_edit) link.source = self link.target = w.widget - graph_edit.add_child(link) links.append(link) func _on_mouse_exited(): @@ -90,8 +88,9 @@ func find_control(gp): if c is GraphNode: if c.get("controls") != null: for w in c.controls: - if Rect2(w.rect_global_position, w.rect_size*w.get_global_transform().get_scale()).has_point(gp): - return { node=c, widget=w } + var widget = c.controls[w] + if Rect2(widget.rect_global_position, widget.rect_size*widget.get_global_transform().get_scale()).has_point(gp): + return { node=c, widget=widget } return null func _input(event): @@ -123,11 +122,9 @@ func pick_linked(): return # Create line that will be shown when looking for a target var viewport = get_viewport() - link = Link.new() - link.clip(graph_edit.rect_global_position, graph_edit.rect_size) + link = Link.new(graph_edit) link.source = self link.end = rect_global_position+0.5*rect_size*get_global_transform().get_scale() - graph_edit.add_child(link) set_process_input(true) pointed_control = null diff --git a/addons/material_maker/widgets/linked_widgets/linked_control_buttons.tscn b/addons/material_maker/widgets/linked_widgets/linked_control_buttons.tscn index f87a71b..761e7c5 100644 --- a/addons/material_maker/widgets/linked_widgets/linked_control_buttons.tscn +++ b/addons/material_maker/widgets/linked_widgets/linked_control_buttons.tscn @@ -4,76 +4,22 @@ [ext_resource path="res://addons/material_maker/icons/link.png" type="Texture" id=2] [ext_resource path="res://addons/material_maker/icons/remove.png" type="Texture" id=3] -[node name="Buttons" type="HBoxContainer" index="0"] - -anchor_left = 0.0 -anchor_top = 0.0 -anchor_right = 0.0 -anchor_bottom = 0.0 +[node name="Buttons" type="HBoxContainer"] margin_right = 60.0 margin_bottom = 22.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 -alignment = 0 script = ExtResource( 1 ) -[node name="Link" type="Button" parent="." index="0"] - -anchor_left = 0.0 -anchor_top = 0.0 -anchor_right = 0.0 -anchor_bottom = 0.0 +[node name="Link" type="Button" parent="."] margin_right = 28.0 margin_bottom = 22.0 -rect_pivot_offset = Vector2( 0, 0 ) -rect_clip_content = false hint_tooltip = "Link new parameter" -focus_mode = 2 -mouse_filter = 0 -mouse_default_cursor_shape = 0 -size_flags_horizontal = 1 -size_flags_vertical = 1 -toggle_mode = false -enabled_focus_mode = 2 -shortcut = null -group = null icon = ExtResource( 2 ) -flat = false -align = 1 -_sections_unfolded = [ "Hint" ] -[node name="Remove" type="Button" parent="." index="1"] - -anchor_left = 0.0 -anchor_top = 0.0 -anchor_right = 0.0 -anchor_bottom = 0.0 +[node name="Remove" type="Button" parent="."] margin_left = 32.0 margin_right = 60.0 margin_bottom = 22.0 -rect_pivot_offset = Vector2( 0, 0 ) -rect_clip_content = false hint_tooltip = "Delete this control" -focus_mode = 2 -mouse_filter = 0 -mouse_default_cursor_shape = 0 -size_flags_horizontal = 1 -size_flags_vertical = 1 -toggle_mode = false -enabled_focus_mode = 2 -shortcut = null -group = null icon = ExtResource( 3 ) -flat = false -align = 1 -_sections_unfolded = [ "Hint" ] - [connection signal="pressed" from="Link" to="." method="_on_Link_pressed"] - [connection signal="pressed" from="Remove" to="." method="_on_Remove_pressed"] - - diff --git a/project.godot b/project.godot index b80c364..0aab12b 100644 --- a/project.godot +++ b/project.godot @@ -84,6 +84,21 @@ _global_script_classes=[ { "language": "GDScript", "path": "res://addons/material_maker/types/gradient.gd" }, { +"base": "GraphNode", +"class": "MMGraphNodeGeneric", +"language": "GDScript", +"path": "res://addons/material_maker/nodes/generic.gd" +}, { +"base": "MMGraphNodeGeneric", +"class": "MMGraphNodeRemote", +"language": "GDScript", +"path": "res://addons/material_maker/nodes/remote.gd" +}, { +"base": "Control", +"class": "MMNodeLink", +"language": "GDScript", +"path": "res://addons/material_maker/widgets/linked_widgets/link.gd" +}, { "base": "Node", "class": "MMType", "language": "GDScript", @@ -105,6 +120,9 @@ _global_script_class_icons={ "MMGenSwitch": "", "MMGenTexture": "", "MMGradient": "", +"MMGraphNodeGeneric": "", +"MMGraphNodeRemote": "", +"MMNodeLink": "", "MMType": "" } From bd24b3e87e17213f2f31495d295bf594789c6896 Mon Sep 17 00:00:00 2001 From: RodZill4 Date: Wed, 25 Sep 2019 08:04:36 +0200 Subject: [PATCH 028/133] More progress on remote, bug fixes, cleanup and changes for standalone release --- addons/material_maker/engine/gen_material.gd | 21 +- addons/material_maker/engine/gen_remote.gd | 11 +- addons/material_maker/engine/loader.gd | 7 +- addons/material_maker/engine/renderer.gd | 2 +- addons/material_maker/library.gd | 3 +- addons/material_maker/main_window.tscn | 1 - addons/material_maker/node_factory.gd | 12 +- addons/material_maker/nodes/blend/blend.gd | 51 ----- addons/material_maker/nodes/blend/blend.tscn | 82 ------- .../material_maker/nodes/combine/combine.gd | 37 --- .../material_maker/nodes/combine/combine.tscn | 143 ------------ .../nodes/decompose/decompose.gd | 21 -- .../nodes/decompose/decompose.tscn | 147 ------------ addons/material_maker/nodes/edit_buttons.gd | 1 + .../nodes/normal_map/normal_map.gd | 64 ------ .../nodes/normal_map/normal_map.tscn | 184 --------------- addons/material_maker/nodes/remote.gd | 23 +- addons/material_maker/nodes/switch/switch.gd | 25 -- .../material_maker/nodes/switch/switch.tscn | 107 --------- .../nodes/transform/transform.gd | 39 ---- .../nodes/transform/transform.tscn | 216 ------------------ addons/material_maker/nodes/warp/warp.gd | 32 --- addons/material_maker/nodes/warp/warp.tscn | 58 ----- 23 files changed, 52 insertions(+), 1235 deletions(-) delete mode 100644 addons/material_maker/nodes/blend/blend.gd delete mode 100644 addons/material_maker/nodes/blend/blend.tscn delete mode 100644 addons/material_maker/nodes/combine/combine.gd delete mode 100644 addons/material_maker/nodes/combine/combine.tscn delete mode 100644 addons/material_maker/nodes/decompose/decompose.gd delete mode 100644 addons/material_maker/nodes/decompose/decompose.tscn delete mode 100644 addons/material_maker/nodes/normal_map/normal_map.gd delete mode 100644 addons/material_maker/nodes/normal_map/normal_map.tscn delete mode 100644 addons/material_maker/nodes/switch/switch.gd delete mode 100644 addons/material_maker/nodes/switch/switch.tscn delete mode 100644 addons/material_maker/nodes/transform/transform.gd delete mode 100644 addons/material_maker/nodes/transform/transform.tscn delete mode 100644 addons/material_maker/nodes/warp/warp.gd delete mode 100644 addons/material_maker/nodes/warp/warp.tscn diff --git a/addons/material_maker/engine/gen_material.gd b/addons/material_maker/engine/gen_material.gd index ac4439b..05a0562 100644 --- a/addons/material_maker/engine/gen_material.gd +++ b/addons/material_maker/engine/gen_material.gd @@ -21,7 +21,7 @@ const ADDON_TEXTURE_LIST = [ { port=0, texture="albedo" }, { port=3, texture="emission" }, { port=4, texture="normal_texture" }, - { ports=[1, 2, 5], default_values=["0.0", "1.0", "1.0"], texture="mrao" }, + { ports=[5, 1, 2], default_values=["1.0", "0.0", "1.0"], texture="orm" }, { port=6, texture="depth_texture" } ] @@ -73,15 +73,16 @@ func generate_material(renderer : MMGenRenderer): func render_textures(renderer : MMGenRenderer): for t in texture_list: - var source = get_source(t.port) - var texture = null - if source != null: - var status = source.generator.render(source.output_index, renderer, 512) - while status is GDScriptFunctionState: - status = yield(status, "completed") - texture = ImageTexture.new() - texture.create_from_image(renderer.get_texture().get_data()) - generated_textures[t.texture] = texture + if t.has("port"): + var source = get_source(t.port) + var texture = null + if source != null: + var status = source.generator.render(source.output_index, renderer, 512) + while status is GDScriptFunctionState: + status = yield(status, "completed") + texture = ImageTexture.new() + texture.create_from_image(renderer.get_texture().get_data()) + generated_textures[t.texture] = texture func update_materials(material_list): for m in material_list: diff --git a/addons/material_maker/engine/gen_remote.gd b/addons/material_maker/engine/gen_remote.gd index 954c533..713d749 100644 --- a/addons/material_maker/engine/gen_remote.gd +++ b/addons/material_maker/engine/gen_remote.gd @@ -52,7 +52,6 @@ func get_parameter_defs(): return rv func set_parameter(p, v): - .set_parameter(p, v) var parent = get_parent() var param_index = p.trim_prefix("param").to_int() var widget = widgets[param_index] @@ -61,8 +60,14 @@ func set_parameter(p, v): for w in widget.linked_widgets: parent.get_node(w.node).set_parameter(w.widget, v) "config_control": - for w in widget.configurations[widget.configurations.keys()[v]]: - parent.get_node(w.node).set_parameter(w.widget, w.value) + if v < widget.configurations.size(): + for w in widget.configurations[widget.configurations.keys()[v]]: + parent.get_node(w.node).set_parameter(w.widget, w.value) + else: + # incorrect configuration index + print("error: incorrect config control parameter value") + return + .set_parameter(p, v) func _serialize(data): data.type = "remote" diff --git a/addons/material_maker/engine/loader.gd b/addons/material_maker/engine/loader.gd index d5aa8f2..f7842a1 100644 --- a/addons/material_maker/engine/loader.gd +++ b/addons/material_maker/engine/loader.gd @@ -68,7 +68,12 @@ static func create_gen(data) -> MMGenBase: generator = MMGenSwitch.new() else: var file = File.new() - if file.open("res://addons/material_maker/nodes/"+data.type+".mmg", File.READ) == OK: + var gen_path = OS.get_executable_path().get_base_dir()+"/generators" + if file.open(gen_path+"/"+data.type+".mmg", File.READ) == OK: + generator = create_gen(parse_json(file.get_as_text())) + generator.model = data.type + file.close() + elif file.open("res://addons/material_maker/nodes/"+data.type+".mmg", File.READ) == OK: generator = create_gen(parse_json(file.get_as_text())) generator.model = data.type file.close() diff --git a/addons/material_maker/engine/renderer.gd b/addons/material_maker/engine/renderer.gd index ea28b29..939ee6a 100644 --- a/addons/material_maker/engine/renderer.gd +++ b/addons/material_maker/engine/renderer.gd @@ -91,7 +91,7 @@ func render_shader(shader, textures, render_size): render_target_update_mode = Viewport.UPDATE_ONCE update_worlds() yield(get_tree(), "idle_frame") - #yield(get_tree(), "idle_frame") + yield(get_tree(), "idle_frame") rendering = false return true emit_signal("done") diff --git a/addons/material_maker/library.gd b/addons/material_maker/library.gd index d565f71..cd5259f 100644 --- a/addons/material_maker/library.gd +++ b/addons/material_maker/library.gd @@ -27,8 +27,7 @@ func get_drag_data(position): func _ready(): var root = create_item() - var lib_path = OS.get_executable_path() - lib_path = lib_path.left(max(lib_path.rfind("\\"), lib_path.rfind("/"))+1)+"library/base.json" + var lib_path = OS.get_executable_path().get_base_dir()+"/library/base.json" if !add_library(lib_path): add_library("res://addons/material_maker/library/base.json") add_library("user://library/user.json") diff --git a/addons/material_maker/main_window.tscn b/addons/material_maker/main_window.tscn index dd905c3..fb86ec5 100644 --- a/addons/material_maker/main_window.tscn +++ b/addons/material_maker/main_window.tscn @@ -96,7 +96,6 @@ tab_align = 0 tab_close_display_policy = 1 [node name="Renderer" parent="." instance=ExtResource( 5 )] -debug_path = "" [node name="NodeFactory" type="Node" parent="."] script = ExtResource( 6 ) diff --git a/addons/material_maker/node_factory.gd b/addons/material_maker/node_factory.gd index c8dd4b5..ac2f2c0 100644 --- a/addons/material_maker/node_factory.gd +++ b/addons/material_maker/node_factory.gd @@ -8,13 +8,9 @@ func _ready(): func create_node(type): var node = null - if File.new().file_exists("res://addons/material_maker/nodes/"+type+".mmn"): - node = preload("res://addons/material_maker/nodes/node_generic.gd").new() - node.model = type + var node_type = load("res://addons/material_maker/nodes/"+type+".tscn") + if node_type != null: + node = node_type.instance() else: - var node_type = load("res://addons/material_maker/nodes/"+type+".tscn") - if node_type != null: - node = node_type.instance() - else: - node = preload("res://addons/material_maker/nodes/generic.tscn").instance() + node = preload("res://addons/material_maker/nodes/generic.tscn").instance() return node diff --git a/addons/material_maker/nodes/blend/blend.gd b/addons/material_maker/nodes/blend/blend.gd deleted file mode 100644 index 27d1270..0000000 --- a/addons/material_maker/nodes/blend/blend.gd +++ /dev/null @@ -1,51 +0,0 @@ -tool -extends "res://addons/material_maker/node_base.gd" - -const BLEND_TYPES = [ - { name="Normal", shortname="normal" }, - { name="Dissolve", shortname="dissolve" }, - { name="Multiply", shortname="multiply" }, - { name="Screen", shortname="screen" }, - { name="Overlay", shortname="overlay" }, - { name="Hard Light", shortname="hard_light" }, - { name="Soft Light", shortname="soft_light" }, - { name="Burn", shortname="burn" }, - { name="Dodge", shortname="dodge" }, - { name="Lighten", shortname="lighten" }, - { name="Darken", shortname="darken" }, - { name="Difference", shortname="difference" } -] - -func _ready(): - $blend_type.clear() - for i in range(BLEND_TYPES.size()): - $blend_type.add_item(BLEND_TYPES[i].name, i) - initialize_properties([ $blend_type, $HBoxContainer/amount ]) - -func _get_shader_code(uv, slot = 0): - var rv = { defs="", code="" } - var src0 = get_source(0) - var src1 = get_source(1) - var src2 = get_source(2) - if src0 == null or src1 == null: - return rv - var src0_code = src0.get_shader_code(uv) - var src1_code = src1.get_shader_code(uv) - var src2_code = { defs="", code="" } - var amount_str = "%.9f" % parameters.amount - if src2 != null: - src2_code = src2.get_shader_code(uv) - amount_str = src2_code.f - 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 += "vec4 %s_%d_rgba = vec4(blend_%s(%s, %s, %s, %s * %s.a), min(1.0, %s.a + %s * %s.a));\n" % [ name, variant_index, BLEND_TYPES[parameters.blend_type].shortname, uv, src0_code.rgb, src1_code.rgb, amount_str, src0_code.rgba, src1_code.rgba, amount_str, src0_code.rgba ] - rv.rgba = "%s_%d_rgba" % [ name, variant_index ] - return rv - -func _get_state_variables(): - return [ "amount" ] diff --git a/addons/material_maker/nodes/blend/blend.tscn b/addons/material_maker/nodes/blend/blend.tscn deleted file mode 100644 index acafef4..0000000 --- a/addons/material_maker/nodes/blend/blend.tscn +++ /dev/null @@ -1,82 +0,0 @@ -[gd_scene load_steps=3 format=2] - -[ext_resource path="res://addons/material_maker/nodes/blend/blend.gd" type="Script" id=1] - -[sub_resource type="Theme" id=1] - -[node name="Blend" type="GraphNode"] -margin_left = 1.0 -margin_right = 160.0 -margin_bottom = 104.0 -mouse_filter = 1 -theme = SubResource( 1 ) -title = "Blend" -show_close = true -slot/0/left_enabled = false -slot/0/left_type = 0 -slot/0/left_color = Color( 1, 1, 1, 1 ) -slot/0/right_enabled = true -slot/0/right_type = 0 -slot/0/right_color = Color( 0, 1, 0, 0.501961 ) -slot/1/left_enabled = true -slot/1/left_type = 0 -slot/1/left_color = Color( 0, 1, 0, 0.501961 ) -slot/1/right_enabled = false -slot/1/right_type = 0 -slot/1/right_color = Color( 1, 1, 1, 1 ) -slot/2/left_enabled = true -slot/2/left_type = 0 -slot/2/left_color = Color( 0, 1, 0, 0.501961 ) -slot/2/right_enabled = false -slot/2/right_type = 0 -slot/2/right_color = Color( 1, 1, 1, 1 ) -slot/3/left_enabled = true -slot/3/left_type = 0 -slot/3/left_color = Color( 0.756863, 0.756863, 0.756863, 1 ) -slot/3/right_enabled = false -slot/3/right_type = 0 -slot/3/right_color = Color( 1, 1, 1, 0.501961 ) -script = ExtResource( 1 ) - -[node name="blend_type" type="OptionButton" parent="."] -margin_left = 16.0 -margin_top = 24.0 -margin_right = 143.0 -margin_bottom = 44.0 -text = "Normal" -items = [ "Normal", null, false, 0, null, "Dissolve", null, false, 1, null, "Multiply", null, false, 2, null, "Screen", null, false, 3, null, "Overlay", null, false, 4, null, "Hard Light", null, false, 5, null, "Soft Light", null, false, 6, null, "Burn", null, false, 7, null, "Dodge", null, false, 8, null, "Lighten", null, false, 9, null, "Darken", null, false, 10, null, "Difference", null, false, 11, null ] -selected = 0 - -[node name="Label1" type="Label" parent="."] -margin_left = 16.0 -margin_top = 44.0 -margin_right = 143.0 -margin_bottom = 58.0 -text = "Source 1" - -[node name="Label2" type="Label" parent="."] -margin_left = 16.0 -margin_top = 59.0 -margin_right = 143.0 -margin_bottom = 73.0 -text = "Source 2" - -[node name="HBoxContainer" type="HBoxContainer" parent="."] -margin_left = 16.0 -margin_top = 74.0 -margin_right = 143.0 -margin_bottom = 98.0 - -[node name="Label3" type="Label" parent="HBoxContainer"] -margin_top = 5.0 -margin_right = 49.0 -margin_bottom = 19.0 -text = "Opacity" - -[node name="amount" type="SpinBox" parent="HBoxContainer"] -margin_left = 53.0 -margin_right = 127.0 -margin_bottom = 24.0 -max_value = 1.0 -step = 0.05 -value = 0.5 diff --git a/addons/material_maker/nodes/combine/combine.gd b/addons/material_maker/nodes/combine/combine.gd deleted file mode 100644 index 45a9f98..0000000 --- a/addons/material_maker/nodes/combine/combine.gd +++ /dev/null @@ -1,37 +0,0 @@ -tool -extends "res://addons/material_maker/node_base.gd" - -func _get_shader_code(uv, slot = 0): - var rv = { defs="", code="" } - var src0 = get_source(0) - var src1 = get_source(1) - var src2 = get_source(2) - var src3 = get_source(3) - var src0_code = { defs="", code="", f="0.0" } - var src1_code = { defs="", code="", f="0.0" } - var src2_code = { defs="", code="", f="0.0" } - var src3_code = { defs="", code="", f="1.0" } - if src0 != null: - src0_code = src0.get_shader_code(uv) - if src1 != null: - src1_code = src1.get_shader_code(uv) - if src2 != null: - src2_code = src2.get_shader_code(uv) - if src3 != null: - src3_code = src3.get_shader_code(uv) - if generated_variants.empty(): - rv.defs = src0_code.defs; - rv.defs += src1_code.defs; - rv.defs += src2_code.defs; - rv.defs += src3_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 - rv.code += src1_code.code - rv.code += src2_code.code - rv.code += src3_code.code - rv.code += "vec4 %s_%d_rgba = vec4(%s, %s, %s, %s);\n" % [ name, variant_index, src0_code.f, src1_code.f, src2_code.f, src3_code.f ] - rv.rgba = "%s_%d_rgba" % [ name, variant_index ] - return rv diff --git a/addons/material_maker/nodes/combine/combine.tscn b/addons/material_maker/nodes/combine/combine.tscn deleted file mode 100644 index 95fc506..0000000 --- a/addons/material_maker/nodes/combine/combine.tscn +++ /dev/null @@ -1,143 +0,0 @@ -[gd_scene load_steps=3 format=2] - -[ext_resource path="res://addons/material_maker/nodes/combine/combine.gd" type="Script" id=1] - -[sub_resource type="Theme" id=1] - - -[node name="Combine" type="GraphNode"] - -anchor_left = 0.0 -anchor_top = 0.0 -anchor_right = 0.0 -anchor_bottom = 0.0 -margin_left = 204.0 -margin_top = 72.0 -margin_right = 306.0 -margin_bottom = 145.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 = "Combine" -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.756863, 0.756863, 0.756863, 1 ) -slot/0/right_enabled = true -slot/0/right_type = 0 -slot/0/right_color = Color( 0.414353, 1, 0.388902, 0.353608 ) -slot/1/left_enabled = true -slot/1/left_type = 0 -slot/1/left_color = Color( 0.756863, 0.756863, 0.756863, 1 ) -slot/1/right_enabled = false -slot/1/right_type = 0 -slot/1/right_color = Color( 0.498039, 0.498039, 1, 1 ) -slot/2/left_enabled = true -slot/2/left_type = 0 -slot/2/left_color = Color( 0.756863, 0.756863, 0.756863, 1 ) -slot/2/right_enabled = false -slot/2/right_type = 0 -slot/2/right_color = Color( 0.498039, 0.498039, 1, 1 ) -slot/3/left_enabled = true -slot/3/left_type = 0 -slot/3/left_color = Color( 0.756863, 0.756863, 0.756863, 1 ) -slot/3/right_enabled = false -slot/3/right_type = 0 -slot/3/right_color = Color( 1, 1, 1, 1 ) -script = ExtResource( 1 ) -_sections_unfolded = [ "Theme", "slot", "slot/0", "slot/1", "slot/2", "slot/3" ] - -[node name="R" 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 = 86.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 = "R" -percent_visible = 1.0 -lines_skipped = 0 -max_lines_visible = -1 - -[node name="G" 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 = 86.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 = "G" -percent_visible = 1.0 -lines_skipped = 0 -max_lines_visible = -1 - -[node name="B" type="Label" 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 = 86.0 -margin_bottom = 67.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 = "B" -percent_visible = 1.0 -lines_skipped = 0 -max_lines_visible = -1 - -[node name="A" type="Label" parent="." index="3"] - -anchor_left = 0.0 -anchor_top = 0.0 -anchor_right = 0.0 -anchor_bottom = 0.0 -margin_left = 16.0 -margin_top = 68.0 -margin_right = 86.0 -margin_bottom = 82.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 = "A" -percent_visible = 1.0 -lines_skipped = 0 -max_lines_visible = -1 - - diff --git a/addons/material_maker/nodes/decompose/decompose.gd b/addons/material_maker/nodes/decompose/decompose.gd deleted file mode 100644 index d42510f..0000000 --- a/addons/material_maker/nodes/decompose/decompose.gd +++ /dev/null @@ -1,21 +0,0 @@ -tool -extends "res://addons/material_maker/node_base.gd" - -const OUTPUTS = [ "r", "g", "b", "a" ] - -func _get_shader_code(uv, output = 0): - var rv = { defs="", code="" } - var src = get_source() - var src_code = { defs="", code="", rgba="vec4(0.0)" } - if src != null: - src_code = src.get_shader_code(uv) - if generated_variants.empty(): - rv.defs = src_code.defs; - 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 - rv.code += "vec4 %s_%d_rgba = %s;\n" % [ name, variant_index, src_code.rgba ] - rv.f = "%s_%d_rgba.%s" % [ name, variant_index, OUTPUTS[output] ] - return rv diff --git a/addons/material_maker/nodes/decompose/decompose.tscn b/addons/material_maker/nodes/decompose/decompose.tscn deleted file mode 100644 index 3e6c074..0000000 --- a/addons/material_maker/nodes/decompose/decompose.tscn +++ /dev/null @@ -1,147 +0,0 @@ -[gd_scene load_steps=3 format=2] - -[ext_resource path="res://addons/material_maker/nodes/decompose/decompose.gd" type="Script" id=1] - -[sub_resource type="Theme" id=1] - - -[node name="Decompose" type="GraphNode"] - -anchor_left = 0.0 -anchor_top = 0.0 -anchor_right = 0.0 -anchor_bottom = 0.0 -margin_left = 204.0 -margin_top = 72.0 -margin_right = 306.0 -margin_bottom = 145.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 = "Decompose" -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.411765, 1, 0.388235, 0.352941 ) -slot/0/right_enabled = true -slot/0/right_type = 0 -slot/0/right_color = Color( 0.756863, 0.756863, 0.756863, 1 ) -slot/1/left_enabled = false -slot/1/left_type = 0 -slot/1/left_color = Color( 0.756863, 0.756863, 0.756863, 1 ) -slot/1/right_enabled = true -slot/1/right_type = 0 -slot/1/right_color = Color( 0.756863, 0.756863, 0.756863, 1 ) -slot/2/left_enabled = false -slot/2/left_type = 0 -slot/2/left_color = Color( 0.756863, 0.756863, 0.756863, 1 ) -slot/2/right_enabled = true -slot/2/right_type = 0 -slot/2/right_color = Color( 0.756863, 0.756863, 0.756863, 1 ) -slot/3/left_enabled = false -slot/3/left_type = 0 -slot/3/left_color = Color( 1, 1, 1, 1 ) -slot/3/right_enabled = true -slot/3/right_type = 0 -slot/3/right_color = Color( 0.756863, 0.756863, 0.756863, 1 ) -script = ExtResource( 1 ) -_sections_unfolded = [ "Theme", "slot", "slot/0", "slot/1", "slot/2", "slot/3" ] - -[node name="R" 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 = 106.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 = "R" -align = 2 -percent_visible = 1.0 -lines_skipped = 0 -max_lines_visible = -1 - -[node name="G" 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 = 106.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 = "G" -align = 2 -percent_visible = 1.0 -lines_skipped = 0 -max_lines_visible = -1 - -[node name="B" type="Label" 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 = 106.0 -margin_bottom = 67.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 = "B" -align = 2 -percent_visible = 1.0 -lines_skipped = 0 -max_lines_visible = -1 - -[node name="A" type="Label" parent="." index="3"] - -anchor_left = 0.0 -anchor_top = 0.0 -anchor_right = 0.0 -anchor_bottom = 0.0 -margin_left = 16.0 -margin_top = 68.0 -margin_right = 106.0 -margin_bottom = 82.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 = "A" -align = 2 -percent_visible = 1.0 -lines_skipped = 0 -max_lines_visible = -1 - - diff --git a/addons/material_maker/nodes/edit_buttons.gd b/addons/material_maker/nodes/edit_buttons.gd index c62bbd5..be98e4e 100644 --- a/addons/material_maker/nodes/edit_buttons.gd +++ b/addons/material_maker/nodes/edit_buttons.gd @@ -1,3 +1,4 @@ +tool extends HBoxContainer func connect_buttons(object, edit_fct, load_fct, save_fct): diff --git a/addons/material_maker/nodes/normal_map/normal_map.gd b/addons/material_maker/nodes/normal_map/normal_map.gd deleted file mode 100644 index aabf72a..0000000 --- a/addons/material_maker/nodes/normal_map/normal_map.gd +++ /dev/null @@ -1,64 +0,0 @@ -tool -extends "res://addons/material_maker/node_base.gd" - -var input_shader = "" -var input_texture -var final_texture - -const CONVOLUTION = { - x=1, - y=1, - kernel=[ - Vector3(-1, -1, 0), Vector3(0, -2, 0), Vector3(1, -1, 0), - Vector3(-2, 0, 0), 0, Vector3(2, 0, 0), - Vector3(-1, 1, 0), Vector3(0, 2, 0), Vector3(1, 1, 0), - ], - epsilon=1.0/1024, - normalize=true, - translate_before_normalize=Vector3(0.0, 0.0, -1.0), - scale_before_normalize=0.5, - translate=Vector3(0.5, 0.5, 0.5), - scale=0.5 -} - -func _ready(): - # init size widget - $HBoxContainer1/size.clear() - for i in range(7): - $HBoxContainer1/size.add_item(str(int(pow(2, 5+i))), i) - parameters.size = 2 - $HBoxContainer1/size.selected = parameters.size - input_texture = ImageTexture.new() - final_texture = ImageTexture.new() - initialize_properties([ $HBoxContainer1/size, $HBoxContainer2/amount ]) - -func _rerender(): - get_parent().renderer.precalculate_shader(input_shader, get_source().get_textures(), int(pow(2, 5+parameters.size)), input_texture, self, "pass_1", []) - -func pass_1(): - var convolution = CONVOLUTION - convolution.epsilon=1.0/pow(2, 5+parameters.size) - convolution.scale_before_normalize = pow(2, parameters.size-1)*parameters.amount - get_parent().renderer.precalculate_shader(get_convolution_shader(convolution), { input=input_texture}, int(pow(2, 5+parameters.size)), final_texture, self, "rerender_targets", []) - -func get_textures(): - var list = {} - list[name] = final_texture - return list - -func _get_shader_code(uv, slot = 0): - var rv = { defs="", code="" } - var src = get_source() - if src == null: - return rv - input_shader = get_parent().renderer.generate_shader(src.get_shader_code_with_globals("UV")) - _rerender() - if generated_variants.empty(): - rv.defs = "uniform sampler2D %s_tex;\n" % [ name ] - var variant_index = generated_variants.find(uv) - if variant_index == -1: - variant_index = generated_variants.size() - generated_variants.append(uv) - rv.code = "vec3 %s_%d_rgb = texture(%s_tex, %s).rgb;\n" % [ name, variant_index, name, uv ] - rv.rgb = "%s_%d_rgb" % [ name, variant_index ] - return rv diff --git a/addons/material_maker/nodes/normal_map/normal_map.tscn b/addons/material_maker/nodes/normal_map/normal_map.tscn deleted file mode 100644 index 2ec9384..0000000 --- a/addons/material_maker/nodes/normal_map/normal_map.tscn +++ /dev/null @@ -1,184 +0,0 @@ -[gd_scene load_steps=3 format=2] - -[ext_resource path="res://addons/material_maker/nodes/normal_map/normal_map.gd" type="Script" id=1] - - -[sub_resource type="Theme" id=1] - - -[node name="NormalMap" 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 = 173.0 -margin_bottom = 75.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 = "Normal Map" -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.756863, 0.756863, 0.756863, 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_type = 0 -slot/1/left_color = Color( 1, 1, 1, 1 ) -slot/1/right_enabled = false -slot/1/right_type = 0 -slot/1/right_color = Color( 1, 1, 1, 1 ) -script = ExtResource( 1 ) -_sections_unfolded = [ "Theme", "slot", "slot/0" ] - -[node name="HBoxContainer1" type="HBoxContainer" 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 = 156.0 -margin_bottom = 44.0 -rect_pivot_offset = Vector2( 0, 0 ) -rect_clip_content = false -mouse_filter = 1 -mouse_default_cursor_shape = 0 -size_flags_horizontal = 3 -size_flags_vertical = 1 -alignment = 0 -_sections_unfolded = [ "Size Flags" ] - -[node name="Label" type="Label" parent="HBoxContainer1" index="0"] - -anchor_left = 0.0 -anchor_top = 0.0 -anchor_right = 0.0 -anchor_bottom = 0.0 -margin_top = 3.0 -margin_right = 61.0 -margin_bottom = 17.0 -rect_pivot_offset = Vector2( 0, 0 ) -rect_clip_content = false -mouse_filter = 2 -mouse_default_cursor_shape = 0 -size_flags_horizontal = 3 -size_flags_vertical = 4 -text = "Grid size:" -percent_visible = 1.0 -lines_skipped = 0 -max_lines_visible = -1 -_sections_unfolded = [ "Anchor", "Margin", "Size Flags" ] - -[node name="size" type="OptionButton" parent="HBoxContainer1" index="1"] - -anchor_left = 0.0 -anchor_top = 0.0 -anchor_right = 0.0 -anchor_bottom = 0.0 -margin_left = 65.0 -margin_right = 140.0 -margin_bottom = 20.0 -rect_min_size = Vector2( 75, 0 ) -rect_pivot_offset = Vector2( 0, 0 ) -rect_clip_content = false -focus_mode = 2 -mouse_filter = 0 -mouse_default_cursor_shape = 0 -size_flags_horizontal = 11 -size_flags_vertical = 1 -toggle_mode = false -action_mode = 0 -enabled_focus_mode = 2 -shortcut = null -group = null -text = "1024" -flat = false -align = 0 -items = [ "32", null, false, 0, null, "64", null, false, 1, null, "128", null, false, 2, null, "256", null, false, 3, null, "512", null, false, 4, null, "1024", null, false, 5, null, "2048", null, false, 6, null ] -selected = 5 -_sections_unfolded = [ "Anchor", "Caret", "Placeholder", "Rect", "Size Flags" ] - -[node name="HBoxContainer2" type="HBoxContainer" 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 = 44.0 -margin_right = 156.0 -margin_bottom = 68.0 -rect_pivot_offset = Vector2( 0, 0 ) -rect_clip_content = false -mouse_filter = 1 -mouse_default_cursor_shape = 0 -size_flags_horizontal = 3 -size_flags_vertical = 1 -alignment = 0 -_sections_unfolded = [ "Size Flags" ] - -[node name="Label" type="Label" parent="HBoxContainer2" index="0"] - -anchor_left = 0.0 -anchor_top = 0.0 -anchor_right = 0.0 -anchor_bottom = 0.0 -margin_top = 5.0 -margin_right = 62.0 -margin_bottom = 19.0 -rect_pivot_offset = Vector2( 0, 0 ) -rect_clip_content = false -mouse_filter = 2 -mouse_default_cursor_shape = 0 -size_flags_horizontal = 3 -size_flags_vertical = 4 -text = "Amount:" -percent_visible = 1.0 -lines_skipped = 0 -max_lines_visible = -1 -_sections_unfolded = [ "Anchor", "Margin", "Size Flags" ] - -[node name="amount" type="SpinBox" parent="HBoxContainer2" index="1"] - -anchor_left = 0.0 -anchor_top = 0.0 -anchor_right = 0.0 -anchor_bottom = 0.0 -margin_left = 66.0 -margin_right = 140.0 -margin_bottom = 24.0 -rect_pivot_offset = Vector2( 0, 0 ) -rect_clip_content = false -mouse_filter = 0 -mouse_default_cursor_shape = 0 -size_flags_horizontal = 1 -size_flags_vertical = 1 -min_value = 0.0 -max_value = 1.0 -step = 0.05 -page = 0.0 -value = 0.5 -exp_edit = false -rounded = false -editable = true -prefix = "" -suffix = "" -_sections_unfolded = [ "Caret", "Placeholder" ] - - diff --git a/addons/material_maker/nodes/remote.gd b/addons/material_maker/nodes/remote.gd index feb3d34..ac42697 100644 --- a/addons/material_maker/nodes/remote.gd +++ b/addons/material_maker/nodes/remote.gd @@ -2,9 +2,6 @@ tool extends MMGraphNodeGeneric class_name MMGraphNodeRemote -const LinkedControl = preload("res://addons/material_maker/widgets/linked_widgets/linked_control.tscn") -const ConfigControl = preload("res://addons/material_maker/widgets/linked_widgets/config_control.tscn") - func add_control(text, control): var index = $Controls.get_child_count() / 4 var label = preload("res://addons/material_maker/widgets/linked_widgets/editable_label.tscn").instance() @@ -32,10 +29,30 @@ func update_node(): control.name = p.name controls[control.name] = control add_control(generator.widgets[i].label, control) + if generator.widgets[i].type == "config_control": + var current = null + if control.get_item_count() > 0: + control.selected = generator.parameters["param"+str(i)] + current = control.get_item_text(control.selected) + control.add_separator() + control.add_item("") + if current != null: + control.add_separator() + control.add_item("") + control.add_item("") i += 1 rect_size = Vector2(0, 0) initialize_properties() +func _on_value_changed(new_value, variable): + var param_index = variable.trim_prefix("param").to_int() + var widget = generator.widgets[param_index] + if widget.type == "config_control" and new_value >= widget.configurations.size(): + var command = new_value - widget.configurations.size() + print(command) + else: + ._on_value_changed(new_value, variable) + func _on_AddLink_pressed(): var widget = Control.new() add_control("Unnamed", widget) diff --git a/addons/material_maker/nodes/switch/switch.gd b/addons/material_maker/nodes/switch/switch.gd deleted file mode 100644 index 9ed8401..0000000 --- a/addons/material_maker/nodes/switch/switch.gd +++ /dev/null @@ -1,25 +0,0 @@ -tool -extends "res://addons/material_maker/node_base.gd" - -func _ready(): - initialize_properties([ $source ]) - -func reset(): - generated = false - generated_variants = [ [], [] ] - -func _get_shader_code(uv, index = 0): - var rv = { defs="", code="" } - var src = get_source(2*parameters.source+index) - var src_code = { defs="", code="", rgb="0.0" } - if src != null: - src_code = src.get_shader_code(uv) - if generated_variants[index].empty(): - rv.defs = src_code.defs; - var variant_index = generated_variants[index].find(uv) - if variant_index == -1: - variant_index = generated_variants[index].size() - generated_variants[index].append(uv) - rv.code = src_code.code - rv.rgb = src_code.rgb - return rv diff --git a/addons/material_maker/nodes/switch/switch.tscn b/addons/material_maker/nodes/switch/switch.tscn deleted file mode 100644 index 34ed4a1..0000000 --- a/addons/material_maker/nodes/switch/switch.tscn +++ /dev/null @@ -1,107 +0,0 @@ -[gd_scene load_steps=3 format=2] - -[ext_resource path="res://addons/material_maker/nodes/switch/switch.gd" type="Script" id=1] - -[sub_resource type="Theme" id=1] - -[node name="Switch" type="GraphNode"] -margin_left = 1.0 -margin_top = 1.0 -margin_right = 100.0 -margin_bottom = 110.0 -mouse_filter = 1 -theme = SubResource( 1 ) -title = "Switch" -show_close = true -slot/0/left_enabled = false -slot/0/left_type = 0 -slot/0/left_color = Color( 0.498039, 0.498039, 1, 1 ) -slot/0/right_enabled = false -slot/0/right_type = 0 -slot/0/right_color = Color( 0.498039, 0.498039, 1, 1 ) -slot/1/left_enabled = true -slot/1/left_type = 0 -slot/1/left_color = Color( 0.498039, 0.498039, 1, 1 ) -slot/1/right_enabled = false -slot/1/right_type = 0 -slot/1/right_color = Color( 0.498039, 0.498039, 1, 1 ) -slot/2/left_enabled = true -slot/2/left_type = 0 -slot/2/left_color = Color( 0.498039, 0.498039, 1, 1 ) -slot/2/right_enabled = true -slot/2/right_type = 0 -slot/2/right_color = Color( 0.498039, 0.498039, 1, 1 ) -slot/3/left_enabled = true -slot/3/left_type = 0 -slot/3/left_color = Color( 0.498039, 0.498039, 1, 1 ) -slot/3/right_enabled = true -slot/3/right_type = 0 -slot/3/right_color = Color( 0.498039, 0.498039, 1, 1 ) -slot/4/left_enabled = true -slot/4/left_type = 0 -slot/4/left_color = Color( 0.498039, 0.498039, 1, 1 ) -slot/4/right_enabled = false -slot/4/right_type = 0 -slot/4/right_color = Color( 1, 0, 0, 1 ) -script = ExtResource( 1 ) - -[node name="source" type="OptionButton" parent="."] -margin_left = 16.0 -margin_top = 24.0 -margin_right = 83.0 -margin_bottom = 44.0 -text = "1" -items = [ "1", null, false, 0, null, "2", null, false, 1, null ] -selected = 0 - -[node name="Label1" type="Label" parent="."] -margin_left = 16.0 -margin_top = 44.0 -margin_right = 83.0 -margin_bottom = 58.0 -text = "A1" - -[node name="HBoxContainer1" type="HBoxContainer" parent="."] -margin_left = 16.0 -margin_top = 59.0 -margin_right = 83.0 -margin_bottom = 73.0 - -[node name="Label1" type="Label" parent="HBoxContainer1"] -margin_right = 54.0 -margin_bottom = 14.0 -size_flags_horizontal = 3 -text = "B1" - -[node name="Label2" type="Label" parent="HBoxContainer1"] -margin_left = 58.0 -margin_right = 67.0 -margin_bottom = 14.0 -size_flags_horizontal = 9 -text = "A" - -[node name="HBoxContainer2" type="HBoxContainer" parent="."] -margin_left = 16.0 -margin_top = 74.0 -margin_right = 83.0 -margin_bottom = 88.0 - -[node name="Label1" type="Label" parent="HBoxContainer2"] -margin_right = 54.0 -margin_bottom = 14.0 -size_flags_horizontal = 3 -text = "A2" - -[node name="Label2" type="Label" parent="HBoxContainer2"] -margin_left = 58.0 -margin_right = 67.0 -margin_bottom = 14.0 -size_flags_horizontal = 9 -text = "B" - -[node name="Label2" type="Label" parent="."] -margin_left = 16.0 -margin_top = 89.0 -margin_right = 83.0 -margin_bottom = 103.0 -text = "B2" diff --git a/addons/material_maker/nodes/transform/transform.gd b/addons/material_maker/nodes/transform/transform.gd deleted file mode 100644 index 040622a..0000000 --- a/addons/material_maker/nodes/transform/transform.gd +++ /dev/null @@ -1,39 +0,0 @@ -tool -extends "res://addons/material_maker/node_base.gd" - -func _ready(): - set_slot(0, true, 0, Color(0.5, 0.5, 1), true, 0, Color(0.5, 0.5, 1)) - initialize_properties([ $HBoxContainer1/translate_x, $HBoxContainer2/translate_y, $HBoxContainer3/rotate, $HBoxContainer4/scale_x, $HBoxContainer5/scale_y, $repeat ]) - -func _get_shader_code(uv, slot = 0): - var rv = { defs="", code="" } - var src = get_source() - if src == null: - return rv - var variant_index = generated_variants.find(uv) - if variant_index == -1: - variant_index = generated_variants.size() - generated_variants.append(uv) - var inputs = [ "", "", "", "", "" ] - for i in range(5): - var tsrc = get_source(i+1) - if tsrc != null: - var tsrc_code = tsrc.get_shader_code(uv) - if generated_variants.size() == 1: - rv.defs += tsrc_code.defs - rv.code += tsrc_code.code - inputs[i] = "*(2.0*(%s)-1.0)" % tsrc_code.f - rv.code += "vec2 %s_%d_uv = %s(%s, vec2(%.9f%s, %.9f%s), %.9f%s, vec2(%.9f%s, %.9f%s));\n" % [ name, variant_index, "transform_repeat" if parameters.repeat else "transform_norepeat", uv, parameters.translate_x, inputs[0], parameters.translate_y, inputs[1], PI*parameters.rotate/180.0, inputs[2], parameters.scale_x, inputs[3], parameters.scale_y, inputs[4] ] - var src_code = src.get_shader_code("%s_%d_uv" % [ name, variant_index ]) - if rv.code != "": - if generated_variants.size() == 1: - rv.defs += src_code.defs - rv.code += src_code.code - rv.rgba = src_code.rgba - return rv - -func deserialize(data): - if data.has("scale"): - parameters.scale_x = data.scale - parameters.scale_y = data.scale - .deserialize(data) diff --git a/addons/material_maker/nodes/transform/transform.tscn b/addons/material_maker/nodes/transform/transform.tscn deleted file mode 100644 index b4aa0cd..0000000 --- a/addons/material_maker/nodes/transform/transform.tscn +++ /dev/null @@ -1,216 +0,0 @@ -[gd_scene load_steps=6 format=2] - -[ext_resource path="res://addons/material_maker/nodes/transform/transform.gd" type="Script" id=1] - -[sub_resource type="StyleBoxEmpty" id=1] - -[sub_resource type="StyleBoxEmpty" id=2] - -[sub_resource type="StyleBoxEmpty" id=3] - -[sub_resource type="StyleBoxEmpty" id=4] - -[node name="Transform" type="GraphNode"] -margin_left = 1.0 -margin_top = 1.0 -margin_right = 185.0 -margin_bottom = 179.0 -mouse_filter = 1 -custom_styles/position = SubResource( 1 ) -custom_styles/defaultfocus = SubResource( 2 ) -custom_styles/breakpoint = SubResource( 3 ) -custom_styles/defaultframe = SubResource( 4 ) -title = "Transform" -show_close = true -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.760784, 0.760784, 0.760784, 1 ) -slot/1/right_enabled = false -slot/1/right_type = 0 -slot/1/right_color = Color( 1, 1, 1, 1 ) -slot/2/left_enabled = true -slot/2/left_type = 0 -slot/2/left_color = Color( 0.760784, 0.760784, 0.760784, 1 ) -slot/2/right_enabled = false -slot/2/right_type = 0 -slot/2/right_color = Color( 1, 1, 1, 1 ) -slot/3/left_enabled = true -slot/3/left_type = 0 -slot/3/left_color = Color( 0.760784, 0.760784, 0.760784, 1 ) -slot/3/right_enabled = false -slot/3/right_type = 0 -slot/3/right_color = Color( 1, 1, 1, 1 ) -slot/4/left_enabled = true -slot/4/left_type = 0 -slot/4/left_color = Color( 0.760784, 0.760784, 0.760784, 1 ) -slot/4/right_enabled = false -slot/4/right_type = 0 -slot/4/right_color = Color( 1, 1, 1, 1 ) -slot/5/left_enabled = true -slot/5/left_type = 0 -slot/5/left_color = Color( 0.761719, 0.761719, 0.761719, 1 ) -slot/5/right_enabled = false -slot/5/right_type = 0 -slot/5/right_color = Color( 1, 1, 1, 1 ) -slot/6/left_enabled = false -slot/6/left_type = 0 -slot/6/left_color = Color( 1, 1, 1, 1 ) -slot/6/right_enabled = false -slot/6/right_type = 0 -slot/6/right_color = Color( 1, 1, 1, 1 ) -script = ExtResource( 1 ) - -[node name="HBoxContainer0" type="HBoxContainer" parent="."] -margin_left = 16.0 -margin_top = 24.0 -margin_right = 168.0 -margin_bottom = 44.0 - -[node name="Input" type="Label" parent="HBoxContainer0"] -margin_right = 74.0 -margin_bottom = 20.0 -rect_min_size = Vector2( 0, 20 ) -size_flags_horizontal = 3 -text = "Input" -valign = 1 - -[node name="Output" type="Label" parent="HBoxContainer0"] -margin_left = 78.0 -margin_right = 152.0 -margin_bottom = 20.0 -rect_min_size = Vector2( 0, 20 ) -size_flags_horizontal = 3 -text = "Output" -align = 2 -valign = 1 - -[node name="HBoxContainer1" type="HBoxContainer" parent="."] -margin_left = 16.0 -margin_top = 44.0 -margin_right = 168.0 -margin_bottom = 68.0 - -[node name="Label" type="Label" parent="HBoxContainer1"] -margin_top = 5.0 -margin_right = 74.0 -margin_bottom = 19.0 -size_flags_horizontal = 3 -text = "Translate X:" - -[node name="translate_x" type="SpinBox" parent="HBoxContainer1"] -margin_left = 78.0 -margin_right = 152.0 -margin_bottom = 24.0 -size_flags_horizontal = 0 -size_flags_vertical = 4 -min_value = -1.0 -max_value = 1.0 -step = 0.05 - -[node name="HBoxContainer2" type="HBoxContainer" parent="."] -margin_left = 16.0 -margin_top = 69.0 -margin_right = 168.0 -margin_bottom = 93.0 - -[node name="Label" type="Label" parent="HBoxContainer2"] -margin_top = 5.0 -margin_right = 74.0 -margin_bottom = 19.0 -size_flags_horizontal = 3 -text = "Translate Y:" - -[node name="translate_y" type="SpinBox" parent="HBoxContainer2"] -margin_left = 78.0 -margin_right = 152.0 -margin_bottom = 24.0 -size_flags_horizontal = 0 -size_flags_vertical = 4 -min_value = -1.0 -max_value = 1.0 -step = 0.05 - -[node name="HBoxContainer3" type="HBoxContainer" parent="."] -margin_left = 16.0 -margin_top = 94.0 -margin_right = 168.0 -margin_bottom = 118.0 - -[node name="Label" type="Label" parent="HBoxContainer3"] -margin_top = 5.0 -margin_right = 74.0 -margin_bottom = 19.0 -size_flags_horizontal = 3 -text = "Rotate:" - -[node name="rotate" type="SpinBox" parent="HBoxContainer3"] -margin_left = 78.0 -margin_right = 152.0 -margin_bottom = 24.0 -size_flags_horizontal = 0 -size_flags_vertical = 4 -min_value = -720.0 -max_value = 720.0 -step = 5.0 - -[node name="HBoxContainer4" type="HBoxContainer" parent="."] -margin_left = 16.0 -margin_top = 119.0 -margin_right = 168.0 -margin_bottom = 143.0 - -[node name="Label" type="Label" parent="HBoxContainer4"] -margin_top = 5.0 -margin_right = 74.0 -margin_bottom = 19.0 -size_flags_horizontal = 3 -text = "Scale X:" - -[node name="scale_x" type="SpinBox" parent="HBoxContainer4"] -margin_left = 78.0 -margin_right = 152.0 -margin_bottom = 24.0 -size_flags_horizontal = 0 -size_flags_vertical = 4 -min_value = 0.05 -max_value = 50.0 -step = 0.05 -value = 1.0 - -[node name="HBoxContainer5" type="HBoxContainer" parent="."] -margin_left = 16.0 -margin_top = 144.0 -margin_right = 168.0 -margin_bottom = 168.0 - -[node name="Label" type="Label" parent="HBoxContainer5"] -margin_top = 5.0 -margin_right = 74.0 -margin_bottom = 19.0 -size_flags_horizontal = 3 -text = "Scale Y:" - -[node name="scale_y" type="SpinBox" parent="HBoxContainer5"] -margin_left = 78.0 -margin_right = 152.0 -margin_bottom = 24.0 -size_flags_horizontal = 0 -size_flags_vertical = 4 -min_value = 0.05 -max_value = 50.0 -step = 0.05 -value = 1.0 - -[node name="repeat" type="CheckBox" parent="."] -margin_left = 16.0 -margin_top = 169.0 -margin_right = 168.0 -margin_bottom = 193.0 -pressed = true -text = "Repeat" diff --git a/addons/material_maker/nodes/warp/warp.gd b/addons/material_maker/nodes/warp/warp.gd deleted file mode 100644 index 209f184..0000000 --- a/addons/material_maker/nodes/warp/warp.gd +++ /dev/null @@ -1,32 +0,0 @@ -tool -extends "res://addons/material_maker/node_base.gd" - -func _ready(): - initialize_properties([ $amount ]) - -func _get_shader_code(uv, slot = 0): - var epsilon = 0.01 - 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("fract(%s+vec2(%.9f, 0.0))" % [ uv, epsilon ]) - var src1_code1 = src1.get_shader_code("fract(%s-vec2(%.9f, 0.0))" % [ uv, epsilon ]) - var src1_code2 = src1.get_shader_code("fract(%s+vec2(0.0, %.9f))" % [ uv, epsilon ]) - var src1_code3 = src1.get_shader_code("fract(%s-vec2(0.0, %.9f))" % [ uv, epsilon ]) - rv.defs = src1_code0.defs - rv.code = src1_code0.code+src1_code1.code+src1_code2.code+src1_code3.code - rv.code += "vec2 %s_%d_uv = %s+%.9f*vec2((%s)-(%s), (%s)-(%s));\n" % [ name, variant_index, uv, parameters.amount, src1_code0.f, src1_code1.f, src1_code2.f, src1_code3.f ] - var src0_code = src0.get_shader_code("%s_%d_uv" % [ name, variant_index ]) - rv.defs += src0_code.defs - rv.code += src0_code.code - rv.code += "vec3 %s_%d_rgb = %s;\n" % [ name, variant_index, src0_code.rgb ] - rv.code += "float %s_%d_f = %s;\n" % [ name, variant_index, src0_code.f ] - rv.rgb = "%s_%d_rgb" % [ name, variant_index ] - rv.f = "%s_%d_f" % [ name, variant_index ] - return rv diff --git a/addons/material_maker/nodes/warp/warp.tscn b/addons/material_maker/nodes/warp/warp.tscn deleted file mode 100644 index 9c01860..0000000 --- a/addons/material_maker/nodes/warp/warp.tscn +++ /dev/null @@ -1,58 +0,0 @@ -[gd_scene load_steps=3 format=2] - -[ext_resource path="res://addons/material_maker/nodes/warp/warp.gd" type="Script" id=1] - -[sub_resource type="Theme" id=1] - -[node name="Warp" type="GraphNode"] -margin_left = 1.0 -margin_top = 1.0 -margin_right = 91.0 -margin_bottom = 84.0 -mouse_filter = 1 -theme = SubResource( 1 ) -title = "Warp" -show_close = true -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.756863, 0.756863, 0.756863, 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 ) - -[node name="Label1" type="Label" parent="."] -margin_left = 16.0 -margin_top = 24.0 -margin_right = 90.0 -margin_bottom = 38.0 -text = "Source" - -[node name="Label2" type="Label" parent="."] -margin_left = 16.0 -margin_top = 38.0 -margin_right = 90.0 -margin_bottom = 52.0 -text = "Displace" - -[node name="amount" type="SpinBox" parent="."] -margin_left = 16.0 -margin_top = 53.0 -margin_right = 90.0 -margin_bottom = 77.0 -max_value = 1.0 -step = 0.05 -value = 0.5 -[connection signal="close_request" from="." to="." method="queue_free"] From 027a31155406b5fdba882c8f8d67958e5e94ea63 Mon Sep 17 00:00:00 2001 From: RodZill4 Date: Wed, 25 Sep 2019 23:29:06 +0200 Subject: [PATCH 029/133] More remote node updates (only serialize is missing I guess...) --- addons/material_maker/engine/gen_remote.gd | 52 +++++++++++++++--- addons/material_maker/main_window.tscn | 1 + addons/material_maker/nodes/remote.gd | 31 ++++++++++- .../linked_widgets/editable_label.tscn | 17 ------ project.godot | 3 + rodz_labs_logo.png | Bin 0 -> 16387 bytes 6 files changed, 77 insertions(+), 27 deletions(-) create mode 100644 rodz_labs_logo.png diff --git a/addons/material_maker/engine/gen_remote.gd b/addons/material_maker/engine/gen_remote.gd index 713d749..42cf317 100644 --- a/addons/material_maker/engine/gen_remote.gd +++ b/addons/material_maker/engine/gen_remote.gd @@ -30,7 +30,9 @@ func get_parameter_defs(): match w.type: "config_control": var p = { name="param"+str(i), label=w.label, type="enum", values=[] } - for c in w.configurations: + var configurations = w.configurations.keys() + configurations.sort() + for c in configurations: p.values.push_back({ name=c, value=c }) rv.append(p) i += 1 @@ -61,7 +63,9 @@ func set_parameter(p, v): parent.get_node(w.node).set_parameter(w.widget, v) "config_control": if v < widget.configurations.size(): - for w in widget.configurations[widget.configurations.keys()[v]]: + var configurations = widget.configurations.keys() + configurations.sort() + for w in widget.configurations[configurations[v]]: parent.get_node(w.node).set_parameter(w.widget, w.value) else: # incorrect configuration index @@ -81,7 +85,7 @@ func create_linked_control(label): func create_config_control(label): var index = widgets.size() - widgets.push_back({ label=label, type="config_control", linked_widgets=[], configurations=[] }) + widgets.push_back({ label=label, type="config_control", linked_widgets=[], configurations={} }) return index func can_link_parameter(index, generator, param): @@ -90,13 +94,47 @@ func can_link_parameter(index, generator, param): func link_parameter(index, generator, param): if !can_link_parameter(index, generator, param): return - widgets[index].linked_widgets.push_back({ node=generator.name, widget=param }) - if widgets[index].linked_widgets.size() == 1: - parameters["param"+str(index)] = generator.parameters[param] + var widget = widgets[index] + widget.linked_widgets.push_back({ node=generator.name, widget=param }) + if widget.linked_widgets.size() == 1: + match widget.type: + "linked_control": + parameters["param"+str(index)] = generator.parameters[param] + "config_control": + parameters["param"+str(index)] = 0 emit_signal("parameter_changed", "", null) func remove_parameter(index): for i in range(index, widgets.size()-2): parameters["param"+str(i)] = parameters["param"+str(i+1)] widgets.remove(index) - emit_signal("parameter_changed", "", null) \ No newline at end of file + emit_signal("parameter_changed", "", null) + +func add_configuration(index, config_name): + var widget = widgets[index] + if widget.type == "config_control": + widget.configurations[config_name] = [] + var configurations = widget.configurations.keys() + configurations.sort() + parameters["param"+str(index)] =configurations.find(config_name) + update_configuration(index, config_name) + +func update_configuration(index, config_name): + var widget = widgets[index] + if widget.type == "config_control": + var c = [] + var parent = get_parent() + for w in widget.linked_widgets: + var g = parent.get_node(w.node) + var value = g.parameters[w.widget] + if typeof(value) == TYPE_ARRAY or typeof(value) == TYPE_DICTIONARY: + value = value.duplicate() + c.push_back({ node=w.node, widget=w.widget, value=value }) + widget.configurations[config_name] = c + emit_signal("parameter_changed", "", null) + +func remove_configuration(index, config_name): + var widget = widgets[index] + if widget.type == "config_control": + widget.configurations.erase(config_name) + emit_signal("parameter_changed", "", null) diff --git a/addons/material_maker/main_window.tscn b/addons/material_maker/main_window.tscn index fb86ec5..8812090 100644 --- a/addons/material_maker/main_window.tscn +++ b/addons/material_maker/main_window.tscn @@ -96,6 +96,7 @@ tab_align = 0 tab_close_display_policy = 1 [node name="Renderer" parent="." instance=ExtResource( 5 )] +debug_path = null [node name="NodeFactory" type="Node" parent="."] script = ExtResource( 6 ) diff --git a/addons/material_maker/nodes/remote.gd b/addons/material_maker/nodes/remote.gd index ac42697..332e48e 100644 --- a/addons/material_maker/nodes/remote.gd +++ b/addons/material_maker/nodes/remote.gd @@ -47,12 +47,37 @@ func update_node(): func _on_value_changed(new_value, variable): var param_index = variable.trim_prefix("param").to_int() var widget = generator.widgets[param_index] - if widget.type == "config_control" and new_value >= widget.configurations.size(): - var command = new_value - widget.configurations.size() - print(command) + if widget.type == "config_control": + var configuration_count = widget.configurations.size() + var control = $Controls.get_child(param_index*4+1) + if new_value < configuration_count: + ._on_value_changed(new_value, variable) + var current = control.get_item_text(new_value) + control.set_item_text(configuration_count+3, "") + control.set_item_text(configuration_count+4, "") + else: + var current = control.get_item_text(generator.parameters[variable]) + var command = new_value - widget.configurations.size() + match command: + 1: + var dialog = preload("res://addons/material_maker/widgets/line_dialog.tscn").instance() + add_child(dialog) + dialog.set_texts("Configuration", "Enter a name for the new configuration") + dialog.connect("ok", self, "do_add_configuration", [ param_index ]) + dialog.popup_centered() + 3: + generator.update_configuration(param_index, current) + 4: + generator.parameters[variable] = 0 + generator.remove_configuration(param_index, current) + _: + print(command) else: ._on_value_changed(new_value, variable) +func do_add_configuration(config_name, param_index): + generator.add_configuration(param_index, config_name) + func _on_AddLink_pressed(): var widget = Control.new() add_control("Unnamed", widget) diff --git a/addons/material_maker/widgets/linked_widgets/editable_label.tscn b/addons/material_maker/widgets/linked_widgets/editable_label.tscn index 9406658..64d4c8f 100644 --- a/addons/material_maker/widgets/linked_widgets/editable_label.tscn +++ b/addons/material_maker/widgets/linked_widgets/editable_label.tscn @@ -3,25 +3,8 @@ [ext_resource path="res://addons/material_maker/widgets/linked_widgets/editable_label.gd" type="Script" id=1] [node name="Label" type="Label"] - -anchor_left = 0.0 -anchor_top = 0.0 -anchor_right = 0.0 -anchor_bottom = 0.0 margin_right = 40.0 margin_bottom = 14.0 -rect_pivot_offset = Vector2( 0, 0 ) -rect_clip_content = false mouse_filter = 0 -mouse_default_cursor_shape = 0 -size_flags_horizontal = 1 -size_flags_vertical = 4 -percent_visible = 1.0 -lines_skipped = 0 -max_lines_visible = -1 script = ExtResource( 1 ) -_sections_unfolded = [ "Mouse" ] - [connection signal="gui_input" from="." to="." method="_on_gui_input"] - - diff --git a/project.godot b/project.godot index 0aab12b..e488d5a 100644 --- a/project.godot +++ b/project.godot @@ -132,6 +132,9 @@ config/name="Material Maker" run/main_scene="res://addons/material_maker/main_window.tscn" config/use_custom_user_dir=true config/custom_user_dir_name="material_maker" +boot_splash/image="res://rodz_labs_logo.png" +boot_splash/fullsize=false +boot_splash/bg_color=Color( 0.0901961, 0.0941176, 0.141176, 1 ) config/icon="res://icon.png" config/release="0.6" diff --git a/rodz_labs_logo.png b/rodz_labs_logo.png new file mode 100644 index 0000000000000000000000000000000000000000..dd7e4d3a8bbe109ff8e77d728e2376c17581a679 GIT binary patch literal 16387 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 literal 0 HcmV?d00001 From f512b977c60011fe83257e17170c2c4ba3a7c4e2 Mon Sep 17 00:00:00 2001 From: RodZill4 Date: Thu, 26 Sep 2019 22:32:49 +0200 Subject: [PATCH 030/133] Remote related fixes --- addons/material_maker/engine/gen_remote.gd | 15 ++- addons/material_maker/engine/loader.gd | 2 +- addons/material_maker/library/base.json | 3 +- addons/material_maker/nodes/generic.gd | 25 ++-- addons/material_maker/nodes/remote.gd | 49 ++++++-- addons/material_maker/nodes/remote.tscn | 2 + addons/material_maker/types/gradient.gd | 2 + .../material_maker/widgets/gradient_editor.gd | 4 +- .../widgets/gradient_editor.tscn | 109 +++--------------- .../widgets/linked_widgets/link.gd | 4 +- project.godot | 6 + 11 files changed, 98 insertions(+), 123 deletions(-) diff --git a/addons/material_maker/engine/gen_remote.gd b/addons/material_maker/engine/gen_remote.gd index 42cf317..92e5fc7 100644 --- a/addons/material_maker/engine/gen_remote.gd +++ b/addons/material_maker/engine/gen_remote.gd @@ -66,7 +66,11 @@ func set_parameter(p, v): var configurations = widget.configurations.keys() configurations.sort() for w in widget.configurations[configurations[v]]: - parent.get_node(w.node).set_parameter(w.widget, w.value) + var node = parent.get_node(w.node) + if node != null: + print(w.value) + print(MMType.deserialize_value(w.value)) + node.set_parameter(w.widget, MMType.deserialize_value(w.value)) else: # incorrect configuration index print("error: incorrect config control parameter value") @@ -126,10 +130,11 @@ func update_configuration(index, config_name): var parent = get_parent() for w in widget.linked_widgets: var g = parent.get_node(w.node) - var value = g.parameters[w.widget] - if typeof(value) == TYPE_ARRAY or typeof(value) == TYPE_DICTIONARY: - value = value.duplicate() - c.push_back({ node=w.node, widget=w.widget, value=value }) + if g != null: + print(g.parameters[w.widget]) + var value = MMType.serialize_value(g.parameters[w.widget]) + print(value) + c.push_back({ node=w.node, widget=w.widget, value=value }) widget.configurations[config_name] = c emit_signal("parameter_changed", "", null) diff --git a/addons/material_maker/engine/loader.gd b/addons/material_maker/engine/loader.gd index f7842a1..bcd576f 100644 --- a/addons/material_maker/engine/loader.gd +++ b/addons/material_maker/engine/loader.gd @@ -51,7 +51,7 @@ static func create_gen(data) -> MMGenBase: generator.set_shader_model(data.model_data) elif data.has("widgets"): generator = MMGenRemote.new() - generator.set_widgets(data.widgets) + generator.set_widgets(data.widgets.duplicate(true)) elif data.has("type"): if data.type == "material": generator = MMGenMaterial.new() diff --git a/addons/material_maker/library/base.json b/addons/material_maker/library/base.json index 08bd7b8..730621a 100644 --- a/addons/material_maker/library/base.json +++ b/addons/material_maker/library/base.json @@ -259,6 +259,7 @@ }, { "tree_item":"Miscellaneous/Remote", - "type":"remote" + "type":"remote", + "widgets":[] } ]} \ No newline at end of file diff --git a/addons/material_maker/nodes/generic.gd b/addons/material_maker/nodes/generic.gd index 1b4481b..332c03a 100644 --- a/addons/material_maker/nodes/generic.gd +++ b/addons/material_maker/nodes/generic.gd @@ -5,7 +5,7 @@ class_name MMGraphNodeGeneric var generator = null setget set_generator var controls = {} -var ignore_parameter_change = false +var ignore_parameter_change = "" func set_generator(g): generator = g @@ -19,7 +19,7 @@ func on_offset_changed(): generator.position = offset func on_parameter_changed(p, v): - if ignore_parameter_change: + if ignore_parameter_change == p: return var o = controls[p] if o is LineEdit: @@ -34,7 +34,7 @@ func on_parameter_changed(p, v): o.pressed = v elif o is ColorPickerButton: o.color = MMType.deserialize_value(v) - elif o is Control and o.filename == "res://addons/material_maker/widgets/gradient_editor.tscn": + elif o is MMGradientEditor: var gradient : MMGradient = MMGradient.new() gradient.deserialize(v) o.value = gradient @@ -72,27 +72,27 @@ func update_shaders(): get_parent().send_changed_signal() func _on_text_changed(new_text, variable): - ignore_parameter_change = true + ignore_parameter_change = variable generator.set_parameter(variable, float(new_text)) - ignore_parameter_change = false + ignore_parameter_change = "" update_shaders() func _on_value_changed(new_value, variable): - ignore_parameter_change = true + ignore_parameter_change = variable generator.set_parameter(variable, new_value) - ignore_parameter_change = false + ignore_parameter_change = "" update_shaders() func _on_color_changed(new_color, variable): - ignore_parameter_change = true + ignore_parameter_change = variable generator.set_parameter(variable, new_color) - ignore_parameter_change = false + ignore_parameter_change = "" update_shaders() func _on_gradient_changed(new_gradient, variable): - ignore_parameter_change = true - generator.set_parameter(variable, new_gradient) - ignore_parameter_change = false + ignore_parameter_change = variable + generator.set_parameter(variable, MMType.serialize_value(new_gradient)) + ignore_parameter_change = "" update_shaders() func create_parameter_control(p : Dictionary): @@ -240,6 +240,7 @@ func edit_generator(): func update_generator(shader_model): generator.set_shader_model(shader_model) update_node() + update_shaders() func load_generator(): var dialog = FileDialog.new() diff --git a/addons/material_maker/nodes/remote.gd b/addons/material_maker/nodes/remote.gd index 332e48e..a85609a 100644 --- a/addons/material_maker/nodes/remote.gd +++ b/addons/material_maker/nodes/remote.gd @@ -2,24 +2,30 @@ tool extends MMGraphNodeGeneric class_name MMGraphNodeRemote +var links = {} + +onready var grid = $Controls + func add_control(text, control): - var index = $Controls.get_child_count() / 4 + var index = grid.get_child_count() / 4 var label = preload("res://addons/material_maker/widgets/linked_widgets/editable_label.tscn").instance() label.set_text(text) - $Controls.add_child(label) - $Controls.add_child(control) + grid.add_child(label) + grid.add_child(control) + control.connect("mouse_entered", self, "on_enter_widget", [ control ]) + control.connect("mouse_exited", self, "on_exit_widget", [ control ]) var button = Button.new() button.icon = preload("res://addons/material_maker/icons/link.png") - $Controls.add_child(button) + grid.add_child(button) button.connect("pressed", self, "_on_Link_pressed", [ index ]) button = Button.new() button.icon = preload("res://addons/material_maker/icons/remove.png") - $Controls.add_child(button) + grid.add_child(button) button.connect("pressed", generator, "remove_parameter", [ index ]) func update_node(): var i : int = 0 - for c in $Controls.get_children(): + for c in grid.get_children(): c.queue_free() yield(get_tree(), "idle_frame") controls = {} @@ -49,7 +55,7 @@ func _on_value_changed(new_value, variable): var widget = generator.widgets[param_index] if widget.type == "config_control": var configuration_count = widget.configurations.size() - var control = $Controls.get_child(param_index*4+1) + var control = grid.get_child(param_index*4+1) if new_value < configuration_count: ._on_value_changed(new_value, variable) var current = control.get_item_text(new_value) @@ -92,7 +98,7 @@ func _on_AddConfig_pressed(): func _on_Link_pressed(index): var link = MMNodeLink.new(get_parent()) - link.pick($Controls.get_child(index*4+1), generator, index) + link.pick(grid.get_child(index*4+1), generator, index) func _on_Remote_resize_request(new_minsize): print("_on_Remote_resize_request") @@ -102,7 +108,32 @@ func _on_HBoxContainer_minimum_size_changed(): print("_on_HBoxContainer_minimum_size_changed "+str($HBoxContainer.rect_min_size)) func on_parameter_changed(p, v): + print("remote.parameter_changed "+str(p)+" "+str(v)) if p == "": update_node() else: - .on_parameter_changed(p, v) \ No newline at end of file + .on_parameter_changed(p, v) + +func on_enter_widget(widget): + print("enter_widget "+widget.name) + var param_index = widget.name.trim_prefix("param").to_int() + var w = generator.widgets[param_index] + var new_links = [] + for l in w.linked_widgets: + var graph_node = get_parent().get_node("node_"+l.node) + if graph_node != null: + var control = graph_node.controls[l.widget] + if control != null: + var link = MMNodeLink.new(get_parent()) + link.show_link(widget, control) + new_links.push_back(link) + # free existing links if any + on_exit_widget(widget) + # store new links + links[widget] = new_links + +func on_exit_widget(widget): + if links.has(widget): + for l in links[widget]: + l.queue_free() + links.erase(widget) diff --git a/addons/material_maker/nodes/remote.tscn b/addons/material_maker/nodes/remote.tscn index 941f019..c0219f8 100644 --- a/addons/material_maker/nodes/remote.tscn +++ b/addons/material_maker/nodes/remote.tscn @@ -53,5 +53,7 @@ margin_right = 60.0 margin_bottom = 22.0 hint_tooltip = "Add configurations" icon = ExtResource( 3 ) +[connection signal="close_request" from="." to="." method="on_close_request"] +[connection signal="offset_changed" from="." to="." method="on_offset_changed"] [connection signal="pressed" from="HBoxContainer/AddLink" to="." method="_on_AddLink_pressed"] [connection signal="pressed" from="HBoxContainer/AddConfig" to="." method="_on_AddConfig_pressed"] diff --git a/addons/material_maker/types/gradient.gd b/addons/material_maker/types/gradient.gd index c56a6d4..ddbb1ec 100644 --- a/addons/material_maker/types/gradient.gd +++ b/addons/material_maker/types/gradient.gd @@ -100,3 +100,5 @@ func deserialize(v): clear() for p in v.points: add_point(p.v, p.c) + else: + print("Cannot deserialize gradient") diff --git a/addons/material_maker/widgets/gradient_editor.gd b/addons/material_maker/widgets/gradient_editor.gd index e79453a..66a343f 100644 --- a/addons/material_maker/widgets/gradient_editor.gd +++ b/addons/material_maker/widgets/gradient_editor.gd @@ -1,5 +1,6 @@ tool extends Control +class_name MMGradientEditor class GradientCursor: extends ColorRect @@ -50,9 +51,10 @@ func _ready(): set_value(MMGradient.new()) func set_value(v): + print("GradientEditor.set_value") value = v for c in get_children(): - if c != $Gradient && c != $Background: + if c != $Gradient and c != $Background: remove_child(c) c.free() for p in value.points: diff --git a/addons/material_maker/widgets/gradient_editor.tscn b/addons/material_maker/widgets/gradient_editor.tscn index ee0fe5d..01e47ec 100644 --- a/addons/material_maker/widgets/gradient_editor.tscn +++ b/addons/material_maker/widgets/gradient_editor.tscn @@ -2,21 +2,17 @@ [ext_resource path="res://addons/material_maker/widgets/gradient_editor.gd" type="Script" id=1] -[sub_resource type="Shader" id=3] - +[sub_resource type="Shader" id=1] code = "shader_type canvas_item; void fragment() { COLOR = vec4(vec3(2.0*fract(0.5*(floor(10.0*UV.x)+floor(2.0*UV.y)))), 1.0); }" -[sub_resource type="ShaderMaterial" id=4] - -render_priority = 0 -shader = SubResource( 3 ) - -[sub_resource type="Shader" id=1] +[sub_resource type="ShaderMaterial" id=2] +shader = SubResource( 1 ) +[sub_resource type="Shader" id=3] code = "shader_type canvas_item; vec4 gradient(float x) { if (x < 0.000000000) { @@ -28,113 +24,42 @@ vec4 gradient(float x) { } void fragment() { COLOR = gradient(UV.x); }" -[sub_resource type="ShaderMaterial" id=2] - -render_priority = 0 -shader = SubResource( 1 ) +[sub_resource type="ShaderMaterial" id=4] +shader = SubResource( 3 ) [sub_resource type="Theme" id=5] - [node name="Control" type="Control"] - -anchor_left = 0.0 -anchor_top = 0.0 -anchor_right = 0.0 -anchor_bottom = 0.0 margin_right = 120.0 margin_bottom = 30.0 rect_min_size = Vector2( 120, 30 ) -rect_pivot_offset = Vector2( 0, 0 ) -rect_clip_content = false -mouse_filter = 0 -mouse_default_cursor_shape = 0 -size_flags_horizontal = 1 -size_flags_vertical = 1 script = ExtResource( 1 ) -_sections_unfolded = [ "Rect" ] - -[node name="Background" type="ColorRect" parent="." index="0"] - -material = SubResource( 4 ) -anchor_left = 0.0 -anchor_top = 0.0 -anchor_right = 0.0 -anchor_bottom = 0.0 -margin_right = 120.0 -margin_bottom = 20.0 -rect_min_size = Vector2( 120, 20 ) -rect_pivot_offset = Vector2( 0, 0 ) -rect_clip_content = false -mouse_filter = 0 -mouse_default_cursor_shape = 0 -size_flags_horizontal = 1 -size_flags_vertical = 1 -color = Color( 1, 1, 1, 1 ) -_sections_unfolded = [ "Material", "Rect" ] - -[node name="Gradient" type="ColorRect" parent="." index="1"] +[node name="Background" type="ColorRect" parent="."] material = SubResource( 2 ) -anchor_left = 0.0 -anchor_top = 0.0 -anchor_right = 0.0 -anchor_bottom = 0.0 margin_right = 120.0 margin_bottom = 20.0 rect_min_size = Vector2( 120, 20 ) -rect_pivot_offset = Vector2( 0, 0 ) -rect_clip_content = false -mouse_filter = 0 -mouse_default_cursor_shape = 0 -size_flags_horizontal = 1 -size_flags_vertical = 1 +mouse_filter = 2 + +[node name="Gradient" type="ColorRect" parent="."] +material = SubResource( 4 ) +margin_right = 120.0 +margin_bottom = 20.0 +rect_min_size = Vector2( 120, 20 ) +mouse_filter = 2 theme = SubResource( 5 ) -color = Color( 1, 1, 1, 1 ) -_sections_unfolded = [ "Material", "Theme" ] -[node name="Popup" type="Popup" parent="Gradient" index="0"] - -visible = false -anchor_left = 0.0 -anchor_top = 0.0 -anchor_right = 0.0 -anchor_bottom = 0.0 +[node name="Popup" type="Popup" parent="Gradient"] margin_left = 47.0 margin_top = 33.0 margin_right = 353.0 margin_bottom = 475.0 -rect_pivot_offset = Vector2( 0, 0 ) -rect_clip_content = false -mouse_filter = 0 -mouse_default_cursor_shape = 0 -size_flags_horizontal = 1 -size_flags_vertical = 1 -popup_exclusive = false -[node name="ColorPicker" type="ColorPicker" parent="Gradient/Popup" index="0"] - -anchor_left = 0.0 -anchor_top = 0.0 -anchor_right = 0.0 -anchor_bottom = 0.0 +[node name="ColorPicker" type="ColorPicker" parent="Gradient/Popup"] margin_left = 4.0 margin_top = 4.0 margin_right = 4.0 margin_bottom = 4.0 rect_scale = Vector2( 0.75, 0.75 ) -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 -alignment = 0 -color = Color( 1, 1, 1, 1 ) -edit_alpha = true -raw_mode = false -_sections_unfolded = [ "Rect" ] - [connection signal="popup_hide" from="Gradient/Popup" to="." method="_on_Popup_popup_hide"] - - diff --git a/addons/material_maker/widgets/linked_widgets/link.gd b/addons/material_maker/widgets/linked_widgets/link.gd index 7d3df28..5e4bf5c 100644 --- a/addons/material_maker/widgets/linked_widgets/link.gd +++ b/addons/material_maker/widgets/linked_widgets/link.gd @@ -46,8 +46,8 @@ func find_control(gp): return null func _draw(): - draw_rect(Rect2(rect_position, rect_size), Color(1.0, 0.0, 0.0, 0.2)) - draw_rect(Rect2(rect_position, rect_size), Color(1.0, 1.0, 0.0), false) + #draw_rect(Rect2(rect_position, rect_size), Color(1.0, 0.0, 0.0, 0.2)) + #draw_rect(Rect2(rect_position, rect_size), Color(1.0, 1.0, 0.0), false) var start = get_global_transform().xform_inv(source.get_global_transform().xform(0.5*source.rect_size)) var color = Color(1, 0.5, 0.5, 0.5) var rect diff --git a/project.godot b/project.godot index e488d5a..ae19cfd 100644 --- a/project.godot +++ b/project.godot @@ -84,6 +84,11 @@ _global_script_classes=[ { "language": "GDScript", "path": "res://addons/material_maker/types/gradient.gd" }, { +"base": "Control", +"class": "MMGradientEditor", +"language": "GDScript", +"path": "res://addons/material_maker/widgets/gradient_editor.gd" +}, { "base": "GraphNode", "class": "MMGraphNodeGeneric", "language": "GDScript", @@ -120,6 +125,7 @@ _global_script_class_icons={ "MMGenSwitch": "", "MMGenTexture": "", "MMGradient": "", +"MMGradientEditor": "", "MMGraphNodeGeneric": "", "MMGraphNodeRemote": "", "MMNodeLink": "", From 101de7f32bed47e25a508f47691106e07ffdfab6 Mon Sep 17 00:00:00 2001 From: RodZill4 Date: Fri, 27 Sep 2019 08:28:33 +0200 Subject: [PATCH 031/133] Removed useless print calls and started adding the "create subgraph" command --- addons/material_maker/engine/gen_graph.gd | 10 +- addons/material_maker/engine/gen_remote.gd | 2 + addons/material_maker/engine/loader.gd | 2 +- addons/material_maker/icons/icons.svg | 95 +++++------ addons/material_maker/main_window.gd | 42 +++-- addons/material_maker/nodes/edit_buttons.tscn | 40 +++-- addons/material_maker/nodes/normal_map.mmg | 2 +- addons/material_maker/nodes/remote.gd | 2 - .../material_maker/widgets/gradient_editor.gd | 1 - .../material_maker/widgets/line_dialog.tscn | 121 +------------ adjust_hsv.mmg | 1 + bricks.mmn | 1 + combine.mmg | 1 + export_presets.cfg | 6 +- noise.mmn | 1 + normal_map.ptex | 1 + remote_test.ptex | 1 + shape_tests.ptex | 1 + test.mmn | 1 + test.png | Bin 1096 -> 208340 bytes test.ptex | 159 +----------------- test2.ptex | 1 + test2.tres | 10 ++ test2_albedo.png | Bin 0 -> 302388 bytes test3.ptex | 1 + test4.ptex | 1 + test5.ptex | 1 + test_buffer.ptex | 1 + test_material.ptex | 1 + 29 files changed, 146 insertions(+), 360 deletions(-) create mode 100644 adjust_hsv.mmg create mode 100644 bricks.mmn create mode 100644 combine.mmg create mode 100644 noise.mmn create mode 100644 normal_map.ptex create mode 100644 remote_test.ptex create mode 100644 shape_tests.ptex create mode 100644 test.mmn create mode 100644 test2.ptex create mode 100644 test2.tres create mode 100644 test2_albedo.png create mode 100644 test3.ptex create mode 100644 test4.ptex create mode 100644 test5.ptex create mode 100644 test_buffer.ptex create mode 100644 test_material.ptex diff --git a/addons/material_maker/engine/gen_graph.gd b/addons/material_maker/engine/gen_graph.gd index ad0b7ba..c968217 100644 --- a/addons/material_maker/engine/gen_graph.gd +++ b/addons/material_maker/engine/gen_graph.gd @@ -12,8 +12,16 @@ func get_type_name(): return label func get_parameter_defs(): + var params = get_node("gen_parameters") + if params != null: + return params.get_parameter_defs() return [] +func set_parameter(p, v): + var params = get_node("gen_parameters") + if params != null: + return params.set_parameter(p, v) + func get_input_defs(): var inputs = get_node("gen_inputs") if inputs != null: @@ -98,10 +106,8 @@ func disconnect_children(from, from_port : int, to, to_port : int): return true func _get_shader_code(uv : String, output_index : int, context : MMGenContext): - print("Getting shader code from graph") var outputs = get_node("gen_outputs") if outputs != null: - print("found!") var rv = outputs._get_shader_code(uv, output_index, context) while rv is GDScriptFunctionState: rv = yield(rv, "completed") diff --git a/addons/material_maker/engine/gen_remote.gd b/addons/material_maker/engine/gen_remote.gd index 92e5fc7..1828cdc 100644 --- a/addons/material_maker/engine/gen_remote.gd +++ b/addons/material_maker/engine/gen_remote.gd @@ -76,6 +76,8 @@ func set_parameter(p, v): print("error: incorrect config control parameter value") return .set_parameter(p, v) + if name == "gen_parameters": + get_parent().parameters[p] = v func _serialize(data): data.type = "remote" diff --git a/addons/material_maker/engine/loader.gd b/addons/material_maker/engine/loader.gd index bcd576f..b428687 100644 --- a/addons/material_maker/engine/loader.gd +++ b/addons/material_maker/engine/loader.gd @@ -62,7 +62,7 @@ static func create_gen(data) -> MMGenBase: elif data.type == "ios": generator = MMGenIOs.new() if data.has("mask"): - generator.mask = data.mask + generator.mask = int(data.mask) generator.ports = data.ports elif data.type == "switch": generator = MMGenSwitch.new() diff --git a/addons/material_maker/icons/icons.svg b/addons/material_maker/icons/icons.svg index 61805a8..2a31081 100644 --- a/addons/material_maker/icons/icons.svg +++ b/addons/material_maker/icons/icons.svg @@ -10,9 +10,9 @@ xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd" xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape" - width="210mm" - height="297mm" - viewBox="0 0 210 297" + width="64" + height="64" + viewBox="0 0 64 64" version="1.1" id="svg8" inkscape:version="0.92.3 (2405546, 2018-03-11)" @@ -48,20 +48,27 @@ borderopacity="1.0" inkscape:pageopacity="0.0" inkscape:pageshadow="2" - inkscape:zoom="1.1274425" - inkscape:cx="116.41955" - inkscape:cy="914.64295" - inkscape:document-units="mm" + inkscape:zoom="14.304427" + inkscape:cx="46.907045" + inkscape:cy="41.347265" + inkscape:document-units="px" inkscape:current-layer="layer1" showgrid="true" inkscape:window-width="1920" inkscape:window-height="1017" inkscape:window-x="-8" inkscape:window-y="-8" - inkscape:window-maximized="1"> + inkscape:window-maximized="1" + inkscape:pagecheckerboard="true" + units="px" + scale-x="2.1" + inkscape:snap-to-guides="false" + inkscape:snap-grids="false"> + id="grid815" + spacingx="4.2333332" + spacingy="4.2333332" /> @@ -71,25 +78,18 @@ image/svg+xml - + - + id="layer1" + transform="translate(0,-280.06665)"> @@ -109,7 +109,7 @@ inkscape:export-xdpi="16.531826" inkscape:export-filename="remove.png" id="g4564" - transform="matrix(0.82426401,0.81188676,-0.82426401,0.81188676,84.358228,-6.2929802)" + transform="matrix(0.43370177,0.42718925,-0.43370177,0.42718925,43.791013,273.09803)" style="fill:#ff0909;fill-opacity:1"> + transform="matrix(0.53954693,0,0,0.52735129,-2.0235322,258.7025)"> @@ -185,17 +185,20 @@ id="g879" inkscape:export-filename="save.png" inkscape:export-xdpi="14" - inkscape:export-ydpi="14"> + inkscape:export-ydpi="14" + transform="matrix(0.52616852,0,0,0.52616852,14.395212,275.18126)"> + d="m 130,152.51953 v 110 h 110 v -99.28906 l -10.71094,-10.71094 z" + style="opacity:1;fill:#14008d;fill-opacity:1;stroke:none;stroke-width:3.77952766;stroke-linecap:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1;paint-order:fill markers stroke" + inkscape:connector-curvature="0" /> + d="m 155,152.51953 v 40 h 60 v -40 z m 40,10 h 10 v 20 h -10 z" + style="opacity:1;fill:#afafaf;fill-opacity:1;stroke:none;stroke-width:4.04048538;stroke-linecap:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1;paint-order:fill markers stroke" + inkscape:connector-curvature="0" /> - - + inkscape:connector-curvature="0" /> + inkscape:export-ydpi="13.499794" + transform="matrix(0.51223521,0,0,0.51223521,5.2214853,275.80647)"> + d="m 330,152.51953 v 110 h 90 v -92.57422 l -17.42773,-17.42578 z" + style="opacity:1;fill:#ffed46;fill-opacity:1;stroke:#c7b115;stroke-width:3.77952766;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1;paint-order:fill markers stroke" + inkscape:connector-curvature="0" /> + d="m 403,152.94727 v 16.57226 h 16.57422 z" + style="opacity:1;fill:#ffed46;fill-opacity:1;stroke:#c7b115;stroke-width:3.77952766;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1;paint-order:fill markers stroke" + inkscape:connector-curvature="0" /> K6!u_1)`;J+h}u?q-<5%Ttx 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