2010-12-05 13:44:02 +00:00
|
|
|
|
// This shader is mostly an adaptation of the shader found at
|
|
|
|
|
// http://www.bonzaisoftware.com/water_tut.html and its glsl conversion
|
|
|
|
|
// available at http://forum.bonzaisoftware.com/viewthread.php?tid=10
|
|
|
|
|
// <20> Michael Horsch - 2005
|
2011-10-07 11:46:01 +00:00
|
|
|
|
// Major update and revisions - 2011-10-07
|
|
|
|
|
// <20> Emilian Huminiuc and Vivian Meazza
|
2010-12-05 13:44:02 +00:00
|
|
|
|
|
2011-09-26 22:35:20 +00:00
|
|
|
|
#version 120
|
|
|
|
|
|
2010-09-29 23:29:16 +00:00
|
|
|
|
varying vec4 waterTex1;
|
|
|
|
|
varying vec4 waterTex2;
|
2011-10-07 11:46:01 +00:00
|
|
|
|
|
2010-09-29 23:29:16 +00:00
|
|
|
|
varying vec3 viewerdir;
|
|
|
|
|
varying vec3 lightdir;
|
|
|
|
|
varying vec3 normal;
|
2009-08-08 10:17:58 +00:00
|
|
|
|
|
2011-10-07 11:46:01 +00:00
|
|
|
|
uniform float osg_SimulationTime;
|
|
|
|
|
uniform float WindE, WindN;
|
|
|
|
|
|
|
|
|
|
/////// functions /////////
|
|
|
|
|
|
|
|
|
|
void rotationmatrix(in float angle, out mat4 rotmat)
|
2012-05-05 18:59:22 +00:00
|
|
|
|
{
|
|
|
|
|
rotmat = mat4( cos( angle ), -sin( angle ), 0.0, 0.0,
|
|
|
|
|
sin( angle ), cos( angle ), 0.0, 0.0,
|
|
|
|
|
0.0 , 0.0 , 1.0, 0.0,
|
|
|
|
|
0.0 , 0.0 , 0.0, 1.0 );
|
|
|
|
|
}
|
2011-10-07 11:46:01 +00:00
|
|
|
|
|
2009-08-08 10:17:58 +00:00
|
|
|
|
void main(void)
|
2012-05-05 18:59:22 +00:00
|
|
|
|
{
|
|
|
|
|
mat4 RotationMatrix;
|
|
|
|
|
vec3 N = normalize(gl_Normal);
|
|
|
|
|
normal = N;
|
|
|
|
|
|
|
|
|
|
viewerdir = vec3(gl_ModelViewMatrixInverse[3]) - vec3(gl_Vertex);
|
|
|
|
|
lightdir = normalize(vec3(gl_ModelViewMatrixInverse * gl_LightSource[0].position));
|
2010-09-29 23:29:16 +00:00
|
|
|
|
|
2012-05-05 18:59:22 +00:00
|
|
|
|
vec4 t1 = vec4(0.0, osg_SimulationTime * 0.005217, 0.0, 0.0);
|
|
|
|
|
vec4 t2 = vec4(0.0, osg_SimulationTime * -0.0012, 0.0, 0.0);
|
2010-09-29 23:29:16 +00:00
|
|
|
|
|
2012-05-05 18:59:22 +00:00
|
|
|
|
float Angle;
|
2010-09-29 23:29:16 +00:00
|
|
|
|
|
2012-05-05 18:59:22 +00:00
|
|
|
|
float windFactor = sqrt(pow(abs(WindE),2)+pow(abs(WindN),2)) * 0.05;
|
2011-12-01 20:56:04 +00:00
|
|
|
|
|
2012-05-05 18:59:22 +00:00
|
|
|
|
if (WindN == 0.0 && WindE == 0.0) {
|
|
|
|
|
Angle = 0.0;
|
|
|
|
|
}else{
|
|
|
|
|
Angle = atan(-WindN, WindE) - atan(1.0);
|
|
|
|
|
}
|
2011-09-26 22:35:20 +00:00
|
|
|
|
|
2012-05-05 18:59:22 +00:00
|
|
|
|
rotationmatrix(Angle, RotationMatrix);
|
|
|
|
|
waterTex1 = gl_MultiTexCoord0 * RotationMatrix - t1 * windFactor;
|
2010-09-29 23:29:16 +00:00
|
|
|
|
|
2012-05-05 18:59:22 +00:00
|
|
|
|
rotationmatrix(Angle, RotationMatrix);
|
|
|
|
|
waterTex2 = gl_MultiTexCoord0 * RotationMatrix - t2 * windFactor;
|
2010-09-29 23:29:16 +00:00
|
|
|
|
|
2012-05-05 18:59:22 +00:00
|
|
|
|
// fog_Func(fogType);
|
|
|
|
|
gl_Position = ftransform();
|
|
|
|
|
}
|