AI GENERATED

蛙始鳴 (かわずはじめてなく)

by kato

PROMPT

蛙が鳴き始める

DATE
2026/6/17
SOURCE
AI GENERATED
MODEL
gemini-2.5-flash
LIKES
1
VIEW SHADER CODE
float rand(vec2 n) {
    return fract(sin(dot(n, vec2(12.9898, 4.1414))) * 43758.5453);
}

float noise(vec2 p) {
    vec2 ip = floor(p);
    vec2 fp = fract(p);
    fp = fp * fp * (3.0 - 2.0 * fp);

    return mix(mix(rand(ip), rand(ip + vec2(1.0, 0.0)), fp.x),
               mix(rand(ip + vec2(0.0, 1.0)), rand(ip + vec2(1.0, 1.0)), fp.x), fp.y);
}

float fbm(vec2 p) {
    float total = 0.0;
    float amplitude = 0.5;
    for (int i = 0; i < 4; i++) {
        total += noise(p) * amplitude;
        p *= 2.0;
        amplitude *= 0.5;
    }
    return total;
}

void mainImage(out vec4 fragColor, in vec2 fragCoord) {
    vec2 uv = (fragCoord * 2.0 - iResolution.xy) / iResolution.y;
    vec3 col = vec3(0.0);

    float time = iTime * 0.2; // Slow down time for a serene feel

    // --- Water surface distortion ---
    vec2 uv_distorted = uv;
    // Add subtle flow and turbulence using FBM
    uv_distorted += fbm(uv * 3.0 + vec2(time * 0.1, time * 0.05)) * 0.1;
    uv_distorted += fbm(uv * 8.0 - vec2(time * 0.03, time * 0.08)) * 0.03;

    // --- Base water color ---
    // A dark, murky pond water palette with slight FBM variation
    vec3 water_base_dark = vec3(0.0, 0.05, 0.1);
    vec3 water_base_light = vec3(0.05, 0.15, 0.1);
    float water_noise_val = fbm(uv_distorted * 2.0 + time * 0.02);
    col = mix(water_base_dark, water_base_light, water_noise_val * 0.5 + 0.5); // Slightly brighter areas

    // --- Croaking sources (frogs) ---
    vec2 frog_positions[3];
    frog_positions[0] = vec2(0.0, 0.0);    // Main frog in the center
    frog_positions[1] = vec2(0.6, -0.4);   // Distant frog 1
    frog_positions[2] = vec2(-0.7, 0.3);   // Distant frog 2

    float croak_speed_base = 3.0;
    float croak_radius_base = 0.1;
    float croak_light_intensity_base = 0.8;
    vec3 frog_glow_color = vec3(0.2, 0.8, 0.2); // Bright green glow for the frogs

    for (int i = 0; i < 3; i++) {
        vec2 frog_pos = frog_positions[i];
        // Offset time for each frog to make croaks asynchronous
        float current_time_offset = time + float(i) * 1.5;

        // Croaking pulse: starts sharp, then fades quickly, simulating a croak sound/light burst
        float croak_pulse = sin(current_time_offset * croak_speed_base + float(i) * 0.5) * 0.5 + 0.5;
        croak_pulse = pow(croak_pulse, 3.0); // Make it sharp and short

        // Scale factors for distant frogs to make them appear smaller and fainter
        float scale_factor = 1.0;
        float ripple_strength_factor = 1.0;
        if (i > 0) { // Distant frogs are smaller and fainter
            scale_factor = 0.5;
            ripple_strength_factor = 0.3;
        }

        // Calculate distance to the frog position on the distorted water surface
        float dist_to_frog = length(uv_distorted - frog_pos);

        // --- Ripples from croaking ---
        float ripple_freq = 15.0;
        float ripple_speed = 1.0;
        float ripple_decay = 0.5;

        // Main ripple wave
        float ripple_wave = sin(dist_to_frog * ripple_freq - current_time_offset * ripple_speed);
        ripple_wave *= exp(-dist_to_frog * ripple_decay); // Decay with distance
        ripple_wave = smoothstep(-0.5, 0.5, ripple_wave) * croak_pulse * ripple_strength_factor;

        // Add a smaller, faster ripple layer for more detail
        float ripple_wave2 = sin(dist_to_frog * ripple_freq * 1.5 - current_time_offset * ripple_speed * 1.2);
        ripple_wave2 *= exp(-dist_to_frog * ripple_decay * 0.8);
        ripple_wave2 = smoothstep(-0.5, 0.5, ripple_wave2) * croak_pulse * ripple_strength_factor * 0.5;

        // Ripple color: a slightly lighter, greenish-cyan highlight
        vec3 ripple_highlight = vec3(0.1, 0.3, 0.2);
        col += ripple_wave * ripple_highlight * 0.5;
        col += ripple_wave2 * ripple_highlight * 0.3;

        // --- Frog glow light ---
        // A soft, green light emanating from the frog, pulsating with the croak
        float glow_radius = croak_radius_base * 2.0 * scale_factor;
        float glow_falloff = smoothstep(glow_radius, glow_radius * 0.3, dist_to_frog);
        col += frog_glow_color * glow_falloff * croak_pulse * croak_light_intensity_base * scale_factor;
    }

    // --- Subtle overall atmospheric haze / color shift ---
    // Add a slight greenish tint to the entire scene, like light reflecting off nearby foliage
    col *= mix(vec3(0.9, 0.95, 0.9), vec3(0.8, 1.0, 0.9), fbm(uv * 0.5 + time * 0.01) * 0.2);

    // --- Vignette ---
    // Darken the edges of the screen for better focus and depth
    float len_uv = length(uv);
    float vignette = smoothstep(1.0, 0.3, len_uv);
    col *= vignette;

    fragColor = vec4(col, 1.0);
}

ZIP を展開して .playground を Xcode でダブルクリックし、Live View を表示して ▶ を押すとシェーダーがアニメーションします。Metal ソースは Resources/Shader.metal に独立ファイルとして入っているので、Xcode 上で直接編集できます。