1 /* DooM2D: Midnight on the Firing Line
2 * coded by Ketmar // Invisible Vector <ketmar@ketmar.no-ip.org>
3 * Understanding is not required. Only obedience.
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
20 #define HUMANIOD_THETA
22 #define INTO_DEPTH (4.0)
24 #define PI (3.14159265)
26 //uniform sampler2D texOcc;
27 uniform vec2 lightTexSize;
29 uniform sampler2D texOccFull; // occluders map, full
30 uniform sampler2D texOccSmall; // occluders, small map
31 uniform vec2 lightPos; // light coords in occluders map
32 uniform vec2 mapPixSize; // size of occluders map
34 // alpha threshold for our occlusion map
35 #define THRESHOLD (0.75)
39 //float dmposx = gl_TexCoord[0].x;
40 //vec2 ltPos = lightPos/mapPixSize;
41 /*if (texture2D(texOccFull, ltPos).a > THRESHOLD) {
42 gl_FragColor = vec4(vec3(1.0), 1.0);
46 float dmposx = gl_FragCoord.x/lightTexSize.x;
47 // theta: 90 and greater
49 float theta = 360.0*dmposx;
50 theta += 90; // turn it
51 //theta = PI*theta/180.0; // to radians
52 theta = radians(theta);
54 float theta = PI*1.5+(dmposx*2.0-1.0)*PI;
56 float nsint = -sin(theta);
57 float ncost = cos(theta);
59 while (dst < lightTexSize.x/2.0) {
60 // sample the occlusion map
61 ltPos = lightPos+vec2(nsint*dst, ncost*dst);
62 vec2 ltsmPos = vec2(floor(ltPos.x/8), floor(ltPos.y/8));
63 ltsmPos = ltsmPos*8+0.5;
64 if (texture2D(texOccSmall, ltsmPos/mapPixSize).a <= THRESHOLD) {
65 //dst = min(dst+8.0, lightTexSize.x/2.0);
69 float dataa = texture2D(texOccFull, ltPos).a;
70 // if we've hit an opaque fragment (occluder), then get new distance
71 // if the new distance is below the current, then we'll use that for our ray
72 if (dataa > THRESHOLD) {
74 // if we hit occluders, trace through it for some more steps, so blur will look better on hitpoints
76 for (float count = 0.0; count <= INTO_DEPTH; count += 1.0) {
78 ltPos = (lightPos+vec2(nsint*dst, ncost*dst))/mapPixSize;
79 dataa = texture2D(texOccFull, ltPos).a;
80 if (dataa <= THRESHOLD) {
86 //dst = max(0.0, dst-ltsyStep);
87 //dst = max(0.0, dst-1.0);
89 break; // the current distance is how far from the top we've come
94 //dst = distance(lightPos, lightPos+vec2(nsint*dst, ncost*dst));
95 dst /= lightTexSize.x;
98 gl_FragColor = vec4(vec3(dst), 1.0);