Skip to content

Commit 09eb73a

Browse files
authoredFeb 11, 2025
update blur glow shader to godot 4.3
* Initial * Fix gaussian blur * Fix viewport positioning
1 parent f36c96a commit 09eb73a

File tree

4 files changed

+51
-43
lines changed

4 files changed

+51
-43
lines changed
 

‎godot/Demos/BlurGlowDemo.tscn

Lines changed: 44 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,22 @@
1-
[gd_scene load_steps=15 format=3 uid="uid://ci11oo63dcfuh"]
1+
[gd_scene load_steps=16 format=3 uid="uid://ci11oo63dcfuh"]
22

33
[ext_resource type="Script" path="res://addons/ShaderSecretsHelper/DemoScreen.gd" id="1"]
44
[ext_resource type="PackedScene" uid="uid://dnei3uy5bhpha" path="res://Demos/Glow2D/BlurGlow/Scene.tscn" id="2"]
55
[ext_resource type="Shader" path="res://Shaders/gaussian_blur.gdshader" id="3"]
66
[ext_resource type="Shader" path="res://Shaders/compose.gdshader" id="4"]
77
[ext_resource type="Shader" path="res://Shaders/glow_prepass.gdshader" id="5"]
8-
[ext_resource type="PackedScene" path="res://Shared/Background2D/Demo2DBackground.tscn" id="7"]
8+
[ext_resource type="Texture2D" uid="uid://7giw201cbixu" path="res://Shared/sprites/robi_shaded.png" id="5_bxej1"]
9+
[ext_resource type="PackedScene" uid="uid://7mqdkojagyav" path="res://Shared/Background2D/Demo2DBackground.tscn" id="7"]
910
[ext_resource type="Script" path="res://Utils/DebugViewer.gd" id="8"]
10-
[ext_resource type="PackedScene" path="res://Shared/DemoInterface.tscn" id="9"]
11+
[ext_resource type="PackedScene" uid="uid://diofpwcvq5elu" path="res://Shared/DemoInterface.tscn" id="9"]
1112

1213
[sub_resource type="ShaderMaterial" id="1"]
1314
shader = ExtResource("3")
15+
shader_parameter/blur_scale = Vector2(1, 1)
1416

1517
[sub_resource type="ShaderMaterial" id="2"]
1618
shader = ExtResource("3")
19+
shader_parameter/blur_scale = Vector2(1, 1)
1720

1821
[sub_resource type="ShaderMaterial" id="3"]
1922
shader = ExtResource("5")
@@ -39,95 +42,100 @@ script = ExtResource("1")
3942

4043
[node name="MaskView" type="SubViewportContainer" parent="."]
4144
self_modulate = Color(1, 1, 1, 0)
42-
anchor_right = 1.0
43-
anchor_bottom = 1.0
45+
anchors_preset = 8
46+
anchor_left = 0.5
47+
anchor_top = 0.5
48+
anchor_right = 0.5
49+
anchor_bottom = 0.5
50+
offset_left = -960.0
51+
offset_top = -540.0
52+
offset_right = 960.0
53+
offset_bottom = 540.0
54+
grow_horizontal = 2
55+
grow_vertical = 2
4456
mouse_filter = 2
4557
stretch = true
46-
__meta__ = {
47-
"_edit_use_anchors_": false
48-
}
4958

5059
[node name="SubViewport" type="SubViewport" parent="MaskView"]
51-
size = Vector2(1920, 1080)
5260
transparent_bg = true
5361
handle_input_locally = false
54-
usage = 0
55-
render_target_update_mode = 3
62+
size = Vector2i(1920, 1080)
63+
render_target_update_mode = 4
5664

5765
[node name="Blur2" type="SubViewportContainer" parent="MaskView/SubViewport"]
5866
material = SubResource("1")
67+
anchors_preset = 15
5968
anchor_right = 1.0
6069
anchor_bottom = 1.0
6170
mouse_filter = 2
6271
stretch = true
63-
__meta__ = {
64-
"_edit_use_anchors_": false
65-
}
6672

6773
[node name="SubViewport" type="SubViewport" parent="MaskView/SubViewport/Blur2"]
68-
size = Vector2(1920, 1080)
6974
transparent_bg = true
7075
handle_input_locally = false
71-
usage = 0
72-
render_target_update_mode = 3
76+
size = Vector2i(1920, 1080)
77+
render_target_update_mode = 4
7378

7479
[node name="Blur1" type="SubViewportContainer" parent="MaskView/SubViewport/Blur2/SubViewport"]
7580
material = SubResource("2")
81+
anchors_preset = 15
7682
anchor_right = 1.0
7783
anchor_bottom = 1.0
7884
mouse_filter = 2
7985
stretch = true
80-
__meta__ = {
81-
"_edit_use_anchors_": false
82-
}
8386

