From 2f1950eaf3a24cb92918774be0d6c68709b4b80f Mon Sep 17 00:00:00 2001 From: TechieDamien Date: Sat, 2 Aug 2025 19:32:49 +0100 Subject: [PATCH] Fixes the drop shadow shader to not rotate with the sprite --- Scripts/ouroboros.gd | 2 +- Shaders/drop_shadow.gdshader | 20 +++++++++++++------- 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/Scripts/ouroboros.gd b/Scripts/ouroboros.gd index 0a541dc..7649db6 100644 --- a/Scripts/ouroboros.gd +++ b/Scripts/ouroboros.gd @@ -7,6 +7,6 @@ var last_rotation_mult = 1 func _process(delta: float) -> void: var head = get_tree().get_first_node_in_group("Head") if head is SnakePart: - modulate = head.COLOURS[[head.colour_index % len(head.COLOURS)]] + modulate = head.COLOURS[head.colour_index % len(head.COLOURS)] last_rotation_mult = head.colour_index + 1 rotate(delta * ROTATION_SPEED * last_rotation_mult) diff --git a/Shaders/drop_shadow.gdshader b/Shaders/drop_shadow.gdshader index f947510..55e77e1 100644 --- a/Shaders/drop_shadow.gdshader +++ b/Shaders/drop_shadow.gdshader @@ -2,13 +2,18 @@ shader_type canvas_item; uniform vec4 drop_shadow_color : source_color = vec4(vec3(0), float(0.5)); uniform vec2 shadow_offset = vec2(float(0), float(0.1)); +varying vec2 actual_shadow_offset; varying vec4 modulate; void vertex() { + // Calculate the sprite's rotation angle from the MODEL_MATRIX (rotation matrix). + float sprite_rotation = atan(MODEL_MATRIX[0][1], MODEL_MATRIX[0][0]); + actual_shadow_offset = mat2(vec2(cos(sprite_rotation), -sin(sprite_rotation)), vec2(sin(sprite_rotation), cos(sprite_rotation))) * shadow_offset; + modulate = COLOR; - float max_offset = abs(shadow_offset.x); - if (abs(shadow_offset.y) > abs(shadow_offset.x)) { - max_offset = abs(shadow_offset.y); + float max_offset = abs(actual_shadow_offset.x); + if (abs(actual_shadow_offset.y) > abs(actual_shadow_offset.x)) { + max_offset = abs(actual_shadow_offset.y); } VERTEX *= float(1) + float(2) * max_offset; } @@ -23,16 +28,17 @@ vec4 mixcolor(vec4 colA, vec4 colB) { return vec4((colA.rgb + colB.a * (colB.rgb - colA.rgb)), colA.a + colB.a); } void fragment() { - float max_offset = abs(shadow_offset.x); - if (abs(shadow_offset.y) > abs(shadow_offset.x)) { - max_offset = abs(shadow_offset.y); + float max_offset = abs(actual_shadow_offset.x); + if (abs(actual_shadow_offset.y) > abs(actual_shadow_offset.x)) { + max_offset = abs(actual_shadow_offset.y); } vec2 uv = UV * float(float(1) + float(2) * max_offset) - vec2(max_offset); vec4 original_color = sample_texture(TEXTURE, uv) * modulate; - vec4 shadow_color = vec4(drop_shadow_color.rgb, sample_texture(TEXTURE, uv - shadow_offset).a * drop_shadow_color.a); + vec4 shadow_color = vec4(drop_shadow_color.rgb, sample_texture(TEXTURE, uv - actual_shadow_offset).a * drop_shadow_color.a); if (shadow_color.a > float(0)) { COLOR = mixcolor(shadow_color, original_color); } else { COLOR = original_color; } + //COLOR = vec4(vec3(sprite_rotation), 1); } \ No newline at end of file