8 ===========================================================================
9 Copyright (C) 2006 Robert Beckebans <trebor_7@users.sourceforge.net>
11 This file is part of XreaL source code.
13 XreaL source code is free software; you can redistribute it
14 and/or modify it under the terms of the GNU General Public License as
15 published by the Free Software Foundation; either version 2 of the License,
16 or (at your option) any later version.
18 XreaL source code is distributed in the hope that it will be
19 useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
20 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 GNU General Public License for more details.
23 You should have received a copy of the GNU General Public License
24 along with XreaL source code; if not, write to the Free Software
25 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
26 ===========================================================================
29 uniform sampler2D u_DiffuseMap;
30 uniform sampler2D u_BumpMap;
31 uniform sampler2D u_AttenuationMapXY;
32 uniform sampler2D u_AttenuationMapZ;
33 uniform vec3 u_LightOrigin;
34 uniform vec3 u_LightColor;
35 uniform float u_LightScale;
37 varying vec3 var_Vertex;
38 varying vec2 var_TexDiffuse;
39 varying vec2 var_TexBump;
40 varying vec4 var_TexAtten;
41 varying mat3 var_OS2TSMatrix;
45 // compute light direction in tangent space
46 vec3 L = normalize(var_OS2TSMatrix * (u_LightOrigin - var_Vertex));
48 // compute normal in tangent space from bumpmap
49 vec3 N = 2.0 * (texture2D(u_BumpMap, var_TexBump).xyz - 0.5);
52 // compute the diffuse term
53 vec4 diffuse = texture2D(u_DiffuseMap, var_TexDiffuse);
54 diffuse.rgb *= u_LightColor * clamp(dot(N, L), 0.0, 1.0);
56 // compute attenuation
57 // vec3 attenuationXY = texture2D(u_AttenuationMapXY, var_TexAtten.xy).rgb;
58 vec3 attenuationXY = texture2DProj(u_AttenuationMapXY, vec3(var_TexAtten.x, var_TexAtten.y, var_TexAtten.w)).rgb;
59 vec3 attenuationZ = texture2D(u_AttenuationMapZ, vec2(var_TexAtten.z, 0)).rgb;
61 // compute final color
63 color.rgb *= attenuationXY;
64 color.rgb *= attenuationZ;
65 color.rgb *= u_LightScale;