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 vec2 lightPos; // light coords in occluders map
31 uniform vec2 mapPixSize; // size of occluders map
33 // alpha threshold for our occlusion map
34 #define THRESHOLD (0.75)
38 //float dmposx = gl_TexCoord[0].x;
39 vec2 ltPos = lightPos/mapPixSize;
40 /*if (texture2D(texOccFull, ltPos).a > THRESHOLD) {
41 gl_FragColor = vec4(vec3(1.0), 1.0);
44 float dmposx = gl_FragCoord.x/lightTexSize.x;
45 // theta: 90 and greater
47 float theta = 360.0*dmposx;
48 theta += 90; // turn it
49 theta = PI*theta/180.0; // to radians
51 float theta = PI*1.5+(dmposx*2.0-1.0)*PI;
53 float nsint = -sin(theta);
54 float ncost = cos(theta);
56 for (dst = 0.0; dst < lightTexSize.x/2.0; dst += 1.0) {
57 // sample the occlusion map
58 ltPos = (lightPos+vec2(nsint*dst, ncost*dst))/mapPixSize;
59 float dataa = texture2D(texOccFull, ltPos).a;
60 // if we've hit an opaque fragment (occluder), then get new distance
61 // if the new distance is below the current, then we'll use that for our ray
62 if (dataa > THRESHOLD) {
64 // if we hit occluders, trace through it for some more steps, so blur will look better on hitpoints
66 for (float count = 0.0; count <= INTO_DEPTH; count += 1.0) {
68 ltPos = (lightPos+vec2(nsint*dst, ncost*dst))/mapPixSize;
69 dataa = texture2D(texOccFull, ltPos).a;
70 if (dataa <= THRESHOLD) {
76 //dst = max(0.0, dst-ltsyStep);
77 //dst = max(0.0, dst-1.0);
79 break; // the current distance is how far from the top we've come
82 dst /= lightTexSize.x;
85 gl_FragColor = vec4(vec3(dst), 1.0);