rendering

Nuggets of WebP format image compression terrible to look at…

Complete code with comments

# define TAU 6.28318530718

#iUniform int MAX_ITER = 5 in {0, 20}
#iUniform float inten = 0.005 in {0.000, 0.010}
#iUniform float OFF = 250.0 in {0.0, 300.0}

void mainImage( out vec4 fragColor, in vec2 fragCoord )
{
    float time = iTime * 0.2 + 23.0;
    vec2 uv = fragCoord.xy / iResolution.xy;

    vec2 p = mod(uv * TAU, TAU) - vec2(OFF);
    vec2 i = vec2(p);
    float c = 1.0;
   
    /// add the @note waveform iteratively
    for (int n = 0; n < MAX_ITER; n++)
    {
        float t = time * (1.0 - (3.5 / float(n + 1)));

        // @note update I, coordinate position waveform offset (distortion)
        i = p + vec2(cos(t - i.x) + sin(t + i.y),
                     sin(t - i.y) + cos(t + i.x));

        /// @note "circular waveform distortion" ray accumulation
        c += 1.0 / length(vec2(p.x / (sin(i.x + t) / inten),
                               p.y / (cos(i.y + t) / inten)));
    }

    c /= float(MAX_ITER);
    // c = clamp(c, 0., 1.);
    c = 1.17 - pow(c, 1.4);
    c = pow(abs(c), 8.0);
    vec3 colour = vec3(c);
  
    fragColor = vec4(clamp(colour, 0..1.), 1.0);
}
Copy the code

The most trick of this algorithm is the iterative superposition of trigonometric functions.

Finally, it is worth noting that c does the following before the final output

    c = 1.17 - pow(c, 1.4);
    c = pow(abs(c), 8.0);
Copy the code

The corresponding function is shown below