X-Git-Url: http://git.tdb.fi/?p=libs%2Fgl.git;a=blobdiff_plain;f=shaderlib%2Fambientocclusion_combine.glsl;h=c1e7f27270a1388703ac8cc744901278180f2ac3;hp=f56bddbc520809cc37ca6ae8d0ca7753751907d6;hb=6a832fe1771f8c7bca0faa0d383fbbab062a1c56;hpb=12f65b4a7cd9739d399c685d22862297f325ca91 diff --git a/shaderlib/ambientocclusion_combine.glsl b/shaderlib/ambientocclusion_combine.glsl index f56bddbc..c1e7f272 100644 --- a/shaderlib/ambientocclusion_combine.glsl +++ b/shaderlib/ambientocclusion_combine.glsl @@ -1,21 +1,23 @@ import postprocess; import ambientocclusion; -////// fragment +#pragma MSP stage(fragment) void main() { vec3 center = unproject(vec3(vertex.xy, texture(depth, texcoord).r)); - float min_depth = project(vec3(center.xy, center.z+occlusion_radius*0.1)).z; - float max_depth = project(vec3(center.xy, center.z-occlusion_radius*0.1)).z; vec2 tex_scale = 1.0/vec2(textureSize(occlusion, 0)); float sum = 0.0; float count = 0.0; for(int i=0; i<4; ++i) for(int j=0; j<4; ++j) { - vec2 offset = vec2(float(i)-1.5, float(j)-1.5)*tex_scale; - float occ = texture(occlusion, texcoord+offset).r; - float sample = texture(depth, texcoord+offset).r; + 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) { sum += occ;