lygia
/v1.1.6
/math
/aastep
)Performs a smoothstep using standard derivatives for anti-aliased edges at any level of magnification. From https://github.com/glslify/glsl-aastep
Use:
aastep(<float> threshold, <float> value)
#ifndef FNC_AASTEP
#define FNC_AASTEP
#if defined(GL_OES_standard_derivatives)
#extension GL_OES_standard_derivatives : enable
#endif
float aastep(float threshold, float value) {
#if !defined(GL_ES) || __VERSION__ >= 300 || defined(GL_OES_standard_derivatives)
float afwidth = 0.7 * length(vec2(dFdx(value), dFdy(value)));
return smoothstep(threshold-afwidth, threshold+afwidth, value);
#elif defined(AA_EDGE)
float afwidth = AA_EDGE;
return smoothstep(threshold-afwidth, threshold+afwidth, value);
#else
return step(threshold, value);
#endif
}
#endif
Use:
aastep(<float> threshold, <float> value)
#ifndef FNC_AASTEP
#define FNC_AASTEP
float aastep(float compValue, float gradient){
float halfChange = fwidth(gradient) / 2;
//base the range of the inverse lerp on the change over one pixel
float lowerEdge = compValue - halfChange;
float upperEdge = compValue + halfChange;
//do the inverse interpolation
float stepped = (gradient - lowerEdge) / (upperEdge - lowerEdge);
stepped = saturate(stepped);
return stepped;
}
#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