1 | #version 120 |
---|
2 | |
---|
3 | /* Bump mapping vertex program for shadow receiving |
---|
4 | In this program, we want to calculate the tangent space light vector |
---|
5 | on a per-vertex level which will get passed to the fragment program, |
---|
6 | or to the fixed function dot3 operation, to produce the per-pixel |
---|
7 | lighting effect. |
---|
8 | */ |
---|
9 | |
---|
10 | // parameters |
---|
11 | uniform vec4 lightPosition; // object space |
---|
12 | uniform mat4 worldViewProj; |
---|
13 | uniform mat4 worldMatrix; |
---|
14 | uniform mat4 texViewProj; |
---|
15 | |
---|
16 | attribute vec4 vertex; |
---|
17 | attribute vec3 normal; |
---|
18 | attribute vec3 tangent; |
---|
19 | attribute vec4 uv0; |
---|
20 | |
---|
21 | varying vec4 uvproj; |
---|
22 | varying vec4 oUv0; |
---|
23 | varying vec3 oTSLightDir; |
---|
24 | |
---|
25 | void main() |
---|
26 | { |
---|
27 | // Calculate output position |
---|
28 | gl_Position = worldViewProj * vertex; |
---|
29 | |
---|
30 | // Pass the main uvs straight through unchanged |
---|
31 | oUv0 = uv0; |
---|
32 | |
---|
33 | // Calculate tangent space light vector |
---|
34 | // Get object space light direction |
---|
35 | // Non-normalised since we'll do that in the fragment program anyway |
---|
36 | vec3 lightDir = lightPosition.xyz - (vertex * lightPosition.w).xyz; |
---|
37 | |
---|
38 | // Calculate the binormal (NB we assume both normal and tangent are |
---|
39 | // already normalised) |
---|
40 | vec3 binormal = cross(normal, tangent); |
---|
41 | |
---|
42 | // Form a rotation matrix out of the vectors, column major for glsl es |
---|
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 | oTSLightDir = rotation * lightDir; |
---|
49 | |
---|
50 | // Projection |
---|
51 | uvproj = texViewProj * (worldMatrix * vertex); |
---|
52 | } |
---|