dbf-udg

diff sdr/dither.p.glsl @ 0:2d27bfd21fc5

initial commit
author John Tsiombikas <nuclear@member.fsf.org>
date Tue, 08 Jan 2013 03:16:48 +0200
parents
children c45c7a1f7d9d
line diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/sdr/dither.p.glsl	Tue Jan 08 03:16:48 2013 +0200
     1.3 @@ -0,0 +1,22 @@
     1.4 +uniform sampler2D framebuf, dither_tex;
     1.5 +uniform int dither_levels, dither_size;
     1.6 +
     1.7 +void main()
     1.8 +{
     1.9 +	float levels = float(dither_levels);
    1.10 +
    1.11 +	vec4 pixel = texture2D(framebuf, gl_TexCoord[0].xy);
    1.12 +	float lum = dot(pixel.xyz, vec3(0.2126, 0.7152, 0.0722));
    1.13 +	float coord_shift = floor(lum * levels) / levels;
    1.14 +
    1.15 +	vec2 dsz2 = vec2(float(dither_size), float(dither_size));
    1.16 +
    1.17 +	vec2 coord = mod(gl_FragCoord.xy, dsz2) / float(dither_size);
    1.18 +	coord.y = coord.y / levels + coord_shift;
    1.19 +	float val = texture2D(dither_tex, coord).x;
    1.20 +
    1.21 +	const vec3 dark_col = vec3(0.043, 0.286, 0.337);
    1.22 +	const vec3 bright_col = vec3(0.965, 0.778, 0.555);
    1.23 +
    1.24 +	gl_FragColor = vec4(mix(dark_col, bright_col, val), 1.0);
    1.25 +}