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
|
/*
===========================================================================
Copyright (C) 2006 Robert Beckebans <trebor_7@users.sourceforge.net>
This file is part of XreaL source code.
XreaL source code is free software; you can redistribute it
and/or modify it under the terms of the GNU General Public License as
published by the Free Software Foundation; either version 2 of the License,
or (at your option) any later version.
XreaL source code 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 General Public License for more details.
You should have received a copy of the GNU General Public License
along with XreaL source code; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
===========================================================================
*/
uniform sampler2D u_DiffuseMap;
uniform sampler2D u_AttenuationMapXY;
uniform sampler2D u_AttenuationMapZ;
uniform vec3 u_LightOrigin;
uniform vec3 u_LightColor;
uniform float u_LightScale;
varying vec3 var_Vertex;
varying vec3 var_Normal;
varying vec2 var_TexDiffuse;
varying vec4 var_TexAtten;
void main()
{
// compute light direction in tangent space
vec3 L = normalize(u_LightOrigin - var_Vertex);
// compute normal in tangent space from normalmap
vec3 N = normalize(var_Normal);
// compute the diffuse term
vec4 diffuse = texture2D(u_DiffuseMap, var_TexDiffuse);
diffuse.rgb *= u_LightColor * clamp(dot(N, L), 0.0, 1.0);
// compute attenuation
// vec3 attenuationXY = texture2D(u_AttenuationMapXY, var_TexAtten.xy).rgb;
vec3 attenuationXY = texture2DProj(u_AttenuationMapXY, vec3(var_TexAtten.x, var_TexAtten.y, var_TexAtten.w)).rgb;
vec3 attenuationZ = texture2D(u_AttenuationMapZ, vec2(var_TexAtten.z, 0)).rgb;
// compute final color
vec4 color = diffuse;
color.rgb *= attenuationXY;
color.rgb *= attenuationZ;
color.rgb *= u_LightScale;
gl_FragColor = color;
}
|