2012-01-28 21:55:52 -05:00
|
|
|
// Shader based on work by Fabien Sanglard
|
|
|
|
// Released under the terms of CC-BY 3.0
|
|
|
|
|
2013-11-30 16:33:06 -05:00
|
|
|
uniform float speed;
|
|
|
|
uniform float height;
|
2013-12-01 11:51:08 -05:00
|
|
|
uniform float waveLength;
|
2013-11-30 16:33:06 -05:00
|
|
|
|
|
|
|
uniform vec3 lightdir;
|
|
|
|
|
2012-01-28 21:55:52 -05:00
|
|
|
varying vec3 lightVec;
|
|
|
|
varying vec3 halfVec;
|
|
|
|
varying vec3 eyeVec;
|
|
|
|
|
|
|
|
void main()
|
|
|
|
{
|
2013-11-30 16:33:06 -05:00
|
|
|
vec4 pos = gl_Vertex;
|
2012-01-28 21:55:52 -05:00
|
|
|
|
2013-12-01 11:51:08 -05:00
|
|
|
pos.y += (sin(pos.x/waveLength + speed) + cos(pos.z/waveLength + speed)) * height;
|
2013-11-30 16:33:06 -05:00
|
|
|
|
|
|
|
vec3 vertexPosition = vec3(gl_ModelViewMatrix * pos);
|
2013-06-18 10:35:29 -04:00
|
|
|
|
2012-01-28 21:55:52 -05:00
|
|
|
// Building the matrix Eye Space -> Tangent Space
|
|
|
|
vec3 n = normalize (gl_NormalMatrix * gl_Normal);
|
2013-11-30 16:33:06 -05:00
|
|
|
// gl_MultiTexCoord1.xyz
|
2012-01-28 21:55:52 -05:00
|
|
|
vec3 t = normalize (gl_NormalMatrix * vec3(1.0, 0.0, 0.0)); // tangent
|
|
|
|
vec3 b = cross (n, t);
|
2013-06-18 10:35:29 -04:00
|
|
|
|
2012-01-28 21:55:52 -05:00
|
|
|
// transform light and half angle vectors by tangent basis
|
|
|
|
vec3 v;
|
|
|
|
v.x = dot (lightdir, t);
|
|
|
|
v.y = dot (lightdir, b);
|
|
|
|
v.z = dot (lightdir, n);
|
|
|
|
lightVec = normalize (v);
|
|
|
|
|
|
|
|
vertexPosition = normalize(vertexPosition);
|
2013-06-18 10:35:29 -04:00
|
|
|
|
2013-11-30 16:33:06 -05:00
|
|
|
eyeVec = normalize(-vertexPosition); // we are in Eye Coordinates, so EyePos is (0,0,0)
|
2012-01-28 21:55:52 -05:00
|
|
|
|
|
|
|
// Normalize the halfVector to pass it to the fragment shader
|
|
|
|
|
|
|
|
// No need to divide by two, the result is normalized anyway.
|
2013-06-18 10:35:29 -04:00
|
|
|
// vec3 halfVector = normalize((vertexPosition + lightDir) / 2.0);
|
2012-01-28 21:55:52 -05:00
|
|
|
vec3 halfVector = normalize(vertexPosition + lightdir);
|
|
|
|
v.x = dot (halfVector, t);
|
|
|
|
v.y = dot (halfVector, b);
|
|
|
|
v.z = dot (halfVector, n);
|
|
|
|
|
|
|
|
// No need to normalize, t,b,n and halfVector are normal vectors.
|
|
|
|
//normalize (v);
|
2013-06-18 10:35:29 -04:00
|
|
|
halfVec = v ;
|
|
|
|
|
2013-11-30 16:33:06 -05:00
|
|
|
gl_Position = gl_ModelViewProjectionMatrix * pos;
|
2013-12-19 18:58:26 -05:00
|
|
|
gl_TexCoord[0] = gl_TextureMatrix[0] * gl_MultiTexCoord0;
|
|
|
|
gl_TexCoord[1] = gl_TextureMatrix[1] * gl_MultiTexCoord1;
|
2013-11-30 16:33:06 -05:00
|
|
|
}
|