diff --git a/Shaders/water.frag b/Shaders/water.frag index c7b204967..1a217c3f8 100644 --- a/Shaders/water.frag +++ b/Shaders/water.frag @@ -1,10 +1,8 @@ - uniform sampler2D water_normalmap; uniform sampler2D water_reflection; uniform sampler2D water_refraction; uniform sampler2D water_dudvmap; uniform sampler2D water_depthmap; -//uniform vec4 waterColor, waterDepth; vec4 waterColor = vec4(0.0,0.2,1.0,1.0); vec4 waterDepth = vec4(0.0,0.2,1.0,1.0); @@ -14,6 +12,7 @@ varying vec4 waterTex1; //moving texcoords varying vec4 waterTex2; //moving texcoords varying vec4 waterTex3; //for projection varying vec4 waterTex4; //viewts +varying float fogCoord; //unit 0 = water_reflection //unit 1 = water_refraction @@ -33,6 +32,8 @@ const vec4 ofive = vec4(0.5,0.5,0.5,1.0); const float exponent = 64.0; +float fogFactor = exp(-gl_Fog.density * gl_Fog.density * fogCoord * fogCoord); + vec4 lightTS = normalize(waterTex0); vec4 viewt = normalize(waterTex4); vec4 disdis = texture2D(water_dudvmap, vec2(waterTex2 * tscale)); @@ -68,7 +69,7 @@ wdepth = vec4(pow(wdepth.x, 4.0)); vec4 invdepth = 1.0 - wdepth; //calculate specular highlight -vec4 vRef = normalize(reflect(-lightTS, vNorm)); +vec4 vRef = normalize(reflect(lightTS, vNorm)); float stemp =max(0.0, dot(viewt, vRef) ); stemp = pow(stemp, exponent); vec4 specular = vec4(stemp); @@ -87,5 +88,10 @@ refl *= fres; //add reflection and refraction tmp = refr + refl; -gl_FragColor = tmp + specular; +if(gl_Fog.density == 1.0) + fogFactor=1.0; + +vec4 finalColor = tmp + specular; + +gl_FragColor = mix(gl_Fog.color,finalColor, fogFactor); } diff --git a/Shaders/water.vert b/Shaders/water.vert index 6b3c8e850..768c15bab 100644 --- a/Shaders/water.vert +++ b/Shaders/water.vert @@ -1,48 +1,47 @@ - varying vec4 waterTex0; varying vec4 waterTex1; varying vec4 waterTex2; varying vec4 waterTex3; varying vec4 waterTex4; -uniform vec4 viewpos, lightpos; -uniform float time, time2; -//unit 0 = water_reflection -//unit 1 = water_refraction -//unit 2 = water_normalmap -//unit 3 = water_dudvmap -//unit 4 = water_depthmap +uniform float osg_SimulationTime; +varying vec3 lightVec; +varying float fogCoord; +varying vec4 ecPosition; void main(void) { -vec4 mpos, temp; + +lightVec = normalize(gl_LightSource[0].position.xyz); +ecPosition = gl_ModelViewMatrix * gl_Vertex; +vec4 lightpos = vec4(lightVec, 1.0); + +vec4 temp; vec4 tangent = vec4(1.0, 0.0, 0.0, 0.0); vec4 norm = vec4(0.0, 1.0, 0.0, 0.0); vec4 binormal = vec4(0.0, 0.0, 1.0, 0.0); -mat4 mvp = gl_ModelViewProjectionMatrix; -mat4 mtx = gl_TextureMatrix[0]; - -temp = viewpos - gl_Vertex; +temp = gl_ModelViewMatrix * gl_Vertex; waterTex4.x = dot(temp, tangent); waterTex4.y = dot(temp, binormal); waterTex4.z = dot(temp, norm); waterTex4.w = 0.0; -temp = lightpos - gl_Vertex; +temp = lightpos; waterTex0.x = dot(temp, tangent); waterTex0.y = dot(temp, binormal); waterTex0.z = dot(temp, norm); waterTex0.w = 0.0; -mpos = mvp * gl_Vertex; -vec4 t1 = vec4(0.0, -time, 0.0,0.0); -vec4 t2 = vec4(0.0, -time2, 0.0,0.0); +vec4 t1 = vec4(0.0, osg_SimulationTime*0.035217, 0.0,0.0); +vec4 t2 = vec4(0.0, osg_SimulationTime*-0.0212, 0.0,0.0); waterTex1 = gl_MultiTexCoord0 + t1; waterTex2 = gl_MultiTexCoord0 + t2; -waterTex3 = mpos; +waterTex3 = gl_MultiTexCoord0; + +fogCoord = abs(ecPosition.z / ecPosition.w); gl_Position = ftransform(); } diff --git a/Textures/Water/water-depth.png b/Textures/Water/water-depth.png index 08084cc95..1096bc9b0 100644 Binary files a/Textures/Water/water-depth.png and b/Textures/Water/water-depth.png differ diff --git a/Textures/Water/water-dudv.png b/Textures/Water/water-dudv.png index d316c58cb..02305a155 100644 Binary files a/Textures/Water/water-dudv.png and b/Textures/Water/water-dudv.png differ diff --git a/Textures/Water/water-normalmap.png b/Textures/Water/water-normalmap.png index f82bbde33..21bd85ded 100644 Binary files a/Textures/Water/water-normalmap.png and b/Textures/Water/water-normalmap.png differ diff --git a/Textures/Water/water-reflection.png b/Textures/Water/water-reflection.png index 4f4c5d87a..f8c6153af 100644 Binary files a/Textures/Water/water-reflection.png and b/Textures/Water/water-reflection.png differ