LYGIA Shader Library

flow (lygia/sample/flow)

sample a texture with a looping flow animation, using a direction to push, an elapse time and a cycle.

Dependencies:

Use:

sampleFlow(<SAMPLER_TYPE> tex, <vec2> st, <vec2> dir, <float> time, <float> cycle)

Check it on Github



#ifndef FNC_SAMPLEFLOW
#define FNC_SAMPLEFLOW
vec4 sampleFlow(SAMPLER_TYPE tex, vec2 st, vec2 dir, float time, float cycle) {
    float halfCycle = cycle * 0.5;

    float flowOffset0 = mod(time, cycle);
    float flowOffset1 = mod(time + halfCycle, cycle);

    float phase0 = flowOffset0;
    float phase1 = flowOffset1;

    // Sample normal map.
    vec4 A = SAMPLER_FNC(tex, (st + dir * phase0) );
    vec4 B = SAMPLER_FNC(tex, (st + dir * phase1) );

    float f = (abs(halfCycle - flowOffset0) / halfCycle);
    return mix( A, B, f );
}
#endif

Dependencies:

Use:

sampleFlow(<SAMPLER_TYPE> tex, <float2> st, <float2> dir, <float> time, <float> cycle)

Check it on Github



#ifndef FNC_SAMPLEFLOW
#define FNC_SAMPLEFLOW
float4 sampleFlow(SAMPLER_TYPE tex, float2 st, float2 dir, float time, float cycle) {
    float halfCycle = cycle * 0.5;

    float flowOffset0 = mod(time, cycle);
    float flowOffset1 = mod(time + halfCycle, cycle);

    float phase0 = flowOffset0;
    float phase1 = flowOffset1;

    // Sample normal map.
    float4 A = SAMPLER_FNC(tex, (st + dir * phase0) );
    float4 B = SAMPLER_FNC(tex, (st + dir * phase1) );

    float f = (abs(halfCycle - flowOffset0) / halfCycle);
    return lerp( A, B, f );
}
#endif

License

LYGIA is dual-licensed under the Prosperity License and the Patron License for sponsors and contributors.

Sponsors and contributors are automatically added to the Patron License and they can ignore the any non-commercial rule of the Prosperity Licensed software (please take a look to the exception).

It's also possible to get a permanent comercial license hook to a single and specific version of LYGIA.

Get the latest news and releases

Sign up for the news letter bellow, joing the LYGIA's channel on Discord or follow the Github repository