From e4525233f14a81a5a6da2b0c0192ee7f7d622560 Mon Sep 17 00:00:00 2001 From: Hellie-xd Date: Fri, 7 Aug 2026 13:04:07 +0200 Subject: [PATCH] more optimized blur shader title says all --- scenes/player/in_game_menu.tscn | 14 +----- scenes/player/prompt.tscn | 9 +--- scenes/ui/optimized_blur_panel.tscn | 78 +++++++++++++++++++++++++++++ shaders/optimized_blur.gdshader | 31 ++++++++++++ shaders/optimized_blur.gdshader.uid | 1 + 5 files changed, 114 insertions(+), 19 deletions(-) create mode 100644 scenes/ui/optimized_blur_panel.tscn create mode 100644 shaders/optimized_blur.gdshader create mode 100644 shaders/optimized_blur.gdshader.uid diff --git a/scenes/player/in_game_menu.tscn b/scenes/player/in_game_menu.tscn index a2c0269..a436173 100644 --- a/scenes/player/in_game_menu.tscn +++ b/scenes/player/in_game_menu.tscn @@ -1,11 +1,7 @@ [gd_scene format=3 uid="uid://y5f3db7clptv"] [ext_resource type="Script" uid="uid://d0g3mdq54p7oh" path="res://scenes/player/in_game_menu_manager.gd" id="1_s4bu6"] -[ext_resource type="Shader" uid="uid://desjwy54cjos8" path="res://shaders/blur_shader.gdshader" id="1_x6hgt"] - -[sub_resource type="ShaderMaterial" id="ShaderMaterial_yf5fn"] -shader = ExtResource("1_x6hgt") -shader_parameter/blur_amount = 2.5 +[ext_resource type="PackedScene" uid="uid://bfg4q1t8s06vv" path="res://scenes/ui/optimized_blur_panel.tscn" id="2_s4bu6"] [node name="InGameMenu" type="Control" unique_id=1952418949] layout_mode = 3 @@ -16,14 +12,8 @@ grow_horizontal = 2 grow_vertical = 2 script = ExtResource("1_s4bu6") -[node name="Panel" type="Panel" parent="." unique_id=501811587] -material = SubResource("ShaderMaterial_yf5fn") +[node name="OptimizedBlurPanel" parent="." unique_id=1779763293 instance=ExtResource("2_s4bu6")] layout_mode = 1 -anchors_preset = 15 -anchor_right = 1.0 -anchor_bottom = 1.0 -grow_horizontal = 2 -grow_vertical = 2 [node name="AspectRatioContainer" type="AspectRatioContainer" parent="." unique_id=1893717599] layout_mode = 1 diff --git a/scenes/player/prompt.tscn b/scenes/player/prompt.tscn index 2b25d75..f6cbb14 100644 --- a/scenes/player/prompt.tscn +++ b/scenes/player/prompt.tscn @@ -1,11 +1,7 @@ [gd_scene format=3 uid="uid://c02fkimxlbrje"] [ext_resource type="Script" uid="uid://csmi0dkeaejty" path="res://scenes/player/prompt.gd" id="1_ddq1g"] -[ext_resource type="Shader" uid="uid://desjwy54cjos8" path="res://shaders/blur_shader.gdshader" id="1_sseo3"] - -[sub_resource type="ShaderMaterial" id="ShaderMaterial_aghy0"] -shader = ExtResource("1_sseo3") -shader_parameter/blur_amount = 2.5 +[ext_resource type="PackedScene" uid="uid://bfg4q1t8s06vv" path="res://scenes/ui/optimized_blur_panel.tscn" id="2_onkvn"] [node name="Prompt" type="Control" unique_id=318901794] layout_mode = 3 @@ -24,8 +20,7 @@ anchor_top = 0.4 anchor_right = 0.6 anchor_bottom = 0.5 -[node name="Panel" type="Panel" parent="AspectRatioContainer" unique_id=530766557] -material = SubResource("ShaderMaterial_aghy0") +[node name="OptimizedBlurPanel" parent="AspectRatioContainer" unique_id=1779763293 instance=ExtResource("2_onkvn")] layout_mode = 2 [node name="Label" type="Label" parent="AspectRatioContainer" unique_id=1563300647] diff --git a/scenes/ui/optimized_blur_panel.tscn b/scenes/ui/optimized_blur_panel.tscn new file mode 100644 index 0000000..e5c7581 --- /dev/null +++ b/scenes/ui/optimized_blur_panel.tscn @@ -0,0 +1,78 @@ +[gd_scene format=3 uid="uid://bfg4q1t8s06vv"] + +[ext_resource type="Shader" uid="uid://dfocpicc6jowx" path="res://shaders/optimized_blur.gdshader" id="1_fuoj5"] + +[sub_resource type="ShaderMaterial" id="ShaderMaterial_3ikdx"] +shader = ExtResource("1_fuoj5") +shader_parameter/direction = Vector2(1, 0) +shader_parameter/size = 2.0 + +[sub_resource type="Shader" id="Shader_fuoj5"] +code = "shader_type canvas_item; + +// Reads the screen behind this object +uniform sampler2D screen_texture : hint_screen_texture, filter_linear_mipmap; + +// Set to (1.0, 0.0) for Horizontal pass, and (0.0, 1.0) for Vertical pass +uniform vec2 direction = vec2(1.0, 0.0); + +// How far the blur spreads +uniform float size = 2.0; + +void fragment() { + // FIX: Grab the exact texture dimensions from our screen sampler + vec2 pixel_size = 1.0 / vec2(textureSize(screen_texture, 0)); + vec2 screen_uv = SCREEN_UV; + + // Center pixel weight + vec4 color = texture(screen_texture, screen_uv) * 0.2270270270; + + // First neighbor (using hardware filtering to sample 2 pixels at once) + vec2 offset1 = pixel_size * direction * 1.3846153846 * size; + color += texture(screen_texture, screen_uv + offset1) * 0.3162162162; + color += texture(screen_texture, screen_uv - offset1) * 0.3162162162; + + // Second neighbor + vec2 offset2 = pixel_size * direction * 3.2307692308 * size; + color += texture(screen_texture, screen_uv + offset2) * 0.0702702703; + color += texture(screen_texture, screen_uv - offset2) * 0.0702702703; + + COLOR = color; +}" + +[sub_resource type="ShaderMaterial" id="ShaderMaterial_igp3v"] +shader = SubResource("Shader_fuoj5") +shader_parameter/direction = Vector2(0, 1) +shader_parameter/size = 2.0 + +[node name="OptimizedBlurPanel" type="Control" unique_id=1779763293] +layout_mode = 3 +anchors_preset = 15 +anchor_right = 1.0 +anchor_bottom = 1.0 +grow_horizontal = 2 +grow_vertical = 2 + +[node name="CaptureScreen" type="BackBufferCopy" parent="." unique_id=1195446396] +copy_mode = 2 + +[node name="HorizontalBlur" type="ColorRect" parent="." unique_id=170203162] +material = SubResource("ShaderMaterial_3ikdx") +layout_mode = 1 +anchors_preset = 15 +anchor_right = 1.0 +anchor_bottom = 1.0 +grow_horizontal = 2 +grow_vertical = 2 + +[node name="CatchHorizontalBlur" type="BackBufferCopy" parent="." unique_id=110780185] +copy_mode = 2 + +[node name="VerticalBlur" type="ColorRect" parent="." unique_id=505478202] +material = SubResource("ShaderMaterial_igp3v") +layout_mode = 1 +anchors_preset = 15 +anchor_right = 1.0 +anchor_bottom = 1.0 +grow_horizontal = 2 +grow_vertical = 2 diff --git a/shaders/optimized_blur.gdshader b/shaders/optimized_blur.gdshader new file mode 100644 index 0000000..c72cfd2 --- /dev/null +++ b/shaders/optimized_blur.gdshader @@ -0,0 +1,31 @@ +shader_type canvas_item; + +// Reads the screen behind this object +uniform sampler2D screen_texture : hint_screen_texture, filter_linear_mipmap; + +// Set to (1.0, 0.0) for Horizontal pass, and (0.0, 1.0) for Vertical pass +uniform vec2 direction = vec2(1.0, 0.0); + +// How far the blur spreads +uniform float size = 2.0; + +void fragment() { + // FIX: Grab the exact texture dimensions from our screen sampler + vec2 pixel_size = 1.0 / vec2(textureSize(screen_texture, 0)); + vec2 screen_uv = SCREEN_UV; + + // Center pixel weight + vec4 color = texture(screen_texture, screen_uv) * 0.2270270270; + + // First neighbor (using hardware filtering to sample 2 pixels at once) + vec2 offset1 = pixel_size * direction * 1.3846153846 * size; + color += texture(screen_texture, screen_uv + offset1) * 0.3162162162; + color += texture(screen_texture, screen_uv - offset1) * 0.3162162162; + + // Second neighbor + vec2 offset2 = pixel_size * direction * 3.2307692308 * size; + color += texture(screen_texture, screen_uv + offset2) * 0.0702702703; + color += texture(screen_texture, screen_uv - offset2) * 0.0702702703; + + COLOR = color; +} \ No newline at end of file diff --git a/shaders/optimized_blur.gdshader.uid b/shaders/optimized_blur.gdshader.uid new file mode 100644 index 0000000..eeedcaf --- /dev/null +++ b/shaders/optimized_blur.gdshader.uid @@ -0,0 +1 @@ +uid://dfocpicc6jowx