5 uniform sampler2D tex0; // 1D distance
6 uniform sampler2D tex1; // background
7 uniform vec2 lightTexSize;
11 #define SOFT_SHADOWS (1.0f)
14 // sample from the 1D distance map
15 //float sample (in vec2 coord, in float r) { return step(r, texture2D(tex0, coord).r); }
16 #define sample(cc_) step(r, texture2D(tex0, vec2(tc.x+(cc_)*blur, tc.y)).r)
20 vec2 vTexCoord0 = gl_TexCoord[0].xy;
21 vec2 btxy = gl_FragCoord.xy/(100.0*8.0);
22 float ltsxi = 1.0/lightTexSize.x;
24 // rectangular to polar
25 vec2 norm = vTexCoord0.st*2.0-1.0;
26 float theta = atan(norm.y, norm.x);
27 float r = length(norm);
28 float coord = (theta+PI)/(2.0*PI);
30 // the tex0 coord to sample our 1D lookup texture
31 // always 0.0 on y axis
32 vec2 tc = vec2(coord, 0.0);
34 // the center tex0 coord, which gives us hard shadows
35 float center = step(r, texture2D(tex0, tc.xy).r); //sample(vec2(tc.x, tc.y), r);
37 // we multiply the blur amount by our distance from center
38 // this leads to more blurriness as the shadow "fades away"
39 float blur = ltsxi*smoothstep(0.0, 1.0, r);
41 // now we use a simple gaussian blur
44 float sum = sample(vec2(tc.x-4.0*blur, tc.y), r)*0.05;
45 sum += sample(vec2(tc.x-3.0*blur, tc.y), r)*0.09;
46 sum += sample(vec2(tc.x-2.0*blur, tc.y), r)*0.12;
47 sum += sample(vec2(tc.x-1.0*blur, tc.y), r)*0.15;
49 sum += sample(vec2(tc.x+1.0*blur, tc.y), r)*0.15;
50 sum += sample(vec2(tc.x+2.0*blur, tc.y), r)*0.12;
51 sum += sample(vec2(tc.x+3.0*blur, tc.y), r)*0.09;
52 sum += sample(vec2(tc.x+4.0*blur, tc.y), r)*0.05;
54 float sum = sample(-4.0)*0.05;
55 sum += sample(-3.0)*0.09;
56 sum += sample(-2.0)*0.12;
57 sum += sample(-1.0)*0.15;
59 sum += sample( 1.0)*0.15;
60 sum += sample( 2.0)*0.12;
61 sum += sample( 3.0)*0.09;
62 sum += sample( 4.0)*0.05;
67 // sum of 1.0 -> in light, 0.0 -> in shadow
68 float lit = mix(center, sum, SOFT_SHADOWS);
70 // multiply the summed amount by our distance, which gives us a radial falloff
71 // then multiply by vertex (light) color
73 //vec4 color = gl_Color*vec4(vec3(1.0), lit*smoothstep(1.0, 0.0, r));
74 lit = lit*smoothstep(1.0, 0.0, r);
75 vec4 bcolor = texture2D(tex1, btxy);
76 if (bcolor.a == 0.0) bcolor = vec4(0.0, 0.0, 0.0, 1.0);
78 if (gl_Color.a == 0.0) {
79 color = bcolor*vec4(vec3(1.0), lit);
82 //vec4 color = bcolor*vec4(vec3(1.0), lit);
83 //vec4 color = bcolor*vec4(vec3(1.0), lit);
84 //color += gl_Color*vec4(vec3(1.0), lit);
87 //color *= gl_Color*vec4(vec3(1.0), lit);
88 //color += bcolor*vec4(vec3(1.0), lit);
91 vec4 ltv = vec4(vec3(1.0), lit);
96 color = mix(color, bcolor, lit);
104 color = mix(bcolor, color, lit);
110 gl_FragColor = color;
111 //float intens = (0.2125*color.x)+(0.7154*color.y)+(0.0721*color.z);
112 //gl_FragColor = vec4(intens, intens, intens, color.w);
113 //gl_FragColor = color;