1
0
Fork 0

Add foam to water effect. Based on work by Emilian Huminuc.

This commit is contained in:
Vivian Meazza 2011-09-26 23:35:20 +01:00
parent 89005caa40
commit e758deced1
6 changed files with 138 additions and 19 deletions

View file

@ -11,14 +11,16 @@
<internal-format>normalized</internal-format>
</texture>
<texture n="2">
<image>Textures/Water/water-normalmap.png</image>
<!--<image>Textures/Water/water-normalmap.png</image>-->
<image>Textures/Water/normalmap2.png</image>
<filter>linear-mipmap-linear</filter>
<wrap-s>repeat</wrap-s>
<wrap-t>repeat</wrap-t>
<internal-format>normalized</internal-format>
</texture>
<texture n="3">
<image>Textures/Water/water-dudv.png</image>
<!--<image>Textures/Water/water-dudv.png</image>-->
<image>Textures/Water/dudvmap2.png</image>
<filter>linear-mipmap-linear</filter>
<wrap-s>repeat</wrap-s>
<wrap-t>repeat</wrap-t>
@ -31,9 +33,22 @@
<wrap-t>repeat</wrap-t>
<internal-format>normalized</internal-format>
</texture>
<texture n="5">
<image>Textures/Water/sea_foam.png</image>
<filter>linear-mipmap-linear</filter>
<wrap-s>repeat</wrap-s>
<wrap-t>repeat</wrap-t>
<internal-format>normalized</internal-format>
</texture>
<saturation>
<use>/rendering/scene/saturation</use>
</saturation>
<status>
<use>/environment/config/enabled</use>
</status>
<overcast>
<use>/rendering/scene/overcast</use>
</overcast>
<cloud-cover0>
<use>/environment/clouds/layer[0]/coverage-type</use>
</cloud-cover0>
@ -49,6 +64,16 @@
<cloud-cover4>
<use>/environment/clouds/layer[4]/coverage-type</use>
</cloud-cover4>
<!--<wind>
<use>/environment/wind-speed-kt</use>
</wind>-->
<windE>
<use>/environment/config/boundary/entry[0]/wind-from-east-fps</use>
</windE>
<windN>
<use>/environment/config/boundary/entry[0]/wind-from-north-fps</use>
</windN>
</parameters>
<technique n="8">
<predicate>
@ -175,6 +200,24 @@
<use>texture[4]/internal-format</use>
</internal-format>
</texture-unit>
<texture-unit>
<unit>5</unit>
<image>
<use>texture[5]/image</use>
</image>
<filter>
<use>texture[5]/filter</use>
</filter>
<wrap-s>
<use>texture[5]/wrap-s</use>
</wrap-s>
<wrap-t>
<use>texture[5]/wrap-t</use>
</wrap-t>
<internal-format>
<use>texture[5]/internal-format</use>
</internal-format>
</texture-unit>
<program>
<vertex-shader>Shaders/water.vert</vertex-shader>
<fragment-shader>Shaders/water.frag</fragment-shader>
@ -199,11 +242,16 @@
<type>sampler-2d</type>
<value type="int">4</value>
</uniform>
<uniform>
<name>sea_foam</name>
<type>sampler-2d</type>
<value type="int">5</value>
</uniform>
<uniform>
<name>saturation</name>
<type>float</type>
<value>0.4</value>
<!--<value><use>saturation</use></value>-->
<!--<value>0.4</value>-->
<value><use>saturation</use></value>
</uniform>
<uniform>
<name>CloudCover0</name>
@ -240,6 +288,35 @@
<use>cloud-cover4</use>
</value>
</uniform>
<uniform>
<name>Status</name>
<type>int</type>
<value>
<use>status</use>
</value>
<!--<value type="int">0</value> -->
</uniform>
<uniform>
<name>Overcast</name>
<type>float</type>
<value>
<use>overcast</use>
</value>
</uniform>
<uniform>
<name>WindE</name>
<type>float</type>
<value>
<use>windE</use>
</value>
</uniform>
<uniform>
<name>WindN</name>
<type>float</type>
<value>
<use>windN</use>
</value>
</uniform>
</pass>
</technique>
<technique n="9">

View file

