lygia
/v1.1.6
/distort
/stretch
)Samples multiple times a texture in the specified direction
Dependencies:
Use:
stretch(<SAMPLER_TYPE> tex, <vec2> st, <vec2> direction [, int samples])
#ifndef STRETCH_SAMPLES
#define STRETCH_SAMPLES 20
#endif
#ifndef STRETCH_TYPE
#define STRETCH_TYPE vec4
#endif
#ifndef STRETCH_SAMPLER_FNC
#define STRETCH_SAMPLER_FNC(TEX, UV) SAMPLER_FNC(TEX, UV)
#endif
#ifndef FNC_STRETCH
#define FNC_STRETCH
STRETCH_TYPE stretch(in SAMPLER_TYPE tex, in vec2 st, in vec2 direction, const int i_samples) {
float f_samples = float(i_samples);
STRETCH_TYPE color = STRETCH_TYPE(0.);
#ifdef PLATFORM_WEBGL
for (int i = 0; i < 50; i++) {
if (i == i_samples) break;
#else
for (int i = 0; i < i_samples; i++) {
#endif
float f_sample = float(i);
STRETCH_TYPE tx = STRETCH_SAMPLER_FNC(tex, st + direction * f_sample);
#ifdef STRETCH_WEIGHT
tx *= STRETCH_WEIGHT;
#endif
color += tx;
}
return color / f_samples;
}
STRETCH_TYPE stretch(in SAMPLER_TYPE tex, in vec2 st, in vec2 direction) {
float f_samples = float(STRETCH_SAMPLES);
STRETCH_TYPE color = STRETCH_TYPE(0.);
for (int i = 0; i < STRETCH_SAMPLES; i++) {
float f_sample = float(i);
STRETCH_TYPE tx = STRETCH_SAMPLER_FNC(tex, st + direction * f_sample);
#ifdef STRETCH_WEIGHT
tx *= STRETCH_WEIGHT;
#endif
color += tx;
}
return color / f_samples;
}
#endif
Dependencies:
Use:
stretch(<SAMPLER_TYPE> tex, <float2> st, <float2> direction [, int samples])
#ifndef STRETCH_SAMPLES
#define STRETCH_SAMPLES 20
#endif
#ifndef STRETCH_TYPE
#define STRETCH_TYPE float4
#endif
#ifndef STRETCH_SAMPLER_FNC
#define STRETCH_SAMPLER_FNC(TEX, UV) SAMPLER_FNC(TEX, UV)
#endif
#ifndef FNC_STRETCH
#define FNC_STRETCH
STRETCH_TYPE stretch(in SAMPLER_TYPE tex, in float2 st, in float2 direction, const int i_samples) {
float f_samples = float(i_samples);
STRETCH_TYPE color = float(0., 0., 0., 0.);
#ifdef PLATFORM_WEBGL
for (int i = 0; i < 50; i++) {
if (i == i_samples) break;
#else
for (int i = 0; i < i_samples; i++) {
#endif
float f_sample = float(i);
STRETCH_TYPE tx = STRETCH_SAMPLER_FNC(tex, st + direction * f_sample);
#ifdef STRETCH_WEIGHT
tx *= STRETCH_WEIGHT;
#endif
color += tx;
}
return color / f_samples;
}
STRETCH_TYPE stretch(in SAMPLER_TYPE tex, in float2 st, in float2 direction) {
float f_samples = float(STRETCH_SAMPLES);
STRETCH_TYPE color = float4(0., 0., 0., 0.);
for (int i = 0; i < STRETCH_SAMPLES; i++) {
float f_sample = float(i);
STRETCH_TYPE tx = STRETCH_SAMPLER_FNC(tex, st + direction * f_sample);
#ifdef STRETCH_WEIGHT
tx *= STRETCH_WEIGHT;
#endif
color += tx;
}
return color / f_samples;
}
#endif
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.
Sign up for the news letter bellow, joing the LYGIA's channel on Discord or follow the Github repository