Update items

This commit is contained in:
2024-09-16 01:05:15 -07:00
parent 660a5f5553
commit 55c521db3a
32 changed files with 480 additions and 142 deletions

View File

@@ -0,0 +1,72 @@
shader_type canvas_item;
render_mode unshaded;
#define MAXCOLORS 16
uniform bool enabled = true;
uniform bool dithering = true;
uniform int colors : hint_range(1, MAXCOLORS) = 12;
uniform int dither_size: hint_range(1, 8) = 1;
float dithering_pattern(ivec2 fragcoord) {
const float pattern[] = {
0.00, 0.50, 0.10, 0.65,
0.75, 0.25, 0.90, 0.35,
0.20, 0.70, 0.05, 0.50,
0.95, 0.40, 0.80, 0.30
};
int x = fragcoord.x % 4;
int y = fragcoord.y % 4;
return pattern[y * 4 + x];
}
float reduce_color(float raw, float dither, int depth) {
float div = 1.0 / float(depth);
float val = 0.0;
int i = 0;
while (i <= MAXCOLORS)
{
if (raw > div * (float(i + 1))) {
i = i + 1;
continue;
}
if (raw * float(depth) - float(i) <= dither * 0.999)
{
val = div * float(i);
}
else
{
val = div * float(i + 1);
}
return val;
i = i+1;
}
return val;
}
void fragment() {
vec4 raw = texture(TEXTURE, SCREEN_UV);
ivec2 uv = ivec2(FRAGCOORD.xy / float(dither_size));
if (enabled == true){
float dithering_value = 1.0;
if (dithering)
{
dithering_value = dithering_pattern(uv);
}
COLOR.r = reduce_color(raw.r, (dithering_value - 0.5) * dithering_value + 0.5, colors - 1);
COLOR.g = reduce_color(raw.g, (dithering_value - 0.5) * dithering_value + 0.5, colors - 1);
COLOR.b = reduce_color(raw.b, (dithering_value - 0.5) * dithering_value + 0.5, colors - 1);
} else {
COLOR.rgb = raw.rgb;
}
}

View File

@@ -12,15 +12,15 @@ float psuedo_rand(float x) {
void fragment() {
vec2 uv = UV;
// Move pixels near the top faster
uv.y -= progress / UV.y;
// Created jagged edges for each pixel on the x-axis
// Created jagged edges for each pixel on the x-axis
uv.y -= progress * meltiness * psuedo_rand(UV.x - mod(UV.x, TEXTURE_PIXEL_SIZE.x));
COLOR = texture(TEXTURE, uv);
// "delete" pixels out of range
if (uv.y <= 0.0) {
COLOR.a = 0.0;

View File

@@ -0,0 +1,44 @@
shader_type spatial;
render_mode unshaded, shadows_disabled, depth_test_disabled, depth_draw_never;
uniform sampler2D SCREEN_TEXTURE: hint_screen_texture, filter_linear_mipmap;
uniform int color_depth : hint_range(1, 8) = 5;
uniform bool dithering = true;
uniform int resolution_scale = 4;
int dithering_pattern(ivec2 fragcoord) {
const int pattern[] = {
-4, +0, -3, +1,
+2, -2, +3, -1,
-3, +1, -4, +0,
+3, -1, +2, -2
};
int x = fragcoord.x % 4;
int y = fragcoord.y % 4;
return pattern[y * 4 + x];
}
void vertex() {
POSITION = vec4(VERTEX.xy, 1.0, 1.0);
}
void fragment() {
ivec2 uv = ivec2(FRAGCOORD.xy / float(resolution_scale));
vec3 color = texelFetch(SCREEN_TEXTURE, uv * resolution_scale, 0).rgb;
// Convert from [0.0, 1.0] range to [0, 255] range
ivec3 c = ivec3(round(color * 255.0));
// Apply the dithering pattern
if (dithering) {
c += ivec3(dithering_pattern(uv));
}
// Truncate from 8 bits to color_depth bits
c >>= (8 - color_depth);
// Convert back to [0.0, 1.0] range
ALBEDO = vec3(c) / float(1 << color_depth);
}