]> icculus.org git repositories - divverent/nexuiz.git/blob - data/glsl/light.vert
weaponsounds, defaultmodel, electrocombo, specmode and weaponmodel colors
[divverent/nexuiz.git] / data / glsl / light.vert
1
2 // ambient+diffuse+specular+normalmap+attenuation+cubemap+fog shader
3 // written by Forest 'LordHavoc' Hale
4
5 // use half floats if available for math performance
6 #ifdef GEFORCEFX
7 #define myhalf half
8 #define myhvec2 hvec2
9 #define myhvec3 hvec3
10 #define myhvec4 hvec4
11 #else
12 #define myhalf float
13 #define myhvec2 vec2
14 #define myhvec3 vec3
15 #define myhvec4 vec4
16 #endif
17
18 uniform vec3 LightPosition;
19
20 varying vec2 TexCoord;
21 varying myhvec3 CubeVector;
22 varying vec3 LightVector;
23
24 #if defined(USESPECULAR) || defined(USEFOG) || defined(USEOFFSETMAPPING)
25 uniform vec3 EyePosition;
26 varying vec3 EyeVector;
27 #endif
28
29 // TODO: get rid of tangentt (texcoord2) and use a crossproduct to regenerate it from tangents (texcoord1) and normal (texcoord3)
30
31 void main(void)
32 {
33         // copy the surface texcoord
34         TexCoord = vec2(gl_TextureMatrix[0] * gl_MultiTexCoord0);
35
36         // transform vertex position into light attenuation/cubemap space
37         // (-1 to +1 across the light box)
38         CubeVector = vec3(gl_TextureMatrix[3] * gl_Vertex);
39
40         // transform unnormalized light direction into tangent space
41         // (we use unnormalized to ensure that it interpolates correctly and then
42         //  normalize it per pixel)
43         vec3 lightminusvertex = LightPosition - gl_Vertex.xyz;
44         LightVector.x = -dot(lightminusvertex, gl_MultiTexCoord1.xyz);
45         LightVector.y = -dot(lightminusvertex, gl_MultiTexCoord2.xyz);
46         LightVector.z = -dot(lightminusvertex, gl_MultiTexCoord3.xyz);
47
48 #if defined(USESPECULAR) || defined(USEFOG) || defined(USEOFFSETMAPPING)
49         // transform unnormalized eye direction into tangent space
50         vec3 eyeminusvertex = EyePosition - gl_Vertex.xyz;
51         EyeVector.x = -dot(eyeminusvertex, gl_MultiTexCoord1.xyz);
52         EyeVector.y = -dot(eyeminusvertex, gl_MultiTexCoord2.xyz);
53         EyeVector.z = -dot(eyeminusvertex, gl_MultiTexCoord3.xyz);
54 #endif
55
56         // transform vertex to camera space, using ftransform to match non-VS
57         // rendering
58         gl_Position = ftransform();
59 }
60