3 * @brief Transform lights to the tangent space. Requires light_vs.glsl and lerp_vs.glsl.
6uniform vec3 SUNDIRECTION;
7out_qualifier vec3 sunDir; /** < Direction towards the sun, in tangent space */
9out_qualifier vec3 eyedir;
11#define R_DYNAMIC_LIGHTS #replace r_dynamic_lights
13uniform vec3 LIGHTPOSITIONS[R_DYNAMIC_LIGHTS];
14out_qualifier vec3 lightDirs[R_DYNAMIC_LIGHTS];
18 * @brief TransformLights
20void TransformLights(void) {
21 /* Load the tangent.*/
22 vec3 tangent = normalize(gl_NormalMatrix * Tangent.xyz);
23 /* Compute the bitangent.*/
24 vec3 bitangent = normalize(cross(normal, tangent)) * Tangent.w;
26 /* Transform the eye direction into tangent space.*/
28 v.x = dot(-point, tangent);
29 v.y = dot(-point, bitangent);
30 v.z = dot(-point, normal);
32 eyedir = normalize(v);
34 /* transform sun direction to tangent space */
35 sunDir.x = dot(SUNDIRECTION, tangent);
36 sunDir.y = dot(SUNDIRECTION, bitangent);
37 sunDir.z = dot(SUNDIRECTION, normal);
39 /* Transform relative light positions into tangent space.*/
41#unroll r_dynamic_lights
42 lpos = LIGHTPOSITIONS[$] - point;
44 lightDirs[$].x = dot(lpos, tangent);
45 lightDirs[$].y = dot(lpos, bitangent);
46 lightDirs[$].z = dot(lpos, normal);