lygia
/filter
/bilinear
)Bilinear or Bartlett filter, a low-pass filter, which means that it blurs the image. It's a convolution that uses a piecewise linear kernel, approximating a "tent" or triangle. Based on https://www.shadertoy.com/view/3djSDt
Dependencies:
Use:
bilinear(<SAMPLER_TYPE> texture, <vec2> st, <vec2> duv [, <int> kernelSize]])
#ifndef BILINEAR_TYPE
#define BILINEAR_TYPE vec4
#endif
#ifndef BILINEAR_SAMPLER_FNC
#define BILINEAR_SAMPLER_FNC(TEX, UV) sampleClamp2edge(TEX, UV)
#endif
#ifndef FNC_BILINEAR
#define FNC_BILINEAR
BILINEAR_TYPE bilinear(in sampler2D tex, vec2 st, vec2 pixel, int radius) {
vec2 coord = st / pixel;
ivec2 pos = ivec2(floor(coord));
float R = float(radius);
BILINEAR_TYPE acc = BILINEAR_TYPE(0.0);
float normalizationConstant = 3.0 / (PI * R*R);
for(int y = pos.y - radius; y <= pos.y + radius;++y)
for(int x = pos.x - radius; x <= pos.x + radius;++x) {
vec2 xy = vec2(x,y);
float mag = length(xy-coord);
float weight = 1.0 - saturate(mag/R);
acc += weight * BILINEAR_SAMPLER_FNC(tex, xy * pixel);
}
return normalizationConstant*acc;
}
#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