2013-12-18 19:13:17 -05:00
|
|
|
#version 130
|
|
|
|
uniform sampler2D texture; //The texture
|
|
|
|
uniform sampler2D normalMap; //The bump-map
|
2011-10-31 21:52:10 -04:00
|
|
|
|
2013-12-18 19:13:17 -05:00
|
|
|
noperspective in vec3 tangent;
|
|
|
|
noperspective in vec3 bitangent;
|
|
|
|
noperspective in vec3 normal;
|
2012-01-15 11:37:15 -05:00
|
|
|
|
2013-12-18 19:13:17 -05:00
|
|
|
vec4 encdepth(float v) {
|
|
|
|
vec4 enc = vec4(1.0, 255.0, 65025.0, 16581375.0) * v;
|
|
|
|
enc = fract(enc);
|
|
|
|
enc -= enc.yzww * vec4(1.0/255.0, 1.0/255.0, 1.0/255.0, 0.0);
|
|
|
|
return enc;
|
|
|
|
}
|
2012-01-15 11:37:15 -05:00
|
|
|
|
|
|
|
void main()
|
|
|
|
{
|
2013-12-18 19:13:17 -05:00
|
|
|
// normal in Tangent Space
|
|
|
|
vec3 TS_normal = 2.0 * texture2D (normalMap, gl_TexCoord[0].st).rgb - 1.0;
|
|
|
|
// Because of interpolation, we need to renormalize
|
|
|
|
vec3 Frag_tangent = normalize(tangent);
|
|
|
|
vec3 Frag_bitangent = normalize(cross(normal, tangent));
|
|
|
|
vec3 Frag_normal = cross(Frag_tangent, Frag_bitangent);
|
2013-06-18 10:35:29 -04:00
|
|
|
|
|
|
|
|
2013-12-18 19:13:17 -05:00
|
|
|
vec3 FragmentNormal = TS_normal.x * Frag_tangent + TS_normal.y * Frag_bitangent + TS_normal.z * Frag_normal;
|
|
|
|
FragmentNormal = normalize(FragmentNormal);
|
|
|
|
|
2012-01-15 11:37:15 -05:00
|
|
|
|
2013-12-18 19:13:17 -05:00
|
|
|
gl_FragData[0] = texture2D (texture, gl_TexCoord[0].st);
|
|
|
|
gl_FragData[1] = vec4(0.5 * FragmentNormal + 0.5, 1.0);
|
|
|
|
gl_FragData[2] = vec4(encdepth(gl_FragCoord.z).xyz, 0.0);
|
2013-06-18 10:35:29 -04:00
|
|
|
}
|