5 uniform sampler2D tex0;
6 uniform vec2 lightTexSize;
9 // alpha threshold for our occlusion map
10 const float THRESHOLD = 0.75;
14 vec2 vTexCoord0 = gl_TexCoord[0].xy;
16 float ltsy = lightTexSize.y;
18 for (float y = 0.0; y < ltsy; y += 1.0) {
19 float yy = ltsy-y-1.0;
20 // rectangular to polar filter
21 vec2 norm = vec2(vTexCoord0.s, y/ltsy)*2.0-1.0;
22 float theta = PI*1.5+norm.x*PI;
23 float r = (1.0+norm.y)*0.5;
24 // coord which we will sample from occlude map
25 vec2 coord = vec2(-r*sin(theta), -r*cos(theta))/2.0+0.5;
26 // sample the occlusion map
27 vec4 data = texture2D(tex0, coord);
28 // if we've hit an opaque fragment (occluder), then get new distance
29 // if the new distance is below the current, then we'll use that for our ray
30 float caster = data.a;
31 if (caster > THRESHOLD) {
32 // the current distance is how far from the top we've come
33 float dst = y/ltsy; // /upScale
34 distance = min(distance, dst);
37 gl_FragColor = vec4(vec3(distance), 1.0);