ShaderToMP4

HomeAccueil / ExamplesExemples

Water surface wavesOndes à la surface de l'eau

Buffer A keeps the height and speed of each point (wave equation); drops fall at regular intervals.Le tampon A garde la hauteur et la vitesse de chaque point (équation des ondes) ; des gouttes tombent à intervalles réguliers.

Water surface waves / Ondes à la surface de l'eau

CategoryCatégorie: Multiple passesPasses multiples - ondes_surface.glsl - 19 lineslignes - File on GitHubFichier sur GitHub

In the program: Examples, choose it, Add to the list. Or copy the code into a file next to the program and drop it on the window.Dans le programme : Exemples, choisissez-le, Ajouter à la liste. Ou copiez le code dans un fichier et glissez-le sur la fenêtre.

This example uses several passes: the files below go together.Cet exemple utilise plusieurs passes : les fichiers ci-dessous vont ensemble.

CodeCode

ondes_surface.glsl

// SPDX-License-Identifier: GPL-3.0-or-later
// Copyright (C) 2026 Patrick JAILLET

// fr: Ondes à la surface de l'eau — Le tampon A garde la hauteur et la vitesse de chaque point (équation des ondes) ; des gouttes tombent à intervalles réguliers.
// en: Water surface waves — Buffer A keeps the height and speed of each point (wave equation); drops fall at regular intervals.

// iChannel0=bufferA
void mainImage(out vec4 fragColor, in vec2 fragCoord) {
    ivec2 p = ivec2(fragCoord);
    float h = texelFetch(iChannel0, p, 0).r;
    vec2 g = vec2(texelFetch(iChannel0, p + ivec2(1, 0), 0).r - texelFetch(iChannel0, p - ivec2(1, 0), 0).r,
                  texelFetch(iChannel0, p + ivec2(0, 1), 0).r - texelFetch(iChannel0, p - ivec2(0, 1), 0).r);
    vec3 n = normalize(vec3(-g * 4.0, 1.0));
    vec3 col = mix(vec3(0.0, 0.15, 0.3), vec3(0.4, 0.8, 0.95), 0.5 + 0.5 * h * 3.0);
    col *= 0.5 + 0.7 * max(dot(n, normalize(vec3(-0.4, 0.5, 0.8))), 0.0);
    col += pow(max(dot(reflect(vec3(0, 0, -1), n), normalize(vec3(-0.4, 0.5, 0.8))), 0.0), 40.0);
    fragColor = vec4(col, 1.0);
}

ondes_surface.bufferA.glsl

// SPDX-License-Identifier: GPL-3.0-or-later
// Copyright (C) 2026 Patrick JAILLET

// iChannel0=bufferA
float hh(float n) { return fract(sin(n * 91.345) * 43758.5453); }
void mainImage(out vec4 fragColor, in vec2 fragCoord) {
    ivec2 p = ivec2(fragCoord);
    vec2 s = texelFetch(iChannel0, p, 0).rg;
    float lap = texelFetch(iChannel0, p + ivec2(1, 0), 0).r + texelFetch(iChannel0, p - ivec2(1, 0), 0).r
              + texelFetch(iChannel0, p + ivec2(0, 1), 0).r + texelFetch(iChannel0, p - ivec2(0, 1), 0).r - 4.0 * s.r;
    float v = (s.g + 0.4 * lap) * 0.995;
    float h = s.r + v;
    int k = iFrame / 40;
    if (iFrame % 40 == 0) {
        vec2 d = iResolution.xy * vec2(0.15 + 0.7 * hh(float(k)), 0.15 + 0.7 * hh(float(k) + 0.5));
        h += 0.9 * smoothstep(8.0, 0.0, length(fragCoord - d));
    }
    if (iFrame < 2) { h = 0.0; v = 0.0; }
    fragColor = vec4(h, v, 0.0, 1.0);
}