outline tweak

This commit is contained in:
Lilith Schier 2026-09-03 17:53:23 +02:00
parent aab5edd1ac
commit c67a1c99e7
2 changed files with 25 additions and 2 deletions

View file

@ -2,6 +2,7 @@ shader_type canvas_item;
uniform sampler2D screen_tex : hint_screen_texture, repeat_disable, filter_nearest;
uniform vec3 outline_color : source_color = vec3(1.0);
uniform float min_value = 0.6;
vec3 inv(vec3 x) {
return 1.0 - x;
@ -9,6 +10,24 @@ vec3 inv(vec3 x) {
vec3 screen(vec3 src, vec3 dst) {
return inv(inv(dst)*inv(src));
}
// All components are in the range [0…1], including hue.
vec3 rgb2hsv(vec3 c)
{
vec4 K = vec4(0.0, -1.0 / 3.0, 2.0 / 3.0, -1.0);
vec4 p = mix(vec4(c.bg, K.wz), vec4(c.gb, K.xy), step(c.b, c.g));
vec4 q = mix(vec4(p.xyw, c.r), vec4(c.r, p.yzx), step(p.x, c.r));
float d = q.x - min(q.w, q.y);
float e = 1.0e-10;
return vec3(abs(q.z + (q.w - q.y) / (6.0 * d + e)), d / (q.x + e), q.x);
}
// All components are in the range [0…1], including hue.
vec3 hsv2rgb(vec3 c)
{
vec4 K = vec4(1.0, 2.0 / 3.0, 1.0 / 3.0, 3.0);
vec3 p = abs(fract(c.xxx + K.xyz) * 6.0 - K.www);
return c.z * mix(K.xxx, clamp(p - K.xxx, 0.0, 1.0), c.y);
}
void fragment() {
vec4 base = textureLod(screen_tex, SCREEN_UV, 0.0);
@ -21,6 +40,9 @@ void fragment() {
min_alpha = min(min_alpha, texture(screen_tex, UV - vec2(0, 1) * SCREEN_PIXEL_SIZE).a);
float edge = clamp(alpha - min_alpha, 0.0, 1.0);
vec3 blended = screen(outline_color.rgb, base.rgb);
vec3 base_hsv = rgb2hsv(base.rgb);
base_hsv.z = clamp(mix(min_value, 1.0, base_hsv.z), 0.0, 1.0);
vec3 boosted = hsv2rgb(base_hsv);
vec3 blended = screen(outline_color.rgb, boosted.rgb);
COLOR = mix(base, vec4(blended, 1.0), edge);
}