1
0
Fork 0
mirror of https://github.com/Orama-Interactive/Pixelorama.git synced 2025-03-13 14:55:18 +00:00
Pixelorama/src/UI/Dialogs/ImageEffects/ShaderEffect.gd
Emmanouil Papadeas 08b03ae0e5
Implement layer effects (#940)
* Basic logic for layer effects

* Add an FX button and the ability to add effects, no way to remove or change properties of effects yet

* Basic and ugly UI for adding and removing effects, no property changing yet

* Swap effects

* Fix preload shader paths

* Change parameters for layer effects

* Change gradient parameter in layer effect shaders, and other fixes

* Use CollapsibleContainers for the shader properties

* Set the correct gradient interpolation mode and color space in the UI

* Make effects of group layers apply to children

* Change `apply_fx` to `apply_effects`, formatting, some extra doc comments

* Apply effects to other canvases, when merging layers and when exporting

* Display humanized names of the shader unifrms

* Some UI improvements to the LayerEffectsSettings

* Add an Enabled button in the layer effects window, and change checkboxes to checkbuttons

* Change BaseLayer.apply_effects() to take a cel as a parameter instead

* Make layer effect buttons be affected by the modulate icon color

* Add option in the View menu whether layer effects are displayed in the canvas or not

* Rename `apply_effects()` to `display_effects()`

* Add translation strings

* Add nearest filter to the gradient map

* Don't change Main.tscn

* Fix more translations

* Change the default cursor shape of the generated UI elements of the layer effects

* Add undo/redo and effect application (apply effect destructively)

There are some errors due to the usage of anonymous lambda methods in undo/redo, but it seems to be working well regardless.

* Make layer effect application work on all cels
2023-11-22 01:06:25 +02:00

72 lines
1.9 KiB
GDScript

extends ImageEffect
var shader: Shader
var params := {}
@onready var shader_loaded_label: Label = $VBoxContainer/ShaderLoadedLabel
@onready var shader_params: BoxContainer = $VBoxContainer/ShaderParams
func _about_to_popup() -> void:
Global.canvas.selection.transform_content_confirm()
var frame := Global.current_project.frames[Global.current_project.current_frame]
DrawingAlgos.blend_selected_cels(selected_cels, frame)
preview_image.copy_from(selected_cels)
preview.texture = ImageTexture.create_from_image(preview_image)
super._about_to_popup()
func commit_action(cel: Image, project := Global.current_project) -> void:
if !shader:
return
var gen := ShaderImageEffect.new()
gen.generate_image(cel, shader, params, project.size)
func _on_ChooseShader_pressed() -> void:
if OS.get_name() == "Web":
Html5FileExchange.load_shader()
else:
$FileDialog.popup_centered(Vector2(300, 340))
func _on_FileDialog_file_selected(path: String) -> void:
var shader_tmp = load(path)
if !shader_tmp is Shader:
return
change_shader(shader_tmp, path.get_file().get_basename())
func set_nodes() -> void:
preview = $VBoxContainer/AspectRatioContainer/Preview
func change_shader(shader_tmp: Shader, shader_name: String) -> void:
shader = shader_tmp
preview.material.shader = shader_tmp
shader_loaded_label.text = tr("Shader loaded:") + " " + shader_name
params.clear()
for child in shader_params.get_children():
child.queue_free()
Global.create_ui_for_shader_uniforms(
shader_tmp, params, shader_params, _set_shader_parameter, _load_texture
)
func _set_shader_parameter(value, param: String) -> void:
var mat: ShaderMaterial = preview.material
mat.set_shader_parameter(param, value)
params[param] = value
func _load_texture(path: String, param: String) -> void:
var image := Image.new()
image.load(path)
if !image:
print("Error loading texture")
return
var image_tex := ImageTexture.create_from_image(image)
_set_shader_parameter(image_tex, param)