8487
[node name="SubViewport" type="SubViewport" parent="MaskView/SubViewport/Blur2/SubViewport/Blur1"]
85-
size = Vector2(1920, 1080)
8688
transparent_bg = true
8789
handle_input_locally = false
88-
usage = 0
89-
render_target_update_mode = 3
90+
size = Vector2i(1920, 1080)
91+
render_target_update_mode = 4
9092

9193
[node name="Sprite2D" type="Sprite2D" parent="MaskView/SubViewport/Blur2/SubViewport/Blur1/SubViewport"]
9294
material = SubResource("3")
9395
position = Vector2(960, 540)
94-
texture = null
96+
scale = Vector2(0.75, 0.75)
97+
texture = ExtResource("5_bxej1")
9598

9699
[node name="MainView" type="SubViewportContainer" parent="."]
97100
material = SubResource("6")
98-
anchor_right = 1.0
99-
anchor_bottom = 1.0
101+
anchors_preset = 8
102+
anchor_left = 0.5
103+
anchor_top = 0.5
104+
anchor_right = 0.5
105+
anchor_bottom = 0.5
106+
offset_left = -960.0
107+
offset_top = -540.0
108+
offset_right = 960.0
109+
offset_bottom = 540.0
110+
grow_horizontal = 2
111+
grow_vertical = 2
100112
mouse_filter = 2
101113
stretch = true
102-
__meta__ = {
103-
"_edit_use_anchors_": false
104-
}
105114

106115
[node name="SubViewport" type="SubViewport" parent="MainView"]
107-
size = Vector2(1920, 1080)
108116
transparent_bg = true
109117
handle_input_locally = false
110-
usage = 0
111-
render_target_update_mode = 3
118+
size = Vector2i(1920, 1080)
119+
render_target_update_mode = 4
112120

113121
[node name="Scene" parent="MainView/SubViewport" instance=ExtResource("2")]
114122

115123
[node name="Sprite2D" parent="MainView/SubViewport/Scene" index="0"]
116124
position = Vector2(960, 540)
117-
scale = Vector2(1, 1)
118125

119126
[node name="RemoteTransform2D" type="RemoteTransform2D" parent="MainView/SubViewport/Scene/Sprite2D" index="0"]
120127
remote_path = NodePath("../../../../../MaskView/SubViewport/Blur2/SubViewport/Blur1/SubViewport/Sprite2D")
121128

122129
[node name="DebugViewer" type="Control" parent="."]
130+
visible = false
131+
layout_mode = 3
132+
anchors_preset = 0
123133
offset_top = 120.0
124134
offset_right = 40.0
125135
offset_bottom = 160.0
126136
script = ExtResource("8")
127-
__meta__ = {
128-
"_edit_use_anchors_": false
129-
}
130137

131138
[node name="DemoInterface" parent="." instance=ExtResource("9")]
139+
anchors_preset = 10
132140

133141
[editable path="MainView/SubViewport/Scene"]
Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1-
[gd_scene format=3 uid="uid://dnei3uy5bhpha"]
1+
[gd_scene load_steps=2 format=3 uid="uid://dnei3uy5bhpha"]
2+
3+
[ext_resource type="Texture2D" uid="uid://7giw201cbixu" path="res://Shared/sprites/robi_shaded.png" id="1_ocuod"]
24

35
[node name="Scene" type="Node2D"]
46

57
[node name="Sprite2D" type="Sprite2D" parent="."]
68
position = Vector2(640, 360)
79
scale = Vector2(0.75, 0.75)
8-
texture = null
10+
texture = ExtResource("1_ocuod")

‎godot/Shaders/gaussian_blur.gdshader

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ shader_type canvas_item;
33
uniform vec2 blur_scale = vec2(1, 0);
44

55
const float SAMPLES = 71.0;
6-
const float TAU = 6.283185307179586476925286766559;
76

87
float gaussian(float x) {
98
float x_squared = x * x;
@@ -14,15 +13,15 @@ float gaussian(float x) {
1413

1514
void fragment() {
1615
vec2 scale = TEXTURE_PIXEL_SIZE * blur_scale;
17-
16+
1817
float total_weight = 0.0;
1918
vec4 color = vec4(0.0);
20-
19+
2120
for (int i = -int(SAMPLES) / 2; i < int(SAMPLES) / 2; ++i) {
2221
float weight = gaussian(float(i));
2322
color += texture(TEXTURE, UV + scale * vec2(float(i))) * weight;
2423
total_weight += weight;
2524
}
26-
25+
2726
COLOR = color / total_weight;
2827
}

‎godot/Utils/DebugViewer.gd

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ func refresh_viewports() -> void:
2828

2929
_texture_rect.custom_minimum_size = Vector2(width, height)
3030
_texture_rect.texture = viewport.get_texture()
31-
_texture_rect.flip_v = true
3231

3332
vbox.add_child(_texture_rect)
3433
add_child(vbox)

0 commit comments

Comments
 (0)
Please sign in to comment.