LYGIA Shader Library

opticalFlow (lygia/sample/opticalFlow)

sample an optical flow direction where the angle is encoded in the Hue and magnitude in the Saturation

Dependencies:

Use:

sampleFlow(<SAMPLER_TYPE> tex, <vec2> st)

Check it on Github




#ifndef SAMPLEOPTICALFLOW_SAMPLE_FNC
#define SAMPLEOPTICALFLOW_SAMPLE_FNC(TEX, UV) SAMPLER_FNC(TEX, UV).rgb
#endif

#ifndef FNC_SAMPLEOPTICALFLOW
#define FNC_SAMPLEOPTICALFLOW
vec2 sampleOpticalFlow(SAMPLER_TYPE tex, vec2 st) {
    vec3 data = SAMPLEOPTICALFLOW_SAMPLE_FNC(tex, st);
    vec3 hsv = rgb2hsv(data.rgb);
    float a = (hsv.x * 2.0 - 1.0) * PI;
    return vec2(cos(a), -sin(a)) * hsv.y;
}

vec2 sampleOpticalFlow(SAMPLER_TYPE tex, vec2 st, vec2 resolution, float max_dist) { return sampleOpticalFlow(tex, st) * (max_dist / resolution); }
#endif

Dependencies:

Use:

sampleFlow(<SAMPLER_TYPE> tex, <float2> st)

Check it on Github




#ifndef SAMPLEOPTICALFLOW_SAMPLE_FNC
#define SAMPLEOPTICALFLOW_SAMPLE_FNC(TEX, UV) SAMPLER_FNC(TEX, UV).rgb
#endif

#ifndef FNC_SAMPLEOPTICALFLOW
#define FNC_SAMPLEOPTICALFLOW
float2 sampleOpticalFlow(SAMPLER_TYPE tex, float2 st) {
    float3 data = SAMPLEOPTICALFLOW_SAMPLE_FNC(tex, st);
    float3 hsv = rgb2hsv(data.rgb);
    float a = (hsv.x * 2.0 - 1.0) * PI;
    return float2(cos(a), -sin(a)) * hsv.y;
}

float2 sampleOpticalFlow(SAMPLER_TYPE tex, float2 st, float2 resolution, float max_dist) { return sampleOpticalFlow(tex, st) * (max_dist / resolution); }
#endif

Licenses

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