Index: ps/trunk/binaries/data/mods/public/shaders/glsl/model_common.fs =================================================================== --- ps/trunk/binaries/data/mods/public/shaders/glsl/model_common.fs +++ ps/trunk/binaries/data/mods/public/shaders/glsl/model_common.fs @@ -128,9 +128,9 @@ vec2 move; float height = 1.0; float scale = effectSettings.z; - + int iter = int(min(20.0, 25.0 - dist/10.0)); - + if (iter > 0) { float s = 1.0/float(iter); @@ -145,9 +145,9 @@ coord += temp; h = texture2D(normTex, coord).a; } - - // Move back to where we collided with the surface. - // This assumes the surface is linear between the sample point before we + + // Move back to where we collided with the surface. + // This assumes the surface is linear between the sample point before we // intersect the surface and after we intersect the surface float hp = texture2D(normTex, coord - move).a; coord -= move * ((h - height) / (s + h - hp)); @@ -168,7 +168,7 @@ #else gl_FragColor.a = 1.0; #endif - + vec3 texdiffuse = tex.rgb; // Apply-coloring based on texture alpha Index: ps/trunk/binaries/data/mods/public/shaders/glsl/water_high.fs =================================================================== --- ps/trunk/binaries/data/mods/public/shaders/glsl/water_high.fs +++ ps/trunk/binaries/data/mods/public/shaders/glsl/water_high.fs @@ -133,7 +133,7 @@ return mix(fogColor, color, fogFactor); } -vec3 getNormal() +vec3 getNormal(vec4 fancyeffects) { float wavyEffect = waveParams1.r; float baseScale = waveParams1.g; @@ -155,7 +155,6 @@ vec3 normal = normalize(mix(vec3(0.0, 1.0, 0.0), ww1, clamp(baseBump + fwaviness / flattenism, 0.0, 1.0))); #if USE_FANCY_EFFECTS - vec4 fancyeffects = texture2D(waterEffectsTex, gl_FragCoord.xy / screenSize); normal = mix(vec3(0.0, 1.0, 0.0), normal, 0.5 + waterInfo.r / 2.0); normal.xz = mix(normal.xz, fancyeffects.rb, fancyeffects.a / 2.0); #else @@ -314,18 +313,40 @@ return vec4(refrColor, alpha); } -void main() +vec4 getFoam(vec4 fancyeffects, float shadow) { - vec3 eyeVec = normalize(v_eyeVec); - vec3 normal = getNormal(); +#if USE_FANCY_EFFECTS + float wavyEffect = waveParams1.r; + float baseScale = waveParams1.g; + float BigMovement = waveParams2.b; + vec3 foam1 = texture2D(normalMap, (normalCoords.st + normalCoords.zw * BigMovement * waviness / 10.0) * (baseScale - waviness / wavyEffect)).aaa; + vec3 foam2 = texture2D(normalMap2, (normalCoords.st + normalCoords.zw * BigMovement * waviness / 10.0) * (baseScale - waviness / wavyEffect)).aaa; + vec3 foam3 = texture2D(normalMap, normalCoords.st / 6.0 - normalCoords.zw * 0.02).aaa; + vec3 foam4 = texture2D(normalMap2, normalCoords.st / 6.0 - normalCoords.zw * 0.02).aaa; + vec3 foaminterp = mix(foam1, foam2, moddedTime); + foaminterp *= mix(foam3, foam4, moddedTime); + + foam1.x = abs(foaminterp.x * WindCosSin.x) + abs(foaminterp.z * WindCosSin.y); + float alpha = (fancyeffects.g + pow(foam1.x * (3.0 + waviness), 2.6 - waviness / 5.5)) * 2.0; + return vec4(sunColor * shadow + ambient, clamp(alpha, 0.0, 1.0)); +#else + return vec4(0.0); +#endif +} + +void main() +{ #if USE_FANCY_EFFECTS vec4 fancyeffects = texture2D(waterEffectsTex, gl_FragCoord.xy / screenSize); - vec4 refrColor = getRefraction(normal, eyeVec, fancyeffects.a); #else - vec4 refrColor = getRefraction(normal, eyeVec, 0.0); + vec4 fancyeffects = vec4(0.0); #endif + vec3 eyeVec = normalize(v_eyeVec); + vec3 normal = getNormal(fancyeffects); + + vec4 refrColor = getRefraction(normal, eyeVec, fancyeffects.a); vec4 reflColor = getReflection(normal, eyeVec); // How perpendicular to the normal our view is. Used for fresnel. @@ -336,32 +357,19 @@ vec3 specular = getSpecular(normal, eyeVec); - vec3 color; #if USE_SHADOWS_ON_WATER && USE_SHADOW float shadow = get_shadow(vec4(v_shadow.xy, v_shadow.zw)); float fresShadow = mix(fresnel, fresnel * shadow, 0.05 + murkiness * 0.2); - color = mix(refrColor.rgb, reflColor.rgb, fresShadow * reflColor.a); + vec3 color = mix(refrColor.rgb, reflColor.rgb, fresShadow * reflColor.a); color += shadow * specular; + vec4 foam = getFoam(fancyeffects, shadow); #else - color = mix(refrColor.rgb, reflColor.rgb, fresnel * reflColor.a); + vec3 color = mix(refrColor.rgb, reflColor.rgb, fresnel * reflColor.a); color += specular; + vec4 foam = getFoam(fancyeffects, 1.0); #endif -#if USE_FANCY_EFFECTS - float wavyEffect = waveParams1.r; - float baseScale = waveParams1.g; - float BigMovement = waveParams2.b; - vec3 foam1 = texture2D(normalMap, (normalCoords.st + normalCoords.zw * BigMovement * waviness / 10.0) * (baseScale - waviness / wavyEffect)).aaa; - vec3 foam2 = texture2D(normalMap2, (normalCoords.st + normalCoords.zw * BigMovement * waviness / 10.0) * (baseScale - waviness / wavyEffect)).aaa; - vec3 foam3 = texture2D(normalMap, normalCoords.st / 6.0 - normalCoords.zw * 0.02).aaa; - vec3 foam4 = texture2D(normalMap2, normalCoords.st / 6.0 - normalCoords.zw * 0.02).aaa; - vec3 foaminterp = mix(foam1, foam2, moddedTime); - foaminterp *= mix(foam3, foam4, moddedTime); - - foam1.x = abs(foaminterp.x * WindCosSin.x) + abs(foaminterp.z * WindCosSin.y); - - color += fancyeffects.g + pow(foam1.x * (3.0 + waviness), 2.6 - waviness / 5.5); -#endif + color = clamp(mix(color, foam.rgb, foam.a), 0.0, 1.0); #if USE_FOG color = get_fog(color); Index: ps/trunk/source/renderer/TerrainRenderer.cpp =================================================================== --- ps/trunk/source/renderer/TerrainRenderer.cpp +++ ps/trunk/source/renderer/TerrainRenderer.cpp @@ -803,6 +803,7 @@ if (WaterMgr->m_WaterReflection) m->fancyWaterShader->Uniform(str_reflectionMatrix, WaterMgr->m_ReflectionMatrix); } + m->fancyWaterShader->Uniform(str_ambient, lightEnv.m_TerrainAmbientColor); m->fancyWaterShader->Uniform(str_sunDir, lightEnv.GetSunDir()); m->fancyWaterShader->Uniform(str_sunColor, lightEnv.m_SunColor); m->fancyWaterShader->Uniform(str_color, WaterMgr->m_WaterColor);