1 | varying vec4 refrCoords; |
---|
2 | varying vec4 normCoords; |
---|
3 | varying vec4 viewCoords; |
---|
4 | varying vec4 viewTangetSpace; |
---|
5 | varying vec4 lightTangetSpace; |
---|
6 | |
---|
7 | uniform vec4 lightPos, cameraPos; |
---|
8 | |
---|
9 | |
---|
10 | void main() |
---|
11 | { |
---|
12 | // Because we have a flat plane for water we already know the vectors for tangent space |
---|
13 | vec4 tangent = vec4(1.0, 0.0, 0.0, 0.0); |
---|
14 | vec4 normal = vec4(0.0, 1.0, 0.0, 0.0); |
---|
15 | vec4 biTangent = vec4(0.0, 0.0, 1.0, 0.0); |
---|
16 | |
---|
17 | // Calculate the vector coming from the vertex to the camera |
---|
18 | vec4 viewDir = cameraPos - gl_Vertex; |
---|
19 | |
---|
20 | // Compute tangent space for the view direction |
---|
21 | viewTangetSpace.x = dot(viewDir, tangent); |
---|
22 | viewTangetSpace.y = dot(viewDir, biTangent); |
---|
23 | viewTangetSpace.z = dot(viewDir, normal); |
---|
24 | viewTangetSpace.w = 1.0; |
---|
25 | |
---|
26 | // Calculate the vector that the light hits the vertex |
---|
27 | vec4 lightDir = lightPos - gl_Vertex; |
---|
28 | |
---|
29 | // Compute tangent space for the light direction |
---|
30 | lightTangetSpace.x = dot(lightDir, tangent); |
---|
31 | lightTangetSpace.y = dot(lightDir, biTangent); |
---|
32 | lightTangetSpace.z = dot(lightDir, normal); |
---|
33 | lightTangetSpace.w = 1.0; |
---|
34 | |
---|
35 | refrCoords = gl_MultiTexCoord1; |
---|
36 | normCoords = gl_MultiTexCoord2; |
---|
37 | |
---|
38 | // This calculates our current projection coordinates |
---|
39 | viewCoords = gl_ModelViewProjectionMatrix * gl_Vertex; |
---|
40 | |
---|
41 | gl_Position = viewCoords; |
---|
42 | } |
---|