#version 120
uniform sampler2D texture;
const float TAU = 6.28318530718;
void main()
{
float angle = gl_Color.b * TAU;
vec2 rotation = vec2(cos(angle), sin(angle));
mat3x3 rot_matrix = mat3x3(vec3(rotation.x, -rotation.y, 0.0), vec3(rotation.y, rotation.x, 0.0), vec3(0.0, 0.0, 1.0));
vec4 normalsColor = texture2D(texture, gl_TexCoord[0].xy);
if (gl_Color.r < 1.0)
normalsColor.r = 1.0 - normalsColor.r;
if (gl_Color.g < 1.0)
normalsColor.g = 1.0 - normalsColor.g;
vec3 normals = normalize(normalsColor.rgb * 2.0 - 1.0);
normals = normals * rot_matrix;
vec4 result = vec4((normals.rgb + 1.0) * 0.5, normalsColor.a);
gl_FragColor = clamp(result, 0.0, 1.0);
}