5 uniform sampler2D tex0; // 1D distance
6 uniform sampler2D tex1; // background
7 uniform vec2 lightTexSize;
8 uniform bool shadowDoBloor;
11 const float softShadows = 1.0f;
14 // sample from the 1D distance map
15 float sample (vec2 coord, float r) {
16 return step(r, texture2D(tex0, coord).r);
21 vec2 vTexCoord0 = gl_TexCoord[0].xy;
22 vec2 btxy = gl_FragCoord.xy/(100.0*8.0);
23 float ltsxi = 1.0/lightTexSize.x;
25 // rectangular to polar
26 vec2 norm = vTexCoord0.st*2.0-1.0;
27 float theta = atan(norm.y, norm.x);
28 float r = length(norm);
29 float coord = (theta+PI)/(2.0*PI);
31 // the tex0 coord to sample our 1D lookup texture
32 // always 0.0 on y axis
33 vec2 tc = vec2(coord, 0.0);
35 // the center tex0 coord, which gives us hard shadows
36 float center = sample(vec2(tc.x, tc.y), r);
38 // we multiply the blur amount by our distance from center
39 // this leads to more blurriness as the shadow "fades away"
40 float blur = ltsxi*smoothstep(0.0, 1.0, r);
42 // now we use a simple gaussian blur
45 sum += sample(vec2(tc.x-4.0*blur, tc.y), r)*0.05;
46 sum += sample(vec2(tc.x-3.0*blur, tc.y), r)*0.09;
47 sum += sample(vec2(tc.x-2.0*blur, tc.y), r)*0.12;
48 sum += sample(vec2(tc.x-1.0*blur, tc.y), r)*0.15;
50 sum += sample(vec2(tc.x+1.0*blur, tc.y), r)*0.15;
51 sum += sample(vec2(tc.x+2.0*blur, tc.y), r)*0.12;
52 sum += sample(vec2(tc.x+3.0*blur, tc.y), r)*0.09;
53 sum += sample(vec2(tc.x+4.0*blur, tc.y), r)*0.05;
58 // sum of 1.0 -> in light, 0.0 -> in shadow
59 float lit = mix(center, sum, softShadows);
61 // multiply the summed amount by our distance, which gives us a radial falloff
62 // then multiply by vertex (light) color
64 //vec4 color = gl_Color*vec4(vec3(1.0), lit*smoothstep(1.0, 0.0, r));
65 lit = lit*smoothstep(1.0, 0.0, r);
66 vec4 bcolor = texture2D(tex1, btxy);
67 if (bcolor.a == 0.0) bcolor = vec4(0.0, 0.0, 0.0, 1.0);
69 if (gl_Color.a == 0.0) {
70 color = bcolor*vec4(vec3(1.0), lit);
73 //vec4 color = bcolor*vec4(vec3(1.0), lit);
74 //vec4 color = bcolor*vec4(vec3(1.0), lit);
75 //color += gl_Color*vec4(vec3(1.0), lit);
78 //color *= gl_Color*vec4(vec3(1.0), lit);
79 //color += bcolor*vec4(vec3(1.0), lit);
82 vec4 ltv = vec4(vec3(1.0), lit);
87 color = mix(color, bcolor, lit);
95 color = mix(bcolor, color, lit);
101 gl_FragColor = color;
102 //float intens = (0.2125*color.x)+(0.7154*color.y)+(0.0721*color.z);
103 //gl_FragColor = vec4(intens, intens, intens, color.w);
104 //gl_FragColor = color;