Debian Codegraph @

pak6-patch088/glsl/texturing.glsl

raw
1 #version 120
2 /*
3 * texturing.glsl
4 * shared texturing routines
5 * Copyright (C) 2010 Jens Loehr <[email protected]>
6 *
7 * This program is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU General Public License as published by the
9 * Free Software Foundation; either version 2 of the License, or (at your
10 * option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
15 * Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License along
18 * with this program; if not, write to the Free Software Foundation, Inc.,
19 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20 */
21
22 /* multi-texturing modes */
23 #define REPLACE 0
24 #define MODULATE 1
25 #define DECAL 2
26 #define BLEND 3
27 #define ADD 4
28 #define COMBINE 5
29
30 vec4 applyTexture2D(sampler2D textureUnit, int type, int index, vec4 color) {
31 vec4 texture = texture2D(textureUnit, gl_TexCoord[index].st);
32
33 if (type == REPLACE) {
34 color = texture;
35 } else if (type == MODULATE) {
36 color *= texture;
37 } else if (type == DECAL) {
38 color = vec4(mix(color.rgb, texture.rgb, texture.a), color.a);
39 } else if (type == BLEND) {
40 color = vec4(mix(color.rgb, gl_TextureEnvColor[index].rgb, texture.rgb), color.a * texture.a);
41 } else if (type == ADD) {
42 color.rgb += texture.rgb;
43 color.a *= texture.a;
44
45 color = clamp(color, 0.0, 1.0);
46 } else {
47 color = clamp(texture * color, 0.0, 1.0);
48 }
49
50 return color;
51 }