1 | attribute vec3 tangent; |
---|
2 | |
---|
3 | uniform vec4 lightPosition; // object space |
---|
4 | uniform vec4 lightPosition1; // object space |
---|
5 | uniform vec4 eyePosition; // object space |
---|
6 | uniform vec4 spotDirection; // object space |
---|
7 | uniform vec4 spotDirection1; // object space |
---|
8 | uniform mat4 worldViewProj; // not actually used but here for compat with HLSL |
---|
9 | uniform mat4 worldMatrix; |
---|
10 | uniform mat4 texViewProj1; |
---|
11 | uniform mat4 texViewProj2; |
---|
12 | |
---|
13 | |
---|
14 | varying vec3 tangentEyeDir; |
---|
15 | varying vec3 tangentLightDir[2]; |
---|
16 | varying vec3 tangentSpotDir[2]; |
---|
17 | varying vec4 shadowUV[2]; |
---|
18 | |
---|
19 | void main() |
---|
20 | { |
---|
21 | gl_Position = ftransform(); |
---|
22 | |
---|
23 | vec4 worldPos = worldMatrix * gl_Vertex; |
---|
24 | |
---|
25 | shadowUV[0] = texViewProj1 * worldPos; |
---|
26 | shadowUV[1] = texViewProj2 * worldPos; |
---|
27 | |
---|
28 | // pass the main uvs straight through unchanged |
---|
29 | gl_TexCoord[0] = gl_MultiTexCoord0; |
---|
30 | |
---|
31 | // calculate tangent space light vector |
---|
32 | // Get object space light direction |
---|
33 | vec3 lightDir = normalize(lightPosition.xyz - (gl_Vertex.xyz * lightPosition.w)); |
---|
34 | vec3 lightDir1 = normalize(lightPosition1.xyz - (gl_Vertex.xyz * lightPosition1.w)); |
---|
35 | |
---|
36 | vec3 eyeDir = (eyePosition - gl_Vertex).xyz; |
---|
37 | |
---|
38 | // Calculate the binormal (NB we assume both normal and tangent are |
---|
39 | // already normalised) |
---|
40 | vec3 binormal = cross(gl_Normal, tangent); |
---|
41 | |
---|
42 | // Form a rotation matrix out of the vectors |
---|
43 | mat3 rotation = mat3(tangent, binormal, gl_Normal); |
---|
44 | |
---|
45 | // Transform the light vector according to this matrix |
---|
46 | tangentLightDir[0] = normalize(rotation * lightDir); |
---|
47 | tangentLightDir[1] = normalize(rotation * lightDir1); |
---|
48 | // Invert the Y on the eye dir since we'll be using this to alter UVs and |
---|
49 | // GL has Y inverted |
---|
50 | tangentEyeDir = normalize(rotation * eyeDir) * vec3(1, -1, 1); |
---|
51 | |
---|
52 | tangentSpotDir[0] = normalize(rotation * -spotDirection.xyz); |
---|
53 | tangentSpotDir[1] = normalize(rotation * -spotDirection1.xyz); |
---|
54 | } |
---|