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