2 * bumpTBN_SH_FP.glsl - ambient, diffuse and specular lighting in tangent space
3 * with shadow mapping and 4-samples PCF
5 * Simple test GLSL shader
6 * Copyright (c) 2007 Cesare Tirabassi <norsetto@ubuntu.com>
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; version 3 of the License.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
18 varying vec3 lvec, vvec;
20 uniform sampler2D colorMap;
21 uniform sampler2D bumpMap;
22 uniform sampler2DShadow shadowMap;
24 const vec2 texmapscale = vec2( 1.0/1024.0, 1.0/1024.0 );
26 vec4 offset_lookup(sampler2DShadow map, vec4 loc, vec2 offset )
28 return shadow2DProj( map, vec4(loc.xy + offset * texmapscale * loc.w, loc.z, loc.w ) );
33 vec3 lv = normalize(lvec);
34 vec3 vv = normalize(vvec);
35 vec3 nv = 2.0*texture2D(bumpMap, gl_TexCoord[0].st).rgb-1.0;
37 float diff = max(dot(lv, nv), 0.0);
41 spec = pow( max( dot(-normalize(reflect(lv,nv)), vv), 0.0), 64.0 );
43 vec4 texture = texture2D(colorMap, gl_TexCoord[0].st);
45 vec2 offset = mod(gl_FragCoord.xy, 2.0);
51 vec4 shadow = ( offset_lookup( shadowMap, gl_TexCoord[1], offset+vec2(-1.5, 0.5) ) +
52 offset_lookup( shadowMap, gl_TexCoord[1], offset+vec2( 0.5, 0.5) ) +
53 offset_lookup( shadowMap, gl_TexCoord[1], offset+vec2(-1.5, -1.5) ) +
54 offset_lookup( shadowMap, gl_TexCoord[1], offset+vec2( 0.5, -1.5) ) )*0.25;
56 // vec4 shadow = shadow2DProj(shadowMap, gl_TexCoord[1]);
58 gl_FragColor = texture*( shadow*( 0.1 + 0.75 * diff + spec * texture.a ) + 0.2 );