added license to scripts and shaders
[dd2d.git] / data / shaders / srlight_final.frag
blob2e5908454b272e3af19982d33020cba6ae21c3b1
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.
4  *
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.
9  *
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.
14  *
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/>.
17  */
18 #version 130
20 #define PI 3.1415926
22 uniform sampler2D tex0; // light
23 uniform sampler2D tex1; // background+foreground
24 uniform sampler2D tex2; // occluders (y-mirrored)
25 uniform vec2 mapPixSize;
29   texture 0 is light (fboLevelLight)
30   texture 1 is background (with all occluders and foreground walls, i.e. what player will see unlit) (fboOrigBack)
31   texture 2 is light mask (fboBackground)
32   shader will look at t2, and
33     if it is occluded, will calc intensity to compensate self-shadowing
34     else take background pixel, blend it with light and draw as-is
38 void main (void) {
39   vec2 vTexCoord0 = gl_TexCoord[0].xy;
40   vec2 btxy = gl_FragCoord.xy/mapPixSize;
41   vec2 lmxy = vec2(btxy.x, 1.0-btxy.y); // occluders, mirrored
43   // if this pixel is not occluded, just blend light
44   if (texture2D(tex2, lmxy).a == 0.0) {
45     // simple light blending
46     vec4 clr = texture2D(tex0, btxy);
47     /*
48     if (clr.r+clr.g+clr.b != 0.0) {
49       clr.a = 0.5;
50     }
51     */
52     //clr.a = 1.0;
53     //clr.r = 1.0;
54     gl_FragColor = clr;
55   } else {
56     // occluded, complex light
57     /*
58     vec4 lcolor = texture2D(tex2, lmxy);
59     if (lcolor.a == 0.0) discard;
60     gl_FragColor = lcolor;
61     */
62     discard;
63   }
64   //gl_FragColor = texture2D(tex0, btxy);
65   //gl_FragColor = texture2D(tex1, btxy);
66   //gl_FragColor = texture2D(tex2, lmxy);