1 <?xml version="1.0" encoding="UTF-8"?>
3 Themaister's Waterpaint shader
5 Placed in the public domain.
7 (From this thread: http://board.byuu.org/viewtopic.php?p=30483#p30483
8 PD declaration here: http://board.byuu.org/viewtopic.php?p=30542#p30542 )
10 <shader language="GLSL">
12 uniform vec2 rubyTextureSize;
16 float x = 0.5 * (1.0 / rubyTextureSize.x);
17 float y = 0.5 * (1.0 / rubyTextureSize.y);
18 vec2 dg1 = vec2( x, y);
19 vec2 dg2 = vec2(-x, y);
20 vec2 dx = vec2(x, 0.0);
21 vec2 dy = vec2(0.0, y);
23 gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;
24 gl_TexCoord[0] = gl_MultiTexCoord0;
25 gl_TexCoord[1].xy = gl_TexCoord[0].xy - dg1;
26 gl_TexCoord[1].zw = gl_TexCoord[0].xy - dy;
27 gl_TexCoord[2].xy = gl_TexCoord[0].xy - dg2;
28 gl_TexCoord[2].zw = gl_TexCoord[0].xy + dx;
29 gl_TexCoord[3].xy = gl_TexCoord[0].xy + dg1;
30 gl_TexCoord[3].zw = gl_TexCoord[0].xy + dy;
31 gl_TexCoord[4].xy = gl_TexCoord[0].xy + dg2;
32 gl_TexCoord[4].zw = gl_TexCoord[0].xy - dx;
37 vec4 compress(vec4 in_color, float threshold, float ratio)
39 vec4 diff = in_color - vec4(threshold);
40 diff = clamp(diff, 0.0, 100.0);
41 return in_color - (diff * (1.0 - 1.0/ratio));
44 uniform sampler2D rubyTexture;
45 uniform vec2 rubyTextureSize;
49 vec3 c00 = texture2D(rubyTexture, gl_TexCoord[1].xy).xyz;
50 vec3 c01 = texture2D(rubyTexture, gl_TexCoord[4].zw).xyz;
51 vec3 c02 = texture2D(rubyTexture, gl_TexCoord[4].xy).xyz;
52 vec3 c10 = texture2D(rubyTexture, gl_TexCoord[1].zw).xyz;
53 vec3 c11 = texture2D(rubyTexture, gl_TexCoord[0].xy).xyz;
54 vec3 c12 = texture2D(rubyTexture, gl_TexCoord[3].zw).xyz;
55 vec3 c20 = texture2D(rubyTexture, gl_TexCoord[2].xy).xyz;
56 vec3 c21 = texture2D(rubyTexture, gl_TexCoord[2].zw).xyz;
57 vec3 c22 = texture2D(rubyTexture, gl_TexCoord[3].xy).xyz;
59 vec2 tex = gl_TexCoord[0].xy;
60 vec2 texsize = rubyTextureSize;
62 vec3 first = mix(c00, c20, fract(tex.x * texsize.x + 0.5));
63 vec3 second = mix(c02, c22, fract(tex.x * texsize.x + 0.5));
65 vec3 mid_horiz = mix(c01, c21, fract(tex.x * texsize.x + 0.5));
66 vec3 mid_vert = mix(c10, c12, fract(tex.y * texsize.y + 0.5));
68 vec3 res = mix(first, second, fract(tex.y * texsize.y + 0.5));
69 vec4 final = vec4(0.26 * (res + mid_horiz + mid_vert) + 3.5 * abs(res - mix(mid_horiz, mid_vert, 0.5)), 1.0);
70 gl_FragColor = compress(final, 0.8, 5.0);