mirror of
https://github.com/Relintai/material-maker.git
synced 2024-12-23 21:16:54 +01:00
Added button to Tones node to adjust levels automatically
This commit is contained in:
parent
3627470239
commit
4502f2c033
@ -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" />
|
||||
<rect
|
||||
style="opacity:1;fill:none;fill-opacity:1;stroke:#000000;stroke-width:0.85721886;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1;paint-order:fill markers stroke"
|
||||
id="rect908"
|
||||
width="2.8650246"
|
||||
height="9.0406466"
|
||||
x="16.686302"
|
||||
y="302.37292"
|
||||
ry="0" />
|
||||
<rect
|
||||
ry="0"
|
||||
y="297.67682"
|
||||
x="20.606815"
|
||||
height="13.736778"
|
||||
width="2.8650253"
|
||||
id="rect910"
|
||||
style="opacity:1;fill:none;fill-opacity:1;stroke:#4e4e4e;stroke-width:0.85721886;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1;paint-order:fill markers stroke" />
|
||||
<rect
|
||||
style="opacity:1;fill:none;fill-opacity:1;stroke:#a9a9a9;stroke-width:0.85721886;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1;paint-order:fill markers stroke"
|
||||
id="rect912"
|
||||
width="2.8650246"
|
||||
height="11.116821"
|
||||
x="24.527328"
|
||||
y="300.29675"
|
||||
ry="0" />
|
||||
<rect
|
||||
ry="0"
|
||||
y="304.64682"
|
||||
x="28.447844"
|
||||
height="6.7667418"
|
||||
width="2.8650246"
|
||||
id="rect914"
|
||||
style="opacity:1;fill:none;fill-opacity:1;stroke:#ffffff;stroke-width:0.85721886;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1;paint-order:fill markers stroke" />
|
||||
<path
|
||||
inkscape:connector-curvature="0"
|
||||
id="path4598-6-2"
|
||||
d="m 23.868329,296.57635 -1.921422,2.02005 -1.696117,-2.29125 a 5.4420629,5.5494302 0 0 0 -1.121274,0.45417 l 0.351782,2.79921 -2.800271,-0.0759 a 5.4420629,5.5494302 0 0 0 -0.336482,1.1114 5.4420629,5.5494302 0 0 0 -0.01172,0.0755 l 2.348852,1.45452 -1.783847,2.16058 a 5.4420629,5.5494302 0 0 0 0.705845,1.02986 l 2.546602,-0.95339 0.540183,2.74829 a 5.4420629,5.5494302 0 0 0 1.239119,0.0834 l 0.851353,-2.6077 2.440798,1.2812 a 5.4420629,5.5494302 0 0 0 0.843823,-0.92816 l -1.472574,-2.31072 2.525556,-1.15689 a 5.4420629,5.5494302 0 0 0 -0.176525,-1.23851 l -2.720271,-0.26982 0.695042,-2.76445 a 5.4420629,5.5494302 0 0 0 -1.048452,-0.62144 z m -1.905851,3.7062 a 1.3605156,1.3873574 0 0 1 1.075273,1.62703 1.3605156,1.3873574 0 0 1 -1.595552,1.09649 1.3605156,1.3873574 0 0 1 -1.075275,-1.62703 1.3605156,1.3873574 0 0 1 1.595554,-1.09649 z"
|
||||
style="opacity:1;fill:#ffffff;fill-opacity:1;stroke:none;stroke-width:0.34617221;stroke-linecap:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1;paint-order:fill markers stroke" />
|
||||
</g>
|
||||
</svg>
|
||||
|
Before Width: | Height: | Size: 39 KiB After Width: | Height: | Size: 42 KiB |
@ -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",
|
||||
|
BIN
material_maker/library/base/filter_tones.png
Normal file
BIN
material_maker/library/base/filter_tones.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 776 B |
@ -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))
|
||||
|
@ -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"]
|
||||
|
@ -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")
|
||||
|
@ -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);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user