]> git.tdb.fi Git - libs/gl.git/blob - shaderlib/ambientocclusion_combine.glsl
Better naming algorithm for objects in scene export
[libs/gl.git] / shaderlib / ambientocclusion_combine.glsl
1 import postprocess;
2 import ambientocclusion;
3
4 #pragma MSP stage(fragment)
5 void main()
6 {
7         vec3 center = unproject(vec3(vertex.xy, texture(depth, texcoord).r));
8         float min_depth = project(vec3(center.xy, center.z+occlusion_radius*0.1)).z;
9         float max_depth = project(vec3(center.xy, center.z-occlusion_radius*0.1)).z;
10         vec2 tex_scale = 1.0/vec2(textureSize(occlusion, 0));
11         float sum = 0.0;
12         float count = 0.0;
13         for(int i=0; i<4; ++i)
14                 for(int j=0; j<4; ++j)
15                 {
16                         vec2 offset = vec2(float(i)-1.5, float(j)-1.5)*tex_scale;
17                         float occ = texture(occlusion, texcoord+offset).r;
18                         float sample = texture(depth, texcoord+offset).r;
19                         if(sample>=min_depth && sample<=max_depth)
20                         {
21                                 sum += occ;
22                                 count += 1.0;
23                         }
24                 }
25         vec4 src_color = texture(source, texcoord);
26         frag_color = vec4(src_color.rgb*mix(1.0, min(sum*2.0/count, 1.0), darkness), src_color.a);
27 }