2 import ambientocclusion;
7 vec3 center = unproject(vec3(vertex.xy, texture(depth, texcoord).r));
8 float min_depth = project(vec3(center.xy, center.z+occlusion_radius*0.1)).z;
9 float max_depth = project(vec3(center.xy, center.z-occlusion_radius*0.1)).z;
10 vec2 tex_scale = 1.0/vec2(textureSize(occlusion, 0));
13 for(int i=0; i<4; ++i)
14 for(int j=0; j<4; ++j)
16 vec2 offset = vec2(float(i)-1.5, float(j)-1.5)*tex_scale;
17 float occ = texture(occlusion, texcoord+offset).r;
18 float depth = texture(depth, texcoord+offset).r;
19 if(depth>=min_depth && depth<=max_depth)
25 vec4 src_color = texture(source, texcoord);
26 frag_color = vec4(src_color.rgb*mix(1.0, min(sum*2.0/count, 1.0), darkness), src_color.a);