adding mask options

This commit is contained in:
2025-07-19 21:52:49 +10:00
parent 5c51691ba7
commit c74dccf1cf
15 changed files with 397 additions and 33 deletions

View File

@@ -0,0 +1,23 @@
shader_type canvas_item;
uniform sampler2D mask_texture : source_color;
uniform bool use_mask = false;
uniform float mask_opacity : hint_range(0.0, 1.0) = 1.0;
void fragment() {
// Get the original sprite color
vec4 sprite_color = texture(TEXTURE, UV);
if (use_mask) {
// Sample the mask texture
vec4 mask_sample = texture(mask_texture, UV);
// Use the mask's alpha channel to determine visibility
float mask_alpha = mask_sample.a * mask_opacity;
// Apply the mask by multiplying the sprite's alpha with the mask alpha
sprite_color.a *= mask_alpha;
}
COLOR = sprite_color;
}

View File

@@ -0,0 +1 @@
uid://btd72itp0cy6b

View File

@@ -1,17 +1,8 @@
shader_type canvas_item;
uniform float speed;
uniform sampler2D backImg: repeat_enable;
uniform sampler2D palette;
uniform float palette_speed = 0.1;
uniform vec4 outline_color : source_color = vec4(1.0, 0.0, 0.0, 0.3);
void fragment(){
vec2 scroll = vec2(1.0,0.0) * TIME * speed;
vec4 tex = texture(TEXTURE, (UV));
float palette_swap = mod(tex.r - TIME * palette_speed, 1.0);
COLOR = vec4(texture(palette, vec2(palette_swap, 0)).rgb, tex.a);
vec4 tex = texture(TEXTURE, UV);
COLOR = vec4(outline_color.rgb, tex.a * outline_color.a);
}

View File

@@ -77,6 +77,12 @@ var ignoreBounce = false
var frames = 1
var animSpeed = 0
#Masking
var mask_texture_path = ""
var mask_texture = null
var use_mask = false
var mask_opacity = 1.0
var remadePolygon = false
var clipped = false
@@ -119,6 +125,9 @@ func _ready():
sprite.texture = tex
# Initialize masking
setupMasking()
var bitmap = BitMap.new()
bitmap.create_from_image_alpha(imageData)
@@ -409,3 +418,53 @@ func visToggle(keys):
func makeVis():
$WobbleOrigin/DragOrigin.visible = true
## Setup masking system
func setupMasking():
if use_mask and mask_texture_path != "":
loadMaskTexture()
updateMaskShader()
## Load mask texture from file path
func loadMaskTexture():
if mask_texture_path == "":
return
var img = Image.new()
var err = img.load(mask_texture_path)
if err != OK:
print_debug("Failed to load mask texture: " + mask_texture_path)
return
mask_texture = ImageTexture.create_from_image(img)
## Apply or remove mask shader
func updateMaskShader():
if use_mask and mask_texture != null:
# Create mask material with shader
var mask_shader = load("res://ui_scenes/selectedSprite/mask.gdshader")
var mask_material = ShaderMaterial.new()
mask_material.shader = mask_shader
mask_material.set_shader_parameter("mask_texture", mask_texture)
mask_material.set_shader_parameter("use_mask", true)
mask_material.set_shader_parameter("mask_opacity", mask_opacity)
sprite.material = mask_material
else:
# Remove mask material
sprite.material = null
## Set mask texture from external source
func setMaskTexture(texture_path: String, opacity: float = 1.0):
mask_texture_path = texture_path
mask_opacity = opacity
use_mask = true
loadMaskTexture()
updateMaskShader()
## Remove masking
func removeMask():
use_mask = false
mask_texture = null
mask_texture_path = ""
updateMaskShader()

View File

@@ -202,8 +202,8 @@ func _on_costume_check_toggled(button_pressed):
## @param button_pressed: bool - Whether StreamDeck should be enabled
func _on_stream_deck_check_toggled(button_pressed):
Saving.settings["useStreamDeck"] = button_pressed
if ElgatoStreamDeck:
ElgatoStreamDeck.refresh_connection()
if get_node_or_null("/root/ElgatoStreamDeck"):
get_node("/root/ElgatoStreamDeck").refresh_connection()
Global.pushUpdate("StreamDeck integration " + ("enabled" if button_pressed else "disabled") + ".")

View File

