]> gitweb.ps.run Git - subsurface_scattering/blobdiff - shaders/fbo_frag.glsl
fix translucency, add gaussian blur to shader
[subsurface_scattering] / shaders / fbo_frag.glsl
index e199245cec69ff67c2d8a394449ecb399e3b4c94..11029923d8555e7017f756de2f733484597f0acc 100644 (file)
@@ -11,24 +11,51 @@ uniform int renderState;
 uniform vec2 samplePositions[13];\r
 uniform vec3 sampleWeights[13];\r
 \r
+vec4 blur(sampler2D tex, vec2 uv, vec2 res) {\r
+  float Pi = 6.28318530718; // Pi*2\r
+    \r
+  // GAUSSIAN BLUR SETTINGS {{{\r
+  float Directions = 16.0; // BLUR DIRECTIONS (Default 16.0 - More is better but slower)\r
+  float Quality = 4.0; // BLUR QUALITY (Default 4.0 - More is better but slower)\r
+  float Size = 8.0; // BLUR SIZE (Radius)\r
+  // GAUSSIAN BLUR SETTINGS }}}\r
+  \r
+  vec2 Radius = Size/res;\r
+  \r
+  // Pixel colour\r
+  vec4 Color = texture(tex, uv);\r
+  \r
+  // Blur calculations\r
+  for( float d=0.0; d<Pi; d+=Pi/Directions) {\r
+    for(float i=1.0/Quality; i<=1.0; i+=1.0/Quality) {\r
+      Color += texture( tex, uv+vec2(cos(d),sin(d))*Radius*i);         \r
+    }\r
+  }\r
+  \r
+  // Output to screen\r
+  Color /= Quality * Directions - 15.0;\r
+  return Color;\r
+}\r
+\r
 void main()\r
 {\r
     if (renderState == 0) {\r
+        FragColor = blur(shadowmapTexture, TexCoords, vec2(screenWidth, screenHeight));\r
+    }\r
+    else if (renderState == 1) {\r
         FragColor = texture(shadowmapTexture, TexCoords);\r
     }\r
     // stencil buffer\r
-    else if (renderState == 1 || texture(irradianceTexture, TexCoords).rgb == vec3(0, 0, 0)) {\r
-        FragColor = texture(irradianceTexture, TexCoords);\r
-    }\r
     else if (renderState == 2) {\r
-        FragColor = texture(shadowmapTexture, TexCoords) * texture(irradianceTexture, TexCoords);\r
+        FragColor = texture(irradianceTexture, TexCoords);\r
     }\r
     else if (renderState == 3) {\r
         vec4 result = vec4(0, 0, 0, 1);\r
         for (int i = 0; i < 13; i++) {\r
-            float oneX = 1.0/screenWidth;\r
-            float oneY = 1.0/screenHeight;\r
-            vec4 sample = texture(irradianceTexture, TexCoords + samplePositions[i] * vec2(oneX, oneY));\r
+            vec2 sampleCoords = TexCoords + samplePositions[i] * vec2(1.0/screenWidth, 1.0/screenHeight);\r
+            //vec4 sample = texture(irradianceTexture, sampleCoords)\r
+            //            * texture(shadowmapTexture, sampleCoords);\r
+            vec4 sample = texture(irradianceTexture, sampleCoords);\r
             vec4 weight = vec4(sampleWeights[i], 1);\r
             result += sample * weight;\r
         }\r