1
0
Fork 0
mirror of https://github.com/Orama-Interactive/Pixelorama.git synced 2025-02-12 16:53:07 +00:00

Add a Gradient layer effect

Alongside its image effect equivalent.
This commit is contained in:
Emmanouil Papadeas 2025-02-11 00:06:40 +02:00
parent 64209c83b9
commit c928b7622e
4 changed files with 74 additions and 12 deletions

View file

@ -150,6 +150,7 @@ static func create_ui_for_shader_uniforms(
var min_value := 0.0
var max_value := 255.0
var step := 1.0
var value := 0.0
var range_values_array: PackedStringArray
if "hint_range" in u_hint:
var range_values: String = u_hint.replace("hint_range(", "")
@ -171,7 +172,7 @@ static func create_ui_for_shader_uniforms(
step = 0.01
if u_value != "":
slider.value = float(u_value)
value = float(u_value)
else:
if range_values_array.size() >= 1:
min_value = int(range_values_array[0])
@ -183,10 +184,11 @@ static func create_ui_for_shader_uniforms(
step = int(range_values_array[2])
if u_value != "":
slider.value = int(u_value)
value = int(u_value)
slider.min_value = min_value
slider.max_value = max_value
slider.step = step
slider.value = value
if params.has(u_name):
slider.value = params[u_name]
else:
@ -205,6 +207,8 @@ static func create_ui_for_shader_uniforms(
slider.allow_greater = true
if u_type != "uvec2":
slider.allow_lesser = true
if u_type != "ivec2":
slider.step = 0.01
slider.size_flags_horizontal = Control.SIZE_EXPAND_FILL
slider.value = vector2
if params.has(u_name):
@ -269,7 +273,14 @@ static func create_ui_for_shader_uniforms(
func(): _shader_update_palette_texture(palette, value_changed, u_name)
)
continue
var create_label := not (u_name.begins_with("curve_") and not current_group.is_empty())
var create_label := true
if not current_group.is_empty():
if u_name.begins_with("curve_"):
create_label = false
if u_name.begins_with("gradient_"):
var group_gradient_str := current_group + "_gradient"
if group_nodes.has(group_gradient_str):
create_label = false
var hbox: HBoxContainer
if create_label:
hbox = HBoxContainer.new()
@ -297,7 +308,44 @@ static func create_ui_for_shader_uniforms(
params, u_name, hbox, value_changed, parent_node, file_selected
)
elif u_name.begins_with("gradient_"):
_create_gradient_texture_ui(params, u_name, hbox, value_changed)
if current_group.is_empty():
_create_gradient_texture_ui(params, u_name, hbox, value_changed)
else:
# If this curve uniform belongs in a group, group them into the same
# CurveEdit node and use an OptionButton to switch between the different curves.
var group_gradient_str := current_group + "_gradient"
if group_nodes.has(group_gradient_str):
var grad_edit := group_nodes[group_gradient_str] as GradientEditNode
if "no_interpolation" in u_name:
value_changed.call_deferred(
grad_edit.get_gradient_texture_no_interpolation(), u_name
)
grad_edit.updated.connect(
func(_gradient, _cc):
value_changed.call(
grad_edit.get_gradient_texture_no_interpolation(), u_name
)
)
elif "offset" in u_name:
value_changed.call_deferred(
grad_edit.get_gradient_offsets_texture(), u_name
)
grad_edit.updated.connect(
func(_gradient, _cc):
value_changed.call(
grad_edit.get_gradient_offsets_texture(), u_name
)
)
else:
value_changed.call_deferred(grad_edit.texture, u_name)
grad_edit.updated.connect(
func(_gradient, _cc): value_changed.call(grad_edit.texture, u_name)
)
else:
var grad_edit := _create_gradient_texture_ui(
params, u_name, hbox, value_changed
)
group_nodes[group_gradient_str] = grad_edit
elif u_name.begins_with("dither_texture"):
var option_button := OptionButton.new()
option_button.size_flags_horizontal = Control.SIZE_EXPAND_FILL
@ -517,7 +565,7 @@ static func _create_simple_texture_ui(
static func _create_gradient_texture_ui(
params: Dictionary, u_name: String, hbox: BoxContainer, value_changed: Callable
) -> void:
) -> GradientEditNode:
var gradient_edit := GRADIENT_EDIT_TSCN.instantiate() as GradientEditNode
gradient_edit.size_flags_horizontal = Control.SIZE_EXPAND_FILL
if params.has(u_name):
@ -535,10 +583,11 @@ static func _create_gradient_texture_ui(
func(_gradient, _cc): value_changed.call(gradient_edit.texture, u_name)
)
hbox.add_child(gradient_edit)
return gradient_edit
static func _create_curve_texture_ui(
params: Dictionary, u_name: String, hbox: Control, value_changed: Callable
params: Dictionary, u_name: String, parent: Control, value_changed: Callable
) -> CurveEdit:
var curve_edit := CurveEdit.new()
curve_edit.size_flags_horizontal = Control.SIZE_EXPAND_FILL
@ -550,7 +599,7 @@ static func _create_curve_texture_ui(
curve_edit.value_changed.connect(
func(curve: Curve): value_changed.call(CurveEdit.to_texture(curve), u_name)
)
hbox.add_child(curve_edit)
parent.add_child(curve_edit)
return curve_edit

View file

@ -2,6 +2,7 @@ shader_type canvas_item;
render_mode unshaded;
uniform sampler2D selection : filter_nearest;
group_uniforms gradient_textures;
// The gradient texture itself, with interpolation.
uniform sampler2D gradient_texture : filter_nearest;
// A Nx1 image, where N is the amount of the different colors of gradient_texture,
@ -10,15 +11,19 @@ uniform sampler2D gradient_texture_no_interpolation : filter_nearest;
// A Nx1 grayscale image, where N is the amount of the different colors of gradient_texture,
// where each pixel contains the offset, ranging from 0-1 of each color. Used in dithering.
uniform sampler2D gradient_offset_texture : filter_nearest;
group_uniforms gradient_options;
// uniform_data shape type:: OptionButton [Linear||Radial]
uniform int shape = 0;
// uniform_data repeat type:: OptionButton [None||Repeat||Mirrored||Truncate]
uniform int repeat = 0;
uniform bool use_dithering = false;
uniform sampler2D dither_texture : filter_nearest, repeat_enable;
uniform float position : hint_range(-0.5, 0.5) = 0.0;
uniform float size : hint_range(0.01, 2.0) = 1.0;
uniform float angle : hint_range(0.0, 360.0) = 0.0;
uniform vec2 center = vec2(0.5);
uniform vec2 radius = vec2(1.0);
uniform bool use_dithering = false;
uniform int shape = 0; // 0 = linear, 1 = radial
uniform int repeat = 0; // 0 = none, 1 = repeat, 2 = mirrored, 3 = truncate
float modify_uv(vec2 uv) {

View file

@ -15,6 +15,9 @@ var effects: Array[LayerEffect] = [
LayerEffect.new(
"Offset", preload("res://src/Shaders/Effects/OffsetPixels.gdshader"), "Transform"
),
LayerEffect.new(
"Gradient", preload("res://src/Shaders/Effects/Gradient.gdshader"), "Procedural"
),
LayerEffect.new(
"Outline", preload("res://src/Shaders/Effects/OutlineInline.gdshader"), "Procedural"
),
@ -54,6 +57,7 @@ var category_submenus := {}
func _ready() -> void:
get_ok_button().size_flags_horizontal = Control.SIZE_EXPAND_FILL
var effect_list_popup := effect_list.get_popup()
for i in effects.size():
_add_effect_to_list(i)

View file

@ -4,13 +4,13 @@
[node name="LayerEffectsSettings" type="AcceptDialog"]
title = "Layer effects"
size = Vector2i(400, 400)
size = Vector2i(600, 400)
script = ExtResource("1_h6h7b")
[node name="VBoxContainer" type="VBoxContainer" parent="."]
offset_left = 8.0
offset_top = 8.0
offset_right = 392.0
offset_right = 592.0
offset_bottom = 351.0
size_flags_horizontal = 3
@ -39,6 +39,10 @@ size_flags_vertical = 3
[node name="DragHighlight" type="ColorRect" parent="."]
visible = false
offset_left = 8.0
offset_top = 8.0
offset_right = 592.0
offset_bottom = 351.0
mouse_filter = 2
color = Color(0, 0.741176, 1, 0.501961)