niveau/transitions: shader de transition

Entre les niveaux et à la mort il y a maintenant un fondu au noir qui se
met en place pour éviter d'avoir la gerbe sur les mouvements de caméra.
la physique est en pause pendant la transition.
This commit is contained in:
Thomas Lavocat
2023-05-11 08:53:46 +02:00
parent bd85e22644
commit 5678bd8c55
13 changed files with 240 additions and 7 deletions

View File

@@ -24,6 +24,7 @@ func dash_fart() -> bool:
func reset(): func reset():
animationPlayer.play("RESET") animationPlayer.play("RESET")
loaded = false loaded = false
loading = false
func _on_animation_player_animation_finished(anim_name: StringName) -> void: func _on_animation_player_animation_finished(anim_name: StringName) -> void:
if anim_name == "reload": if anim_name == "reload":

View File

@@ -4,7 +4,11 @@ class_name HUD extends CanvasLayer
@onready var gauge2 := $FartGauge2 as FartGauge @onready var gauge2 := $FartGauge2 as FartGauge
@onready var gauge3 := $FartGauge3 as FartGauge @onready var gauge3 := $FartGauge3 as FartGauge
@onready var shader := $TransitionShader
signal fart_reloaded() signal fart_reloaded()
signal screen_is_black()
signal screen_is_ready()
var cheese_number = 0 var cheese_number = 0
var gauges = [] var gauges = []
@@ -15,7 +19,6 @@ func _ready() -> void:
gauge3.connect("reload_done", cheese_loaded) gauge3.connect("reload_done", cheese_loaded)
gauges = [gauge1, gauge2, gauge3] gauges = [gauge1, gauge2, gauge3]
func reset(): func reset():
cheese_number = 0 cheese_number = 0
for gauge in gauges: for gauge in gauges:
@@ -34,3 +37,17 @@ func dash_fart():
func cheese_loaded(): func cheese_loaded():
fart_reloaded.emit() fart_reloaded.emit()
func begin_scene_transition():
print("start scene transition")
shader.fade_out()
func end_scene_transition():
print("end scene transition")
shader.fade_in()
func _on_transition_shader_fade_in_done() -> void:
screen_is_ready.emit()
func _on_transition_shader_fade_out_done() -> void:
screen_is_black.emit()

View File

@@ -1,8 +1,11 @@
[gd_scene load_steps=2 format=3 uid="uid://dvlb4thqhqke"] [gd_scene load_steps=4 format=3 uid="uid://dvlb4thqhqke"]
[ext_resource type="PackedScene" uid="uid://dsgt6b1bqi6ui" path="res://HUD/fart_gauge.tscn" id="1_4e2i3"] [ext_resource type="PackedScene" uid="uid://dsgt6b1bqi6ui" path="res://HUD/fart_gauge.tscn" id="1_4e2i3"]
[ext_resource type="Script" path="res://HUD/hud.gd" id="1_e1sc7"]
[ext_resource type="PackedScene" uid="uid://17macg0q4k8l" path="res://shaders/transition_shader.tscn" id="2_gh8iu"]
[node name="HUD" type="CanvasLayer"] [node name="HUD" type="CanvasLayer"]
script = ExtResource("1_e1sc7")
[node name="FartGauge3" parent="." instance=ExtResource("1_4e2i3")] [node name="FartGauge3" parent="." instance=ExtResource("1_4e2i3")]
position = Vector2(242, 6) position = Vector2(242, 6)
@@ -18,3 +21,10 @@ scale = Vector2(0.7, 0.7)
position = Vector2(51, 6) position = Vector2(51, 6)
rotation = -1.5708 rotation = -1.5708
scale = Vector2(0.7, 0.7) scale = Vector2(0.7, 0.7)
[node name="TransitionShader" parent="." instance=ExtResource("2_gh8iu")]
offset_right = 0.0
offset_bottom = 0.0
[connection signal="fade_in_done" from="TransitionShader" to="." method="_on_transition_shader_fade_in_done"]
[connection signal="fade_out_done" from="TransitionShader" to="." method="_on_transition_shader_fade_out_done"]

18
game.gd
View File

