]> git.tdb.fi Git - libs/gl.git/blob - shaderlib/ambientocclusion_combine.glsl
Move postprocessor shaders to the builtin shaderlib
[libs/gl.git] / shaderlib / ambientocclusion_combine.glsl
1 import postprocess;
2 import ambientocclusion;
3
4 ////// fragment
5 void main()
6 {
7         float sample = depth_ratio.x/(texture(depth, texcoord).r-depth_ratio.y);
8         float sum = 1.0;
9         float count = 1.0;
10         for(int i=0; i<=3; ++i)
11                 for(int j=0; j<=3; ++j)
12                 {
13                         vec2 offs = vec2(float(i)-1.5, float(j)-1.5)/screen_size;
14                         float dxy = length(offs)*-sample;
15                         float dz = depth_ratio.x/(texture(depth, texcoord+offs).r-depth_ratio.y)-sample;
16                         if(abs(dz)<3.0*dxy)
17                         {
18                                 sum += texture(occlusion, texcoord+offs).r;
19                                 count += 1.0;
20                         }
21                 }
22         frag_color = texture(source, texcoord)*sum/count;
23 }