- vec2 offs = vec2(float(i)-1.5, float(j)-1.5)/screen_size;
- float dxy = length(offs)*-sample;
- float dz = depth_ratio.x/(texture(depth, texcoord+offs).r-depth_ratio.y)-sample;
- if(abs(dz)<3.0*dxy)
+ vec2 offset = vec2(float(i), float(j))-1.5;
+ vec2 sample_coord = texcoord+offset*tex_scale;
+ float occ = texture(occlusion, sample_coord).r;
+ float sample = texture(depth, sample_coord).r;
+ float z_range = occlusion_radius*length(offset)*edge_depth_threshold;
+ float min_depth = project(vec3(center.xy, center.z+z_range)).z;
+ float max_depth = project(vec3(center.xy, center.z-z_range)).z;
+ if(sample>=min_depth && sample<=max_depth)