Nimbin[12]?Games / Entropie / entropie/assets/shaders/ui.frag

Entropie git · main

Entropie festival game; first steps

sdl c game entropie cmake · first commit 2026-10-10 · last commit 2026-11-02 (19 hours ago) · synced 10 hours ago

C 88.5% Markdown 9.1% GLSL 2.3%
git clone https://git.christianimmanuel.de/games/Entropie.gitwget https://git.christianimmanuel.de/games/Entropie/archive/Entropie.tar.gz
entropie/assets/shaders/ui.frag 1.4 KB · 35 lines raw
// Text and painted patches over the picture, in the style of the ink pass:
// letters boil a little with the animation clock, patches are paper with
// ragged, boiling edges and an ink rim.

in vec2 UV;
out vec4 FragColor;

uniform sampler2D tex;
uniform vec4  textColor;  // rgb + opacity
uniform int   mode;       // 0 = text, 1 = painted patch
uniform vec2  rectSize;   // pixels
uniform float boilTime;
uniform float rim;        // patch: how much ink around its edge

const vec3 INK = vec3(0.10, 0.07, 0.14);

void main() {
    vec2 px = UV * rectSize;
    if (mode == 0) {
        // Hand-lettered: the strokes tremble a little, stepped like the drawings
        vec2 wobble = (vec2(valueNoise(vec3(px * 0.09, boilTime * 3.0)),
                            valueNoise(vec3(px * 0.09 + 17.0, boilTime * 3.0))) - 0.5) * 1.3;
        float a = texture(tex, UV + wobble / rectSize).a;
        FragColor = vec4(textColor.rgb, a * textColor.a);
        return;
    }
    float edge  = min(min(px.x, rectSize.x - px.x), min(px.y, rectSize.y - px.y));
    float rag   = (valueNoise(vec3(px * 0.06, boilTime * 2.0)) - 0.5) * 5.0;
    float shape = smoothstep(0.0, 1.5, edge + rag);
    float grain = fbm3(vec3(px * 0.025, 3.0));
    vec3  color = textColor.rgb * (0.86 + 0.28 * grain);
    float line  = 1.0 - smoothstep(1.2, 3.0, edge + rag * 0.6);
    color = mix(color, INK, line * rim);
    FragColor = vec4(color, shape * textColor.a);
}