2014-02-12 16:16:10 -05:00
|
|
|
#version 330
|
2014-01-17 17:50:06 -05:00
|
|
|
uniform sampler2D normalMap;
|
2011-10-31 21:52:10 -04:00
|
|
|
|
2013-12-18 19:13:17 -05:00
|
|
|
noperspective in vec3 tangent;
|
|
|
|
noperspective in vec3 bitangent;
|
2014-01-09 12:08:23 -05:00
|
|
|
in vec2 uv;
|
2014-01-27 17:29:46 -05:00
|
|
|
out vec2 EncodedNormal;
|
|
|
|
|
|
|
|
// from Crytek "a bit more deferred CryEngine"
|
|
|
|
vec2 EncodeNormal(vec3 n)
|
|
|
|
{
|
|
|
|
return normalize(n.xy) * sqrt(n.z * 0.5 + 0.5);
|
|
|
|
}
|
2012-01-15 11:37:15 -05:00
|
|
|
|
|
|
|
void main()
|
|
|
|
{
|
2013-12-18 19:13:17 -05:00
|
|
|
// normal in Tangent Space
|
2014-01-19 12:53:35 -05:00
|
|
|
vec3 TS_normal = 2.0 * texture (normalMap, uv).rgb - 1.0;
|
2013-12-18 19:13:17 -05:00
|
|
|
// Because of interpolation, we need to renormalize
|
|
|
|
vec3 Frag_tangent = normalize(tangent);
|
2014-01-17 15:29:39 -05:00
|
|
|
vec3 Frag_normal = normalize(cross(Frag_tangent, bitangent));
|
|
|
|
vec3 Frag_bitangent = cross(Frag_normal, Frag_tangent);
|
2013-06-18 10:35:29 -04:00
|
|
|
|
2014-01-27 16:21:16 -05:00
|
|
|
vec3 FragmentNormal = TS_normal.x * Frag_tangent + TS_normal.y * Frag_bitangent - TS_normal.z * Frag_normal;
|
2014-01-27 17:29:46 -05:00
|
|
|
EncodedNormal = 0.5 * EncodeNormal(normalize(FragmentNormal)) + 0.5;
|
2013-06-18 10:35:29 -04:00
|
|
|
}
|