@@ -75,6 +75,15 @@ func setImage():
$VisToggle/setToggle/Label.text = "toggle: \"" + Global.heldSprite.toggle + "\""
# Update masking controls
$Masking/useMaskCheckbox.button_pressed = Global.heldSprite.use_mask
$Masking/maskOpacityLabel.text = "mask opacity: " + str(Global.heldSprite.mask_opacity)
$Masking/maskOpacity.value = Global.heldSprite.mask_opacity
if Global.heldSprite.mask_texture_path.is_empty():
$Masking/maskPathLabel.text = "mask: (none)"
else:
$Masking/maskPathLabel.text = "mask: " + Global.heldSprite.mask_texture_path.get_file()
changeRotLimit()
setLayerButtons()
@@ -364,8 +373,25 @@ func _on_delete_pressed():
func _on_set_toggle_pressed():
$VisToggle/setToggle/Label.text = "toggle: AWAITING INPUT"
await Global.main.fatfuckingballs
var keys = await Global.main.spriteVisToggles
var key = keys[0]
Global.heldSprite.toggle = key
$VisToggle/setToggle/Label.text = "toggle: \"" + Global.heldSprite.toggle + "\""
## Masking signal handlers
func _on_use_mask_checkbox_toggled(button_pressed):
Global.heldSprite.use_mask = button_pressed
Global.heldSprite.updateMaskShader()
func _on_mask_opacity_value_changed(value):
Global.heldSprite.mask_opacity = value
$Masking/maskOpacityLabel.text = "mask opacity: " + str(value)
Global.heldSprite.updateMaskShader()
func _on_select_mask_pressed():
Global.main.openMaskSelection()
func updateMaskDisplay(path: String):
$Masking/maskPathLabel.text = "mask: " + path.get_file()
$Masking/useMaskCheckbox.button_pressed = true
func _on_clear_mask_pressed():
Global.heldSprite.removeMask()
$Masking/maskPathLabel.text = "mask: (none)"
$Masking/useMaskCheckbox.button_pressed = false

View File

@@ -29,7 +29,7 @@
[ext_resource type="Texture2D" uid="uid://gflmeocxfnrq" path="res://ui_scenes/settings/deleteHotkey.png" id="27_fgu6g"]
[sub_resource type="RectangleShape2D" id="RectangleShape2D_21kva"]
size = Vector2(245, 1341)
size = Vector2(245, 1596.5)
[sub_resource type="ShaderMaterial" id="ShaderMaterial_hxmah"]
shader = ExtResource("3_ky0lu")
@@ -14285,7 +14285,7 @@ script = ExtResource("1_hp0e3")
z_index = -2
[node name="CollisionShape2D" type="CollisionShape2D" parent="Area2D"]
position = Vector2(122.5, 670.5)
position = Vector2(122.5, 725)
shape = SubResource("RectangleShape2D_21kva")
[node name="Border" type="Sprite2D" parent="."]
@@ -14910,6 +14910,66 @@ position = Vector2(-2, -2)
texture = ExtResource("27_fgu6g")
centered = false
[node name="Masking" type="Node2D" parent="."]
position = Vector2(0, 1360.83)
[node name="animationBox" type="Sprite2D" parent="Masking"]
position = Vector2(125, 92.4052)
scale = Vector2(1, 0.905768)
texture = ExtResource("15_wqi8b")
[node name="maskingLabel" type="Label" parent="Masking"]
offset_left = 20.0
offset_right = 120.0
offset_bottom = 26.0
text = "MASKING"
horizontal_alignment = 1
[node name="useMaskCheckbox" type="CheckBox" parent="Masking"]
offset_left = 20.0
offset_top = 30.0
offset_right = 200.0
offset_bottom = 54.0
text = "Use Mask"
[node name="maskOpacityLabel" type="Label" parent="Masking"]
offset_left = 20.0
offset_top = 60.0
offset_right = 200.0
offset_bottom = 86.0
text = "mask opacity: 1.0"
[node name="maskOpacity" type="HSlider" parent="Masking"]
offset_left = 20.0
offset_top = 90.0
offset_right = 200.0
offset_bottom = 106.0
max_value = 1.0
step = 0.01
value = 1.0
[node name="maskPathLabel" type="Label" parent="Masking"]
offset_left = 20.0
offset_top = 120.0
offset_right = 400.0
offset_bottom = 146.0
text = "mask: (none)"
autowrap_mode = 2
[node name="selectMask" type="Button" parent="Masking"]
offset_left = 20.0
offset_top = 150.0
offset_right = 120.0
offset_bottom = 181.0
text = "Select Mask"
[node name="clearMask" type="Button" parent="Masking"]
offset_left = 130.0
offset_top = 150.0
offset_right = 220.0
offset_bottom = 181.0
text = "Clear Mask"
[connection signal="pressed" from="Buttons/Speaking/speaking" to="." method="_on_speaking_pressed"]
[connection signal="pressed" from="Buttons/Blinking/blinking" to="." method="_on_blinking_pressed"]
[connection signal="pressed" from="Buttons/Trash/trash" to="." method="_on_trash_pressed"]
@@ -14941,3 +15001,7 @@ centered = false
[connection signal="pressed" from="Layers/Layer10/layerButton10" to="." method="_on_layer_button_10_pressed"]
[connection signal="pressed" from="VisToggle/setToggle" to="." method="_on_set_toggle_pressed"]
[connection signal="pressed" from="VisToggle/setToggle/delete" to="." method="_on_delete_pressed"]
[connection signal="toggled" from="Masking/useMaskCheckbox" to="." method="_on_use_mask_checkbox_toggled"]
[connection signal="value_changed" from="Masking/maskOpacity" to="." method="_on_mask_opacity_value_changed"]
[connection signal="pressed" from="Masking/selectMask" to="." method="_on_select_mask_pressed"]
[connection signal="pressed" from="Masking/clearMask" to="." method="_on_clear_mask_pressed"]