diff options
| -rw-r--r-- | Assets/Shaders/crt_shader.gdshader | 127 | ||||
| -rw-r--r-- | Assets/Shaders/crt_shader.tres | 21 | ||||
| -rw-r--r-- | Assets/Styles/DefaultFlatPanel.tres | 2 | ||||
| -rw-r--r-- | Assets/Styles/DefaultInvertedFlatPanel.tres | 2 | ||||
| -rw-r--r-- | Assets/Themes/Default.tres | 4 | ||||
| -rw-r--r-- | Scenes/Game/Game.tscn | 19 | ||||
| -rw-r--r-- | Scenes/MonitorEffect.tscn | 23 | ||||
| -rw-r--r-- | Scenes/Texty.tscn | 20 | ||||
| -rw-r--r-- | project.godot | 13 |
9 files changed, 120 insertions, 111 deletions
diff --git a/Assets/Shaders/crt_shader.gdshader b/Assets/Shaders/crt_shader.gdshader index 445472e..5c698a6 100644 --- a/Assets/Shaders/crt_shader.gdshader +++ b/Assets/Shaders/crt_shader.gdshader @@ -9,76 +9,75 @@ 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 bool chromatic_abberation_enabled = true; +uniform float chromatic_abberation_amount : hint_range(0.0, 10.0, 0.01) = 4.0; + +uniform bool vignette_enabled = 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; + +uniform bool scan_lines_enabled = true; +uniform float scan_lines_count : hint_range(0, 180, 1) = 180; +uniform float scan_lines_opacity : hint_range(0.0, 1.0, 0.01) = 1.0; + +uniform float boost_intensity : hint_range(1.0, 2.0, 0.01) = 1.2; + +const float PI = 3.14159265359; + +/** + * Apply chromatic abberation the the given texture. + */ +vec3 chromatic_abberation(sampler2D tex, vec2 uv, vec2 screen_size) { + float adjusted_amount = chromatic_abberation_amount / screen_size.x; + + vec3 color; + + color.r = texture(tex, vec2(clamp(uv.x + adjusted_amount, 0.0, 1.0), uv.y)).r; + color.g = texture(tex, uv).g; + color.b = texture(tex, vec2(clamp(uv.x - adjusted_amount, 0.0, 1.0), uv.y)).b; + + return color; +} + +/** + * Apply a vignette. + */ +vec3 vignette(vec3 color, vec2 uv, vec2 screen_size) { + 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); + return color * vignette; } +/** + * Apply scan lines + */ +vec3 scan_lines(vec3 color, vec2 uv) { + float strength = clamp(sin(uv.y * scan_lines_count * PI * 2.0), 0.65, 0.85); + vec3 scan_line = vec3(pow(strength, scan_lines_opacity)); + return color * scan_line * boost_intensity; +} 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; - } + vec3 color = texture(SCREEN_TEXTURE, SCREEN_UV).rgb; + vec2 screen_size = 1.0 / SCREEN_PIXEL_SIZE; + + color = mix( + color, + chromatic_abberation(SCREEN_TEXTURE, SCREEN_UV, screen_size), + float(chromatic_abberation_enabled) + ); + + color = mix( + color, + vignette(color, SCREEN_UV, screen_size), + float(vignette_enabled) + ); + + color = mix( + color, + scan_lines(color, SCREEN_UV), + float(scan_lines_enabled) + ); COLOR = vec4(color, 1.0); }
\ No newline at end of file diff --git a/Assets/Shaders/crt_shader.tres b/Assets/Shaders/crt_shader.tres index 1612d82..cf5c247 100644 --- a/Assets/Shaders/crt_shader.tres +++ b/Assets/Shaders/crt_shader.tres @@ -4,18 +4,11 @@ [resource] shader = ExtResource( 1 ) -shader_param/screen_size = Vector2( 640, 480 ) -shader_param/show_curvature = false -shader_param/curvature_x_amount = 6.0 -shader_param/curvature_y_amount = 4.0 -shader_param/corner_color = Color( 0, 0, 0, 1 ) -shader_param/show_vignette = true +shader_param/chromatic_abberation_enabled = true +shader_param/chromatic_abberation_amount = 4.0 +shader_param/vignette_enabled = true shader_param/vignette_opacity = 0.1 -shader_param/show_horizontal_scan_lines = true -shader_param/horizontal_scan_lines_amount = 90.0 -shader_param/horizontal_scan_lines_opacity = 0.1 -shader_param/show_vertical_scan_lines = false -shader_param/vertical_scan_lines_amount = 320.0 -shader_param/vertical_scan_lines_opacity = 1.0 -shader_param/boost = 1.25 -shader_param/aberration_amount = 1.5 +shader_param/scan_lines_enabled = true +shader_param/scan_lines_count = 180.0 +shader_param/scan_lines_opacity = 1.0 +shader_param/boost_intensity = 1.3 diff --git a/Assets/Styles/DefaultFlatPanel.tres b/Assets/Styles/DefaultFlatPanel.tres index 3186dbe..567307c 100644 --- a/Assets/Styles/DefaultFlatPanel.tres +++ b/Assets/Styles/DefaultFlatPanel.tres @@ -1,4 +1,4 @@ [gd_resource type="StyleBoxFlat" format=2] [resource] -bg_color = Color( 0, 0, 0, 1 ) +bg_color = Color( 0.1, 0.1, 0.1, 1 ) diff --git a/Assets/Styles/DefaultInvertedFlatPanel.tres b/Assets/Styles/DefaultInvertedFlatPanel.tres index 16f668c..7c678fe 100644 --- a/Assets/Styles/DefaultInvertedFlatPanel.tres +++ b/Assets/Styles/DefaultInvertedFlatPanel.tres @@ -1,4 +1,4 @@ [gd_resource type="StyleBoxFlat" format=2] [resource] -bg_color = Color( 0, 0.956863, 0, 1 ) +bg_color = Color( 0.243137, 0.811765, 0.235294, 1 ) diff --git a/Assets/Themes/Default.tres b/Assets/Themes/Default.tres index 32fc4b7..c56e746 100644 --- a/Assets/Themes/Default.tres +++ b/Assets/Themes/Default.tres @@ -19,7 +19,7 @@ InvertedLabel/colors/font_color = Color( 0, 0, 0, 1 ) InvertedPanelContainer/styles/panel = ExtResource( 1 ) InvertedRichTextLabel/colors/default_color = Color( 0, 0, 0, 1 ) -Label/colors/font_color = Color( 1, 1, 1, 1 ) +Label/colors/font_color = Color( 0.243137, 0.811765, 0.235294, 1 ) Label/styles/normal = SubResource( 3 ) LineEdit/colors/cursor_color = Color( 0, 0, 0, 1 ) LineEdit/colors/font_color = Color( 0, 0, 0, 1 ) @@ -28,6 +28,6 @@ LineEdit/styles/focus = SubResource( 7 ) LineEdit/styles/normal = SubResource( 1 ) LineEdit/styles/read_only = SubResource( 2 ) PanelContainer/styles/panel = ExtResource( 2 ) -RichTextLabel/colors/default_color = Color( 0, 0.956863, 0, 1 ) +RichTextLabel/colors/default_color = Color( 0.243137, 0.811765, 0.235294, 1 ) RichTextLabel/styles/focus = SubResource( 5 ) RichTextLabel/styles/normal = SubResource( 6 ) diff --git a/Scenes/Game/Game.tscn b/Scenes/Game/Game.tscn index e2f7bc2..9762066 100644 --- a/Scenes/Game/Game.tscn +++ b/Scenes/Game/Game.tscn @@ -13,29 +13,36 @@ script = ExtResource( 4 ) [node name="Screen" parent="." instance=ExtResource( 1 )] [node name="TopBar" parent="Screen/ScreenContainer" index="0"] -margin_bottom = 27.0 +margin_right = 800.0 +margin_bottom = 26.0 [node name="StatusArea" parent="Screen/ScreenContainer/TopBar" index="0" instance=ExtResource( 5 )] unique_name_in_owner = true +margin_right = 800.0 +margin_bottom = 26.0 Title = "Adventure Title" [node name="Content" parent="Screen/ScreenContainer" index="1"] -margin_top = 27.0 -margin_bottom = 455.0 +margin_top = 26.0 +margin_right = 800.0 +margin_bottom = 575.0 [node name="OutputArea" parent="Screen/ScreenContainer/Content" index="0" instance=ExtResource( 2 )] unique_name_in_owner = true anchor_right = 0.0 anchor_bottom = 0.0 -margin_right = 640.0 -margin_bottom = 428.0 +margin_right = 800.0 +margin_bottom = 549.0 OutputBlockScene = ExtResource( 6 ) [node name="BottomBar" parent="Screen/ScreenContainer" index="2"] -margin_top = 455.0 +margin_top = 575.0 +margin_right = 800.0 +margin_bottom = 600.0 [node name="InputArea" parent="Screen/ScreenContainer/BottomBar" index="0" instance=ExtResource( 3 )] unique_name_in_owner = true +margin_right = 800.0 [connection signal="CommandSubmitted" from="Screen/ScreenContainer/BottomBar/InputArea" to="." method="OnCommandSubmitted"] [connection signal="UnknownInputSubmitted" from="Screen/ScreenContainer/BottomBar/InputArea" to="." method="OnUnknownInputSubmitted"] diff --git a/Scenes/MonitorEffect.tscn b/Scenes/MonitorEffect.tscn new file mode 100644 index 0000000..a717629 --- /dev/null +++ b/Scenes/MonitorEffect.tscn @@ -0,0 +1,23 @@ +[gd_scene load_steps=3 format=2] + +[ext_resource path="res://Assets/Shaders/crt_shader.gdshader" type="Shader" id=1] + +[sub_resource type="ShaderMaterial" id=1] +shader = ExtResource( 1 ) +shader_param/chromatic_abberation_enabled = true +shader_param/chromatic_abberation_amount = 3.0 +shader_param/vignette_enabled = true +shader_param/vignette_opacity = 0.05 +shader_param/scan_lines_enabled = true +shader_param/scan_lines_count = 120.0 +shader_param/scan_lines_opacity = 0.5 +shader_param/boost_intensity = 1.3 + +[node name="MonitorEffect" type="CanvasLayer"] +layer = 2 + +[node name="ShaderRectangle" type="ColorRect" parent="."] +material = SubResource( 1 ) +anchor_right = 1.0 +anchor_bottom = 1.0 +rect_clip_content = true diff --git a/Scenes/Texty.tscn b/Scenes/Texty.tscn deleted file mode 100644 index 28822b5..0000000 --- a/Scenes/Texty.tscn +++ /dev/null @@ -1,20 +0,0 @@ -[gd_scene load_steps=3 format=2] - -[ext_resource path="res://Assets/Shaders/crt_shader.tres" type="Material" id=1] -[ext_resource path="res://Scenes/Game/Game.tscn" type="PackedScene" id=2] - -[node name="Texty" type="Node"] - -[node name="Terminal" type="CanvasLayer" parent="."] - -[node name="Game" parent="Terminal" instance=ExtResource( 2 )] - -[node name="Screen" type="CanvasLayer" parent="."] - -[node name="Shader" type="ColorRect" parent="Screen"] -material = ExtResource( 1 ) -anchor_right = 1.0 -anchor_bottom = 1.0 -mouse_filter = 2 -size_flags_horizontal = 3 -size_flags_vertical = 3 diff --git a/project.godot b/project.godot index 3f00c81..72e325e 100644 --- a/project.godot +++ b/project.godot @@ -39,14 +39,17 @@ _global_script_class_icons={ [application] config/name="Texty" -run/main_scene="res://Scenes/Texty.tscn" +run/main_scene="res://Scenes/Game/Game.tscn" run/delta_sync_after_draw=true config/icon="res://icon.png" +[autoload] + +MonitorEffect="res://Scenes/MonitorEffect.tscn" + [display] -window/size/width=640 -window/size/height=480 +window/size/width=800 window/energy_saving/keep_screen_on=false window/stretch/mode="viewport" window/stretch/aspect="expand" @@ -76,4 +79,8 @@ common/enable_pause_aware_picking=true [rendering] +quality/driver/fallback_to_gles2=true +quality/intended_usage/framebuffer_allocation=0 +quality/intended_usage/framebuffer_allocation.mobile=0 +2d/snapping/use_gpu_pixel_snap=true environment/default_environment="res://default_env.tres" |
