2014-08-18 11:49:44 -04:00
|
|
|
#ifdef GL_ARB_bindless_texture
|
|
|
|
layout(bindless_sampler) uniform sampler2D normalMap;
|
|
|
|
layout(bindless_sampler) uniform sampler2D DiffuseForAlpha;
|
|
|
|
#else
|
2014-01-17 17:50:06 -05:00
|
|
|
uniform sampler2D normalMap;
|
2014-04-23 11:58:15 -04:00
|
|
|
uniform sampler2D DiffuseForAlpha;
|
2014-08-18 11:49:44 -04:00
|
|
|
#endif
|
2011-10-31 21:52:10 -04:00
|
|
|
|
2014-02-28 11:29:05 -05:00
|
|
|
in vec3 tangent;
|
|
|
|
in vec3 bitangent;
|
2014-01-09 12:08:23 -05:00
|
|
|
in vec2 uv;
|
2014-04-06 17:26:45 -04:00
|
|
|
out vec3 EncodedNormal;
|
2014-03-21 13:10:54 -04:00
|
|
|
|
|
|
|
vec2 EncodeNormal(vec3 n);
|
2012-01-15 11:37:15 -05:00
|
|
|
|
|
|
|
void main()
|
|
|
|
{
|
2014-04-23 11:58:15 -04:00
|
|
|
// normal in Tangent Space
|
|
|
|
vec3 TS_normal = 2.0 * texture(normalMap, uv).rgb - 1.0;
|
|
|
|
float alpha = texture(DiffuseForAlpha, uv).a;
|
|
|
|
// Because of interpolation, we need to renormalize
|
|
|
|
vec3 Frag_tangent = normalize(tangent);
|
|
|
|
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-04-23 11:58:15 -04:00
|
|
|
vec3 FragmentNormal = TS_normal.x * Frag_tangent + TS_normal.y * Frag_bitangent - TS_normal.z * Frag_normal;
|
|
|
|
EncodedNormal.xy = 0.5 * EncodeNormal(normalize(FragmentNormal)) + 0.5;
|
2014-12-04 18:09:15 -05:00
|
|
|
EncodedNormal.z = 1. - alpha;
|
2013-06-18 10:35:29 -04:00
|
|
|
}
|