uniform vec3 fvLightPosition;
uniform vec3 fvEyePosition;
uniform float fTime0_X;
uniform float fTimeScale;
uniform float fWavesScale;

varying vec2 Texcoord;
varying vec2 Texcoord2;
varying vec3 ViewDirection;
varying vec3 LightDirection;
   
attribute vec3 rm_Binormal;
attribute vec3 rm_Tangent;
   
void main( void )
{

   Texcoord2.x = gl_Vertex.x;
   Texcoord2.y = gl_Vertex.y;   

   float fTime = fTime0_X * fTimeScale;

   vec4 pos = gl_Vertex * fWavesScale;
   
   float wave = sin(pos.x+pos.y+pos.z+fTime);
   
   pos.x = sin(gl_Vertex.y+fTime*fTimeScale);
   pos.y = sin(gl_Vertex.z+fTime*fTimeScale);
   pos.z = sin(gl_Vertex.x+fTime*fTimeScale);
   pos.w = 0.0;
   
   gl_Position = gl_ProjectionMatrix * gl_ModelViewMatrix * (gl_Vertex + vec4(gl_Normal*wave,0));
   
   Texcoord    = gl_MultiTexCoord0.xy;
   Texcoord.x += wave/100.0+fTime/100.0;
    
   vec4 fvObjectPosition = gl_ModelViewMatrix * gl_Vertex;
   
   vec3 fvViewDirection  = fvEyePosition - fvObjectPosition.xyz;
   vec3 fvLightDirection = fvLightPosition - fvObjectPosition.xyz;
     
   vec3 fvNormal         = gl_NormalMatrix * gl_Normal;
   vec3 fvBinormal       = gl_NormalMatrix * rm_Binormal;
   vec3 fvTangent        = gl_NormalMatrix * rm_Tangent;
      
   ViewDirection.x  = dot( fvTangent, fvViewDirection );
   ViewDirection.y  = dot( fvBinormal, fvViewDirection );
   ViewDirection.z  = dot( fvNormal, fvViewDirection );
   
   LightDirection.x  = dot( fvTangent, fvLightDirection.xyz );
   LightDirection.y  = dot( fvBinormal, fvLightDirection.xyz );
   LightDirection.z  = dot( fvNormal, fvLightDirection.xyz );
   
}