lygia
/v1.1.6
/filter
/sharpen
/fast
)sharpening convolutional operation
Dependencies:
Use:
sharpen(<SAMPLER_TYPE> texture, <vec2> st, <vec2> pixel)
#ifndef SHARPENFAST_KERNELSIZE
#ifdef SHARPEN_KERNELSIZE
#define SHARPENFAST_KERNELSIZE SHARPEN_KERNELSIZE
#else
#define SHARPENFAST_KERNELSIZE 2
#endif
#endif
#ifndef SHARPENFAST_TYPE
#ifdef SHARPEN_TYPE
#define SHARPENFAST_TYPE SHARPEN_TYPE
#else
#define SHARPENFAST_TYPE vec3
#endif
#endif
#ifndef SHARPENFAST_SAMPLER_FNC
#ifdef SHARPEN_SAMPLER_FNC
#define SHARPENFAST_SAMPLER_FNC(TEX, UV) SHARPEN_SAMPLER_FNC(TEX, UV)
#else
#define SHARPENFAST_SAMPLER_FNC(TEX, UV) SAMPLER_FNC(TEX, UV).rgb
#endif
#endif
#ifndef FNC_SHARPENFAST
#define FNC_SHARPENFAST
SHARPENFAST_TYPE sharpenFast(in SAMPLER_TYPE tex, in vec2 coords, in vec2 pixel, float strenght) {
SHARPENFAST_TYPE sum = SHARPENFAST_TYPE(0.);
for (int i = 0; i < SHARPENFAST_KERNELSIZE; i++) {
float f_size = float(i) + 1.;
f_size *= strenght;
sum += -1. * SHARPENFAST_SAMPLER_FNC(tex, coords + vec2( -1., 0.) * pixel * f_size);
sum += -1. * SHARPENFAST_SAMPLER_FNC(tex, coords + vec2( 0., -1.) * pixel * f_size);
sum += 5. * SHARPENFAST_SAMPLER_FNC(tex, coords + vec2( 0., 0.) * pixel * f_size);
sum += -1. * SHARPENFAST_SAMPLER_FNC(tex, coords + vec2( 0., 1.) * pixel * f_size);
sum += -1. * SHARPENFAST_SAMPLER_FNC(tex, coords + vec2( 1., 0.) * pixel * f_size);
}
return sum / float(SHARPENFAST_KERNELSIZE);
}
SHARPENFAST_TYPE sharpenFast(in SAMPLER_TYPE tex, in vec2 coords, in vec2 pixel) {
SHARPENFAST_TYPE sum = SHARPENFAST_TYPE(0.);
for (int i = 0; i < SHARPENFAST_KERNELSIZE; i++) {
float f_size = float(i) + 1.;
sum += -1. * SHARPENFAST_SAMPLER_FNC(tex, coords + vec2( -1., 0.) * pixel * f_size);
sum += -1. * SHARPENFAST_SAMPLER_FNC(tex, coords + vec2( 0., -1.) * pixel * f_size);
sum += 5. * SHARPENFAST_SAMPLER_FNC(tex, coords + vec2( 0., 0.) * pixel * f_size);
sum += -1. * SHARPENFAST_SAMPLER_FNC(tex, coords + vec2( 0., 1.) * pixel * f_size);
sum += -1. * SHARPENFAST_SAMPLER_FNC(tex, coords + vec2( 1., 0.) * pixel * f_size);
}
return sum / float(SHARPENFAST_KERNELSIZE);
}
#endif
Dependencies:
Use:
sharpen(<SAMPLER_TYPE> texture, <float2> st, <float2> pixel)
#ifndef SHARPENFAST_KERNELSIZE
#ifdef SHARPEN_KERNELSIZE
#define SHARPENFAST_KERNELSIZE SHARPEN_KERNELSIZE
#else
#define SHARPENFAST_KERNELSIZE 2
#endif
#endif
#ifndef SHARPENFAST_TYPE
#ifdef SHARPEN_TYPE
#define SHARPENFAST_TYPE SHARPEN_TYPE
#else
#define SHARPENFAST_TYPE float3
#endif
#endif
#ifndef SHARPENFAST_SAMPLER_FNC
#ifdef SHARPEN_SAMPLER_FNC
#define SHARPENFAST_SAMPLER_FNC(TEX, UV) SHARPEN_SAMPLER_FNC(TEX, UV)
#else
#define SHARPENFAST_SAMPLER_FNC(TEX, UV) SAMPLER_FNC(TEX, UV).rgb
#endif
#endif
#ifndef FNC_SHARPENFAST
#define FNC_SHARPENFAST
SHARPENFAST_TYPE sharpenFast(in SAMPLER_TYPE tex, in float2 coords, in float2 pixel, float strenght) {
SHARPENFAST_TYPE sum = float4(0.0,0.0,0.0,0.0);
for (int i = 0; i < SHARPENFAST_KERNELSIZE; i++) {
float f_size = float(i) + 1.;
f_size *= strenght;
sum += -1. * SHARPENFAST_SAMPLER_FNC(tex, coords + float2( -1., 0.) * pixel * f_size);
sum += -1. * SHARPENFAST_SAMPLER_FNC(tex, coords + float2( 0., -1.) * pixel * f_size);
sum += 5. * SHARPENFAST_SAMPLER_FNC(tex, coords + float2( 0., 0.) * pixel * f_size);
sum += -1. * SHARPENFAST_SAMPLER_FNC(tex, coords + float2( 0., 1.) * pixel * f_size);
sum += -1. * SHARPENFAST_SAMPLER_FNC(tex, coords + float2( 1., 0.) * pixel * f_size);
}
return sum / float(SHARPENFAST_KERNELSIZE);
}
SHARPENFAST_TYPE sharpenFast(in SAMPLER_TYPE tex, in float2 coords, in float2 pixel) {
SHARPENFAST_TYPE sum = float4(0.0,0.0,0.0,0.0);
for (int i = 0; i < SHARPENFAST_KERNELSIZE; i++) {
float f_size = float(i) + 1.;
sum += -1. * SHARPENFAST_SAMPLER_FNC(tex, coords + float2( -1., 0.) * pixel * f_size);
sum += -1. * SHARPENFAST_SAMPLER_FNC(tex, coords + float2( 0., -1.) * pixel * f_size);
sum += 5. * SHARPENFAST_SAMPLER_FNC(tex, coords + float2( 0., 0.) * pixel * f_size);
sum += -1. * SHARPENFAST_SAMPLER_FNC(tex, coords + float2( 0., 1.) * pixel * f_size);
sum += -1. * SHARPENFAST_SAMPLER_FNC(tex, coords + float2( 1., 0.) * pixel * f_size);
}
return sum / float(SHARPENFAST_KERNELSIZE);
}
#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