/
dgl_draw.fsh
100 lines (91 loc) · 3.05 KB
/
dgl_draw.fsh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
/*
* The Doomsday Engine Project
* Common OpenGL Shaders: Legacy DGL Drawing
*
* Copyright (c) 2017 Jaakko Keränen <jaakko.keranen@iki.fi>
*
* @par License
* LGPL: http://www.gnu.org/licenses/lgpl.html
*
* <small>This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; either version 3 of the License, or (at your
* option) any later version. This program is distributed in the hope that it
* will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty
* of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser
* General Public License for more details. You should have received a copy of
* the GNU Lesser General Public License along with this program; if not, see:
* http://www.gnu.org/licenses</small>
*/
#version 330
#include "../include/fog.glsl"
uniform int uTexEnabled;
uniform int uTexMode;
uniform vec4 uTexModeColor;
uniform float uAlphaLimit;
uniform sampler2D uTex0;
uniform sampler2D uTex1;
in vec4 vColor;
in vec2 vTexCoord[2];
void main()
{
out_FragColor = vColor;
// Colors from textures.
vec4 texColor[2] = vec4[2] (vec4(1.0), vec4(1.0));
if ((uTexEnabled & 0x1) != 0) {
texColor[0] = texture(uTex0, vTexCoord[0]);
}
if ((uTexEnabled & 0x2) != 0) {
texColor[1] = texture(uTex1, vTexCoord[1]);
}
// Modulate the texture colors in the requested manner.
switch (uTexMode) {
case 0:
// No modulation: just replace with texture.
out_FragColor = texColor[0];
break;
case 1:
// Normal texture modulation with primary color.
out_FragColor *= texColor[0];
break;
case 2:
// Texture interpolation and modulation with primary color.
out_FragColor.rgb *= mix(texColor[0].rgb, texColor[1].rgb, uTexModeColor.a);
break;
case 3:
// Texture interpolation.
out_FragColor.rgb = mix(texColor[0].rgb, texColor[1].rgb, uTexModeColor.a);
break;
case 4:
// Sector light, dynamic light, and texture.
out_FragColor.rgb += texColor[0].a * uTexModeColor.rgb;
out_FragColor *= texColor[1];
break;
case 6:
// Simple dynlight addition (add to primary color).
out_FragColor.rgb += texColor[0].a * uTexModeColor.rgb;
break;
case 8:
// Texture and Detail.
out_FragColor *= texColor[0];
out_FragColor.rgb *= texColor[1].rgb * 2.0;
break;
case 10:
// Sector light * texture + dynamic light.
out_FragColor *= texColor[0];
out_FragColor.rgb += texColor[1].rgb * uTexModeColor.rgb;
break;
case 11:
// Normal modulation, alpha of 2nd stage.
// Tex0: texture
// Tex1: shiny texture
out_FragColor.rgb *= texColor[1].rgb;
out_FragColor.a *= texColor[0].a;
break;
}
// Alpha test.
if (out_FragColor.a <= uAlphaLimit) {
discard;
}
applyFog();
}