add palette approx shader

This commit is contained in:
yuki 2025-11-24 17:35:50 -03:00
parent d53073ad1a
commit 73c65415f1
6 changed files with 131 additions and 1 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 464 B

View file

@ -0,0 +1,40 @@
[remap]
importer="texture"
type="CompressedTexture2D"
uid="uid://h5523ru86vrd"
path="res://.godot/imported/forgotten.png-16ceeb0132426814a27475a2e3efca51.ctex"
metadata={
"vram_texture": false
}
[deps]
source_file="res://assets/palettes/forgotten.png"
dest_files=["res://.godot/imported/forgotten.png-16ceeb0132426814a27475a2e3efca51.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

View file

@ -1,4 +1,4 @@
[gd_scene load_steps=8 format=3 uid="uid://bxhyxox662buj"]
[gd_scene load_steps=11 format=3 uid="uid://bxhyxox662buj"]
[ext_resource type="Script" uid="uid://pcl0om2k32g6" path="res://scenes/room/room.gd" id="1_8xru0"]
[ext_resource type="Script" uid="uid://diou146pyb0br" path="res://scenes/room/room_camera.gd" id="3_y1kpu"]
@ -7,11 +7,28 @@
[ext_resource type="Script" uid="uid://d2xitfobwbk20" path="res://scenes/room/states/room_playing.gd" id="5_w7vtx"]
[ext_resource type="Script" uid="uid://drnrd5xlt8imm" path="res://scenes/room/states/room_exiting.gd" id="6_7jj40"]
[ext_resource type="Script" uid="uid://ceevyto3vbq7c" path="res://scenes/room/states/room_paused.gd" id="6_gui0a"]
[ext_resource type="Shader" uid="uid://bxvmsjxx0tj21" path="res://shaders/palette.gdshader" id="8_dv301"]
[ext_resource type="Texture2D" uid="uid://h5523ru86vrd" path="res://assets/palettes/forgotten.png" id="9_68b7a"]
[sub_resource type="ShaderMaterial" id="ShaderMaterial_ip1yl"]
shader = ExtResource("8_dv301")
shader_parameter/palette = ExtResource("9_68b7a")
shader_parameter/palette_size = 120
[node name="Room" type="Node2D"]
y_sort_enabled = true
script = ExtResource("1_8xru0")
[node name="CanvasLayer" type="CanvasLayer" parent="."]
[node name="ColorRect" type="ColorRect" parent="CanvasLayer"]
material = SubResource("ShaderMaterial_ip1yl")
anchors_preset = 15
anchor_right = 1.0
anchor_bottom = 1.0
grow_horizontal = 2
grow_vertical = 2
[node name="RoomDirector" type="Node" parent="." node_paths=PackedStringArray("initial_state")]
process_mode = 3
script = ExtResource("4_vaubn")

View file

@ -6,6 +6,7 @@
[sub_resource type="Resource" id="Resource_t5fpq"]
script = ExtResource("2_06s2n")
initial_spawn = Vector2i(25, 40)
loopable = true
loop_size = Rect2i(0, 0, 320, 240)
metadata/_custom_type_script = "uid://bamoq5wi0lkdy"
@ -14,6 +15,58 @@ metadata/_custom_type_script = "uid://bamoq5wi0lkdy"
config = SubResource("Resource_t5fpq")
[node name="Sprite2D" type="Sprite2D" parent="." index="2"]
z_index = 1
position = Vector2(232, 144)
texture = ExtResource("3_06s2n")
offset = Vector2(0, -50)
[node name="Sprite2D5" type="Sprite2D" parent="." index="3"]
z_index = 1
position = Vector2(232, 384)
texture = ExtResource("3_06s2n")
offset = Vector2(0, -50)
[node name="Sprite2D2" type="Sprite2D" parent="." index="4"]
z_index = 1
position = Vector2(-88, 144)
texture = ExtResource("3_06s2n")
offset = Vector2(0, -50)
[node name="Sprite2D3" type="Sprite2D" parent="." index="5"]
z_index = 1
position = Vector2(232, -104)
texture = ExtResource("3_06s2n")
offset = Vector2(0, -50)
[node name="Sprite2D8" type="Sprite2D" parent="." index="6"]
z_index = 1
position = Vector2(552, -104)
texture = ExtResource("3_06s2n")
offset = Vector2(0, -50)
[node name="Sprite2D9" type="Sprite2D" parent="." index="7"]
z_index = 1
position = Vector2(552, 384)
texture = ExtResource("3_06s2n")
offset = Vector2(0, -50)
[node name="Sprite2D6" type="Sprite2D" parent="." index="8"]
z_index = 1
position = Vector2(-88, 384)
texture = ExtResource("3_06s2n")
offset = Vector2(0, -50)
[node name="Sprite2D7" type="Sprite2D" parent="." index="9"]
z_index = 1
position = Vector2(-88, -104)
texture = ExtResource("3_06s2n")
offset = Vector2(0, -50)
[node name="Sprite2D4" type="Sprite2D" parent="." index="10"]
z_index = 1
position = Vector2(552, 144)
texture = ExtResource("3_06s2n")
offset = Vector2(0, -50)
[node name="ColorRect" parent="CanvasLayer" index="0"]
metadata/_edit_lock_ = true

19
shaders/palette.gdshader Normal file
View file

@ -0,0 +1,19 @@
shader_type canvas_item;
uniform sampler2D SCREEN_TEXTURE : hint_screen_texture, filter_linear_mipmap;
uniform sampler2D palette : hint_default_black; // Insert a palette from lospec for instance
uniform int palette_size = 16;
void fragment(){
vec4 color = texture(SCREEN_TEXTURE, SCREEN_UV);
vec4 new_color = vec4(.0);
for (int i = 0; i < palette_size; i++) {
vec4 palette_color = texture(palette, vec2(1.0 / float(palette_size) * float(i), .0));
if (distance(palette_color, color) < distance(new_color, color)) {
new_color = palette_color;
}
}
COLOR = new_color;
}

View file

@ -0,0 +1 @@
uid://bxvmsjxx0tj21