20130420
[gdash.git] / shaders / Phosphor-simple.shader
blob4026f7ce874e111a55501cc385471717a33631a1
1 <?xml version="1.0" encoding="UTF-8"?>
2 <!--
3 Plain (and obviously inaccurate) phosphor.
4 Author: Themaister
5 License: Public Domain
6 -->
7 <shader language="GLSL">
8 <fragment filter="linear"><![CDATA[
9 uniform sampler2D rubyTexture;
10 uniform vec2 rubyTextureSize;
12 vec3 to_focus(float pixel)
14 pixel = mod(pixel + 3.0, 3.0);
15 if (pixel >= 2.0) // Blue
16 return vec3(pixel - 2.0, 0.0, 3.0 - pixel);
17 else if (pixel >= 1.0) // Green
18 return vec3(0.0, 2.0 - pixel, pixel - 1.0);
19 else // Red
20 return vec3(1.0 - pixel, pixel, 0.0);
23 void main()
25 float y = mod(gl_TexCoord[0].y * rubyTextureSize.y, 1.0);
26 float intensity = exp(-0.2 * y);
28 vec2 one_x = vec2(1.0 / (3.0 * rubyTextureSize.x), 0.0);
30 vec3 color = texture2D(rubyTexture, gl_TexCoord[0].xy - 0.0 * one_x).rgb;
31 vec3 color_prev = texture2D(rubyTexture, gl_TexCoord[0].xy - 1.0 * one_x).rgb;
32 vec3 color_prev_prev = texture2D(rubyTexture, gl_TexCoord[0].xy - 2.0 * one_x).rgb;
34 float pixel_x = 3.0 * gl_TexCoord[0].x * rubyTextureSize.x;
36 vec3 focus = to_focus(pixel_x - 0.0);
37 vec3 focus_prev = to_focus(pixel_x - 1.0);
38 vec3 focus_prev_prev = to_focus(pixel_x - 2.0);
40 vec3 result =
41 0.8 * color * focus +
42 0.6 * color_prev * focus_prev +
43 0.3 * color_prev_prev * focus_prev_prev;
45 result = 2.3 * pow(result, vec3(1.4));
47 gl_FragColor = vec4(intensity * result, 1.0);
49 ]]></fragment>
50 </shader>