mirror of
https://github.com/Relintai/material-maker.git
synced 2025-01-13 07:41:14 +01:00
Optimized tones UI and added histogram panel
This commit is contained in:
parent
b4a122aac1
commit
29048fc307
@ -15,6 +15,7 @@ onready var projects = $VBoxContainer/Layout/SplitRight/ProjectsPane/Projects
|
||||
onready var layout = $VBoxContainer/Layout
|
||||
var library
|
||||
var preview_2d
|
||||
var histogram
|
||||
var preview_3d
|
||||
var hierarchy
|
||||
|
||||
@ -131,6 +132,7 @@ func _ready() -> void:
|
||||
layout.load_panes(config_cache)
|
||||
library = layout.get_pane("Library")
|
||||
preview_2d = layout.get_pane("Preview2D")
|
||||
histogram = layout.get_pane("Histogram")
|
||||
preview_3d = layout.get_pane("Preview3D")
|
||||
preview_3d.connect("need_update", self, "update_preview_3d")
|
||||
hierarchy = layout.get_pane("Hierarchy")
|
||||
@ -585,9 +587,11 @@ func update_preview_2d(node = null) -> void:
|
||||
break
|
||||
if node != null:
|
||||
preview_2d.set_generator(node.generator)
|
||||
histogram.set_generator(node.generator)
|
||||
preview_2d_background.set_generator(node.generator)
|
||||
else:
|
||||
preview_2d.set_generator(null)
|
||||
histogram.set_generator(null)
|
||||
preview_2d_background.set_generator(null)
|
||||
|
||||
func update_preview_3d(previews : Array) -> void:
|
||||
|
@ -10,6 +10,7 @@ const PANES = [
|
||||
{ name="Library", scene=preload("res://material_maker/library.tscn"), position="TopLeft" },
|
||||
{ name="Preview2D", scene=preload("res://material_maker/preview/preview_2d_panel.tscn"), position="BottomLeft" },
|
||||
{ name="Preview3D", scene=preload("res://material_maker/preview/preview_3d_panel.tscn"), position="BottomLeft" },
|
||||
{ name="Histogram", scene=preload("res://material_maker/widgets/histogram/histogram.tscn"), position="BottomLeft" },
|
||||
{ name="Hierarchy", scene=preload("res://material_maker/widgets/graph_tree/hierarchy_pane.tscn"), position="TopRight" }
|
||||
]
|
||||
|
||||
|
@ -69,19 +69,10 @@ func _ready() -> void:
|
||||
cursor_out_max = Cursor.new(Color(1.0, 1.0, 1.0), 1.0, false)
|
||||
$Histogram.add_child(cursor_out_max)
|
||||
|
||||
func set_generator(g) -> void:
|
||||
.set_generator(g)
|
||||
generator.connect("parameter_changed", self, "on_parameter_changed")
|
||||
_on_Mode_item_selected(0)
|
||||
|
||||
func on_parameter_changed(p, v) -> void:
|
||||
if p == "__input_changed__":
|
||||
var source = generator.get_source(0)
|
||||
var result = source.generator.render(source.output_index, 128, true)
|
||||
while result is GDScriptFunctionState:
|
||||
result = yield(result, "completed")
|
||||
result.copy_to_texture($Histogram.get_image_texture())
|
||||
result.release()
|
||||
$Histogram.set_generator(source.generator, source.output_index)
|
||||
|
||||
func get_parameter(n : String) -> float:
|
||||
var value = generator.get_parameter(n)
|
||||
|
@ -1,10 +1,67 @@
|
||||
extends Control
|
||||
|
||||
func update_histogram() -> void:
|
||||
pass
|
||||
var generator : MMGenBase = null
|
||||
var output : int = 0
|
||||
|
||||
onready var image : ColorRect = $ViewportImage/ColorRect
|
||||
|
||||
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")
|
||||
|
||||
func set_generator(g : MMGenBase, o : int = 0) -> void:
|
||||
if is_instance_valid(generator):
|
||||
generator.disconnect("parameter_changed", self, "on_parameter_changed")
|
||||
var source = { defs="", code="", textures={}, type="f", f="1.0" }
|
||||
if is_instance_valid(g):
|
||||
generator = g
|
||||
output = o
|
||||
generator.connect("parameter_changed", self, "on_parameter_changed")
|
||||
var param_defs : Array = generator.get_parameter_defs()
|
||||
var gen_output_defs = generator.get_output_defs()
|
||||
if ! gen_output_defs.empty():
|
||||
var context : MMGenContext = MMGenContext.new()
|
||||
source = generator.get_shader_code("uv", output, context)
|
||||
while source is GDScriptFunctionState:
|
||||
source = yield(source, "completed")
|
||||
if source.empty():
|
||||
source = { defs="", code="", textures={}, type="f", f="1.0" }
|
||||
# Update shader
|
||||
image.material.shader.code = MMGenBase.generate_preview_shader(source, source.type, "uniform vec2 size;void fragment() {COLOR = preview_2d(UV);}")
|
||||
# Get parameter values from the shader code
|
||||
var regex = RegEx.new()
|
||||
regex.compile("uniform\\s+(\\w+)\\s+([\\w_\\d]+)\\s*=\\s*([^;]+);")
|
||||
for p in regex.search_all(image.material.shader.code):
|
||||
image.material.set_shader_param(p.strings[2], float(p.strings[3]))
|
||||
# Set texture params
|
||||
if source.has("textures"):
|
||||
for k in source.textures.keys():
|
||||
image.material.set_shader_param(k, source.textures[k])
|
||||
update_histogram()
|
||||
|
||||
func on_parameter_changed(n : String, v) -> void:
|
||||
if n == "__input_changed__":
|
||||
set_generator(generator, output)
|
||||
var p = generator.get_parameter_def(n)
|
||||
if p.has("type"):
|
||||
match p.type:
|
||||
"float", "color", "gradient":
|
||||
pass
|
||||
_:
|
||||
set_generator(generator, output)
|
||||
|
||||
func on_float_parameters_changed(parameter_changes : Dictionary) -> void:
|
||||
var need_update : bool = false
|
||||
for n in parameter_changes.keys():
|
||||
for p in VisualServer.shader_get_param_list(image.material.shader.get_rid()):
|
||||
if p.name == n:
|
||||
image.material.set_shader_param(n, parameter_changes[n])
|
||||
need_update = true
|
||||
break
|
||||
if need_update:
|
||||
update_histogram()
|
||||
|
||||
func update_histogram() -> void:
|
||||
pass
|
||||
|
@ -96,7 +96,9 @@ resource_local_to_scene = true
|
||||
shader = SubResource( 10 )
|
||||
shader_param/tex = SubResource( 11 )
|
||||
|
||||
[node name="Histogram" type="Control"]
|
||||
[node name="Histogram" type="Control" groups=[
|
||||
"preview",
|
||||
]]
|
||||
margin_right = 64.0
|
||||
margin_bottom = 64.0
|
||||
script = ExtResource( 1 )
|
||||
|
Loading…
Reference in New Issue
Block a user