1 uniform sampler2D baseTexture;
2 uniform sampler2D normalTexture;
7 vec2 uv = gl_TexCoord[0].st;
9 //texture sampling rate
10 const float step = 1.0 / 256.0;
11 float tl = texture2D(normalTexture, vec2(uv.x - step, uv.y + step)).r;
12 float t = texture2D(normalTexture, vec2(uv.x - step, uv.y - step)).r;
13 float tr = texture2D(normalTexture, vec2(uv.x + step, uv.y + step)).r;
14 float r = texture2D(normalTexture, vec2(uv.x + step, uv.y)).r;
15 float br = texture2D(normalTexture, vec2(uv.x + step, uv.y - step)).r;
16 float b = texture2D(normalTexture, vec2(uv.x, uv.y - step)).r;
17 float bl = texture2D(normalTexture, vec2(uv.x - step, uv.y - step)).r;
18 float l = texture2D(normalTexture, vec2(uv.x - step, uv.y)).r;
19 float dX = (tr + 2.0 * r + br) - (tl + 2.0 * l + bl);
20 float dY = (bl + 2.0 * b + br) - (tl + 2.0 * t + tr);
21 vec4 bump = vec4 (normalize(vec3 (dX, dY, 0.1)),1.0);
22 float height = 2.0 * texture2D(normalTexture, vec2(uv.x, uv.y)).r - 1.0;
23 vec4 base = texture2D(baseTexture, uv).rgba;
24 vec3 L = normalize(vec3(0.0, 0.75, 1.0));
25 float specular = pow(clamp(dot(reflect(L, bump.xyz), yawVec), 0.0, 1.0), 1.0);
26 float diffuse = dot(yawVec, bump.xyz);
28 vec3 color = (1.1 * diffuse + 0.05 * height + 0.5 * specular) * base.rgb;
29 vec4 col = vec4(color.rgb, base.a);
31 gl_FragColor = vec4(col.rgb, base.a);