lygia
/v1.1.6
/filter
/mean
)adapted version of mean average sampling on four coorners of a sampled point from https://github.com/BradLarson/GPUImage2
Dependencies:
Use:
mean(<SAMPLER_TYPE> texture, <vec2> st, <vec2> pixel)
#ifndef MEAN_TYPE
#define MEAN_TYPE vec4
#endif
#ifndef MEAN_AMOUNT
#define MEAN_AMOUNT mean4
#endif
#ifndef MEAN_SAMPLER_FNC
#define MEAN_SAMPLER_FNC(TEX, UV) SAMPLER_FNC(TEX, UV)
#endif
#ifndef FNC_AVERAGE
#define FNC_AVERAGE
MEAN_TYPE mean4(in SAMPLER_TYPE tex, in vec2 st, in vec2 pixel) {
MEAN_TYPE topLeft = MEAN_SAMPLER_FNC(tex, st - pixel);
MEAN_TYPE bottomLeft = MEAN_SAMPLER_FNC(tex, st + vec2(-pixel.x, pixel.y));
MEAN_TYPE topRight = MEAN_SAMPLER_FNC(tex, st + vec2(pixel.x, -pixel.y));
MEAN_TYPE bottomRight = MEAN_SAMPLER_FNC(tex, st + pixel);
return 0.25 * (topLeft + topRight + bottomLeft + bottomRight);
}
MEAN_TYPE mean(in SAMPLER_TYPE tex, in vec2 st, in vec2 pixel) {
return MEAN_AMOUNT(tex, st, pixel);
}
#endif
Dependencies:
Use:
mean(<SAMPLER_TYPE> texture, <float2> st, <float2> pixel)
#ifndef MEAN_TYPE
#define MEAN_TYPE float4
#endif
#ifndef MEAN_AMOUNT
#define MEAN_AMOUNT mean4
#endif
#ifndef MEAN_SAMPLER_FNC
#define MEAN_SAMPLER_FNC(TEX, UV) SAMPLER_FNC(TEX, UV)
#endif
#ifndef FNC_AVERAGE
#define FNC_AVERAGE
MEAN_TYPE mean4(in SAMPLER_TYPE tex, in float2 st, in float2 pixel) {
MEAN_TYPE topLeft = MEAN_SAMPLER_FNC(tex, st - pixel);
MEAN_TYPE bottomLeft = MEAN_SAMPLER_FNC(tex, st + float2(-pixel.x, pixel.y));
MEAN_TYPE topRight = MEAN_SAMPLER_FNC(tex, st + float2(pixel.x, -pixel.y));
MEAN_TYPE bottomRight = MEAN_SAMPLER_FNC(tex, st + pixel);
return 0.25 * (topLeft + topRight + bottomLeft + bottomRight);
}
MEAN_TYPE mean(in SAMPLER_TYPE tex, in float2 st, in float2 pixel) {
return MEAN_AMOUNT(tex, st, pixel);
}
#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