]> git.tdb.fi Git - libs/gl.git/blobdiff - shaderlib/ambientocclusion_combine.glsl
Move postprocessor shaders to the builtin shaderlib
[libs/gl.git] / shaderlib / ambientocclusion_combine.glsl
diff --git a/shaderlib/ambientocclusion_combine.glsl b/shaderlib/ambientocclusion_combine.glsl
new file mode 100644 (file)
index 0000000..572ba2f
--- /dev/null
@@ -0,0 +1,23 @@
+import postprocess;
+import ambientocclusion;
+
+////// fragment
+void main()
+{
+       float sample = depth_ratio.x/(texture(depth, texcoord).r-depth_ratio.y);
+       float sum = 1.0;
+       float count = 1.0;
+       for(int i=0; i<=3; ++i)
+               for(int j=0; j<=3; ++j)
+               {
+                       vec2 offs = vec2(float(i)-1.5, float(j)-1.5)/screen_size;
+                       float dxy = length(offs)*-sample;
+                       float dz = depth_ratio.x/(texture(depth, texcoord+offs).r-depth_ratio.y)-sample;
+                       if(abs(dz)<3.0*dxy)
+                       {
+                               sum += texture(occlusion, texcoord+offs).r;
+                               count += 1.0;
+                       }
+               }
+       frag_color = texture(source, texcoord)*sum/count;
+}