]> gitweb.ps.run Git - subsurface_scattering/blob - shaders/fbo_frag.glsl
pre cleanup
[subsurface_scattering] / shaders / fbo_frag.glsl
1 #version 330 core\r
2 out vec4 FragColor;\r
3   \r
4 in vec2 TexCoords;\r
5 \r
6 uniform sampler2D shadowmapTexture;\r
7 uniform sampler2D irradianceTexture;\r
8 uniform int screenWidth;\r
9 uniform int screenHeight;\r
10 uniform int renderState;\r
11 uniform vec2 samplePositions[13];\r
12 uniform vec3 sampleWeights[13];\r
13 \r
14 vec4 blur(sampler2D tex, vec2 uv, vec2 res) {\r
15   float Pi = 6.28318530718; // Pi*2\r
16     \r
17   // GAUSSIAN BLUR SETTINGS {{{\r
18   float Directions = 16.0; // BLUR DIRECTIONS (Default 16.0 - More is better but slower)\r
19   float Quality = 4.0; // BLUR QUALITY (Default 4.0 - More is better but slower)\r
20   float Size = 8.0; // BLUR SIZE (Radius)\r
21   // GAUSSIAN BLUR SETTINGS }}}\r
22   \r
23   vec2 Radius = Size/res;\r
24   \r
25   // Pixel colour\r
26   vec4 Color = texture(tex, uv);\r
27   \r
28   // Blur calculations\r
29   for( float d=0.0; d<Pi; d+=Pi/Directions) {\r
30     for(float i=1.0/Quality; i<=1.0; i+=1.0/Quality) {\r
31       Color += texture( tex, uv+vec2(cos(d),sin(d))*Radius*i);          \r
32     }\r
33   }\r
34   \r
35   // Output to screen\r
36   Color /= Quality * Directions - 15.0;\r
37   return Color;\r
38 }\r
39 \r
40 void main()\r
41 {\r
42     if (renderState == 0) {\r
43         FragColor = blur(shadowmapTexture, TexCoords, vec2(screenWidth, screenHeight));\r
44     }\r
45     else if (renderState == 1) {\r
46         FragColor = texture(shadowmapTexture, TexCoords);\r
47     }\r
48     // stencil buffer\r
49     else if (renderState == 2) {\r
50         FragColor = texture(irradianceTexture, TexCoords);\r
51     }\r
52     else if (renderState == 3) {\r
53         vec4 result = vec4(0, 0, 0, 1);\r
54         for (int i = 0; i < 13; i++) {\r
55             vec2 sampleCoords = TexCoords + samplePositions[i] * vec2(1.0/screenWidth, 1.0/screenHeight);\r
56             //vec4 sample = texture(irradianceTexture, sampleCoords)\r
57             //            * texture(shadowmapTexture, sampleCoords);\r
58             vec4 sample = texture(irradianceTexture, sampleCoords);\r
59             vec4 weight = vec4(sampleWeights[i], 1);\r
60             result += sample * weight;\r
61         }\r
62         FragColor = result;\r
63     }\r
64 }\r