From 1e2e5dc4317a9151f093e0bb3112f024e5629015 Mon Sep 17 00:00:00 2001 From: Emmanouil Papadeas <35376950+OverloadedOrama@users.noreply.github.com> Date: Fri, 13 Sep 2024 01:02:48 +0300 Subject: [PATCH] Fix wrong preview in the gradient dialog when editing the gradient and dithering is enabled --- src/UI/Dialogs/ImageEffects/GradientDialog.gd | 11 +++++++---- src/UI/Dialogs/ImageEffects/GradientDialog.tscn | 9 +++------ 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/UI/Dialogs/ImageEffects/GradientDialog.gd b/src/UI/Dialogs/ImageEffects/GradientDialog.gd index 316d870f0..49b022073 100644 --- a/src/UI/Dialogs/ImageEffects/GradientDialog.gd +++ b/src/UI/Dialogs/ImageEffects/GradientDialog.gd @@ -63,17 +63,20 @@ func commit_action(cel: Image, project := Global.current_project) -> void: var dither_texture := selected_dither_matrix.texture var gradient := gradient_edit.gradient - var n_of_colors := gradient.offsets.size() + var offsets := gradient.offsets + offsets.sort() + var n_of_colors := offsets.size() # Pass the gradient offsets as an array to the shader - # ...but since Godot 3.x doesn't support uniform arrays, instead we construct + # ...but we can't provide arrays with variable sizes as uniforms, instead we construct # a nx1 grayscale texture with each offset stored in each pixel, and pass it to the shader var offsets_image := Image.create(n_of_colors, 1, false, Image.FORMAT_L8) # Construct an image that contains the selected colors of the gradient without interpolation var gradient_image := Image.create(n_of_colors, 1, false, Image.FORMAT_RGBA8) for i in n_of_colors: - var c := gradient.offsets[i] + var c := offsets[i] offsets_image.set_pixel(i, 0, Color(c, c, c, c)) - gradient_image.set_pixel(i, 0, gradient.colors[i]) + var actual_index := gradient.offsets.find(offsets[i]) + gradient_image.set_pixel(i, 0, gradient.colors[actual_index]) var offsets_tex := ImageTexture.create_from_image(offsets_image) var gradient_tex: Texture2D if shader == shader_linear: diff --git a/src/UI/Dialogs/ImageEffects/GradientDialog.tscn b/src/UI/Dialogs/ImageEffects/GradientDialog.tscn index 004eea72b..f1c59b593 100644 --- a/src/UI/Dialogs/ImageEffects/GradientDialog.tscn +++ b/src/UI/Dialogs/ImageEffects/GradientDialog.tscn @@ -32,10 +32,9 @@ unique_name_in_owner = true layout_mode = 2 size_flags_horizontal = 3 mouse_default_cursor_shape = 2 -item_count = 2 selected = 0 +item_count = 2 popup/item_0/text = "Linear" -popup/item_0/id = 0 popup/item_1/text = "Radial" popup/item_1/id = 1 @@ -47,10 +46,9 @@ text = "Dithering pattern:" unique_name_in_owner = true layout_mode = 2 mouse_default_cursor_shape = 2 -item_count = 1 selected = 0 +item_count = 1 popup/item_0/text = "None" -popup/item_0/id = 0 [node name="RepeatLabel" type="Label" parent="VBoxContainer/GradientOptions" index="4" groups=["gradient_common"]] layout_mode = 2 @@ -60,10 +58,9 @@ text = "Repeat:" unique_name_in_owner = true layout_mode = 2 mouse_default_cursor_shape = 2 -item_count = 4 selected = 0 +item_count = 4 popup/item_0/text = "None" -popup/item_0/id = 0 popup/item_1/text = "Repeat" popup/item_1/id = 1 popup/item_2/text = "Mirror"