]> git.tdb.fi Git - libs/gl.git/blob - builtin_data/_ambientocclusion_occlude.glsl
Rearrange postprocessing shaders
[libs/gl.git] / builtin_data / _ambientocclusion_occlude.glsl
1 import flat_effect;
2 import _ambientocclusion;
3
4 #pragma MSP stage(fragment)
5 layout(location=0) out float frag_out;
6 void main()
7 {
8         vec4 rv = texture(rotate, gl_FragCoord.xy/4.0)*2.0-1.0;
9         mat3 transform = mat3(rv.xy, 0.0, rv.zx, 0.0, 0.0, 0.0, rv.w)*occlusion_radius;
10         vec3 center = unproject(vec3(vertex.xy, texture(depth, texcoord).r));
11         float min_depth = project(vec3(center.xy, center.z+occlusion_radius)).z;
12         float occlusion_sum = 0.0;
13         float count = 0.0;
14         for(int i=0; i<n_samples; ++i)
15         {
16                 vec3 psp = project(center+transform*sample_points[i]);
17                 float sample = texture(depth, psp.xy*0.5+0.5).r;
18                 if(sample>=min_depth)
19                 {
20                         if(sample<psp.z)
21                                 occlusion_sum += 1.0;
22                         count += 1.0;
23                 }
24         }
25         frag_out = 1.0-occlusion_sum/count;
26 }