cool dithering

This commit is contained in:
Spencer Killen 2022-12-19 11:24:25 -07:00
parent 76aa38d71c
commit 59017b30b4
Signed by: sjkillen
GPG Key ID: F307025B65C860BA
4 changed files with 57 additions and 10 deletions

View File

@ -1,2 +0,0 @@
36673
/home/squirrel/.local/bin/godot_mono

View File

@ -4,7 +4,9 @@
[sub_resource type="ShaderMaterial" id=1]
shader = ExtResource( 1 )
shader_param/param = 15.0
shader_param/param = 13.0
shader_param/scale = 2.0
shader_param/grid = 4
shader_param/anim_period = 1.65
[node name="CanvasLayer" type="CanvasLayer"]

View File

@ -110,18 +110,57 @@ vec3 band_colors_preserve_hue_lum(vec3 rgb)
return hsv2rgb(hsv);
}
uniform float scale = 2.0;
uniform int grid = 5;
vec3 band_dither(vec3 rgb, vec2 uv)
{
uv *= (1.0 / scale);
int x = int(mod(uv.x, float(grid))) + 1;
int y = int(mod(uv.y, float(grid))) + 1;
vec3 hsv = rgb2hsv(rgb);
int g = int(round(mix(float(grid), float(2), fract(hsv.r * param))));
if (x % g == 0 && y % g == 0) {
hsv.r = ceil(hsv.r * param) / param;
} else {
hsv.r = floor(hsv.r * param) / param;
}
vec3 lab = xyz2lab(rgb2xyz(rgb));
if (x % g == 0 && y % g == 0) {
lab.r = ceil(lab.r * (param / 100.0)) / (param / 100.0);
} else {
lab.r = floor(lab.r * (param / 100.0)) / (param / 100.0);
}
// Into HSV
vec2 sv = rgb2hsv(xyz2rgb(lab2xyz(lab))).gb;
hsv.gb = sv;
return hsv2rgb(hsv);
}
uniform float anim_period : hint_range(0.1, 5, 0.01);
void fragment()
{
vec3 rgb = textureLod(SCREEN_TEXTURE, SCREEN_UV, 0.0).rgb;
vec3 banded_preserved = band_colors_preserve_hue_lum(rgb);
vec3 banded_nostalgia = band_colors(rgb);
float weight = mod(TIME, anim_period) / anim_period;
float double_weight = mod(TIME, anim_period*2.0) / (anim_period*2.0);
weight = double_weight > 0.5 ? (1.-weight) : weight;
vec3 mixed = mix(banded_nostalgia, banded_preserved, weight);
COLOR.rgb = mixed;
vec3 banded_preserved = band_dither(rgb, FRAGCOORD.xy);
//vec3 banded_nostalgia = band_colors(rgb);
//float weight = mod(TIME, anim_period) / anim_period;
//float double_weight = mod(TIME, anim_period*2.0) / (anim_period*2.0);
//weight = double_weight > 0.5 ? (1.-weight) : weight;
//vec3 mixed = mix(banded_nostalgia, banded_preserved, weight);
//COLOR.rgb = mixed;
COLOR.rgb = banded_preserved;
}
"

View File

@ -25,3 +25,11 @@ light_energy = 16.0
light_indirect_energy = 1.306
omni_range = 8.917
omni_attenuation = 2.73208
[node name="SpotLight" type="SpotLight" parent="."]
transform = Transform( -0.999987, 5.82069e-11, 0.00514878, 0.00507827, 0.164927, 0.986293, -0.000849173, 0.986306, -0.164925, 0, 4.25661, -0.823411 )
light_color = Color( 0.623529, 0.247059, 0.756863, 1 )
light_energy = 30.0
light_specular = 0.594
spot_range = 13.9301
spot_angle = 57.9366