diff --git a/material_maker/icons/icons.svg b/material_maker/icons/icons.svg
index ab74fb5..f4a511c 100644
--- a/material_maker/icons/icons.svg
+++ b/material_maker/icons/icons.svg
@@ -55,9 +55,9 @@
borderopacity="1.0"
inkscape:pageopacity="0.0"
inkscape:pageshadow="2"
- inkscape:zoom="40.459032"
- inkscape:cx="12.31719"
- inkscape:cy="41.781829"
+ inkscape:zoom="7.152214"
+ inkscape:cx="122.70346"
+ inkscape:cy="36.247815"
inkscape:document-units="px"
inkscape:current-layer="layer1"
showgrid="true"
@@ -605,5 +605,42 @@
sodipodi:end="0.0018129957"
sodipodi:open="true"
d="m 15.411452,304.10377 a 7.4148879,7.4346347 0 0 1 -7.4502054,7.39166 7.4148879,7.4346347 0 0 1 -7.37939334,-7.46273 7.4148879,7.4346347 0 0 1 7.43561054,-7.40642 7.4148879,7.4346347 0 0 1 7.3941002,7.44808" />
+
+
+
+
+
diff --git a/material_maker/library/base.json b/material_maker/library/base.json
index a2962cc..b792392 100644
--- a/material_maker/library/base.json
+++ b/material_maker/library/base.json
@@ -2289,6 +2289,50 @@
"tree_item": "Filter/AdjustHSV",
"type": "adjust_hsv"
},
+ {
+ "collapsed": true,
+ "icon": "filter_tones",
+ "name": "tones",
+ "parameters": {
+ "in_max": {
+ "a": 1,
+ "b": 1,
+ "g": 1,
+ "r": 1,
+ "type": "Color"
+ },
+ "in_mid": {
+ "a": 0.5,
+ "b": 0.5,
+ "g": 0.5,
+ "r": 0.5,
+ "type": "Color"
+ },
+ "in_min": {
+ "a": 0,
+ "b": 0,
+ "g": 0,
+ "r": 0,
+ "type": "Color"
+ },
+ "out_max": {
+ "a": 1,
+ "b": 1,
+ "g": 1,
+ "r": 1,
+ "type": "Color"
+ },
+ "out_min": {
+ "a": 0,
+ "b": 0,
+ "g": 0,
+ "r": 0,
+ "type": "Color"
+ }
+ },
+ "tree_item": "Filter/Tones",
+ "type": "tones"
+ },
{
"collapsed": true,
"icon": "filter_greyscale",
diff --git a/material_maker/library/base/filter_tones.png b/material_maker/library/base/filter_tones.png
new file mode 100644
index 0000000..b2809d0
Binary files /dev/null and b/material_maker/library/base/filter_tones.png differ
diff --git a/material_maker/nodes/tones.gd b/material_maker/nodes/tones.gd
index f8a496e..aff0e33 100644
--- a/material_maker/nodes/tones.gd
+++ b/material_maker/nodes/tones.gd
@@ -36,11 +36,13 @@ class Cursor:
if ev is InputEventMouseMotion && (ev.button_mask & 1) != 0:
rect_position.x += ev.relative.x
rect_position.x = min(max(-0.5*WIDTH, rect_position.x), get_parent().rect_size.x-0.5*WIDTH)
- var new_position = (rect_position.x+0.5*WIDTH)/get_parent().rect_size.x
- if new_position != position:
- position = new_position
- get_parent().get_parent().update_value(self, position)
- update()
+ update_value((rect_position.x+0.5*WIDTH)/get_parent().rect_size.x)
+
+ func update_value(p : float) -> void:
+ if p != position:
+ set_value(p)
+ get_parent().get_parent().update_value(self, position)
+ update()
func set_value(v : float):
position = v
@@ -70,7 +72,6 @@ func _ready() -> void:
func set_generator(g) -> void:
.set_generator(g)
generator.connect("parameter_changed", self, "on_parameter_changed")
- update_node()
_on_Mode_item_selected(0)
func on_parameter_changed(p, v) -> void:
@@ -84,7 +85,7 @@ func on_parameter_changed(p, v) -> void:
func get_parameter(n : String) -> float:
var value = generator.get_parameter(n)
- match $Mode.selected:
+ match $Bar/Mode.selected:
1:
return value.r
2:
@@ -104,7 +105,7 @@ func _on_Mode_item_selected(_id):
func set_parameter(n : String, v : float, d : float) -> void:
var value = generator.get_parameter(n)
- match $Mode.selected:
+ match $Bar/Mode.selected:
0:
value.r = v
value.g = v
@@ -134,44 +135,36 @@ func update_value(control : Cursor, value : float) -> void:
set_parameter("out_max", value, 1)
get_parent().send_changed_signal()
-# Everything below is only meant for editing the shader
-
-func update_node() -> void:
- if has_node("NodeEditButtons"):
- var r = $NodeEditButtons
- remove_child(r)
- r.free()
- rect_size = Vector2(0, 0)
- if generator.is_editable():
- var edit_buttons = preload("res://material_maker/nodes/edit_buttons.tscn").instance()
- add_child(edit_buttons)
- edit_buttons.connect_buttons(self, "edit_generator", "load_generator", "save_generator")
- set_slot(edit_buttons.get_index(), false, 0, Color(0.0, 0.0, 0.0), false, 0, Color(0.0, 0.0, 0.0))
-
-func edit_generator() -> void:
- if generator.has_method("edit"):
- generator.edit(self)
-
-func update_generator(shader_model : Dictionary) -> void:
- generator.set_shader_model(shader_model)
- update_node()
-
-func save_generator() -> void:
- 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) -> void:
- 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(JSON.print(data, "\t", true))
- file.close()
- mm_loader.update_predefined_generators()
+func _on_Auto_pressed():
+ var histogram = $Histogram.get_histogram_texture().get_data()
+ histogram.lock()
+ var in_min : int = -1
+ var in_mid : int = -1
+ var in_mid_value : float = 0
+ var in_max : int = -1
+ var histogram_size = histogram.get_size().x
+ for i in range(histogram_size):
+ var color : Color = histogram.get_pixel(i, 0)
+ var value : float
+ match $Bar/Mode.selected:
+ 0:
+ value = (color.r+color.g+color.b)/3.0
+ 1:
+ value = color.r
+ 2:
+ value = color.g
+ 3:
+ value = color.b
+ 4:
+ value = color.a
+ if value > 0.0:
+ if in_min == -1:
+ in_min = i
+ in_max = i
+ if in_mid_value < value:
+ in_mid = i
+ in_mid_value = value
+ histogram.unlock()
+ cursor_in_min.update_value(in_min/(histogram_size-1))
+ cursor_in_mid.update_value(in_mid/(histogram_size-1))
+ cursor_in_max.update_value(in_max/(histogram_size-1))
diff --git a/material_maker/nodes/tones.tscn b/material_maker/nodes/tones.tscn
index 4e6ee22..bd5f634 100644
--- a/material_maker/nodes/tones.tscn
+++ b/material_maker/nodes/tones.tscn
@@ -1,7 +1,13 @@
-[gd_scene load_steps=3 format=2]
+[gd_scene load_steps=5 format=2]
[ext_resource path="res://material_maker/nodes/tones.gd" type="Script" id=1]
[ext_resource path="res://material_maker/widgets/histogram/histogram.tscn" type="PackedScene" id=2]
+[ext_resource path="res://material_maker/icons/icons.svg" type="Texture" id=3]
+
+[sub_resource type="AtlasTexture" id=1]
+flags = 4
+atlas = ExtResource( 3 )
+region = Rect2( 16, 80, 16, 16 )
[node name="Tones" type="GraphNode"]
anchor_right = 1.0
@@ -41,15 +47,32 @@ __meta__ = {
"_edit_use_anchors_": false
}
-[node name="Mode" type="OptionButton" parent="."]
+[node name="Bar" type="HBoxContainer" parent="."]
margin_left = 16.0
margin_top = 24.0
margin_right = 208.0
margin_bottom = 44.0
+__meta__ = {
+"_edit_use_anchors_": false
+}
+
+[node name="Mode" type="OptionButton" parent="Bar"]
+margin_right = 172.0
+margin_bottom = 20.0
+size_flags_horizontal = 3
text = "Luminance"
items = [ "Luminance", null, false, 0, null, "Red", null, false, 1, null, "Green", null, false, 2, null, "Blue", null, false, 3, null, "Alpha", null, false, 4, null ]
selected = 0
+[node name="Auto" type="TextureButton" parent="Bar"]
+margin_left = 176.0
+margin_top = 2.0
+margin_right = 192.0
+margin_bottom = 18.0
+hint_tooltip = "Set levels automatically"
+size_flags_vertical = 4
+texture_normal = SubResource( 1 )
+
[node name="Spacer1" type="Control" parent="."]
margin_left = 16.0
margin_top = 45.0
@@ -76,4 +99,5 @@ rect_min_size = Vector2( 0, 4 )
__meta__ = {
"_edit_use_anchors_": false
}
-[connection signal="item_selected" from="Mode" to="." method="_on_Mode_item_selected"]
+[connection signal="item_selected" from="Bar/Mode" to="." method="_on_Mode_item_selected"]
+[connection signal="pressed" from="Bar/Auto" to="." method="_on_Auto_pressed"]
diff --git a/material_maker/widgets/histogram/histogram.gd b/material_maker/widgets/histogram/histogram.gd
index ce43ecc..d2ae909 100644
--- a/material_maker/widgets/histogram/histogram.gd
+++ b/material_maker/widgets/histogram/histogram.gd
@@ -5,3 +5,6 @@ func update_histogram() -> void:
func get_image_texture() -> ImageTexture:
return $ViewportImage/ColorRect.material.get_shader_param("tex")
+
+func get_histogram_texture() -> ImageTexture:
+ return $Control.material.get_shader_param("tex")
diff --git a/material_maker/widgets/histogram/histogram.tscn b/material_maker/widgets/histogram/histogram.tscn
index ff72eb1..02670ed 100644
--- a/material_maker/widgets/histogram/histogram.tscn
+++ b/material_maker/widgets/histogram/histogram.tscn
@@ -81,7 +81,7 @@ void fragment() {
for (int i = 0; i < 128; ++i) {
highest = max(highest, texture(tex, vec2(float(i)/128.0, 0.0)));
}
- vec4 value = step(vec4(0.95-UV.y)*highest/0.9, 0.5*(texture(tex, vec2(max(0.0, UV.x-0.015), 0.0))+texture(tex, vec2(min(1.0, UV.x+0.015), 0.0))));
+ vec4 value = step(vec4(0.95-UV.y)*highest/0.9, texture(tex, vec2(UV.x, 0.0)));
float alpha = step(0.1, dot(value, vec4(1.0)));
COLOR = vec4(mix(value.rgb, vec3(0.5), 0.3*value.a), alpha);
}