summary refs log tree commit diff stats
path: root/shaders/ntsc.fragment
diff options
context:
space:
mode:
Diffstat (limited to 'shaders/ntsc.fragment')
-rw-r--r--shaders/ntsc.fragment64
1 files changed, 64 insertions, 0 deletions
diff --git a/shaders/ntsc.fragment b/shaders/ntsc.fragment new file mode 100644 index 0000000..12d6873 --- /dev/null +++ b/shaders/ntsc.fragment
@@ -0,0 +1,64 @@
1#version 330 core
2
3in vec2 UV;
4
5out vec3 color;
6
7uniform sampler2D curFrameSampler;
8uniform sampler2D NTSCArtifactSampler;
9uniform sampler2D prevFrameSampler;
10
11const float Tuning_Sharp = 0.8;
12const vec4 Tuning_Persistence = vec4(0.7,0.7,0.7,0.7);
13const float Tuning_Bleed = 0.5;
14const float Tuning_NTSC = 0.35;
15uniform float NTSCLerp;
16
17const vec2 RcpScrWidth = vec2(1.0f / 320.f, 0.0f);
18const vec2 RcpScrHeight = vec2(0.0f, 1.0f / 200.0f);
19
20float Brightness(vec4 InVal)
21{
22 return dot(InVal, vec4(0.299, 0.587, 0.114, 0.0));
23}
24
25const float SharpWeight[3] = float[3](1.0, -0.3162277, 0.1);
26
27void main()
28{
29 vec4 NTSCArtifact1 = texture(NTSCArtifactSampler, UV);
30 vec4 NTSCArtifact2 = texture(NTSCArtifactSampler, UV + RcpScrHeight);
31 vec4 NTSCArtifact = mix(NTSCArtifact1, NTSCArtifact2, NTSCLerp);
32
33 vec2 LeftUV = UV - RcpScrWidth;
34 vec2 RightUV = UV + RcpScrWidth;
35
36 vec4 Cur_Left = texture(curFrameSampler, LeftUV);
37 vec4 Cur_Local = texture(curFrameSampler, UV);
38 vec4 Cur_Right = texture(curFrameSampler, RightUV);
39
40 vec4 Prev_Left = texture(prevFrameSampler, LeftUV);
41 vec4 Prev_Local = texture(prevFrameSampler, UV);
42 vec4 Prev_Right = texture(prevFrameSampler, RightUV);
43
44 Cur_Local = clamp(Cur_Local + (((Cur_Left - Cur_Local) + (Cur_Right - Cur_Local)) * Tuning_NTSC), vec4(0,0,0,0), vec4(1,1,1,1));
45
46 float curBrt = Brightness(Cur_Local);
47 float offset = 0;
48
49 for (int i=0; i<3; ++i)
50 {
51 vec2 StepSize = (RcpScrWidth * float(i+1));
52 vec4 neighborleft = texture(curFrameSampler, UV - StepSize);
53 vec4 neighborright = texture(curFrameSampler, UV + StepSize);
54
55 float NBrtL = Brightness(neighborleft);
56 float NBrtR = Brightness(neighborright);
57 offset += ((curBrt - NBrtL) + (curBrt - NBrtR)) * SharpWeight[i];
58 }
59
60 Cur_Local = clamp(Cur_Local + (offset * Tuning_Sharp * mix(vec4(1,1,1,1), NTSCArtifact, Tuning_NTSC)), vec4(0,0,0,0), vec4(1,1,1,1));
61 Cur_Local = clamp(max(Cur_Local, Tuning_Persistence * (1.0 / (1.0 + (2.0 * Tuning_Bleed))) * (Prev_Local + ((Prev_Left + Prev_Right) * Tuning_Bleed))), vec4(0,0,0,0), vec4(1,1,1,1));
62
63 color = Cur_Local.xyz;
64}