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