Render text in a different viewport, apply the outline shader only to the normal one
This commit is contained in:
parent
ca40ca4207
commit
eaf9edfd53
9 changed files with 109 additions and 34 deletions
|
@ -22,6 +22,7 @@ class Entrypoint extends Object:
|
||||||
self.initial_velocity = initial_velocity_
|
self.initial_velocity = initial_velocity_
|
||||||
|
|
||||||
const SCENES = {
|
const SCENES = {
|
||||||
|
"menu": "uid://bqmpoix37kutp",
|
||||||
"intro": "uid://c6w7lrydi43ts",
|
"intro": "uid://c6w7lrydi43ts",
|
||||||
"test": "uid://dqf665b540tfg",
|
"test": "uid://dqf665b540tfg",
|
||||||
}
|
}
|
||||||
|
@ -38,7 +39,10 @@ var current_scene_name: String = ""
|
||||||
|
|
||||||
func _pre_load_checks() -> bool:
|
func _pre_load_checks() -> bool:
|
||||||
if NodeRegistry.level_root_container == null:
|
if NodeRegistry.level_root_container == null:
|
||||||
push_error("Can't load level, level_root is not registered yet.")
|
push_error("Can't load level, level_root_container is not registered yet.")
|
||||||
|
return false
|
||||||
|
if NodeRegistry.level_text_root_container == null:
|
||||||
|
push_error("Can't load level, level_text_root_container is not registered yet.")
|
||||||
return false
|
return false
|
||||||
if NodeRegistry.player == null:
|
if NodeRegistry.player == null:
|
||||||
push_error("Can't load entrypoint, player is not registered yet.")
|
push_error("Can't load entrypoint, player is not registered yet.")
|
||||||
|
@ -55,14 +59,20 @@ func load_scene(scn_name: String, force_reload: bool = false) -> bool:
|
||||||
push_error("Level " + scn_name + " doesn't exist.")
|
push_error("Level " + scn_name + " doesn't exist.")
|
||||||
return false
|
return false
|
||||||
unload_scene()
|
unload_scene()
|
||||||
var scn = load(SCENES[scn_name])
|
var scn: Node2D = load(SCENES[scn_name]).instantiate()
|
||||||
NodeRegistry.level_root_container.add_child(scn.instantiate())
|
NodeRegistry.level_root_container.add_child(scn)
|
||||||
|
for t in get_tree().get_nodes_in_group("text_viewport"):
|
||||||
|
t.reparent(NodeRegistry.level_text_root_container)
|
||||||
return true
|
return true
|
||||||
|
|
||||||
func unload_scene():
|
func unload_scene():
|
||||||
if NodeRegistry.level_root_container != null:
|
for container in [
|
||||||
for c in NodeRegistry.level_root_container.get_children():
|
NodeRegistry.level_root_container,
|
||||||
c.queue_free()
|
NodeRegistry.level_text_root_container
|
||||||
|
]:
|
||||||
|
if container != null:
|
||||||
|
for c in container.get_children():
|
||||||
|
c.queue_free()
|
||||||
|
|
||||||
func load_entrypoint(ep_name: String) -> bool: # returns true on success
|
func load_entrypoint(ep_name: String) -> bool: # returns true on success
|
||||||
if not ep_name in ENTRYPOINTS:
|
if not ep_name in ENTRYPOINTS:
|
||||||
|
@ -86,6 +96,5 @@ func load_menu():
|
||||||
if not _pre_load_checks():
|
if not _pre_load_checks():
|
||||||
return false
|
return false
|
||||||
unload_scene()
|
unload_scene()
|
||||||
NodeRegistry.level_root_container.add_child(MENU_SCENE.instantiate())
|
|
||||||
NodeRegistry.player.position = mainmenu_player_pos
|
NodeRegistry.player.position = mainmenu_player_pos
|
||||||
return true
|
return load_scene("menu", true)
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
extends Node
|
extends Node
|
||||||
|
|
||||||
var player: CharacterBody2D
|
var player: CharacterBody2D
|
||||||
var level_root_container: Node
|
var level_root_container: Node2D
|
||||||
|
var level_text_root_container: Node2D
|
||||||
|
|
|
@ -23,7 +23,11 @@ void fragment() {
|
||||||
rgb_distortion_v_min,
|
rgb_distortion_v_min,
|
||||||
rgb_distortion_v_max
|
rgb_distortion_v_max
|
||||||
);
|
);
|
||||||
COLOR.r = textureLod(screen_texture, SCREEN_UV - (v_ * 0.01), v).r;
|
vec2 screen_uv_r = SCREEN_UV - (v_ * 0.01);
|
||||||
COLOR.g = textureLod(screen_texture, SCREEN_UV + (v_ * 0.01), v).g;
|
vec2 screen_uv_g = SCREEN_UV + (v_ * 0.01);
|
||||||
COLOR.b = textureLod(screen_texture, SCREEN_UV, v).b;
|
vec2 screen_uv_b = SCREEN_UV;
|
||||||
|
COLOR.r = textureLod(screen_texture, screen_uv_r, v).r;
|
||||||
|
COLOR.g = textureLod(screen_texture, screen_uv_g, v).g;
|
||||||
|
COLOR.b = textureLod(screen_texture, screen_uv_b, v).b;
|
||||||
|
COLOR.a = 1.0;
|
||||||
}
|
}
|
||||||
|
|
5
core/shadowing_camera_2d.gd
Normal file
5
core/shadowing_camera_2d.gd
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
extends Camera2D
|
||||||
|
|
||||||
|
func _physics_process(_delta: float) -> void:
|
||||||
|
var orig_camera: Camera2D = NodeRegistry.player.camera
|
||||||
|
self.global_position = -orig_camera.get_viewport_transform().origin
|
7
main.gd
7
main.gd
|
@ -1,6 +1,7 @@
|
||||||
extends Node2D
|
extends Node
|
||||||
|
|
||||||
func _ready() -> void:
|
func _ready() -> void:
|
||||||
NodeRegistry.level_root_container = $LevelRoot
|
NodeRegistry.player = %Player
|
||||||
NodeRegistry.player = $Player
|
NodeRegistry.level_root_container = %LevelRootContainer
|
||||||
|
NodeRegistry.level_text_root_container = %LevelTextRootContainer
|
||||||
Levels.load_menu()
|
Levels.load_menu()
|
||||||
|
|
61
main.tscn
61
main.tscn
|
@ -1,17 +1,66 @@
|
||||||
[gd_scene load_steps=5 format=3 uid="uid://c13h0uf5fgx60"]
|
[gd_scene load_steps=6 format=3 uid="uid://c13h0uf5fgx60"]
|
||||||
|
|
||||||
[ext_resource type="Script" path="res://main.gd" id="1_m407c"]
|
[ext_resource type="Script" path="res://main.gd" id="1_m407c"]
|
||||||
[ext_resource type="PackedScene" uid="uid://dxp3dru2lrv6h" path="res://core/shaders/outline/outline_canvas_layer.tscn" id="2_ta1pa"]
|
[ext_resource type="PackedScene" uid="uid://dxp3dru2lrv6h" path="res://core/shaders/outline/outline_canvas_layer.tscn" id="2_ta1pa"]
|
||||||
[ext_resource type="PackedScene" uid="uid://jmy11lqcs4c" path="res://core/shaders/distortion/distortion_canvas_layer.tscn" id="3_emkei"]
|
[ext_resource type="PackedScene" uid="uid://jmy11lqcs4c" path="res://core/shaders/distortion/distortion_canvas_layer.tscn" id="3_emkei"]
|
||||||
[ext_resource type="PackedScene" uid="uid://ebb4pfxklatj" path="res://player/player.tscn" id="5_0agpg"]
|
[ext_resource type="PackedScene" uid="uid://ebb4pfxklatj" path="res://player/player.tscn" id="5_0agpg"]
|
||||||
|
[ext_resource type="Script" path="res://core/shadowing_camera_2d.gd" id="5_rlmue"]
|
||||||
|
|
||||||
[node name="Main" type="Node2D"]
|
[node name="Main" type="Control"]
|
||||||
|
layout_mode = 3
|
||||||
|
anchors_preset = 15
|
||||||
|
anchor_right = 1.0
|
||||||
|
anchor_bottom = 1.0
|
||||||
|
grow_horizontal = 2
|
||||||
|
grow_vertical = 2
|
||||||
script = ExtResource("1_m407c")
|
script = ExtResource("1_m407c")
|
||||||
|
|
||||||
[node name="LevelRoot" type="Node2D" parent="."]
|
[node name="MainViewportContainer" type="SubViewportContainer" parent="."]
|
||||||
|
layout_mode = 1
|
||||||
|
anchors_preset = 15
|
||||||
|
anchor_right = 1.0
|
||||||
|
anchor_bottom = 1.0
|
||||||
|
grow_horizontal = 2
|
||||||
|
grow_vertical = 2
|
||||||
|
stretch = true
|
||||||
|
|
||||||
[node name="OutlineShader" parent="." instance=ExtResource("2_ta1pa")]
|
[node name="MainViewport" type="SubViewport" parent="MainViewportContainer"]
|
||||||
|
handle_input_locally = false
|
||||||
|
canvas_item_default_texture_filter = 0
|
||||||
|
size = Vector2i(800, 450)
|
||||||
|
render_target_update_mode = 4
|
||||||
|
|
||||||
|
[node name="LevelRootContainer" type="Node2D" parent="MainViewportContainer/MainViewport"]
|
||||||
|
unique_name_in_owner = true
|
||||||
|
|
||||||
|
[node name="Player" parent="MainViewportContainer/MainViewport" instance=ExtResource("5_0agpg")]
|
||||||
|
unique_name_in_owner = true
|
||||||
|
|
||||||
|
[node name="OutlineShader" parent="MainViewportContainer/MainViewport" instance=ExtResource("2_ta1pa")]
|
||||||
|
|
||||||
|
[node name="TextViewportContainer" type="SubViewportContainer" parent="."]
|
||||||
|
editor_description = "All nodes in the text_viewport group will be rendered in this viewport instead."
|
||||||
|
layout_mode = 1
|
||||||
|
anchors_preset = 15
|
||||||
|
anchor_right = 1.0
|
||||||
|
anchor_bottom = 1.0
|
||||||
|
grow_horizontal = 2
|
||||||
|
grow_vertical = 2
|
||||||
|
stretch = true
|
||||||
|
|
||||||
|
[node name="TextViewport" type="SubViewport" parent="TextViewportContainer"]
|
||||||
|
transparent_bg = true
|
||||||
|
handle_input_locally = false
|
||||||
|
canvas_item_default_texture_filter = 0
|
||||||
|
size = Vector2i(800, 450)
|
||||||
|
render_target_update_mode = 4
|
||||||
|
|
||||||
|
[node name="LevelTextRootContainer" type="Node2D" parent="TextViewportContainer/TextViewport"]
|
||||||
|
unique_name_in_owner = true
|
||||||
|
|
||||||
|
[node name="ShadowingCamera2D" type="Camera2D" parent="TextViewportContainer/TextViewport"]
|
||||||
|
editor_description = "Shadows the camera in MainViewportContainer"
|
||||||
|
anchor_mode = 0
|
||||||
|
script = ExtResource("5_rlmue")
|
||||||
|
|
||||||
[node name="DistortionShader" parent="." instance=ExtResource("3_emkei")]
|
[node name="DistortionShader" parent="." instance=ExtResource("3_emkei")]
|
||||||
|
|
||||||
[node name="Player" parent="." instance=ExtResource("5_0agpg")]
|
|
||||||
|
|
|
@ -8,16 +8,6 @@
|
||||||
position = Vector2(0, -1)
|
position = Vector2(0, -1)
|
||||||
script = ExtResource("1_g2w4y")
|
script = ExtResource("1_g2w4y")
|
||||||
|
|
||||||
[node name="Label" type="Label" parent="."]
|
|
||||||
offset_left = -192.0
|
|
||||||
offset_top = -15.0
|
|
||||||
offset_right = 192.0
|
|
||||||
offset_bottom = 65.0
|
|
||||||
theme_override_font_sizes/font_size = 52
|
|
||||||
text = "Main Menu"
|
|
||||||
horizontal_alignment = 1
|
|
||||||
vertical_alignment = 2
|
|
||||||
|
|
||||||
[node name="StaticBody2D" type="StaticBody2D" parent="."]
|
[node name="StaticBody2D" type="StaticBody2D" parent="."]
|
||||||
|
|
||||||
[node name="Polygon" parent="StaticBody2D" instance=ExtResource("1_8p275")]
|
[node name="Polygon" parent="StaticBody2D" instance=ExtResource("1_8p275")]
|
||||||
|
@ -26,13 +16,13 @@ polygon = PackedVector2Array(-256, 209, 320, 209, 320, 193, -272, 193, -272, 601
|
||||||
[node name="SaveGameSlots" type="Node2D" parent="."]
|
[node name="SaveGameSlots" type="Node2D" parent="."]
|
||||||
position = Vector2(-448, 177)
|
position = Vector2(-448, 177)
|
||||||
|
|
||||||
[node name="Saves" type="Label" parent="SaveGameSlots"]
|
[node name="Saves" type="Label" parent="SaveGameSlots" groups=["text_viewport"]]
|
||||||
offset_left = -64.0
|
offset_left = -64.0
|
||||||
offset_top = -176.0
|
offset_top = -176.0
|
||||||
offset_right = 64.0
|
offset_right = 64.0
|
||||||
offset_bottom = -112.0
|
offset_bottom = -112.0
|
||||||
theme_override_font_sizes/font_size = 42
|
theme_override_font_sizes/font_size = 42
|
||||||
text = "Saves"
|
text = "saves"
|
||||||
horizontal_alignment = 1
|
horizontal_alignment = 1
|
||||||
vertical_alignment = 2
|
vertical_alignment = 2
|
||||||
|
|
||||||
|
@ -53,3 +43,13 @@ slot_label = "2"
|
||||||
position = Vector2(0, 384)
|
position = Vector2(0, 384)
|
||||||
slot_idx = 3
|
slot_idx = 3
|
||||||
slot_label = "3"
|
slot_label = "3"
|
||||||
|
|
||||||
|
[node name="Label" type="Label" parent="." groups=["text_viewport"]]
|
||||||
|
offset_left = -192.0
|
||||||
|
offset_top = -15.0
|
||||||
|
offset_right = 192.0
|
||||||
|
offset_bottom = 65.0
|
||||||
|
theme_override_font_sizes/font_size = 52
|
||||||
|
text = "rectangular"
|
||||||
|
horizontal_alignment = 1
|
||||||
|
vertical_alignment = 2
|
||||||
|
|
|
@ -23,7 +23,7 @@ color = Color(0, 1, 0, 1)
|
||||||
polygon = PackedVector2Array(-64, 48, -44, 48, -44, 24, -64, 24)
|
polygon = PackedVector2Array(-64, 48, -44, 48, -44, 24, -64, 24)
|
||||||
color = Color(1, 0, 0, 1)
|
color = Color(1, 0, 0, 1)
|
||||||
|
|
||||||
[node name="Label" type="Label" parent="."]
|
[node name="Label" type="Label" parent="." groups=["text_viewport"]]
|
||||||
offset_left = -16.0
|
offset_left = -16.0
|
||||||
offset_top = -32.0
|
offset_top = -32.0
|
||||||
offset_right = 16.0
|
offset_right = 16.0
|
||||||
|
|
|
@ -30,8 +30,14 @@ settings/stdout/print_fps=true
|
||||||
|
|
||||||
window/size/viewport_width=800
|
window/size/viewport_width=800
|
||||||
window/size/viewport_height=450
|
window/size/viewport_height=450
|
||||||
|
window/size/mode=3
|
||||||
window/stretch/mode="viewport"
|
window/stretch/mode="viewport"
|
||||||
window/stretch/aspect="expand"
|
window/stretch/aspect="expand"
|
||||||
|
window/stretch/scale_mode="integer"
|
||||||
|
|
||||||
|
[global_group]
|
||||||
|
|
||||||
|
text_viewport="Render this in the TextViewport"
|
||||||
|
|
||||||
[input]
|
[input]
|
||||||
|
|
||||||
|
|
Reference in a new issue