@@ -13,6 +13,9 @@ var last_spawn_point = null
var princesse : Princess = null var princesse : Princess = null
var goto_destination
var goto_spawn_point
# Called when the node enters the scene tree for the first time. # Called when the node enters the scene tree for the first time.
func _ready() -> void: func _ready() -> void:
go_to(scene_name, null) go_to(scene_name, null)
@@ -25,11 +28,20 @@ func enter_door(destination : String, other_side_position : Vector2):
call_deferred("go_to", destination, other_side_position) call_deferred("go_to", destination, other_side_position)
func go_to(destination : String, spawn_point): func go_to(destination : String, spawn_point):
goto_destination = destination
goto_spawn_point = spawn_point
hud.begin_scene_transition()
func _on_hud_screen_is_black() -> void:
var destination = goto_destination
var spawn_point = goto_spawn_point
var old_princesse :Princess = null var old_princesse :Princess = null
if current_scence: if current_scence:
old_princesse = current_scence.find_child("Princesse") old_princesse = current_scence.find_child("Princesse")
old_princesse.disconnect("cheese_collected", hud_load_cheese) old_princesse.disconnect("cheese_collected", hud_load_cheese)
old_princesse.disconnect("dash_fart", hud_unload_cheese) old_princesse.disconnect("dash_fart", hud_unload_cheese)
#old_princesse.disconnect("princess_is_dead", princess_death)
remove_child(current_scence) remove_child(current_scence)
if destination == "level_1": if destination == "level_1":
@@ -54,6 +66,9 @@ func go_to(destination : String, spawn_point):
princesse.copy_from(old_princesse) princesse.copy_from(old_princesse)
princesse.connect("cheese_collected", hud_load_cheese) princesse.connect("cheese_collected", hud_load_cheese)
princesse.connect("dash_fart", hud_unload_cheese) princesse.connect("dash_fart", hud_unload_cheese)
#princesse.connect("princess_is_dead", princess_death)
hud.end_scene_transition()
# vient de la princesse quand elle a ramassé un fromage # vient de la princesse quand elle a ramassé un fromage
func hud_load_cheese(): func hud_load_cheese():
@@ -67,3 +82,6 @@ func hud_unload_cheese():
# quand le fromage est chargé, le jeu le signale à la princesse # quand le fromage est chargé, le jeu le signale à la princesse
func _on_hud_fart_reloaded() -> void: func _on_hud_fart_reloaded() -> void:
princesse.reload_fart() princesse.reload_fart()
func _on_hud_screen_is_ready() -> void:
princesse.go_out_and_play()

View File

@@ -1,13 +1,13 @@
[gd_scene load_steps=4 format=3 uid="uid://dn0b30kvaeasf"] [gd_scene load_steps=3 format=3 uid="uid://dn0b30kvaeasf"]
[ext_resource type="Script" path="res://game.gd" id="1_yny56"] [ext_resource type="Script" path="res://game.gd" id="1_yny56"]
[ext_resource type="PackedScene" uid="uid://dvlb4thqhqke" path="res://HUD/hud.tscn" id="2_0fnfe"] [ext_resource type="PackedScene" uid="uid://dvlb4thqhqke" path="res://HUD/hud.tscn" id="2_0fnfe"]
[ext_resource type="Script" path="res://HUD/hud.gd" id="3_x1wcj"]
[node name="game" type="Node"] [node name="game" type="Node"]
script = ExtResource("1_yny56") script = ExtResource("1_yny56")
[node name="HUD" parent="." instance=ExtResource("2_0fnfe")] [node name="HUD" parent="." instance=ExtResource("2_0fnfe")]
script = ExtResource("3_x1wcj")
[connection signal="fart_reloaded" from="HUD" to="." method="_on_hud_fart_reloaded"] [connection signal="fart_reloaded" from="HUD" to="." method="_on_hud_fart_reloaded"]
[connection signal="screen_is_black" from="HUD" to="." method="_on_hud_screen_is_black"]
[connection signal="screen_is_ready" from="HUD" to="." method="_on_hud_screen_is_ready"]

View File

@@ -512,7 +512,7 @@ func get_new_animation() -> String:
return animation_new return animation_new
func _physics_process(_delta: float) -> void: func _physics_process(_delta: float) -> void:
if dead: if dead or locked:
return return
compute_state() compute_state()
read_input() read_input()
@@ -540,7 +540,7 @@ func death() -> void:
dead = true dead = true
death_animation.play(&"death") death_animation.play(&"death")
func _ready(): func go_out_and_play():
locked = false locked = false
dead = false dead = false

BIN
shaders/masks/curtain.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 146 KiB

View File

@@ -0,0 +1,35 @@
[remap]
importer="texture"
type="CompressedTexture2D"
uid="uid://b5mne7k2hxq4m"
path.s3tc="res://.godot/imported/curtain.png-5dbd4676444a95ae3c4ec4f3e7000c6e.s3tc.ctex"
metadata={
"imported_formats": ["s3tc_bptc"],
"vram_texture": true
}
[deps]
source_file="res://shaders/masks/curtain.png"
dest_files=["res://.godot/imported/curtain.png-5dbd4676444a95ae3c4ec4f3e7000c6e.s3tc.ctex"]
[params]
compress/mode=2
compress/high_quality=false
compress/lossy_quality=0.7
compress/hdr_compression=1
compress/normal_map=0
compress/channel_pack=0
mipmaps/generate=true
mipmaps/limit=-1
roughness/mode=0
roughness/src_normal=""
process/fix_alpha_border=true
process/premult_alpha=false
process/normal_map_invert_y=false
process/hdr_as_srgb=false
process/hdr_clamp_exposure=false
process/size_limit=0
detect_3d/compress_to=0

BIN
shaders/masks/shards.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 81 KiB

View File

