Rev | Line | |
---|
[12083] | 1 | #version 150 |
---|
| 2 | |
---|
| 3 | uniform vec4 lightPosition; // object space |
---|
| 4 | uniform vec3 eyePosition; // object space |
---|
| 5 | uniform mat4 worldViewProj; // not actually used but here for compat with HLSL |
---|
| 6 | |
---|
| 7 | out vec3 oEyeDir; |
---|
| 8 | out vec3 oLightDir; |
---|
| 9 | out vec3 oHalfAngle; |
---|
| 10 | out vec4 oUv0; |
---|
| 11 | |
---|
| 12 | in vec3 normal; |
---|
| 13 | in vec3 tangent; |
---|
| 14 | in vec4 uv0; |
---|
| 15 | in vec4 position; |
---|
| 16 | |
---|
| 17 | /* Vertex program that moves light and eye vectors into texture tangent space at vertex */ |
---|
| 18 | |
---|
| 19 | void main() |
---|
| 20 | { |
---|
| 21 | // Calculate output position |
---|
| 22 | gl_Position = worldViewProj * position; |
---|
| 23 | |
---|
| 24 | // Pass the main uvs straight through unchanged |
---|
| 25 | oUv0 = uv0; |
---|
| 26 | |
---|
| 27 | vec3 lightDir = lightPosition.xyz - (position.xyz * lightPosition.w); |
---|
| 28 | |
---|
| 29 | vec3 eyeDir = eyePosition - position.xyz; |
---|
| 30 | |
---|
| 31 | // Calculate the binormal (NB we assume both normal and tangent are |
---|
| 32 | // already normalised) |
---|
| 33 | // NB looks like nvidia cross params are BACKWARDS to what you'd expect |
---|
| 34 | // this equates to NxT, not TxN |
---|
| 35 | vec3 localbinormal = cross(tangent, normal); |
---|
| 36 | |
---|
| 37 | // Form a rotation matrix out of the vectors, column major for glsl es |
---|
| 38 | mat3 TBN = mat3(tangent, localbinormal, normal); |
---|
| 39 | |
---|
| 40 | // Transform the light vector according to this matrix |
---|
| 41 | oLightDir = normalize(TBN * lightDir); |
---|
| 42 | oEyeDir = normalize(TBN * eyeDir); |
---|
| 43 | oHalfAngle = normalize(oEyeDir + oLightDir); |
---|
| 44 | } |
---|
| 45 | |
---|
Note: See
TracBrowser
for help on using the repository browser.