1 | #version 100 |
---|
2 | precision highp int; |
---|
3 | precision highp float; |
---|
4 | |
---|
5 | attribute vec3 tangent; |
---|
6 | attribute vec4 position; |
---|
7 | attribute vec3 normal; |
---|
8 | |
---|
9 | uniform mat4 world; |
---|
10 | uniform mat4 worldViewProj; |
---|
11 | uniform mat4 texViewProj; |
---|
12 | uniform vec4 lightPosition; // object space |
---|
13 | uniform vec4 shadowDepthRange; |
---|
14 | |
---|
15 | varying vec3 tangentLightDir; |
---|
16 | varying vec4 vUv0; |
---|
17 | varying vec4 vUv1; |
---|
18 | |
---|
19 | attribute vec4 uv0; |
---|
20 | attribute vec4 uv1; |
---|
21 | |
---|
22 | void main() |
---|
23 | { |
---|
24 | gl_Position = worldViewProj * position; |
---|
25 | |
---|
26 | vec4 worldPos = world * position; |
---|
27 | vec4 lightPos = vec4(300.0, 750.0, -700.0, 1.0); |
---|
28 | |
---|
29 | // Get object space light direction |
---|
30 | vec3 lightDir = normalize(lightPos.xyz - (position.xyz * lightPos.w)); |
---|
31 | |
---|
32 | // calculate shadow map coords |
---|
33 | vUv0 = texViewProj * worldPos; |
---|
34 | #if LINEAR_RANGE |
---|
35 | // adjust by fixed depth bias, rescale into range |
---|
36 | vUv0.z = (uv0.z - shadowDepthRange.x) * shadowDepthRange.w; |
---|
37 | #endif |
---|
38 | |
---|
39 | vUv1 = uv1; |
---|
40 | |
---|
41 | // Calculate the binormal (NB we assume both normal and tangent are |
---|
42 | // already normalised) |
---|
43 | vec3 binormal = cross(normal, tangent); |
---|
44 | |
---|
45 | // Form a rotation matrix out of the vectors, column major for glsl es |
---|
46 | mat3 rotation = mat3(vec3(tangent[0], binormal[0], normal[0]), |
---|
47 | vec3(tangent[1], binormal[1], normal[1]), |
---|
48 | vec3(tangent[2], binormal[2], normal[2])); |
---|
49 | |
---|
50 | // Transform the light vector according to this matrix |
---|
51 | tangentLightDir = normalize(rotation * lightDir); |
---|
52 | } |
---|