more optimized blur shader
title says all
This commit is contained in:
parent
62f51b1c13
commit
e4525233f1
5 changed files with 114 additions and 19 deletions
|
|
@ -1,11 +1,7 @@
|
||||||
[gd_scene format=3 uid="uid://y5f3db7clptv"]
|
[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="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"]
|
[ext_resource type="PackedScene" uid="uid://bfg4q1t8s06vv" path="res://scenes/ui/optimized_blur_panel.tscn" id="2_s4bu6"]
|
||||||
|
|
||||||
[sub_resource type="ShaderMaterial" id="ShaderMaterial_yf5fn"]
|
|
||||||
shader = ExtResource("1_x6hgt")
|
|
||||||
shader_parameter/blur_amount = 2.5
|
|
||||||
|
|
||||||
[node name="InGameMenu" type="Control" unique_id=1952418949]
|
[node name="InGameMenu" type="Control" unique_id=1952418949]
|
||||||
layout_mode = 3
|
layout_mode = 3
|
||||||
|
|
@ -16,14 +12,8 @@ grow_horizontal = 2
|
||||||
grow_vertical = 2
|
grow_vertical = 2
|
||||||
script = ExtResource("1_s4bu6")
|
script = ExtResource("1_s4bu6")
|
||||||
|
|
||||||
[node name="Panel" type="Panel" parent="." unique_id=501811587]
|
[node name="OptimizedBlurPanel" parent="." unique_id=1779763293 instance=ExtResource("2_s4bu6")]
|
||||||
material = SubResource("ShaderMaterial_yf5fn")
|
|
||||||
layout_mode = 1
|
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]
|
[node name="AspectRatioContainer" type="AspectRatioContainer" parent="." unique_id=1893717599]
|
||||||
layout_mode = 1
|
layout_mode = 1
|
||||||
|
|
|
||||||
|
|
@ -1,11 +1,7 @@
|
||||||
[gd_scene format=3 uid="uid://c02fkimxlbrje"]
|
[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="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"]
|
[ext_resource type="PackedScene" uid="uid://bfg4q1t8s06vv" path="res://scenes/ui/optimized_blur_panel.tscn" id="2_onkvn"]
|
||||||
|
|
||||||
[sub_resource type="ShaderMaterial" id="ShaderMaterial_aghy0"]
|
|
||||||
shader = ExtResource("1_sseo3")
|
|
||||||
shader_parameter/blur_amount = 2.5
|
|
||||||
|
|
||||||
[node name="Prompt" type="Control" unique_id=318901794]
|
[node name="Prompt" type="Control" unique_id=318901794]
|
||||||
layout_mode = 3
|
layout_mode = 3
|
||||||
|
|
@ -24,8 +20,7 @@ anchor_top = 0.4
|
||||||
anchor_right = 0.6
|
anchor_right = 0.6
|
||||||
anchor_bottom = 0.5
|
anchor_bottom = 0.5
|
||||||
|
|
||||||
[node name="Panel" type="Panel" parent="AspectRatioContainer" unique_id=530766557]
|
[node name="OptimizedBlurPanel" parent="AspectRatioContainer" unique_id=1779763293 instance=ExtResource("2_onkvn")]
|
||||||
material = SubResource("ShaderMaterial_aghy0")
|
|
||||||
layout_mode = 2
|
layout_mode = 2
|
||||||
|
|
||||||
[node name="Label" type="Label" parent="AspectRatioContainer" unique_id=1563300647]
|
[node name="Label" type="Label" parent="AspectRatioContainer" unique_id=1563300647]
|
||||||
|
|
|
||||||
78
scenes/ui/optimized_blur_panel.tscn
Normal file
78
scenes/ui/optimized_blur_panel.tscn
Normal file
|
|
@ -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
|
||||||
31
shaders/optimized_blur.gdshader
Normal file
31
shaders/optimized_blur.gdshader
Normal file
|
|
@ -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;
|
||||||
|
}
|
||||||
1
shaders/optimized_blur.gdshader.uid
Normal file
1
shaders/optimized_blur.gdshader.uid
Normal file
|
|
@ -0,0 +1 @@
|
||||||
|
uid://dfocpicc6jowx
|
||||||
Loading…
Reference in a new issue