@ -3,13 +3,18 @@
// available at http://forum.bonzaisoftware.com/viewthread.php?tid=10
// © Michael Horsch - 2005
#version 120
#pragma debug(on)
uniform sampler2D water_normalmap;
uniform sampler2D water_reflection;
uniform sampler2D water_dudvmap;
uniform sampler2D water_reflection_grey;
uniform sampler2D sea_foam;
uniform float saturation;
uniform float saturation, Overcast, WindE, WindN;
uniform float CloudCover0, CloudCover1, CloudCover2, CloudCover3, CloudCover4;
uniform int Status;
varying vec4 waterTex1; //moving texcoords
varying vec4 waterTex2; //moving texcoords
@ -36,20 +41,37 @@ void main(void)
const float water_shininess = 240.0;
// calculate wind effects
float windEffect = sqrt(pow(abs(WindE),2)+pow(abs(WindN),2)) * 0.6;
float windScale = 10.0/(6.0 + 8.0 * smoothstep(0.0,0.8,windEffect * 0.05));
// approximate cloud cover
float cover = 0;
cover = min(min(min(min(CloudCover0, CloudCover1),CloudCover2),CloudCover3),CloudCover4);
float cover = 0.0;
//bool Status = true;
if (Status == 1){
cover = min(min(min(min(CloudCover0, CloudCover1),CloudCover2),CloudCover3),CloudCover4);
} else {
// hack to allow for Overcast not to be set by Local Weather
if (Overcast == 0){
cover = 5;
} else {
cover = Overcast * 5;
}
}
vec4 viewt = normalize(waterTex4);
vec4 disdis = texture2D(water_dudvmap, vec2(waterTex2 * tscale)) * 2.0 - 1.0;
vec4 dist = texture2D(water_dudvmap, vec2(waterTex1 + disdis*sca2)) * 2.0 - 1.0;
vec4 disdis = texture2D(water_dudvmap, vec2(waterTex2 * tscale)* windScale) * 2.0 - 1.0;
vec4 dist = texture2D(water_dudvmap, vec2(waterTex1 + disdis*sca2)* windScale) * 2.0 - 1.0;
vec4 fdist = normalize(dist);
fdist *= sca;
//normalmap
vec4 nmap0 = texture2D(water_normalmap, vec2(waterTex1+ disdis*sca2)) * 2.0 - 1.0;
vec4 nmap2 = texture2D(water_normalmap, vec2(waterTex2 * tscale)) * 2.0 - 1.0;
vec4 nmap0 = texture2D(water_normalmap, vec2(waterTex1+ disdis*sca2) * windScale) * 2.0 - 1.0;
vec4 nmap2 = texture2D(water_normalmap, vec2(waterTex2 * tscale) * windScale) * 2.0 - 1.0;
vec4 vNorm = normalize(nmap0 + nmap2);
//load reflection
@ -70,20 +92,20 @@ void main(void)
refl.a *= 1.0;
}
vec3 N0 = vec3(texture2D(water_normalmap, vec2(waterTex1+ disdis*sca2)) * 2.0 - 1.0);
vec3 N1 = vec3(texture2D(water_normalmap, vec2(waterTex2 * tscale)) * 2.0 - 1.0);
vec3 N0 = vec3(texture2D(water_normalmap, vec2(waterTex1+ disdis*sca2) * windScale) * 2.0 - 1.0);
vec3 N1 = vec3(texture2D(water_normalmap, vec2(waterTex2 * tscale) * windScale) * 2.0 - 1.0);
vec3 N = normalize(normal+N0+N1);
// specular
vec3 specular_color = vec3(gl_LightSource[0].diffuse)
* pow(max(0.0, dot(N, H)), water_shininess) * 6.0;
vec4 specular = vec4(specular_color, 0.5);
specular = specular * saturation;
specular = specular * saturation * 0.4;
//calculate fresnel
vec4 invfres = vec4( dot(vNorm, viewt) );
vec4 fres = vec4(1.0) + invfres;
vec4 fres = vec4(1.0) + invfres;
refl *= fres;
//calculate the fog factor
@ -95,7 +117,7 @@ void main(void)
if(gl_Fog.density == 1.0)
fogFactor=1.0;
//calculate final colour
//calculate final colour
vec4 ambient_light = gl_LightSource[0].diffuse;
vec4 finalColor;
@ -107,7 +129,17 @@ void main(void)
finalColor = refl;
}
if (windEffect >= 10.0){
float windScale3 = pow(windScale, 3);
if (N.g >= 0.0005 + 0.085 * windScale3){
vec4 foam_texel = texture2D(sea_foam, vec2(waterTex1+ disdis*sca2) * windScale3 * 50.0);
finalColor = mix(finalColor, max(finalColor, foam_texel), smoothstep(0.0005 + 0.085 * windScale3, 0.1, N.g));
}
}
finalColor *= ambient_light;
gl_FragColor = mix(gl_Fog.color, finalColor, fogFactor);
}

View file

@ -3,11 +3,14 @@
// available at http://forum.bonzaisoftware.com/viewthread.php?tid=10
// © Michael Horsch - 2005
#version 120
varying vec4 waterTex1;
varying vec4 waterTex2;
varying vec4 waterTex4;
varying vec4 ecPosition;
uniform float osg_SimulationTime;
uniform float WindE, WindN;
varying vec3 viewerdir;
varying vec3 lightdir;
varying vec3 normal;
@ -24,11 +27,18 @@ lightdir = normalize(vec3(gl_ModelViewMatrixInverse * gl_LightSource[0].position
waterTex4 = vec4( ecPosition.xzy, 0.0 );
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);
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);
//float windFactor = sqrt(pow(abs(WindE),2)+pow(abs(WindN),2)) * 0.3;
float windFactor = 0.001;
waterTex1 = gl_MultiTexCoord0 + t1;
waterTex1.x += WindE * windFactor;
waterTex1.y += WindN * windFactor;
waterTex2 = gl_MultiTexCoord0 + t2;
waterTex2.x += WindE * windFactor;
waterTex2.y += WindN * windFactor;
gl_Position = ftransform();
}

BIN
Textures/Water/dudvmap2.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 770 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 770 KiB

BIN
Textures/Water/sea_foam.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 61 KiB