Un shader de transition entre les scènes

ça fait plus propre braw
This commit is contained in:
Thomas
2025-04-14 17:24:10 +02:00
parent bf2ed6312d
commit 5e32ed4196
13 changed files with 228 additions and 18 deletions

BIN
shaders/masks/curtain.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 146 KiB

View File

@@ -0,0 +1,36 @@
[remap]
importer="texture"
type="CompressedTexture2D"
uid="uid://b5mne7k2hxq4m"
path.s3tc="res://.godot/imported/curtain.png-5dbd4676444a95ae3c4ec4f3e7000c6e.s3tc.ctex"
path.etc2="res://.godot/imported/curtain.png-5dbd4676444a95ae3c4ec4f3e7000c6e.etc2.ctex"
metadata={
"imported_formats": ["s3tc_bptc", "etc2_astc"],
"vram_texture": true
}
[deps]
source_file="res://shaders/masks/curtain.png"
dest_files=["res://.godot/imported/curtain.png-5dbd4676444a95ae3c4ec4f3e7000c6e.s3tc.ctex", "res://.godot/imported/curtain.png-5dbd4676444a95ae3c4ec4f3e7000c6e.etc2.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,36 @@
[remap]
importer="texture"
type="CompressedTexture2D"
uid="uid://dwn3g5smhhcb0"
path.s3tc="res://.godot/imported/shards.png-8f1a380663fac4b8c90fd5ea54d3ed72.s3tc.ctex"
path.etc2="res://.godot/imported/shards.png-8f1a380663fac4b8c90fd5ea54d3ed72.etc2.ctex"
metadata={
"imported_formats": ["s3tc_bptc", "etc2_astc"],
"vram_texture": true
}
[deps]
source_file="res://shaders/masks/shards.png"
dest_files=["res://.godot/imported/shards.png-8f1a380663fac4b8c90fd5ea54d3ed72.s3tc.ctex", "res://.godot/imported/shards.png-8f1a380663fac4b8c90fd5ea54d3ed72.etc2.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,20 @@
extends CanvasLayer
signal fade_in_done()
signal fade_out_done()
@onready var player := $TransitionShader/AnimationPlayer as AnimationPlayer
func fade_in():
player.play(&"fade_in")
func fade_out():
visible = true
player.play(&"fade_out")
func _on_animation_player_animation_finished(anim_name: StringName) -> void:
if anim_name == "fade_in":
fade_in_done.emit()
visible = false
elif anim_name == "fade_out":
fade_out_done.emit()

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,71 @@
[gd_scene load_steps=8 format=3 uid="uid://17macg0q4k8l"]
[ext_resource type="Script" path="res://shaders/transition_shader.gd" id="1_aj5xt"]
[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="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="CanvasLayer" type="CanvasLayer"]
visible = false
script = ExtResource("1_aj5xt")
[node name="TransitionShader" type="ColorRect" parent="."]
material = SubResource("ShaderMaterial_g48os")
anchors_preset = 15
anchor_right = 1.0
anchor_bottom = 1.0
grow_horizontal = 2
grow_vertical = 2
size_flags_horizontal = 3
size_flags_vertical = 3
color = Color(0, 0, 0, 1)
[node name="AnimationPlayer" type="AnimationPlayer" parent="TransitionShader"]
libraries = {
"": SubResource("AnimationLibrary_kedvi")
}
[connection signal="animation_finished" from="TransitionShader/AnimationPlayer" to="." method="_on_animation_player_animation_finished"]