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;
17 float ltsyStep = 1.0/ltsy;
19 for (float y = 0.0; y < ltsy; y += 1.0, yinv += ltsyStep) {
20 // rectangular to polar filter
21 //vec2 norm = vec2(vTexCoord0.s, /*y/ltsy*/yinv)*2.0-1.0;
22 vec2 norm = vec2(vTexCoord0.s, y/ltsy)*2.0-1.0;
23 float theta = PI*1.5+norm.x*PI;
24 float r = (1.0+norm.y)*0.5;
25 // coord which we will sample from occlude map
26 vec2 coord = vec2(-r*sin(theta), -r*cos(theta))/2.0+0.5;
27 // sample the occlusion map
28 vec4 data = texture2D(tex0, coord);
29 // if we've hit an opaque fragment (occluder), then get new distance
30 // if the new distance is below the current, then we'll use that for our ray
31 float caster = data.a;
32 if (caster > THRESHOLD) {
33 // the current distance is how far from the top we've come
34 float dst = y/ltsy; // /upScale
35 distance = min(distance, dst);
38 gl_FragColor = vec4(vec3(distance), 1.0);