mirror of
https://github.com/Orama-Interactive/Pixelorama.git
synced 2025-01-31 07:29:49 +00:00
Preload image effect shaders
This commit is contained in:
parent
72aef23cce
commit
2cab2af561
|
@ -4,14 +4,8 @@ extends Reference
|
|||
signal done
|
||||
|
||||
|
||||
func generate_image(
|
||||
_img: Image,
|
||||
_shaderpath: String,
|
||||
_params: Dictionary,
|
||||
size: Vector2 = Global.current_project.size
|
||||
):
|
||||
var shader = load(_shaderpath)
|
||||
_img.unlock()
|
||||
func generate_image(img: Image, shader: Shader, params: Dictionary, size: Vector2) -> void:
|
||||
img.unlock()
|
||||
var viewport_texture := Image.new()
|
||||
var vp = VisualServer.viewport_create()
|
||||
var canvas = VisualServer.canvas_create()
|
||||
|
@ -27,14 +21,14 @@ func generate_image(
|
|||
VisualServer.viewport_set_canvas_transform(vp, canvas, Transform())
|
||||
VisualServer.canvas_item_set_parent(ci_rid, canvas)
|
||||
var texture = ImageTexture.new()
|
||||
texture.create_from_image(_img)
|
||||
texture.create_from_image(img)
|
||||
VisualServer.canvas_item_add_texture_rect(ci_rid, Rect2(Vector2(0, 0), size), texture)
|
||||
|
||||
var mat_rid = VisualServer.material_create()
|
||||
VisualServer.material_set_shader(mat_rid, shader.get_rid())
|
||||
VisualServer.canvas_item_set_material(ci_rid, mat_rid)
|
||||
for key in _params:
|
||||
VisualServer.material_set_param(mat_rid, key, _params[key])
|
||||
for key in params:
|
||||
VisualServer.material_set_param(mat_rid, key, params[key])
|
||||
|
||||
VisualServer.viewport_set_update_mode(vp, VisualServer.VIEWPORT_UPDATE_ONCE)
|
||||
VisualServer.viewport_set_vflip(vp, true)
|
||||
|
@ -45,5 +39,5 @@ func generate_image(
|
|||
VisualServer.free_rid(ci_rid)
|
||||
VisualServer.free_rid(mat_rid)
|
||||
viewport_texture.convert(Image.FORMAT_RGBA8)
|
||||
_img.copy_from(viewport_texture)
|
||||
img.copy_from(viewport_texture)
|
||||
emit_signal("done")
|
||||
|
|
|
@ -5,14 +5,14 @@ var green := true
|
|||
var blue := true
|
||||
var alpha := false
|
||||
|
||||
var shader_path: String = "res://src/Shaders/Desaturate.shader"
|
||||
var shader: Shader = preload("res://src/Shaders/Desaturate.shader")
|
||||
|
||||
var confirmed: bool = false
|
||||
|
||||
|
||||
func _about_to_show():
|
||||
var sm: ShaderMaterial = ShaderMaterial.new()
|
||||
sm.shader = load(shader_path)
|
||||
func _about_to_show() -> void:
|
||||
var sm := ShaderMaterial.new()
|
||||
sm.shader = shader
|
||||
preview.set_material(sm)
|
||||
._about_to_show()
|
||||
|
||||
|
@ -28,9 +28,9 @@ func _confirmed() -> void:
|
|||
._confirmed()
|
||||
|
||||
|
||||
func commit_action(_cel: Image, _project: Project = Global.current_project) -> void:
|
||||
var selection = _project.bitmap_to_image(_project.selection_bitmap, false)
|
||||
var selection_tex = ImageTexture.new()
|
||||
func commit_action(cel: Image, project: Project = Global.current_project) -> void:
|
||||
var selection: Image = project.bitmap_to_image(project.selection_bitmap, false)
|
||||
var selection_tex := ImageTexture.new()
|
||||
selection_tex.create_from_image(selection)
|
||||
|
||||
if !confirmed:
|
||||
|
@ -40,19 +40,19 @@ func commit_action(_cel: Image, _project: Project = Global.current_project) -> v
|
|||
preview.material.set_shader_param("alpha", alpha)
|
||||
preview.material.set_shader_param("selection", selection_tex)
|
||||
preview.material.set_shader_param("affect_selection", selection_checkbox.pressed)
|
||||
preview.material.set_shader_param("has_selection", _project.has_selection)
|
||||
preview.material.set_shader_param("has_selection", project.has_selection)
|
||||
else:
|
||||
var params = {
|
||||
var params := {
|
||||
"red": red,
|
||||
"blue": blue,
|
||||
"green": green,
|
||||
"alpha": alpha,
|
||||
"selection": selection_tex,
|
||||
"affect_selection": selection_checkbox.pressed,
|
||||
"has_selection": _project.has_selection
|
||||
"has_selection": project.has_selection
|
||||
}
|
||||
var gen: ShaderImageEffect = ShaderImageEffect.new()
|
||||
gen.generate_image(_cel, shader_path, params, _project.size)
|
||||
var gen := ShaderImageEffect.new()
|
||||
gen.generate_image(cel, shader, params, project.size)
|
||||
yield(gen, "done")
|
||||
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
extends ImageEffect
|
||||
|
||||
var shader_path: String = "res://src/Shaders/HSV.shader"
|
||||
var shader: Shader = preload("res://src/Shaders/HSV.shader")
|
||||
|
||||
var live_preview: bool = true
|
||||
var confirmed: bool = false
|
||||
|
@ -18,8 +18,8 @@ onready var wait_time_spinbox = $VBoxContainer/WaitSettings/WaitTime
|
|||
|
||||
func _about_to_show() -> void:
|
||||
reset()
|
||||
var sm: ShaderMaterial = ShaderMaterial.new()
|
||||
sm.shader = load(shader_path)
|
||||
var sm := ShaderMaterial.new()
|
||||
sm.shader = shader
|
||||
preview.set_material(sm)
|
||||
._about_to_show()
|
||||
|
||||
|
@ -36,9 +36,9 @@ func _confirmed() -> void:
|
|||
reset()
|
||||
|
||||
|
||||
func commit_action(_cel: Image, _project: Project = Global.current_project) -> void:
|
||||
var selection = _project.bitmap_to_image(_project.selection_bitmap, false)
|
||||
var selection_tex = ImageTexture.new()
|
||||
func commit_action(cel: Image, project: Project = Global.current_project) -> void:
|
||||
var selection: Image = project.bitmap_to_image(project.selection_bitmap, false)
|
||||
var selection_tex := ImageTexture.new()
|
||||
selection_tex.create_from_image(selection)
|
||||
|
||||
if !confirmed:
|
||||
|
@ -47,18 +47,18 @@ func commit_action(_cel: Image, _project: Project = Global.current_project) -> v
|
|||
preview.material.set_shader_param("val_shift_amount", val_slider.value / 100)
|
||||
preview.material.set_shader_param("selection", selection_tex)
|
||||
preview.material.set_shader_param("affect_selection", selection_checkbox.pressed)
|
||||
preview.material.set_shader_param("has_selection", _project.has_selection)
|
||||
preview.material.set_shader_param("has_selection", project.has_selection)
|
||||
else:
|
||||
var params = {
|
||||
var params := {
|
||||
"hue_shift_amount": hue_slider.value / 360,
|
||||
"sat_shift_amount": sat_slider.value / 100,
|
||||
"val_shift_amount": val_slider.value / 100,
|
||||
"selection": selection_tex,
|
||||
"affect_selection": selection_checkbox.pressed,
|
||||
"has_selection": _project.has_selection
|
||||
"has_selection": project.has_selection
|
||||
}
|
||||
var gen: ShaderImageEffect = ShaderImageEffect.new()
|
||||
gen.generate_image(_cel, shader_path, params, _project.size)
|
||||
var gen := ShaderImageEffect.new()
|
||||
gen.generate_image(cel, shader, params, project.size)
|
||||
yield(gen, "done")
|
||||
|
||||
|
||||
|
|
|
@ -5,14 +5,14 @@ var green := true
|
|||
var blue := true
|
||||
var alpha := false
|
||||
|
||||
var shader_path: String = "res://src/Shaders/Invert.shader"
|
||||
var shader: Shader = preload("res://src/Shaders/Invert.shader")
|
||||
|
||||
var confirmed: bool = false
|
||||
|
||||
|
||||
func _about_to_show() -> void:
|
||||
var sm: ShaderMaterial = ShaderMaterial.new()
|
||||
sm.shader = load(shader_path)
|
||||
var sm := ShaderMaterial.new()
|
||||
sm.shader = shader
|
||||
preview.set_material(sm)
|
||||
._about_to_show()
|
||||
|
||||
|
@ -28,9 +28,9 @@ func _confirmed() -> void:
|
|||
._confirmed()
|
||||
|
||||
|
||||
func commit_action(_cel: Image, _project: Project = Global.current_project) -> void:
|
||||
var selection = _project.bitmap_to_image(_project.selection_bitmap, false)
|
||||
var selection_tex = ImageTexture.new()
|
||||
func commit_action(cel: Image, project: Project = Global.current_project) -> void:
|
||||
var selection: Image = project.bitmap_to_image(project.selection_bitmap, false)
|
||||
var selection_tex := ImageTexture.new()
|
||||
selection_tex.create_from_image(selection)
|
||||
|
||||
if !confirmed:
|
||||
|
@ -40,19 +40,19 @@ func commit_action(_cel: Image, _project: Project = Global.current_project) -> v
|
|||
preview.material.set_shader_param("alpha", alpha)
|
||||
preview.material.set_shader_param("selection", selection_tex)
|
||||
preview.material.set_shader_param("affect_selection", selection_checkbox.pressed)
|
||||
preview.material.set_shader_param("has_selection", _project.has_selection)
|
||||
preview.material.set_shader_param("has_selection", project.has_selection)
|
||||
else:
|
||||
var params = {
|
||||
var params := {
|
||||
"red": red,
|
||||
"blue": blue,
|
||||
"green": green,
|
||||
"alpha": alpha,
|
||||
"selection": selection_tex,
|
||||
"affect_selection": selection_checkbox.pressed,
|
||||
"has_selection": _project.has_selection
|
||||
"has_selection": project.has_selection
|
||||
}
|
||||
var gen: ShaderImageEffect = ShaderImageEffect.new()
|
||||
gen.generate_image(_cel, shader_path, params, _project.size)
|
||||
var gen := ShaderImageEffect.new()
|
||||
gen.generate_image(cel, shader, params, project.size)
|
||||
yield(gen, "done")
|
||||
|
||||
|
||||
|
|
Loading…
Reference in a new issue