X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=builtin_data%2F_ambientocclusion_combine.glsl;fp=builtin_data%2F_ambientocclusion_combine.glsl;h=616bada9e4b88b5cda6c5b139a363bd1a907d261;hb=9a63244c1342337915c4610401a24c09fa72cc3d;hp=0000000000000000000000000000000000000000;hpb=73bef37da97b6da0b99227f63235cb52c4e56c44;p=libs%2Fgl.git diff --git a/builtin_data/_ambientocclusion_combine.glsl b/builtin_data/_ambientocclusion_combine.glsl new file mode 100644 index 00000000..616bada9 --- /dev/null +++ b/builtin_data/_ambientocclusion_combine.glsl @@ -0,0 +1,29 @@ +import postprocess; +import _ambientocclusion; + +#pragma MSP stage(fragment) +void main() +{ + vec3 center = unproject(vec3(vertex.xy, texture(depth, texcoord).r)); + 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), 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; + count += 1.0; + } + } + vec4 src_color = texture(source, texcoord); + frag_color = vec4(src_color.rgb*mix(1.0, min(sum*2.0/count, 1.0), darkness), src_color.a); +}