summary refs log tree commit diff stats
path: root/shaders
diff options
context:
space:
mode:
authorKelly Rauchenberger <fefferburbia@gmail.com>2015-02-14 12:09:41 -0500
committerKelly Rauchenberger <fefferburbia@gmail.com>2015-02-14 12:09:41 -0500
commitde5a458cb037bb8e1e80c849c5e6525f9413b43a (patch)
tree97d7aebcf21e4db3c3e19d4a9c7ec906114e5558 /shaders
downloadtherapy-de5a458cb037bb8e1e80c849c5e6525f9413b43a.tar.gz
therapy-de5a458cb037bb8e1e80c849c5e6525f9413b43a.tar.bz2
therapy-de5a458cb037bb8e1e80c849c5e6525f9413b43a.zip
Monitor stuff is looking pretty cool!
Diffstat (limited to 'shaders')
-rw-r--r--shaders/blit.fragment12
-rw-r--r--shaders/blit.vertex13
-rw-r--r--shaders/fill.fragment10
-rw-r--r--shaders/fill.vertex8
-rw-r--r--shaders/final.fragment56
-rw-r--r--shaders/final.vertex14
-rw-r--r--shaders/ntsc.fragment64
-rw-r--r--shaders/ntsc.vertex11
8 files changed, 188 insertions, 0 deletions
diff --git a/shaders/blit.fragment b/shaders/blit.fragment new file mode 100644 index 0000000..07a0279 --- /dev/null +++ b/shaders/blit.fragment
@@ -0,0 +1,12 @@
1#version 330 core
2
3in vec2 UV;
4
5out vec3 color;
6
7uniform sampler2D srctex;
8
9void main()
10{
11 color = texture(srctex, UV).xyz;
12}
diff --git a/shaders/blit.vertex b/shaders/blit.vertex new file mode 100644 index 0000000..4a9aa6a --- /dev/null +++ b/shaders/blit.vertex
@@ -0,0 +1,13 @@
1#version 330 core
2
3layout(location = 0) in vec2 vertexPosition;
4layout(location = 1) in vec2 texcoordPosition;
5
6out vec2 UV;
7
8void main()
9{
10 gl_Position = vec4(vertexPosition, 0.0f, 1.0f);
11
12 UV = texcoordPosition;
13}
diff --git a/shaders/fill.fragment b/shaders/fill.fragment new file mode 100644 index 0000000..ab7d9c9 --- /dev/null +++ b/shaders/fill.fragment
@@ -0,0 +1,10 @@
1#version 330 core
2
3out vec3 color;
4
5uniform vec3 vecColor;
6
7void main()
8{
9 color = vecColor;
10}
diff --git a/shaders/fill.vertex b/shaders/fill.vertex new file mode 100644 index 0000000..44445fe --- /dev/null +++ b/shaders/fill.vertex
@@ -0,0 +1,8 @@
1#version 330 core
2
3layout(location = 0) in vec3 vertexPosition;
4
5void main()
6{
7 gl_Position = vec4(vertexPosition, 1);
8}
diff --git a/shaders/final.fragment b/shaders/final.fragment new file mode 100644 index 0000000..c900973 --- /dev/null +++ b/shaders/final.fragment
@@ -0,0 +1,56 @@
1#version 330 core
2
3in vec2 UV;
4in vec3 norm;
5
6out vec3 color;
7
8uniform sampler2D rendertex;
9uniform sampler2D scanlinestex;
10
11const vec2 UVScalar = vec2(1.0, 1.0);
12const vec2 UVOffset = vec2(0.0, 0.0);
13const vec2 CRTMask_Scale = vec2(85.0, 153.6);
14const vec2 CRTMask_Offset = vec2(0.0, 0.0);
15const float Tuning_Overscan = 1.0;
16const float Tuning_Dimming = 0.5;
17const float Tuning_Satur = 1.35;
18const float Tuning_ReflScalar = 0.3;
19const float Tuning_Barrel = 0.12;
20const float Tuning_Scanline_Brightness = 0.25;
21const float Tuning_Scanline_Opacity = 0.5;
22const float Tuning_Diff_Brightness = 0.5;
23const float Tuning_Spec_Brightness = 0.35;
24const float Tuning_Spec_Power = 50.0;
25const float Tuning_Fres_Brightness = 1.0;
26const vec3 Tuning_LightPos = vec3(5.0, -10.0, 0.0);
27
28vec4 sampleCRT(vec2 uv)
29{
30 vec2 ScaledUV = uv;
31 ScaledUV *= UVScalar;
32 ScaledUV += UVOffset;
33
34 vec2 scanuv = ScaledUV * CRTMask_Scale;
35 vec3 scantex = texture(scanlinestex, scanuv).rgb;
36 scantex += Tuning_Scanline_Brightness;
37 scantex = mix(vec3(1,1,1), scantex, Tuning_Scanline_Opacity);
38
39 vec2 overscanuv = (ScaledUV * Tuning_Overscan) - ((Tuning_Overscan - 1.0f) * 0.5f);
40 overscanuv = overscanuv - vec2(0.5, 0.5);
41 float rsq = (overscanuv.x*overscanuv.x) + (overscanuv.y*overscanuv.y);
42 overscanuv = overscanuv + (overscanuv * (Tuning_Barrel * rsq)) + vec2(0.5,0.5);
43
44 vec3 comptex = texture(rendertex, overscanuv).rgb;
45
46 vec4 emissive = vec4(comptex * scantex, 1);
47 float desat = dot(vec4(0.299, 0.587, 0.114, 0.0), emissive);
48 emissive = mix(vec4(desat, desat, desat, 1), emissive, Tuning_Satur);
49
50 return emissive;
51}
52
53void main()
54{
55 color = sampleCRT(UV).rgb;
56}
diff --git a/shaders/final.vertex b/shaders/final.vertex new file mode 100644 index 0000000..825eb49 --- /dev/null +++ b/shaders/final.vertex
@@ -0,0 +1,14 @@
1#version 330 core
2
3layout(location = 0) in vec3 vertexPosition_modelspace;
4layout(location = 1) in vec3 vertexNormal;
5
6out vec2 UV;
7out vec3 norm;
8
9void main()
10{
11 gl_Position = vec4(vertexPosition_modelspace,1);
12 UV = (vertexPosition_modelspace.xy+vec2(1,1))/2.0;
13 norm = vertexNormal;
14}
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}
diff --git a/shaders/ntsc.vertex b/shaders/ntsc.vertex new file mode 100644 index 0000000..81f8af3 --- /dev/null +++ b/shaders/ntsc.vertex
@@ -0,0 +1,11 @@
1#version 330 core
2
3layout(location = 0) in vec3 vertexPosition_modelspace;
4
5out vec2 UV;
6
7void main()
8{
9 gl_Position = vec4(vertexPosition_modelspace,1);
10 UV = (vertexPosition_modelspace.xy+vec2(1,1))/2.0;
11}