0.00
60.0 fps

Moon 🌕

Moon

Log in to post a comment.

#version 300 es
precision highp float;

uniform float iTime;
uniform float iLoop;
in vec2 vScreen;
uniform vec2  iResolution;

out vec4 fragColor;

uniform float moonSize; // value=0.75, min=0.5, max=1.5, step=0.001

// source: https://thebookofshaders.com/11/
float random(in vec2 st) {
    return fract(sin(dot(st.xy, vec2(1.456,78.123))) * 4358.234);
}

void main() {
    vec2 q = vScreen.xy;
    
    // ping-pong the time
    float t = iLoop;
    if (t > 0.5) t = 1.0 - t;
    t = smoothstep(0., 1., t * 2.0);
    
    vec3 col = mix(vec3(0), vec3(1), smoothstep(0.5, 0.505 + 2./iResolution.y, length(q * moonSize)));
    vec3 moon = mix( col, vec3(q*q, q), t + 0.5);
    float brightness = (0.2126 * moon.r + 0.7152 * moon.g +  0.0722 * moon.b) / 3.0;
    fragColor = vec4(
        mix(vec3(random(q*(t+12.0))), vec3(brightness), 0.96),
        1.0
    );
}