summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJan Tuomi <jan@jantuomi.fi>2025-11-26 18:41:11 +0200
committerJan Tuomi <jan@jantuomi.fi>2025-11-26 18:41:11 +0200
commit194f6e369c9f31df6e6ab4b46c7423d031f26264 (patch)
treea6d748b1b8f48ae35d8c8f4e0edb552075d192ca
parenta991d59e784cc0a44a63be5e8f8e98fe27b05224 (diff)
Improve shader
-rw-r--r--assets/pal_aap-micro12.pngbin0 -> 128 bytes
-rw-r--r--assets/pal_aap-micro12.png.import40
-rw-r--r--assets/pal_gray12.pngbin0 -> 89 bytes
-rw-r--r--assets/pal_gray12.png.import40
-rw-r--r--docs/index.html2
-rw-r--r--docs/index.pckbin3815896 -> 3819588 bytes
-rw-r--r--docs/index.service.worker.js2
-rw-r--r--door.gd2
-rw-r--r--mat_palette.gdshader64
-rw-r--r--mat_palette.tres19
-rw-r--r--palette_shader.gd8
-rw-r--r--palette_shader.gd.uid1
-rw-r--r--top.gd6
-rw-r--r--top.tscn97
-rw-r--r--transition_manager.gd.uid1
-rw-r--r--transition_manager.tscn101
-rw-r--r--transition_player.gd (renamed from transition_manager.gd)8
-rw-r--r--transition_player.gd.uid1
18 files changed, 219 insertions, 173 deletions
diff --git a/assets/pal_aap-micro12.png b/assets/pal_aap-micro12.png
new file mode 100644
index 0000000..c2906a3
--- /dev/null
+++ b/assets/pal_aap-micro12.png
Binary files differ
diff --git a/assets/pal_aap-micro12.png.import b/assets/pal_aap-micro12.png.import
new file mode 100644
index 0000000..c6009eb
--- /dev/null
+++ b/assets/pal_aap-micro12.png.import
@@ -0,0 +1,40 @@
+[remap]
+
+importer="texture"
+type="CompressedTexture2D"
+uid="uid://bp4x8ebxvbfp1"
+path="res://.godot/imported/pal_aap-micro12.png-e80c32871a2c033fcd1a993fe9f864d2.ctex"
+metadata={
+"vram_texture": false
+}
+
+[deps]
+
+source_file="res://assets/pal_aap-micro12.png"
+dest_files=["res://.godot/imported/pal_aap-micro12.png-e80c32871a2c033fcd1a993fe9f864d2.ctex"]
+
+[params]
+
+compress/mode=0
+compress/high_quality=false
+compress/lossy_quality=0.7
+compress/uastc_level=0
+compress/rdo_quality_loss=0.0
+compress/hdr_compression=1
+compress/normal_map=0
+compress/channel_pack=0
+mipmaps/generate=false
+mipmaps/limit=-1
+roughness/mode=0
+roughness/src_normal=""
+process/channel_remap/red=0
+process/channel_remap/green=1
+process/channel_remap/blue=2
+process/channel_remap/alpha=3
+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=1
diff --git a/assets/pal_gray12.png b/assets/pal_gray12.png
new file mode 100644
index 0000000..4cba261
--- /dev/null
+++ b/assets/pal_gray12.png
Binary files differ
diff --git a/assets/pal_gray12.png.import b/assets/pal_gray12.png.import
new file mode 100644
index 0000000..4f35867
--- /dev/null
+++ b/assets/pal_gray12.png.import
@@ -0,0 +1,40 @@
+[remap]
+
+importer="texture"
+type="CompressedTexture2D"
+uid="uid://cp2wfnxy5po8i"
+path="res://.godot/imported/pal_gray12.png-b028283c92601d2b89df447f3a27e5d6.ctex"
+metadata={
+"vram_texture": false
+}
+
+[deps]
+
+source_file="res://assets/pal_gray12.png"
+dest_files=["res://.godot/imported/pal_gray12.png-b028283c92601d2b89df447f3a27e5d6.ctex"]
+
+[params]
+
+compress/mode=0
+compress/high_quality=false
+compress/lossy_quality=0.7
+compress/uastc_level=0
+compress/rdo_quality_loss=0.0
+compress/hdr_compression=1
+compress/normal_map=0
+compress/channel_pack=0
+mipmaps/generate=false
+mipmaps/limit=-1
+roughness/mode=0
+roughness/src_normal=""
+process/channel_remap/red=0
+process/channel_remap/green=1
+process/channel_remap/blue=2
+process/channel_remap/alpha=3
+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=1
diff --git a/docs/index.html b/docs/index.html
index fb60c30..431efa5 100644
--- a/docs/index.html
+++ b/docs/index.html
@@ -112,7 +112,7 @@ body {
<script src="index.js"></script>
<script>
-const GODOT_CONFIG = {"args":[],"canvasResizePolicy":2,"emscriptenPoolSize":8,"ensureCrossOriginIsolationHeaders":true,"executable":"index","experimentalVK":false,"fileSizes":{"index.pck":3815896,"index.wasm":38034280},"focusCanvas":true,"gdextensionLibs":[],"godotPoolSize":4,"serviceWorker":"index.service.worker.js"};
+const GODOT_CONFIG = {"args":[],"canvasResizePolicy":2,"emscriptenPoolSize":8,"ensureCrossOriginIsolationHeaders":true,"executable":"index","experimentalVK":false,"fileSizes":{"index.pck":3819588,"index.wasm":38034280},"focusCanvas":true,"gdextensionLibs":[],"godotPoolSize":4,"serviceWorker":"index.service.worker.js"};
const GODOT_THREADS_ENABLED = false;
const engine = new Engine(GODOT_CONFIG);
diff --git a/docs/index.pck b/docs/index.pck
index c1cc666..a305bf9 100644
--- a/docs/index.pck
+++ b/docs/index.pck
Binary files differ
diff --git a/docs/index.service.worker.js b/docs/index.service.worker.js
index e1a7bd4..4fdcb00 100644
--- a/docs/index.service.worker.js
+++ b/docs/index.service.worker.js
@@ -4,7 +4,7 @@
// Incrementing CACHE_VERSION will kick off the install event and force
// previously cached resources to be updated from the network.
/** @type {string} */
-const CACHE_VERSION = '1764153772|1018290046';
+const CACHE_VERSION = '1764175235|10897656112';
/** @type {string} */
const CACHE_PREFIX = 'MobileMetroidvan-sw-cache-';
const CACHE_NAME = CACHE_PREFIX + CACHE_VERSION;
diff --git a/door.gd b/door.gd
index 9197812..a0202f8 100644
--- a/door.gd
+++ b/door.gd
@@ -29,7 +29,7 @@ func _get(property):
func _on_body_entered(_player: Player) -> void:
if not Engine.is_editor_hint():
var top: Top = get_tree().root.get_node("Top")
- top.get_transition_manager().room_transition(self, _target_room, _target_door)
+ top.get_transition_player().room_transition(self, _target_room, _target_door)
func _get_property_list() -> Array[Dictionary]:
var rooms: PackedStringArray = []
diff --git a/mat_palette.gdshader b/mat_palette.gdshader
index e24a6ee..03c664a 100644
--- a/mat_palette.gdshader
+++ b/mat_palette.gdshader
@@ -1,54 +1,30 @@
shader_type canvas_item;
-uniform vec4 palette_0 : source_color;
-uniform vec4 palette_1 : source_color;
-uniform vec4 palette_2 : source_color;
-uniform vec4 palette_3 : source_color;
-uniform vec4 palette_4 : source_color;
-uniform vec4 palette_5 : source_color;
-uniform vec4 palette_6 : source_color;
-uniform vec4 palette_7 : source_color;
-uniform vec4 palette_8 : source_color;
-uniform vec4 palette_9 : source_color;
-uniform vec4 palette_10 : source_color;
-uniform vec4 palette_11 : source_color;
+uniform sampler2D screen_texture : hint_screen_texture, repeat_disable, filter_nearest;
-const int N_COLORS = 12;
-
-uniform sampler2D screen_texture : hint_screen_texture;
+uniform float brightness : hint_range(-1, 1) = 0;
+uniform sampler2D source_palette;
+uniform sampler2D target_palette;
void fragment() {
- vec4 palette[N_COLORS] = { palette_0, palette_1, palette_2, palette_3, palette_4, palette_5, palette_6, palette_7, palette_8, palette_9, palette_10, palette_11 };
vec4 screen_color = texture(screen_texture, SCREEN_UV);
- // Compute source color value
- float sv = 0.f;
- for (int i = 0; i < 3; i++) {
- if (screen_color[i] > sv) { sv = screen_color[i]; }
- }
+ ivec2 pal_size = textureSize(source_palette, 0);
- int pal_i = int(floor((sv * 0.99f) * float(N_COLORS)));
- vec4 result = palette[pal_i];
- /*
- float min_dist = 999.f; // always bigger than 1.0
- vec4 result;
- for (int i = 0; i < N_COLORS; i++) {
- vec4 pc = palette[i];
- // Compute palette color value
- float pv = 0.f;
- for (int j = 0; j < 3; j++) {
- if (pc[j] > pv) { pv = pc[j]; }
- }
- float dist = abs(pv - sv);
- if (dist < min_dist) {
- min_dist = dist;
- result = pc;
+ float color_diff = 1.0;
+ int nearest_swatch = 0;
+
+ for (int swatch=0; swatch < pal_size.x; swatch++) {
+ vec4 sampled_color = texelFetch(source_palette, ivec2(swatch,0), 0);
+ float new_color_diff = distance(sampled_color, screen_color);
+
+ if (new_color_diff < color_diff) {
+ color_diff = new_color_diff;
+ nearest_swatch = swatch;
}
}
- */
- COLOR = vec4(result.rgb, COLOR.a);
+
+ int swatch_offset = int(brightness * float(pal_size.x));
+ int target_swatch = clamp(nearest_swatch + swatch_offset, 0, pal_size.x -1);
+
+ COLOR = texelFetch(target_palette, ivec2(target_swatch, 0), 0);
}
-
-//void light() {
-// // Called for every pixel for every light affecting the CanvasItem.
-// // Uncomment to replace the default light processing function with this one.
-//}
diff --git a/mat_palette.tres b/mat_palette.tres
index 4bdf09e..d11ea5b 100644
--- a/mat_palette.tres
+++ b/mat_palette.tres
@@ -1,18 +1,11 @@
-[gd_resource type="ShaderMaterial" load_steps=2 format=3 uid="uid://bb4b8jm2tyy81"]
+[gd_resource type="ShaderMaterial" load_steps=4 format=3 uid="uid://bb4b8jm2tyy81"]
[ext_resource type="Shader" uid="uid://dug36yc62jfj5" path="res://mat_palette.gdshader" id="1_tt8pc"]
+[ext_resource type="Texture2D" uid="uid://cp2wfnxy5po8i" path="res://assets/pal_gray12.png" id="2_wx43e"]
+[ext_resource type="Texture2D" uid="uid://bp4x8ebxvbfp1" path="res://assets/pal_aap-micro12.png" id="3_cppgj"]
[resource]
shader = ExtResource("1_tt8pc")
-shader_parameter/palette_0 = Color(0, 0, 0, 1)
-shader_parameter/palette_1 = Color(0.2509804, 0.15686275, 0.34901962, 1)
-shader_parameter/palette_2 = Color(0.20784314, 0.21568628, 0.3882353, 1)
-shader_parameter/palette_3 = Color(0.15294118, 0.37254903, 0.46666667, 1)
-shader_parameter/palette_4 = Color(0.21960784, 0.5294118, 0.44313726, 1)
-shader_parameter/palette_5 = Color(0.3529412, 0.61960787, 0.36078432, 1)
-shader_parameter/palette_6 = Color(1, 0.91764706, 0.3882353, 1)
-shader_parameter/palette_7 = Color(0.84705883, 0.58431375, 0.26666668, 1)
-shader_parameter/palette_8 = Color(0.5529412, 0.5176471, 0.2901961, 1)
-shader_parameter/palette_9 = Color(0.7372549, 0.69803923, 0.43529412, 1)
-shader_parameter/palette_10 = Color(1, 0.8980392, 0.7490196, 1)
-shader_parameter/palette_11 = Color(1, 1, 1, 1)
+shader_parameter/brightness = 4.7499999933364734e-08
+shader_parameter/source_palette = ExtResource("2_wx43e")
+shader_parameter/target_palette = ExtResource("3_cppgj")
diff --git a/palette_shader.gd b/palette_shader.gd
new file mode 100644
index 0000000..e4b9865
--- /dev/null
+++ b/palette_shader.gd
@@ -0,0 +1,8 @@
+class_name PaletteShader
+extends CanvasLayer
+
+# Set by TransitionPlayer animation
+var brightness: float = 0.3
+
+func _process(_delta: float) -> void:
+ $ColorRect.material.set_shader_parameter("brightness", brightness)
diff --git a/palette_shader.gd.uid b/palette_shader.gd.uid
new file mode 100644
index 0000000..3fac16d
--- /dev/null
+++ b/palette_shader.gd.uid
@@ -0,0 +1 @@
+uid://cph2apstgper1
diff --git a/top.gd b/top.gd
index fd96dff..843dafa 100644
--- a/top.gd
+++ b/top.gd
@@ -43,8 +43,8 @@ func replace_active_room(new_room: Node, on_changed: Callable):
func get_map() -> Map:
return $Map
-func get_transition_manager() -> TransitionManager:
- return $TransitionManager
+func get_transition_player() -> TransitionPlayer:
+ return $TransitionPlayer
func open_pause_menu():
get_tree().paused = true
@@ -70,7 +70,7 @@ func game_save():
func game_load():
save_state.load(SAVE_PATH)
- $TransitionManager.room_transition(
+ $TransitionPlayer.room_transition(
null,
save_state.get_value(SAVE_SECTION, SAVE_ACTIVE_ROOM_PATH, ROOM_NEW_GAME),
save_state.get_value(SAVE_SECTION, SAVE_LAST_DOOR_NAME)
diff --git a/top.tscn b/top.tscn
index 20764e8..8350343 100644
--- a/top.tscn
+++ b/top.tscn
@@ -1,23 +1,112 @@
-[gd_scene load_steps=6 format=3 uid="uid://cey3jxnpmommt"]
+[gd_scene load_steps=11 format=3 uid="uid://cey3jxnpmommt"]
[ext_resource type="Material" uid="uid://bb4b8jm2tyy81" path="res://mat_palette.tres" id="1_edsjh"]
[ext_resource type="Script" uid="uid://dxbspy72bg0db" path="res://top.gd" id="1_on2c2"]
-[ext_resource type="PackedScene" uid="uid://c2shuyjjq06p8" path="res://transition_manager.tscn" id="3_2exal"]
[ext_resource type="PackedScene" uid="uid://cseqghymhiyqo" path="res://map.tscn" id="3_58ij3"]
+[ext_resource type="Script" uid="uid://cph2apstgper1" path="res://palette_shader.gd" id="5_ch5ua"]
[ext_resource type="PackedScene" uid="uid://cciwccvljuuyq" path="res://touch_screen_ui.tscn" id="5_edsjh"]
+[ext_resource type="Script" uid="uid://civ5a43u5151a" path="res://transition_player.gd" id="6_ch5ua"]
+
+[sub_resource type="Animation" id="Animation_58ij3"]
+length = 0.001
+tracks/0/type = "value"
+tracks/0/imported = false
+tracks/0/enabled = true
+tracks/0/path = NodePath("PaletteShader:brightness")
+tracks/0/interp = 1
+tracks/0/loop_wrap = true
+tracks/0/keys = {
+"times": PackedFloat32Array(0),
+"transitions": PackedFloat32Array(1),
+"update": 0,
+"values": [0.0]
+}
+
+[sub_resource type="Animation" id="Animation_edsjh"]
+resource_name = "room_trans_end"
+length = 2.0
+tracks/0/type = "method"
+tracks/0/imported = false
+tracks/0/enabled = true
+tracks/0/path = NodePath("TransitionPlayer")
+tracks/0/interp = 1
+tracks/0/loop_wrap = true
+tracks/0/keys = {
+"times": PackedFloat32Array(2),
+"transitions": PackedFloat32Array(1),
+"values": [{
+"args": [],
+"method": &"_transition_end"
+}]
+}
+tracks/1/type = "value"
+tracks/1/imported = false
+tracks/1/enabled = true
+tracks/1/path = NodePath("PaletteShader:brightness")
+tracks/1/interp = 1
+tracks/1/loop_wrap = true
+tracks/1/keys = {
+"times": PackedFloat32Array(0, 2),
+"transitions": PackedFloat32Array(1, 1),
+"update": 0,
+"values": [-1.0, 0.30000000000000004]
+}
+
+[sub_resource type="Animation" id="Animation_2exal"]
+resource_name = "room_trans_start"
+length = 2.0
+tracks/0/type = "method"
+tracks/0/imported = false
+tracks/0/enabled = true
+tracks/0/path = NodePath("TransitionPlayer")
+tracks/0/interp = 1
+tracks/0/loop_wrap = true
+tracks/0/keys = {
+"times": PackedFloat32Array(2),
+"transitions": PackedFloat32Array(1),
+"values": [{
+"args": [],
+"method": &"_transition_start"
+}]
+}
+tracks/1/type = "value"
+tracks/1/imported = false
+tracks/1/enabled = true
+tracks/1/path = NodePath("PaletteShader:brightness")
+tracks/1/interp = 1
+tracks/1/loop_wrap = true
+tracks/1/keys = {
+"times": PackedFloat32Array(0, 2),
+"transitions": PackedFloat32Array(1, 1),
+"update": 0,
+"values": [0.30000000000000004, -1.0]
+}
+
+[sub_resource type="AnimationLibrary" id="AnimationLibrary_2exal"]
+_data = {
+&"RESET": SubResource("Animation_58ij3"),
+&"room_trans_end": SubResource("Animation_edsjh"),
+&"room_trans_start": SubResource("Animation_2exal")
+}
[node name="Top" type="Node2D"]
process_mode = 3
material = ExtResource("1_edsjh")
script = ExtResource("1_on2c2")
-[node name="TransitionManager" parent="." instance=ExtResource("3_2exal")]
-
[node name="Map" parent="." instance=ExtResource("3_58ij3")]
[node name="TouchScreenUI" parent="." instance=ExtResource("5_edsjh")]
+[node name="TransitionPlayer" type="AnimationPlayer" parent="."]
+libraries = {
+&"": SubResource("AnimationLibrary_2exal")
+}
+speed_scale = 3.0
+script = ExtResource("6_ch5ua")
+
[node name="PaletteShader" type="CanvasLayer" parent="."]
+script = ExtResource("5_ch5ua")
[node name="ColorRect" type="ColorRect" parent="PaletteShader"]
material = ExtResource("1_edsjh")
diff --git a/transition_manager.gd.uid b/transition_manager.gd.uid
deleted file mode 100644
index aedf462..0000000
--- a/transition_manager.gd.uid
+++ /dev/null
@@ -1 +0,0 @@
-uid://kfbrnj68jtyf
diff --git a/transition_manager.tscn b/transition_manager.tscn
deleted file mode 100644
index 3389dd1..0000000
--- a/transition_manager.tscn
+++ /dev/null
@@ -1,101 +0,0 @@
-[gd_scene load_steps=6 format=3 uid="uid://c2shuyjjq06p8"]
-
-[ext_resource type="Script" uid="uid://kfbrnj68jtyf" path="res://transition_manager.gd" id="1_xqma1"]
-
-[sub_resource type="Animation" id="Animation_58ij3"]
-length = 0.001
-tracks/0/type = "value"
-tracks/0/imported = false
-tracks/0/enabled = true
-tracks/0/path = NodePath(".:color")
-tracks/0/interp = 1
-tracks/0/loop_wrap = true
-tracks/0/keys = {
-"times": PackedFloat32Array(0),
-"transitions": PackedFloat32Array(1),
-"update": 0,
-"values": [Color(0, 0, 0, 0)]
-}
-
-[sub_resource type="Animation" id="Animation_edsjh"]
-resource_name = "room_trans_end"
-length = 2.0
-tracks/0/type = "value"
-tracks/0/imported = false
-tracks/0/enabled = true
-tracks/0/path = NodePath(".:color")
-tracks/0/interp = 1
-tracks/0/loop_wrap = true
-tracks/0/keys = {
-"times": PackedFloat32Array(0, 2),
-"transitions": PackedFloat32Array(1, 1),
-"update": 0,
-"values": [Color(0, 0, 0, 1), Color(0, 0, 0, 0)]
-}
-tracks/1/type = "method"
-tracks/1/imported = false
-tracks/1/enabled = true
-tracks/1/path = NodePath("..")
-tracks/1/interp = 1
-tracks/1/loop_wrap = true
-tracks/1/keys = {
-"times": PackedFloat32Array(2),
-"transitions": PackedFloat32Array(1),
-"values": [{
-"args": [],
-"method": &"_transition_end"
-}]
-}
-
-[sub_resource type="Animation" id="Animation_2exal"]
-resource_name = "room_trans_start"
-length = 2.0
-tracks/0/type = "value"
-tracks/0/imported = false
-tracks/0/enabled = true
-tracks/0/path = NodePath(".:color")
-tracks/0/interp = 1
-tracks/0/loop_wrap = true
-tracks/0/keys = {
-"times": PackedFloat32Array(0, 2),
-"transitions": PackedFloat32Array(1, 1),
-"update": 0,
-"values": [Color(0, 0, 0, 0), Color(0, 0, 0, 1)]
-}
-tracks/1/type = "method"
-tracks/1/imported = false
-tracks/1/enabled = true
-tracks/1/path = NodePath("..")
-tracks/1/interp = 1
-tracks/1/loop_wrap = true
-tracks/1/keys = {
-"times": PackedFloat32Array(2),
-"transitions": PackedFloat32Array(1),
-"values": [{
-"args": [],
-"method": &"_transition_start"
-}]
-}
-
-[sub_resource type="AnimationLibrary" id="AnimationLibrary_2exal"]
-_data = {
-&"RESET": SubResource("Animation_58ij3"),
-&"room_trans_end": SubResource("Animation_edsjh"),
-&"room_trans_start": SubResource("Animation_2exal")
-}
-
-[node name="TransitionManager" type="CanvasLayer"]
-script = ExtResource("1_xqma1")
-
-[node name="ColorRect" type="ColorRect" parent="."]
-offset_right = 192.0
-offset_bottom = 108.0
-mouse_filter = 2
-color = Color(0, 0, 0, 0)
-
-[node name="AnimationPlayer" type="AnimationPlayer" parent="."]
-root_node = NodePath("../ColorRect")
-libraries = {
-&"": SubResource("AnimationLibrary_2exal")
-}
-speed_scale = 3.0
diff --git a/transition_manager.gd b/transition_player.gd
index 390f854..0960497 100644
--- a/transition_manager.gd
+++ b/transition_player.gd
@@ -1,5 +1,5 @@
-class_name TransitionManager
-extends CanvasLayer
+class_name TransitionPlayer
+extends AnimationPlayer
var _transition_room: Node
var _transition_door_name: Variant # String or null
@@ -17,7 +17,7 @@ func room_transition(from_door: Door, to_room_path: String, door_name: Variant):
# Start animation
# The animation calls _change_room at a specific time
- $AnimationPlayer.play("room_trans_start")
+ play("room_trans_start")
var room = ResourceLoader.load(to_room_path)
_transition_room = room.instantiate()
@@ -47,7 +47,7 @@ func _on_room_changed():
player.position = door.position
player.set_forced_input(door.exit_towards)
- $AnimationPlayer.play("room_trans_end")
+ play("room_trans_end")
top.game_save()
func _transition_end():
diff --git a/transition_player.gd.uid b/transition_player.gd.uid
new file mode 100644
index 0000000..4b1ca1a
--- /dev/null
+++ b/transition_player.gd.uid
@@ -0,0 +1 @@
+uid://civ5a43u5151a