[12115] | 1 | #version 150 |
---|
| 2 | |
---|
| 3 | in vec3 tangent; |
---|
| 4 | in vec3 normal; |
---|
| 5 | in vec4 vertex; |
---|
| 6 | in vec4 uv1; |
---|
| 7 | |
---|
| 8 | uniform mat4 world; |
---|
| 9 | uniform mat4 worldViewProj; |
---|
| 10 | uniform mat4 texViewProj; |
---|
| 11 | uniform vec4 lightPosition; // object space |
---|
| 12 | uniform vec4 shadowDepthRange; |
---|
| 13 | |
---|
| 14 | out vec3 tangentLightDir; |
---|
| 15 | out vec4 oUv0; |
---|
| 16 | out vec4 oUv1; |
---|
| 17 | |
---|
| 18 | void main() |
---|
| 19 | { |
---|
| 20 | gl_Position = worldViewProj * vertex; |
---|
| 21 | |
---|
| 22 | vec4 worldPos = world * vertex; |
---|
| 23 | |
---|
| 24 | // Get object space light direction |
---|
| 25 | vec3 lightDir = normalize(lightPosition.xyz - (vertex.xyz * lightPosition.w)); |
---|
| 26 | |
---|
| 27 | // calculate shadow map coords |
---|
| 28 | oUv0 = texViewProj * worldPos; |
---|
| 29 | #if LINEAR_RANGE |
---|
| 30 | // adjust by fixed depth bias, rescale into range |
---|
| 31 | oUv0.z = (oUv0.z - shadowDepthRange.x) * shadowDepthRange.w; |
---|
| 32 | #endif |
---|
| 33 | |
---|
| 34 | // pass the main uvs straight through unchanged |
---|
| 35 | oUv1 = uv1; |
---|
| 36 | |
---|
| 37 | // Calculate the binormal (NB we assume both normal and tangent are |
---|
| 38 | // already normalised) |
---|
| 39 | vec3 binormal = cross(normal, tangent); |
---|
| 40 | |
---|
| 41 | // Form a rotation matrix out of the vectors |
---|
| 42 | mat3 rotation = mat3(tangent, binormal, normal); |
---|
| 43 | // mat3 rotation = mat3(vec3(tangent[0], binormal[0], normal[0]), |
---|
| 44 | // vec3(tangent[1], binormal[1], normal[1]), |
---|
| 45 | // vec3(tangent[2], binormal[2], normal[2])); |
---|
| 46 | |
---|
| 47 | // Transform the light vector according to this matrix |
---|
| 48 | tangentLightDir = normalize(rotation * lightDir); |
---|
| 49 | } |
---|
| 50 | |
---|