X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=shaderlib%2Fambientocclusion_occlude.glsl;fp=shaderlib%2Fambientocclusion_occlude.glsl;h=f9b755c9c7b71d0667dae0c940cd275b87c69ad0;hb=e55f79ccb21e8c1be3d86f127e3ec1583e58ce92;hp=0000000000000000000000000000000000000000;hpb=b2764a3a349b48d7445202faa903383386c09a4c;p=libs%2Fgl.git diff --git a/shaderlib/ambientocclusion_occlude.glsl b/shaderlib/ambientocclusion_occlude.glsl new file mode 100644 index 00000000..f9b755c9 --- /dev/null +++ b/shaderlib/ambientocclusion_occlude.glsl @@ -0,0 +1,23 @@ +import postprocess; +import ambientocclusion; + +////// fragment +void main() +{ + mat2 transform = mat2(texture(rotate, texcoord*screen_size/4.0)*2.0-1.0) + *mat2(screen_size.y/screen_size.x, 0.0, 0.0, 1.0)*3.0/screen_size.y; + float sample = depth_ratio.x/(texture(depth, texcoord).r-depth_ratio.y); + float sum = 0.0; + for(int i=0; i<=3; ++i) + for(int j=0; j<=3; ++j) + { + vec2 offs = transform*vec2(float(i)-1.5, float(j)-1.5); + 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) + sum += atan(dz/dxy)/1.570796; + else if(dz<0.0) + sum -= 0.8; + } + frag_color = vec4(min(1.0-sum*darkness/16.0, 1.0), 0.0, 0.0, 1.0); +}