]> git.tdb.fi Git - libs/gl.git/blob - shaderlib/ambientocclusion_occlude.glsl
Add setup/finish_frame methods to OccludedScene and ZSortedScene
[libs/gl.git] / shaderlib / ambientocclusion_occlude.glsl
1 import postprocess;
2 import ambientocclusion;
3
4 ////// fragment
5 void main()
6 {
7         mat2 transform = mat2(texture(rotate, texcoord*screen_size/4.0)*2.0-1.0)
8                 *mat2(screen_size.y/screen_size.x, 0.0, 0.0, 1.0)*3.0/screen_size.y;
9         float sample = depth_ratio.x/(texture(depth, texcoord).r-depth_ratio.y);
10         float sum = 0.0;
11         for(int i=0; i<=3; ++i)
12                 for(int j=0; j<=3; ++j)
13                 {
14                         vec2 offs = transform*vec2(float(i)-1.5, float(j)-1.5);
15                         float dxy = length(offs)*-sample;
16                         float dz = depth_ratio.x/(texture(depth, texcoord+offs).r-depth_ratio.y)-sample;
17                         if(abs(dz)<3.0*dxy)
18                                 sum += atan(dz/dxy)/1.570796;
19                         else if(dz<0.0)
20                                 sum -= 0.8;
21                 }
22         frag_color = vec4(min(1.0-sum*darkness/16.0, 1.0), 0.0, 0.0, 1.0);
23 }