]> git.tdb.fi Git - libs/gl.git/blob - builtin_data/_ambientocclusion_combine.glsl
Copy the location when moving output declarations out of functions
[libs/gl.git] / builtin_data / _ambientocclusion_combine.glsl
1 import postprocess;
2 import _ambientocclusion;
3
4 #pragma MSP stage(fragment)
5 void main()
6 {
7         vec3 center = unproject(vec3(vertex.xy, texture(depth, texcoord).r));
8         vec2 tex_scale = 1.0/vec2(textureSize(occlusion, 0));
9         float sum = 0.0;
10         float count = 0.0;
11         for(int i=0; i<4; ++i)
12                 for(int j=0; j<4; ++j)
13                 {
14                         vec2 offset = vec2(float(i), float(j))-1.5;
15                         vec2 sample_coord = texcoord+offset*tex_scale;
16                         float occ = texture(occlusion, sample_coord).r;
17                         float sample = texture(depth, sample_coord).r;
18                         float z_range = occlusion_radius*length(offset)*edge_depth_threshold;
19                         float min_depth = project(vec3(center.xy, center.z+z_range)).z;
20                         float max_depth = project(vec3(center.xy, center.z-z_range)).z;
21                         if(sample>=min_depth && sample<=max_depth)
22                         {
23                                 sum += occ;
24                                 count += 1.0;
25                         }
26                 }
27         vec4 src_color = texture(source, texcoord);
28         frag_color = vec4(src_color.rgb*mix(1.0, min(sum*2.0/count, 1.0), darkness), src_color.a);
29 }