@@ -0,0 +1,35 @@
[remap]
importer="texture"
type="CompressedTexture2D"
uid="uid://dwn3g5smhhcb0"
path.s3tc="res://.godot/imported/shards.png-8f1a380663fac4b8c90fd5ea54d3ed72.s3tc.ctex"
metadata={
"imported_formats": ["s3tc_bptc"],
"vram_texture": true
}
[deps]
source_file="res://shaders/masks/shards.png"
dest_files=["res://.godot/imported/shards.png-8f1a380663fac4b8c90fd5ea54d3ed72.s3tc.ctex"]
[params]
compress/mode=2
compress/high_quality=false
compress/lossy_quality=0.7
compress/hdr_compression=1
compress/normal_map=0
compress/channel_pack=0
mipmaps/generate=true
mipmaps/limit=-1
roughness/mode=0
roughness/src_normal=""
process/fix_alpha_border=true
process/premult_alpha=false
process/normal_map_invert_y=false
process/hdr_as_srgb=false
process/hdr_clamp_exposure=false
process/size_limit=0
detect_3d/compress_to=0

View File

@@ -0,0 +1,11 @@
extends ColorRect
# Called when the node enters the scene tree for the first time.
func _ready() -> void:
pass # Replace with function body.
# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta: float) -> void:
pass

View File

@@ -0,0 +1,16 @@
shader_type canvas_item;
render_mode unshaded;
uniform float cutoff: hint_range(0.0, 1.0);
uniform float smooth_size: hint_range(0.0, 0.1);
uniform sampler2D mask: hint_default_black;
void fragment() {
float value = texture(mask, UV).r;
float alpha = smoothstep(
cutoff,
cutoff + smooth_size,
value * (1.0 - smooth_size) + smooth_size
);
COLOR = vec4(COLOR.rgb, alpha);
}

View File

@@ -0,0 +1,90 @@
[gd_scene load_steps=8 format=3 uid="uid://17macg0q4k8l"]
[ext_resource type="Shader" path="res://shaders/transition_shader.gdshader" id="1_kyfmm"]
[ext_resource type="Texture2D" uid="uid://b5mne7k2hxq4m" path="res://shaders/masks/curtain.png" id="2_pg1r4"]
[sub_resource type="ShaderMaterial" id="ShaderMaterial_g48os"]
shader = ExtResource("1_kyfmm")
shader_parameter/cutoff = 0.0
shader_parameter/smooth_size = 0.1
shader_parameter/mask = ExtResource("2_pg1r4")
[sub_resource type="GDScript" id="GDScript_rrd13"]
script/source = "class_name FadeShader extends ColorRect
signal fade_in_done()
signal fade_out_done()
@onready var player := $\"AnimationPlayer\" as AnimationPlayer
func fade_in():
player.play(&\"fade_in\")
func fade_out():
player.play(&\"fade_out\")
func _on_animation_player_animation_finished(anim_name: StringName) -> void:
if anim_name == \"fade_in\":
fade_in_done.emit()
elif anim_name == \"fade_out\":
fade_out_done.emit()
"
[sub_resource type="Animation" id="Animation_yg4ht"]
resource_name = "fade_in"
length = 0.5
tracks/0/type = "value"
tracks/0/imported = false
tracks/0/enabled = true
tracks/0/path = NodePath(".:material:shader_parameter/cutoff")
tracks/0/interp = 1
tracks/0/loop_wrap = true
tracks/0/keys = {
"times": PackedFloat32Array(0.2, 0.4),
"transitions": PackedFloat32Array(1, 0.450625),
"update": 0,
"values": [0.0, 1.0]
}
[sub_resource type="Animation" id="Animation_mavdc"]
resource_name = "fade_out"
length = 0.25
tracks/0/type = "value"
tracks/0/imported = false
tracks/0/enabled = true
tracks/0/path = NodePath(".:material:shader_parameter/cutoff")
tracks/0/interp = 1
tracks/0/loop_wrap = true
tracks/0/keys = {
"times": PackedFloat32Array(0, 0.2),
"transitions": PackedFloat32Array(1, 1),
"update": 0,
"values": [1.0, 0.0]
}
[sub_resource type="AnimationLibrary" id="AnimationLibrary_kedvi"]
_data = {
"fade_in": SubResource("Animation_yg4ht"),
"fade_out": SubResource("Animation_mavdc")
}
[node name="TransitionShader" type="ColorRect"]
material = SubResource("ShaderMaterial_g48os")
anchors_preset = 15
anchor_right = 1.0
anchor_bottom = 1.0
offset_right = -1680.0
offset_bottom = -945.0
grow_horizontal = 2
grow_vertical = 2
size_flags_horizontal = 3
size_flags_vertical = 3
color = Color(0, 0, 0, 1)
script = SubResource("GDScript_rrd13")
[node name="AnimationPlayer" type="AnimationPlayer" parent="."]
libraries = {
"": SubResource("AnimationLibrary_kedvi")
}
[connection signal="animation_finished" from="AnimationPlayer" to="." method="_on_animation_player_animation_finished"]