X-Git-Url: http://git.tdb.fi/?p=libs%2Fgl.git;a=blobdiff_plain;f=shaderlib%2Fambientocclusion_occlude.glsl;h=2a10bde34613cb9cd933c2caa437c6cc781ff162;hp=f9b755c9c7b71d0667dae0c940cd275b87c69ad0;hb=73bef37da97b6da0b99227f63235cb52c4e56c44;hpb=e55f79ccb21e8c1be3d86f127e3ec1583e58ce92 diff --git a/shaderlib/ambientocclusion_occlude.glsl b/shaderlib/ambientocclusion_occlude.glsl index f9b755c9..2a10bde3 100644 --- a/shaderlib/ambientocclusion_occlude.glsl +++ b/shaderlib/ambientocclusion_occlude.glsl @@ -1,23 +1,25 @@ import postprocess; import ambientocclusion; -////// fragment +#pragma MSP stage(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) + vec4 rv = texture(rotate, gl_FragCoord.xy/4.0)*2.0-1.0; + mat3 transform = mat3(rv.xy, 0.0, rv.zx, 0.0, 0.0, 0.0, rv.w)*occlusion_radius; + vec3 center = unproject(vec3(vertex.xy, texture(depth, texcoord).r)); + float min_depth = project(vec3(center.xy, center.z+occlusion_radius)).z; + float occlusion_sum = 0.0; + float count = 0.0; + for(int i=0; i=min_depth) { - 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; + if(sample