UFO: Alien Invasion
Loading...
Searching...
No Matches
transform_lights_vs.glsl
Go to the documentation of this file.
1/**
2 * @file
3 * @brief Transform lights to the tangent space. Requires light_vs.glsl and lerp_vs.glsl.
4 */
5
6uniform vec3 SUNDIRECTION;
7out_qualifier vec3 sunDir; /** < Direction towards the sun, in tangent space */
8
9out_qualifier vec3 eyedir;
10
11#define R_DYNAMIC_LIGHTS #replace r_dynamic_lights
12#if r_dynamic_lights
13uniform vec3 LIGHTPOSITIONS[R_DYNAMIC_LIGHTS];
14out_qualifier vec3 lightDirs[R_DYNAMIC_LIGHTS];
15#endif
16
17/**
18 * @brief TransformLights
19 */
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;
25
26 /* Transform the eye direction into tangent space.*/
27 vec3 v;
28 v.x = dot(-point, tangent);
29 v.y = dot(-point, bitangent);
30 v.z = dot(-point, normal);
31
32 eyedir = normalize(v);
33
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);
38
39 /* Transform relative light positions into tangent space.*/
40 vec3 lpos;
41#unroll r_dynamic_lights
42 lpos = LIGHTPOSITIONS[$] - point;
43
44 lightDirs[$].x = dot(lpos, tangent);
45 lightDirs[$].y = dot(lpos, bitangent);
46 lightDirs[$].z = dot(lpos, normal);
47#endunroll
48}