summary refs log tree commit diff stats
path: root/shaders
diff options
context:
space:
mode:
authorKelly Rauchenberger <fefferburbia@gmail.com>2015-02-23 10:49:56 -0500
committerKelly Rauchenberger <fefferburbia@gmail.com>2015-02-23 10:49:56 -0500
commit0751446e1d069263d25abcff49a32a380231709a (patch)
treeaf47582053b30d018c3f1d02e0462aa1eab1b6bb /shaders
parentcecdba5cd996cea3ebd2534aea7a3e3a41205b9c (diff)
downloadtherapy-0751446e1d069263d25abcff49a32a380231709a.tar.gz
therapy-0751446e1d069263d25abcff49a32a380231709a.tar.bz2
therapy-0751446e1d069263d25abcff49a32a380231709a.zip
Rewrote bloom so it's not super slow, also removed the frame from the screen mesh
Diffstat (limited to 'shaders')
-rw-r--r--shaders/bloom1.fragment50
-rw-r--r--shaders/bloom2.fragment58
-rw-r--r--shaders/final.fragment10
3 files changed, 26 insertions, 92 deletions
diff --git a/shaders/bloom1.fragment b/shaders/bloom1.fragment index cfb2799..0a89ea1 100644 --- a/shaders/bloom1.fragment +++ b/shaders/bloom1.fragment
@@ -4,51 +4,13 @@ in vec2 UV;
4 4
5out vec3 color; 5out vec3 color;
6 6
7uniform sampler2D screenTex; 7uniform vec2 offset;
8uniform float iGlobalTime; 8uniform sampler2D inTex;
9uniform vec2 resolution;
10
11float nrand(vec2 n)
12{
13 return fract(sin(dot(n.xy, vec2(19.9898, 78.233))) * 43758.5453);
14}
15
16vec2 rot2d(vec2 p, float a)
17{
18 vec2 sc = vec2(sin(a), cos(a));
19 return vec2(dot(p, vec2(sc.y, -sc.x)), dot(p, sc.xy));
20}
21 9
22void main() 10void main()
23{ 11{
24 const int NUM_TAPS = 12; 12 color = vec3(0.0);
25 float max_siz = 15.0; 13 color += (5.0/16.0) * texture(inTex, UV - offset).rgb;
26 14 color += (6.0/16.0) * texture(inTex, UV).rgb;
27 vec2 fTaps_Poisson[NUM_TAPS]; 15 color += (5.0/16.0) * texture(inTex, UV + offset).rgb;
28 fTaps_Poisson[0] = vec2(-.326, -.406);
29 fTaps_Poisson[1] = vec2(-.840, -.074);
30 fTaps_Poisson[2] = vec2(-.696, .457);
31 fTaps_Poisson[3] = vec2(-.203, .621);
32 fTaps_Poisson[4] = vec2( .962, -.195);
33 fTaps_Poisson[5] = vec2( .473, -.480);
34 fTaps_Poisson[6] = vec2( .519, .767);
35 fTaps_Poisson[7] = vec2( .185, -.893);
36 fTaps_Poisson[8] = vec2( .507, .064);
37 fTaps_Poisson[9] = vec2( .896, .412);
38 fTaps_Poisson[10] = vec2(-.322, -.933);
39 fTaps_Poisson[11] = vec2(-.792, -.598);
40
41 vec4 sum = vec4(0);
42 float rnd = 6.28 * nrand(UV + fract(iGlobalTime));
43 vec4 basis = vec4(rot2d(vec2(1,0), rnd), rot2d(vec2(0,1), rnd));
44 for (int i=0; i<NUM_TAPS; i++)
45 {
46 vec2 ofs = fTaps_Poisson[i];
47 ofs = vec2(dot(ofs, basis.xz), dot(ofs, basis.yw));
48
49 vec2 texcoord = UV + max_siz * ofs / resolution;
50 sum += texture(screenTex, texcoord, -10.0);
51 }
52
53 color = (sum / vec4(NUM_TAPS)).rgb;
54} 16}
diff --git a/shaders/bloom2.fragment b/shaders/bloom2.fragment index 1d9cac4..eca56ea 100644 --- a/shaders/bloom2.fragment +++ b/shaders/bloom2.fragment
@@ -4,58 +4,30 @@ in vec2 UV;
4 4
5out vec3 color; 5out vec3 color;
6 6
7uniform sampler2D screenTex; 7uniform sampler2D clearTex;
8uniform sampler2D downsampledTex; 8uniform sampler2D blurTex;
9uniform float iGlobalTime; 9uniform float iGlobalTime;
10uniform vec2 resolution;
11 10
12float nrand(vec2 n) 11float nrand(vec2 n)
13{ 12{
14 return fract(sin(dot(n.xy, vec2(19.9898, 78.233))) * 43758.5453); 13 return fract(sin(dot(n.xy, vec2(19.9898, 78.233))) * 43758.5453);
15} 14}
16 15
17vec2 rot2d(vec2 p, float a)
18{
19 vec2 sc = vec2(sin(a), cos(a));
20 return vec2(dot(p, vec2(sc.y, -sc.x)), dot(p, sc.xy));
21}
22
23void main() 16void main()
24{ 17{
25 const int NUM_TAPS = 12; 18 color = vec3(0.0);
26 float max_siz = 1.0; 19 //color += texture(tex2, UV).rgb / 2.0;
27 20 color += texture(blurTex, UV).rgb;
28 vec2 fTaps_Poisson[NUM_TAPS]; 21 color = max(vec3(0.0), color - 0.25);
29 fTaps_Poisson[0] = vec2(-.326, -.406); 22 //color *= color;
30 fTaps_Poisson[1] = vec2(-.840, -.074);
31 fTaps_Poisson[2] = vec2(-.696, .457);
32 fTaps_Poisson[3] = vec2(-.203, .621);
33 fTaps_Poisson[4] = vec2( .962, -.195);
34 fTaps_Poisson[5] = vec2( .473, -.480);
35 fTaps_Poisson[6] = vec2( .519, .767);
36 fTaps_Poisson[7] = vec2( .185, -.893);
37 fTaps_Poisson[8] = vec2( .507, .064);
38 fTaps_Poisson[9] = vec2( .896, .412);
39 fTaps_Poisson[10] = vec2(-.322, -.933);
40 fTaps_Poisson[11] = vec2(-.792, -.598);
41
42 vec4 sum = vec4(0);
43 float rnd = 6.28 * nrand(UV + fract(iGlobalTime));
44 vec4 basis = vec4(rot2d(vec2(1,0), rnd), rot2d(vec2(0,1), rnd));
45 for (int i=0; i<NUM_TAPS; i++)
46 {
47 vec2 ofs = fTaps_Poisson[i];
48 ofs = vec2(dot(ofs, basis.xz), dot(ofs, basis.yw));
49
50 vec2 texcoord = UV + max_siz * ofs / (resolution / vec2(16.0));
51 sum += texture(downsampledTex, texcoord, -10.0);
52 }
53 23
54 vec3 bloom_c = (sum / vec4(NUM_TAPS)).rgb; 24 float flicker = 0.5 + nrand(vec2(iGlobalTime));
55 bloom_c *= bloom_c; 25 //flicker *= (flicker);
56 //bloom_c = vec3(bloom_c.r*bloom_c.r, bloom_c.g*bloom_c.g, bloom_c.b*bloom_c.b); 26 flicker = sqrt(flicker);
57 //bloom_c = vec3(bloom_c.r*bloom_c.r, bloom_c.g*bloom_c.g, bloom_c.b*bloom_c.b); 27 //flicker = pow(flicker, 1.0/8.0);
58 //bloom_c = max(bloom_c - 0.25, vec3(0,0,0)); 28 color *= flicker;
29 //color *= mix(vec3(0.0), color, flicker);
59 30
60 color = texture(screenTex, UV).rgb + bloom_c; 31 color += texture(clearTex, UV).rgb;
32 //color = clamp(color, vec3(0.0), vec3(1.0));
61} 33}
diff --git a/shaders/final.fragment b/shaders/final.fragment index f9d8995..b6c49a8 100644 --- a/shaders/final.fragment +++ b/shaders/final.fragment
@@ -12,11 +12,11 @@ uniform sampler2D scanlinestex;
12 12
13const float Tuning_Overscan = 1.08; 13const float Tuning_Overscan = 1.08;
14const float Tuning_Dimming = 0.0; 14const float Tuning_Dimming = 0.0;
15const float Tuning_Satur = 1.0; 15const float Tuning_Satur = 1.13;
16const float Tuning_ReflScalar = 0.3; 16const float Tuning_ReflScalar = 0.3;
17const float Tuning_Barrel = 0; //0.12; 17const float Tuning_Barrel = 0;//0.12;
18const float Tuning_Scanline_Brightness = 0.45; 18const float Tuning_Scanline_Brightness = 0.45;
19const float Tuning_Scanline_Opacity = 0.5; 19const float Tuning_Scanline_Opacity = 0.55;
20const float Tuning_Diff_Brightness = 0.75; 20const float Tuning_Diff_Brightness = 0.75;
21const float Tuning_Spec_Brightness = 0.35; 21const float Tuning_Spec_Brightness = 0.35;
22const float Tuning_Spec_Power = 50.0; 22const float Tuning_Spec_Power = 50.0;
@@ -26,7 +26,7 @@ uniform vec2 resolution;
26 26
27vec4 sampleCRT(vec2 uv) 27vec4 sampleCRT(vec2 uv)
28{ 28{
29 vec2 CRTMask_Scale = resolution / vec2(6.0, 5.0); 29 vec2 CRTMask_Scale = vec2(320.0,200.0) / vec2(2.0, 1.0);
30 30
31 vec2 scanuv = uv * CRTMask_Scale; 31 vec2 scanuv = uv * CRTMask_Scale;
32 vec3 scantex = texture(scanlinestex, scanuv).rgb; 32 vec3 scantex = texture(scanlinestex, scanuv).rgb;
@@ -61,7 +61,7 @@ void main()
61 spec = pow(spec, Tuning_Spec_Power); 61 spec = pow(spec, Tuning_Spec_Power);
62 vec4 colorspec = vec4(0.25, 0.25, 0.25, 1) * spec * Tuning_Spec_Brightness; 62 vec4 colorspec = vec4(0.25, 0.25, 0.25, 1) * spec * Tuning_Spec_Brightness;
63 63
64 float fres = 1.0f - dot(camDir, norm); 64 float fres = 1.0 - dot(camDir, norm);
65 fres = (fres*fres) * Tuning_Fres_Brightness; 65 fres = (fres*fres) * Tuning_Fres_Brightness;
66 vec4 colorfres = vec4(0.45, 0.4, 0.5, 1) * fres; 66 vec4 colorfres = vec4(0.45, 0.4, 0.5, 1) * fres;
67 67