summary refs log tree commit diff stats
path: root/shaders/final.fragment
diff options
context:
space:
mode:
Diffstat (limited to 'shaders/final.fragment')
-rw-r--r--shaders/final.fragment56
1 files changed, 56 insertions, 0 deletions
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}