2 uniform sampler2D texmap;
3 uniform sampler2D lightmap;
5 varying vec3 vdir, ldir[3], normal;
7 //#define KD gl_FrontMaterial.diffuse.rgb
8 #define KD vec3(1.0, 1.0, 1.0)
10 #define KS gl_FrontMaterial.specular.rgb
11 #define SPOW gl_FrontMaterial.shininess
13 #define LD(i) gl_LightSource[i].diffuse.rgb
14 #define LS(i) gl_LightSource[i].specular.rgb
16 vec3 calc_diffuse(in vec3 n, in vec3 l, in vec3 lcol)
18 float ndotl = max(dot(n, l), 0.0);
19 return KD * lcol * ndotl;
22 vec3 calc_specular(in vec3 n, in vec3 l, in vec3 v, in vec3 lcol)
24 vec3 h = normalize(l + v);
25 float ndoth = max(dot(n, h), 0.0);
26 return KS * lcol * pow(ndoth, SPOW);
31 vec3 texel = texture2D(texmap, gl_TexCoord[0].st).rgb;
32 vec3 lumel = texture2D(lightmap, gl_TexCoord[1].st).rgb;
34 vec3 n = normalize(normal);
35 vec3 v = normalize(vdir);
37 vec3 diffuse = lumel * texel * 1.8;
38 vec3 specular = vec3(0.0, 0.0, 0.0);
41 for(int i=0; i<3; i++) {
42 vec3 l = normalize(ldir[i]);
43 diffuse += calc_diffuse(n, l, LD(i)) * texel;
44 specular += calc_specular(n, l, v, LS(i));
48 vec3 ambient = gl_LightModel.ambient.rgb * KD * texel;
49 gl_FragColor.rgb = ambient + diffuse;// + specular;
50 gl_FragColor.a = gl_FrontMaterial.diffuse.a;