Created
September 23, 2011 19:40
-
-
Save Themaister/1238256 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* (Inaccurate) Phosphor shader | |
* Author: Themaister | |
* Licesese: Public Domain | |
*/ | |
struct coords | |
{ | |
float2 coord; | |
float2 coord_prev; | |
float2 coord_prev_prev; | |
float2 tex_index; | |
}; | |
struct input | |
{ | |
float2 video_size; | |
float2 texture_size; | |
float2 output_size; | |
}; | |
void main_vertex( | |
float4 position : POSITION, | |
out float4 oPosition : POSITION, | |
uniform float4x4 modelViewProj, | |
float2 tex : TEXCOORD, | |
uniform input IN, | |
out coords co | |
) | |
{ | |
oPosition = mul(modelViewProj, position); | |
float2 one_x = float2(1.0 / (3.0 * IN.texture_size.x), 0.0); | |
co = coords( | |
tex - 0.0 * one_x, | |
tex - 1.0 * one_x, | |
tex - 2.0 * one_x, | |
tex * IN.texture_size | |
); | |
} | |
float3 to_focus(float pixel) | |
{ | |
pixel = fmod(pixel + 3.0, 3.0); | |
if (pixel >= 2.0) // Blue | |
return float3(pixel - 2.0, 0.0, 3.0 - pixel); | |
else if (pixel >= 1.0) // Green | |
return float3(0.0, 2.0 - pixel, pixel - 1.0); | |
else // Red | |
return float3(1.0 - pixel, pixel, 0.0); | |
} | |
float4 main_fragment(in coords co, uniform sampler2D samp : TEXUNIT0) : COLOR | |
{ | |
float y = fmod(co.tex_index.y, 1.0); | |
float intensity = exp(-0.2 * y); | |
float3 color = tex2D(samp, co.coord).rgb; | |
float3 color_prev = tex2D(samp, co.coord_prev).rgb; | |
float3 color_prev_prev = tex2D(samp, co.coord_prev_prev).rgb; | |
float pixel_x = 3.0 * co.tex_index.x; | |
float3 focus = to_focus(pixel_x - 0.0); | |
float3 focus_prev = to_focus(pixel_x - 1.0); | |
float3 focus_prev_prev = to_focus(pixel_x - 2.0); | |
float3 result = | |
0.8 * color * focus + | |
0.6 * color_prev * focus_prev + | |
0.3 * color_prev_prev * focus_prev_prev; | |
result = 2.3 * pow(result, float3(1.4)); | |
return float4(intensity * result, 1.0); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment