lygia
/v1.1.6
/color
/dither
/interleavedGradientNoise
)Jimenez 2014, "Next Generation Post-Processing in Call of Duty" http://advances.realtimerendering.com/s2014/index.html
Use:
<vec4|vec3|float> interleavedGradientNoise(<vec4|vec3|float> value, <float> time)
#ifndef HIGHP
#if defined(TARGET_MOBILE) && defined(GL_ES)
#define HIGHP highp
#else
#define HIGHP
#endif
#endif
#ifdef DITHER_ANIMATED
#define DITHER_INTERLEAVEDGRADIENTNOISE_ANIMATED
#endif
#ifndef DITHER_INTERLEAVEDGRADIENTNOISE
#define DITHER_INTERLEAVEDGRADIENTNOISE
float interleavedGradientNoise(const HIGHP in vec2 n) {
return fract(52.982919 * fract(dot(vec2(0.06711, 0.00584), n)));
}
float ditherInterleavedGradientNoise(float b, const HIGHP in float time) {
vec2 st = gl_FragCoord.xy;
#ifdef DITHER_INTERLEAVEDGRADIENTNOISE_ANIMATED
st += 1337.0*fract(time);
#endif
float noise = interleavedGradientNoise(st);
// remap from [0..1[ to [-1..1[
noise = (noise * 2.0) - 1.0;
return b + noise / 255.0;
}
vec3 ditherInterleavedGradientNoise(vec3 rgb, const HIGHP in float time) {
vec2 st = gl_FragCoord.xy;
#ifdef DITHER_INTERLEAVEDGRADIENTNOISE_ANIMATED
st += 1337.0*fract(time);
#endif
float noise = interleavedGradientNoise(st);
// remap from [0..1[ to [-1..1[
noise = (noise * 2.0) - 1.0;
return rgb.rgb + noise / 255.0;
}
vec4 ditherInterleavedGradientNoise(vec4 rgba, const HIGHP in float time) {
return vec4(ditherInterleavedGradientNoise(rgba.rgb, time), rgba.a);
}
#endif
Use:
<float4|float3|float> interleavedGradientNoise(<float4|float3|float> value, <float> time)
#ifdef DITHER_ANIMATED
#define DITHER_INTERLEAVEDGRADIENTNOISE_ANIMATED
#endif
#ifndef DITHER_INTERLEAVEDGRADIENTNOISE
#define DITHER_INTERLEAVEDGRADIENTNOISE
float interleavedGradientNoise(const in float2 n) {
return frac(52.982919 * frac(dot(float2(0.06711, 0.00584), n)));
}
float ditherInterleavedGradientNoise(float b, float2 fragcoord, const in float time) {
#ifdef DITHER_INTERLEAVEDGRADIENTNOISE_ANIMATED
fragcoord += 1337.0 * frac(time);
#endif
float noise = interleavedGradientNoise(fragcoord);
// remap from [0..1[ to [-1..1[
noise = (noise * 2.0) - 1.0;
return b + noise / 255.0;
}
float3 ditherInterleavedGradientNoise(float3 rgb, float2 fragcoord, const in float time) {
#ifdef DITHER_INTERLEAVEDGRADIENTNOISE_ANIMATED
fragcoord += 1337.0 * frac(time);
#endif
float noise = interleavedGradientNoise(fragcoord);
// remap from [0..1[ to [-1..1[
noise = (noise * 2.0) - 1.0;
return rgb.rgb + noise / 255.0;
}
float4 ditherInterleavedGradientNoise(float4 rgba, float2 fragcoord, const in float time) {
return float4(ditherInterleavedGradientNoise(rgba.rgb, fragcoord, time), rgba.a);
}
#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