summary refs log tree commit diff stats
path: root/shaders
diff options
context:
space:
mode:
authorKelly Rauchenberger <fefferburbia@gmail.com>2015-02-15 15:23:19 -0500
committerKelly Rauchenberger <fefferburbia@gmail.com>2015-02-15 15:23:19 -0500
commit783b308990e7c4ef0837a102a138778f73e4d2b7 (patch)
tree77931fcf919f8c8e7996430994c452376aae293f /shaders
parent297c093d398e7d6e5fcc5dc6ba1056ede25abf6f (diff)
downloadtherapy-783b308990e7c4ef0837a102a138778f73e4d2b7.tar.gz
therapy-783b308990e7c4ef0837a102a138778f73e4d2b7.tar.bz2
therapy-783b308990e7c4ef0837a102a138778f73e4d2b7.zip
Added bloom!
Diffstat (limited to 'shaders')
-rw-r--r--shaders/bloom1.fragment53
-rw-r--r--shaders/bloom1.vertex11
-rw-r--r--shaders/bloom2.fragment57
-rw-r--r--shaders/bloom2.vertex11
-rw-r--r--shaders/final.fragment50
-rw-r--r--shaders/final.vertex23
6 files changed, 195 insertions, 10 deletions
diff --git a/shaders/bloom1.fragment b/shaders/bloom1.fragment new file mode 100644 index 0000000..77031f2 --- /dev/null +++ b/shaders/bloom1.fragment
@@ -0,0 +1,53 @@
1#version 330 core
2
3in vec2 UV;
4
5out vec3 color;
6
7uniform sampler2D screenTex;
8uniform float iGlobalTime;
9
10float nrand(vec2 n)
11{
12 return fract(sin(dot(n.xy, vec2(19.9898, 78.233))) * 43758.5453);
13}
14
15vec2 rot2d(vec2 p, float a)
16{
17 vec2 sc = vec2(sin(a), cos(a));
18 return vec2(dot(p, vec2(sc.y, -sc.x)), dot(p, sc.xy));
19}
20
21void main()
22{
23 const int NUM_TAPS = 12;
24 float max_siz = 1.0;
25
26 vec2 fTaps_Poisson[NUM_TAPS];
27 fTaps_Poisson[0] = vec2(-.326, -.406);
28 fTaps_Poisson[1] = vec2(-.840, -.074);
29 fTaps_Poisson[2] = vec2(-.696, .457);
30 fTaps_Poisson[3] = vec2(-.203, .621);
31 fTaps_Poisson[4] = vec2( .962, -.195);
32 fTaps_Poisson[5] = vec2( .473, -.480);
33 fTaps_Poisson[6] = vec2( .519, .767);
34 fTaps_Poisson[7] = vec2( .185, -.893);
35 fTaps_Poisson[8] = vec2( .507, .064);
36 fTaps_Poisson[9] = vec2( .896, .412);
37 fTaps_Poisson[10] = vec2(-.322, -.933);
38 fTaps_Poisson[11] = vec2(-.792, -.598);
39
40 vec4 sum = vec4(0);
41 float rnd = 6.28 * nrand(UV + fract(iGlobalTime));
42 vec4 basis = vec4(rot2d(vec2(1,0), rnd), rot2d(vec2(0,1), rnd));
43 for (int i=0; i<NUM_TAPS; i++)
44 {
45 vec2 ofs = fTaps_Poisson[i];
46 ofs = vec2(dot(ofs, basis.xz), dot(ofs, basis.yw));
47
48 vec2 texcoord = UV + max_siz * ofs / vec2(1024.0,768.0);
49 sum += texture(screenTex, texcoord, -10.0);
50 }
51
52 color = (sum / vec4(NUM_TAPS)).rgb;
53}
diff --git a/shaders/bloom1.vertex b/shaders/bloom1.vertex new file mode 100644 index 0000000..37eeeb0 --- /dev/null +++ b/shaders/bloom1.vertex
@@ -0,0 +1,11 @@
1#version 330 core
2
3layout(location = 0) in vec3 vPos;
4
5out vec2 UV;
6
7void main()
8{
9 gl_Position = vec4(vPos, 1);
10 UV = (vPos.xy + vec2(1,1))/2;
11}
diff --git a/shaders/bloom2.fragment b/shaders/bloom2.fragment new file mode 100644 index 0000000..323f441 --- /dev/null +++ b/shaders/bloom2.fragment
@@ -0,0 +1,57 @@
1#version 330 core
2
3in vec2 UV;
4
5out vec3 color;
6
7uniform sampler2D screenTex;
8uniform sampler2D downsampledTex;
9uniform float iGlobalTime;
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
22void main()
23{
24 const int NUM_TAPS = 12;
25 float max_siz = 1.0;
26
27 vec2 fTaps_Poisson[NUM_TAPS];
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 / vec2(64.0,48.0);
50 sum += texture(downsampledTex, texcoord, -10.0);
51 }
52
53 vec3 bloom_c = (sum / vec4(NUM_TAPS)).rgb;
54 bloom_c = vec3(bloom_c.r*bloom_c.r, bloom_c.g*bloom_c.g, bloom_c.b*bloom_c.b);
55
56 color = texture(screenTex, UV).rgb + bloom_c;
57}
diff --git a/shaders/bloom2.vertex b/shaders/bloom2.vertex new file mode 100644 index 0000000..37eeeb0 --- /dev/null +++ b/shaders/bloom2.vertex
@@ -0,0 +1,11 @@
1#version 330 core
2
3layout(location = 0) in vec3 vPos;
4
5out vec2 UV;
6
7void main()
8{
9 gl_Position = vec4(vPos, 1);
10 UV = (vPos.xy + vec2(1,1))/2;
11}
diff --git a/shaders/final.fragment b/shaders/final.fragment index c900973..5feccb9 100644 --- a/shaders/final.fragment +++ b/shaders/final.fragment
@@ -1,7 +1,10 @@
1#version 330 core 1#version 330 core
2 2
3in vec2 UV; 3in vec2 UV;
4in vec3 norm; 4in vec3 normIn;
5in vec3 camDirIn;
6in vec3 lightDirIn;
7//in vec3 vertPos;
5 8
6out vec3 color; 9out vec3 color;
7 10
@@ -10,20 +13,19 @@ uniform sampler2D scanlinestex;
10 13
11const vec2 UVScalar = vec2(1.0, 1.0); 14const vec2 UVScalar = vec2(1.0, 1.0);
12const vec2 UVOffset = vec2(0.0, 0.0); 15const vec2 UVOffset = vec2(0.0, 0.0);
13const vec2 CRTMask_Scale = vec2(85.0, 153.6); 16const vec2 CRTMask_Scale = vec2(85.0, 153.6)*4.0;
14const vec2 CRTMask_Offset = vec2(0.0, 0.0); 17const vec2 CRTMask_Offset = vec2(0.0, 0.0);
15const float Tuning_Overscan = 1.0; 18const float Tuning_Overscan = 1.0;
16const float Tuning_Dimming = 0.5; 19const float Tuning_Dimming = 0.0;
17const float Tuning_Satur = 1.35; 20const float Tuning_Satur = 1.35;
18const float Tuning_ReflScalar = 0.3; 21const float Tuning_ReflScalar = 0.3;
19const float Tuning_Barrel = 0.12; 22const float Tuning_Barrel = 0; //0.12;
20const float Tuning_Scanline_Brightness = 0.25; 23const float Tuning_Scanline_Brightness = 0.5;
21const float Tuning_Scanline_Opacity = 0.5; 24const float Tuning_Scanline_Opacity = 0.5;
22const float Tuning_Diff_Brightness = 0.5; 25const float Tuning_Diff_Brightness = 0.5;
23const float Tuning_Spec_Brightness = 0.35; 26const float Tuning_Spec_Brightness = 0.35;
24const float Tuning_Spec_Power = 50.0; 27const float Tuning_Spec_Power = 50.0;
25const float Tuning_Fres_Brightness = 1.0; 28const float Tuning_Fres_Brightness = 1.0;
26const vec3 Tuning_LightPos = vec3(5.0, -10.0, 0.0);
27 29
28vec4 sampleCRT(vec2 uv) 30vec4 sampleCRT(vec2 uv)
29{ 31{
@@ -52,5 +54,39 @@ vec4 sampleCRT(vec2 uv)
52 54
53void main() 55void main()
54{ 56{
55 color = sampleCRT(UV).rgb; 57 vec3 norm = normalize(normIn);
58 vec3 camDir = normalize(camDirIn);
59 vec3 lightDir = normalize(lightDirIn);
60 //vec3 refl = reflect(camDir, normIn);
61
62 float diffuse = clamp(dot(norm, lightDir), 0.0f, 1.0f);
63 vec4 colordiff = vec4(0.175, 0.15, 0.2, 1) * diffuse * Tuning_Diff_Brightness;
64
65 vec3 halfVec = normalize(lightDir + camDir);
66 float spec = clamp(dot(norm, halfVec), 0.0f, 1.0f);
67 spec = pow(spec, Tuning_Spec_Power);
68 vec4 colorspec = vec4(0.25, 0.25, 0.25, 1) * spec * Tuning_Spec_Brightness;
69
70 float fres = 1.0f - dot(camDir, norm);
71 fres = (fres*fres) * Tuning_Fres_Brightness;
72 vec4 colorfres = vec4(0.45, 0.4, 0.5, 1) * fres;/*
73
74 float lambertian = max(dot(camDirNorm,norm),0.0);
75 vec4 colorspec = vec4(0.0);
76 vec4 colorfres = vec4(0.0);
77 vec4 colordiff = vec4(0.175,0.15,0.2,1) * lambertian * Tuning_Diff_Brightness;
78 if (lambertian > 0.0)
79 {
80 vec3 viewDir = normalize(-vertPos);
81 vec3 halfDir = normalize(camDirNorm + viewDir);
82 float specAngle = max(dot(halfDir, normnorm), 0.0);
83 colorspec = vec4(0.25,0.25,0.25,1) * pow(specAngle, Tuning_Spec_Power) * Tuning_Spec_Brightness;
84 }*/
85
86 vec4 emissive = sampleCRT(UV);
87
88 vec4 nearfinal = colorfres + colordiff + colorspec + emissive;
89 vec4 final = nearfinal * mix(vec4(1,1,1,1), vec4(0,0,0,0), Tuning_Dimming);
90
91 color = final.rgb;
56} 92}
diff --git a/shaders/final.vertex b/shaders/final.vertex index 825eb49..dda8626 100644 --- a/shaders/final.vertex +++ b/shaders/final.vertex
@@ -4,11 +4,28 @@ layout(location = 0) in vec3 vertexPosition_modelspace;
4layout(location = 1) in vec3 vertexNormal; 4layout(location = 1) in vec3 vertexNormal;
5 5
6out vec2 UV; 6out vec2 UV;
7out vec3 norm; 7out vec3 normIn;
8out vec3 camDirIn;
9out vec3 lightDirIn;
10//out vec3 vertPos;
11
12uniform mat4 MVP;
13uniform mat4 worldMat;
14
15const vec3 Tuning_LightPos = vec3(1, 1, 1.0);
8 16
9void main() 17void main()
10{ 18{
11 gl_Position = vec4(vertexPosition_modelspace,1); 19 gl_Position = MVP * vec4(vertexPosition_modelspace,1);
12 UV = (vertexPosition_modelspace.xy+vec2(1,1))/2.0; 20 UV = (vertexPosition_modelspace.xy+vec2(1,1))/2.0;
13 norm = vertexNormal; 21 normIn = vertexNormal;
22
23 mat3 invWorldRot = transpose(mat3(worldMat[0].xyz, worldMat[1].xyz, worldMat[2].xyz));
24 //mat3 invWorldRot = mat3(1.0f);
25 vec3 worldPos = (worldMat * vec4(vertexPosition_modelspace,1)).xyz;
26 camDirIn = invWorldRot * (vec3(0,0,1) - worldPos);
27 //camDir = worldPos;
28 lightDirIn = invWorldRot * (Tuning_LightPos - worldPos);
29 //vec4 vertPos4 = vec4(vertexPosition_modelspace,1);
30 //vertPos = vec3(vertPos4) / vertPos4.w;
14} 31}