mirror of
https://github.com/Orama-Interactive/Pixelorama.git
synced 2025-02-13 09:13:07 +00:00
Users can now add custom dithering matrix images
Not exposed somewhere in the UI yet, but users can now add custom dithering pattern as images in "user://dither_matrices". Right now only used for gradient generation.
This commit is contained in:
parent
a28b526645
commit
5df01a9170
|
@ -6,6 +6,30 @@ const BASIS_SLIDERS_TSCN := preload("res://src/UI/Nodes/Sliders/BasisSliders.tsc
|
||||||
const GRADIENT_EDIT_TSCN := preload("res://src/UI/Nodes/GradientEdit.tscn")
|
const GRADIENT_EDIT_TSCN := preload("res://src/UI/Nodes/GradientEdit.tscn")
|
||||||
const NOISE_GENERATOR := preload("res://src/UI/Nodes/NoiseGeneratorDialog.tscn")
|
const NOISE_GENERATOR := preload("res://src/UI/Nodes/NoiseGeneratorDialog.tscn")
|
||||||
|
|
||||||
|
static var dither_matrices: Array[DitherMatrix] = [
|
||||||
|
DitherMatrix.new(preload("res://assets/dither-matrices/bayer2.png"), "Bayer 2x2"),
|
||||||
|
DitherMatrix.new(preload("res://assets/dither-matrices/bayer4.png"), "Bayer 4x4"),
|
||||||
|
DitherMatrix.new(preload("res://assets/dither-matrices/bayer8.png"), "Bayer 8x8"),
|
||||||
|
DitherMatrix.new(preload("res://assets/dither-matrices/bayer16.png"), "Bayer 16x16"),
|
||||||
|
]
|
||||||
|
|
||||||
|
|
||||||
|
class DitherMatrix:
|
||||||
|
var texture: Texture2D
|
||||||
|
var name: String
|
||||||
|
|
||||||
|
func _init(_texture: Texture2D, _name: String) -> void:
|
||||||
|
texture = _texture
|
||||||
|
name = _name
|
||||||
|
|
||||||
|
|
||||||
|
static func load_dither_matrix_from_file(file_path: String) -> void:
|
||||||
|
var dither_image := Image.load_from_file(file_path)
|
||||||
|
if is_instance_valid(dither_image):
|
||||||
|
var dither_tex := ImageTexture.create_from_image(dither_image)
|
||||||
|
var dither_matrix := DitherMatrix.new(dither_tex, file_path.get_file().get_basename())
|
||||||
|
dither_matrices.append(dither_matrix)
|
||||||
|
|
||||||
|
|
||||||
static func create_ui_for_shader_uniforms(
|
static func create_ui_for_shader_uniforms(
|
||||||
shader: Shader,
|
shader: Shader,
|
||||||
|
|
|
@ -169,6 +169,12 @@ func _init() -> void:
|
||||||
DirAccess.make_dir_recursive_absolute("user://backups")
|
DirAccess.make_dir_recursive_absolute("user://backups")
|
||||||
Global.shrink = _get_auto_display_scale()
|
Global.shrink = _get_auto_display_scale()
|
||||||
_handle_layout_files()
|
_handle_layout_files()
|
||||||
|
# Load dither matrix images.
|
||||||
|
var dither_matrices_path := "user://dither_matrices"
|
||||||
|
if DirAccess.dir_exists_absolute(dither_matrices_path):
|
||||||
|
for file_name in DirAccess.get_files_at(dither_matrices_path):
|
||||||
|
var file_path := dither_matrices_path.path_join(file_name)
|
||||||
|
ShaderLoader.load_dither_matrix_from_file(file_path)
|
||||||
|
|
||||||
|
|
||||||
func _ready() -> void:
|
func _ready() -> void:
|
||||||
|
|
|
@ -7,13 +7,7 @@ var shader_linear := preload("res://src/Shaders/Effects/Gradients/Linear.gdshade
|
||||||
var shader_linear_dither := preload("res://src/Shaders/Effects/Gradients/LinearDithering.gdshader")
|
var shader_linear_dither := preload("res://src/Shaders/Effects/Gradients/LinearDithering.gdshader")
|
||||||
|
|
||||||
var shader := shader_linear
|
var shader := shader_linear
|
||||||
var dither_matrices: Array[DitherMatrix] = [
|
var selected_dither_matrix := ShaderLoader.dither_matrices[0]
|
||||||
DitherMatrix.new(preload("res://assets/dither-matrices/bayer2.png"), "Bayer 2x2"),
|
|
||||||
DitherMatrix.new(preload("res://assets/dither-matrices/bayer4.png"), "Bayer 4x4"),
|
|
||||||
DitherMatrix.new(preload("res://assets/dither-matrices/bayer8.png"), "Bayer 8x8"),
|
|
||||||
DitherMatrix.new(preload("res://assets/dither-matrices/bayer16.png"), "Bayer 16x16"),
|
|
||||||
]
|
|
||||||
var selected_dither_matrix := dither_matrices[0]
|
|
||||||
|
|
||||||
@onready var options_cont: Container = $VBoxContainer/GradientOptions
|
@onready var options_cont: Container = $VBoxContainer/GradientOptions
|
||||||
@onready var gradient_edit: GradientEditNode = $VBoxContainer/GradientEdit
|
@onready var gradient_edit: GradientEditNode = $VBoxContainer/GradientEdit
|
||||||
|
@ -27,22 +21,13 @@ var selected_dither_matrix := dither_matrices[0]
|
||||||
@onready var radius_slider := $"%RadiusSlider" as ValueSliderV2
|
@onready var radius_slider := $"%RadiusSlider" as ValueSliderV2
|
||||||
|
|
||||||
|
|
||||||
class DitherMatrix:
|
|
||||||
var texture: Texture2D
|
|
||||||
var name: String
|
|
||||||
|
|
||||||
func _init(_texture: Texture2D, _name: String) -> void:
|
|
||||||
texture = _texture
|
|
||||||
name = _name
|
|
||||||
|
|
||||||
|
|
||||||
func _ready() -> void:
|
func _ready() -> void:
|
||||||
super._ready()
|
super._ready()
|
||||||
var sm := ShaderMaterial.new()
|
var sm := ShaderMaterial.new()
|
||||||
sm.shader = shader
|
sm.shader = shader
|
||||||
preview.set_material(sm)
|
preview.set_material(sm)
|
||||||
|
|
||||||
for matrix in dither_matrices:
|
for matrix in ShaderLoader.dither_matrices:
|
||||||
dithering_option_button.add_item(matrix.name)
|
dithering_option_button.add_item(matrix.name)
|
||||||
|
|
||||||
# Set as in the Animate enum
|
# Set as in the Animate enum
|
||||||
|
@ -140,7 +125,7 @@ func _value_v2_changed(_value: Vector2) -> void:
|
||||||
func _on_DitheringOptionButton_item_selected(index: int) -> void:
|
func _on_DitheringOptionButton_item_selected(index: int) -> void:
|
||||||
if index > 0:
|
if index > 0:
|
||||||
shader = shader_linear_dither
|
shader = shader_linear_dither
|
||||||
selected_dither_matrix = dither_matrices[index - 1]
|
selected_dither_matrix = ShaderLoader.dither_matrices[index - 1]
|
||||||
else:
|
else:
|
||||||
shader = shader_linear
|
shader = shader_linear
|
||||||
update_preview()
|
update_preview()
|
||||||
|
|
Loading…
Reference in a new issue