-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathCRT.tscn
124 lines (103 loc) · 4.08 KB
/
CRT.tscn
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
[gd_scene load_steps=4 format=2]
[ext_resource path="res://CRT.gd" type="Script" id=1]
[sub_resource type="Shader" id=1]
code = "/*
Godot 3 2D CRT Shader.
A 2D shader for Godot 3 simulating a CRT..
Author: hiulit
Repository: https://github.com/hiulit/Godot-3-2D-CRT-Shader
Issues: https://github.com/hiulit/Godot-3-2D-CRT-Shader/issues
License: MIT https://github.com/hiulit/Godot-3-2D-CRT-Shader/blob/master/LICENSE
*/
shader_type canvas_item;
const float PI = 3.14159265359;
uniform vec2 screen_size = vec2(320.0, 180.0);
uniform bool show_curvature = true;
uniform float curvature_x_amount : hint_range(3.0, 15.0, 0.01) = float(6.0);
uniform float curvature_y_amount : hint_range(3.0, 15.0, 0.01) = float(4.0);
uniform vec4 corner_color : hint_color = vec4(0.0, 0.0, 0.0, 1.0);
uniform bool show_vignette = true;
uniform float vignette_opacity : hint_range(0.0, 1.0, 0.01) = 0.2;
uniform bool show_horizontal_scan_lines = true;
uniform float horizontal_scan_lines_amount : hint_range(0.0, 180.0, 0.1) = 180.0;
uniform float horizontal_scan_lines_opacity : hint_range(0.0, 1.0, 0.01) = 1.0;
uniform bool show_vertical_scan_lines = false;
uniform float vertical_scan_lines_amount : hint_range(0.0, 320.0, 0.1) = 320.0;
uniform float vertical_scan_lines_opacity : hint_range(0.0, 1.0, 0.01) = 1.0;
uniform float boost : hint_range(1.0, 2.0, 0.01) = 1.2;
uniform float aberration_amount : hint_range(0.0, 10.0, 0.01) = 0.0;
vec2 uv_curve(vec2 uv) {
if (show_curvature) {
uv = uv * 2.0 - 1.0;
vec2 offset = abs(uv.yx) / vec2(curvature_x_amount, curvature_y_amount);
uv = uv + uv * offset * offset;
uv = uv * 0.5 + 0.5;
}
return uv;
}
void fragment() {
vec2 uv = uv_curve(UV);
vec2 screen_uv = uv_curve(SCREEN_UV);
vec3 color = texture(SCREEN_TEXTURE, screen_uv).rgb;
if (aberration_amount > 0.0) {
float adjusted_amount = aberration_amount / screen_size.x;
color.r = texture(SCREEN_TEXTURE, vec2(screen_uv.x + adjusted_amount, screen_uv.y)).r;
color.g = texture(SCREEN_TEXTURE, screen_uv).g;
color.b = texture(SCREEN_TEXTURE, vec2(screen_uv.x - adjusted_amount, screen_uv.y)).b;
}
if (show_vignette) {
float vignette = uv.x * uv.y * (1.0 - uv.x) * (1.0 - uv.y);
vignette = clamp(pow((screen_size.x / 4.0) * vignette, vignette_opacity), 0.0, 1.0);
color *= vignette;
}
if (show_horizontal_scan_lines) {
float s = sin(screen_uv.y * horizontal_scan_lines_amount * PI * 2.0);
s = (s * 0.5 + 0.5) * 0.9 + 0.1;
vec4 scan_line = vec4(vec3(pow(s, horizontal_scan_lines_opacity)), 1.0);
color *= scan_line.rgb;
}
if (show_vertical_scan_lines) {
float s = sin(screen_uv.x * vertical_scan_lines_amount * PI * 2.0);
s = (s * 0.5 + 0.5) * 0.9 + 0.1;
vec4 scan_line = vec4(vec3(pow(s, vertical_scan_lines_opacity)), 1.0);
color *= scan_line.rgb;
}
if (show_horizontal_scan_lines || show_vertical_scan_lines) {
color *= boost;
}
// Fill the blank space of the corners, left by the curvature, with black.
if (uv.x < 0.0 || uv.x > 1.0 || uv.y < 0.0 || uv.y > 1.0) {
color = corner_color.rgb;
}
COLOR = vec4(color, 1.0);
}"
[sub_resource type="ShaderMaterial" id=2]
shader = SubResource( 1 )
shader_param/screen_size = Vector2( 500, 800 )
shader_param/show_curvature = true
shader_param/curvature_x_amount = 4.0
shader_param/curvature_y_amount = 6.0
shader_param/corner_color = Color( 0, 0, 0, 0.784314 )
shader_param/show_vignette = true
shader_param/vignette_opacity = 0.2
shader_param/show_horizontal_scan_lines = false
shader_param/horizontal_scan_lines_amount = 180.0
shader_param/horizontal_scan_lines_opacity = 0.9
shader_param/show_vertical_scan_lines = true
shader_param/vertical_scan_lines_amount = 320.0
shader_param/vertical_scan_lines_opacity = 0.9
shader_param/boost = 1.5
shader_param/aberration_amount = 0.0
[node name="CRT" type="CanvasLayer"]
script = ExtResource( 1 )
[node name="CRTOverlay" type="ColorRect" parent="."]
material = SubResource( 2 )
anchor_right = 1.0
anchor_bottom = 1.0
mouse_filter = 2
__meta__ = {
"_edit_use_anchors_": false
}
[node name="ShakeTimer" type="Timer" parent="."]
wait_time = 0.1
[connection signal="timeout" from="ShakeTimer" to="." method="_on_ShakeTimer_timeout"]