1/*
2GLSL conversion of Michael Horsch water demo
3http://www.bonzaisoftware.com/wfs.html
4Converted by Mars_999
58/20/2005
6*/
7uniform vec3 m_lightPos;
8uniform float m_time;
9
10uniform mat4 g_WorldViewProjectionMatrix;
11uniform mat4 g_WorldViewMatrix;
12uniform mat4 g_ViewMatrix;
13uniform vec3 g_CameraPosition;
14uniform mat3 g_NormalMatrix;
15
16attribute vec4 inPosition;
17attribute vec2 inTexCoord;
18attribute vec3 inTangent;
19attribute vec3 inNormal;
20
21varying vec4 lightDir;
22varying vec4 waterTex1;
23varying vec4 waterTex2;
24varying vec4 position;
25varying vec4 viewDir;
26varying vec4 viewpos;
27varying vec4 viewLightDir;
28varying vec4 viewCamDir;
29
30
31//unit 0 = water_reflection
32//unit 1 = water_refraction
33//unit 2 = water_normalmap
34//unit 3 = water_dudvmap
35//unit 4 = water_depthmap
36
37void main(void)
38{
39    viewpos.x = g_CameraPosition.x;
40    viewpos.y = g_CameraPosition.y;
41    viewpos.z = g_CameraPosition.z;
42    viewpos.w = 1.0;
43
44    vec4  temp;
45    vec4 tangent = vec4(1.0, 0.0, 0.0, 0.0);
46    vec4 norm = vec4(0.0, 1.0, 0.0, 0.0);
47    vec4 binormal = vec4(0.0, 0.0, 1.0, 0.0);
48
49
50    temp = viewpos - inPosition;
51
52    viewDir.x = dot(temp, tangent);
53    viewDir.y = dot(temp, binormal);
54    viewDir.z = dot(temp, norm);
55    viewDir.w = 0.0;
56
57    temp = vec4(m_lightPos,1.0)- inPosition;
58    lightDir.x = dot(temp, tangent);
59    lightDir.y = dot(temp, binormal);
60    lightDir.z = dot(temp, norm);
61    lightDir.w = 0.0;
62
63   vec4 viewSpaceLightPos=g_ViewMatrix*vec4(m_lightPos,1.0);
64   vec4 viewSpacePos=g_WorldViewMatrix*inPosition;
65   vec3 wvNormal  = normalize(g_NormalMatrix * inNormal);
66   vec3 wvTangent = normalize(g_NormalMatrix * inTangent);
67   vec3 wvBinormal = cross(wvNormal, wvTangent);
68   mat3 tbnMat = mat3(wvTangent, wvBinormal, wvNormal);
69
70    temp = viewSpaceLightPos - viewSpacePos;
71    viewLightDir.xyz=temp.xyz*tbnMat;
72    viewLightDir.w = 0.0;
73
74    temp = -viewSpacePos;
75    viewCamDir.xyz =temp.xyz*tbnMat;
76    viewCamDir.w = 0.0;
77
78
79    vec4 t1 = vec4(0.0, -m_time, 0.0,0.0);
80    vec4 t2 = vec4(0.0, m_time, 0.0,0.0);
81
82    waterTex1 =vec4(inTexCoord,0.0,0.0) + t1;
83    waterTex2 =vec4(inTexCoord ,0.0,0.0)+ t2;
84
85    position = g_WorldViewProjectionMatrix * inPosition;
86    gl_Position = position;
87}
88