dbf-udg

view sdr/dither.p.glsl @ 11:5f99c4c7a9fe

now it looks pretty much ok
author John Tsiombikas <nuclear@member.fsf.org>
date Wed, 20 Feb 2013 04:55:03 +0200
parents 403ec1be3a1a
children 1abbed71e9c9
line source
1 uniform sampler2D framebuf, dither_tex;
2 uniform int dither_levels, dither_size;
4 uniform float tfadein;
6 vec4 fetch_pixel(vec2 texcoord)
7 {
8 float x = step(0.5, mod(texcoord.y, 0.5) / 0.5);
9 float offs = mix(1.0 - tfadein, tfadein - 1.0, x);
10 vec2 tc = texcoord + vec2(offs, 0.0);
12 return (1.0 - step(1.0, tc.x)) * step(0.0, tc.x) * texture2D(framebuf, tc);
13 }
15 void main()
16 {
17 float levels = float(dither_levels);
19 //vec4 pixel = texture2D(framebuf, gl_TexCoord[0].xy);
20 vec4 pixel = fetch_pixel(gl_TexCoord[0].xy);
21 float lum = dot(pixel.xyz, vec3(0.2126, 0.7152, 0.0722));
22 float coord_shift = floor(lum * levels) / levels;
24 vec2 dsz2 = vec2(float(dither_size), float(dither_size));
26 vec2 coord = mod(gl_FragCoord.xy, dsz2) / float(dither_size);
27 coord.y = coord.y / levels + coord_shift;
28 float val = texture2D(dither_tex, coord).x;
30 const vec3 dark_col = vec3(0.043, 0.286, 0.337);
31 const vec3 bright_col = vec3(0.965, 0.778, 0.555);
33 gl_FragColor = vec4(mix(dark_col, bright_col, val), 1.0);
34 }