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