lygia
/v1.1.6
/color
/dither
/vlachos
)Vlachos 2016, "Advanced VR Rendering" http://alex.vlachos.com/graphics/Alex_Vlachos_Advanced_VR_Rendering_GDC2015.pdf
Use:
<vec4|vec3|float> ditherVlachos(<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_VLACHOS_ANIMATED
#endif
#ifndef DITHER_VLACHOS
#define DITHER_VLACHOS
float ditherVlachos(float b, const HIGHP in float time) {
vec2 st = gl_FragCoord.xy;
#ifdef DITHER_VLACHOS_ANIMATED
st += 1337.0*fract(time);
#endif
HIGHP float noise = dot(vec2(171.0, 231.0), st);
noise = fract(noise / 71.0);
// remap from [0..1[ to [-1..1[
noise = (noise * 2.0) - 1.0;
return b + (noise / 255.0);
}
vec3 ditherVlachos(vec3 rgb, const HIGHP in float time) {
vec2 st = gl_FragCoord.xy;
#ifdef DITHER_VLACHOS_ANIMATED
st += 1337.0*fract(time);
#endif
HIGHP vec3 noise = vec3(dot(vec2(171.0, 231.0), st));
noise = fract(noise / vec3(103.0, 71.0, 97.0));
return rgb.rgb + (noise / 255.0);
}
vec4 ditherVlachos(vec4 rgba, const HIGHP in float time) {
return vec4(ditherVlachos(rgba.rgb, time), rgba.a);
}
#endif
Use:
<float4|float3|float> ditherVlachos(<float4|float3|float> value, <float> time)
#ifdef DITHER_ANIMATED
#define DITHER_VLACHOS_ANIMATED
#endif
#ifndef DITHER_VLACHOS
#define DITHER_VLACHOS
float ditherVlachos(float b, float2 fragcoord, const in float time) {
#ifdef DITHER_VLACHOS_ANIMATED
fragcoord += 1337.0*frac(time);
#endif
float noise = dot(float2(171.0, 231.0), fragcoord);
noise = frac(noise / 71.0);
// remap from [0..1[ to [-1..1[
noise = (noise * 2.0) - 1.0;
return b + (noise / 255.0);
}
float3 ditherVlachos(float3 rgb, float2 fragcoord, const in float time) {
#ifdef DITHER_VLACHOS_ANIMATED
fragcoord += 1337.0 * frac(time);
#endif
float n = dot(float2(171.0, 231.0), fragcoord);
float3 noise = float3(n, n, n);
noise = frac(noise / float3(103.0, 71.0, 97.0));
return rgb.rgb + (noise / 255.0);
}
float4 ditherVlachos(float4 rgba, float2 fragcoord, const in float time) {
return float4(ditherVlachos(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