1
0
Fork 0

Shader trick to generate surf at steep coastlines

This commit is contained in:
Thorsten Renk 2013-06-07 14:35:25 +03:00
parent b3bb82dd88
commit c937881caf
4 changed files with 41 additions and 4 deletions

View file

@ -508,6 +508,11 @@
<use>sea_b</use> <use>sea_b</use>
</value> </value>
</uniform> </uniform>
<uniform>
<name>ocean_flag</name>
<type>int</type>
<value>0</value>
</uniform>
<!-- END fog include --> <!-- END fog include -->
</pass> </pass>
</technique> </technique>
@ -870,6 +875,11 @@
<use>sea_b</use> <use>sea_b</use>
</value> </value>
</uniform> </uniform>
<uniform>
<name>ocean_flag</name>
<type>int</type>
<value>0</value>
</uniform>
<!-- END fog include --> <!-- END fog include -->
</pass> </pass>
</technique> </technique>

View file

@ -562,6 +562,11 @@
<type>int</type> <type>int</type>
<value><use>quality_level</use></value> <value><use>quality_level</use></value>
</uniform> </uniform>
<uniform>
<name>ocean_flag</name>
<type>int</type>
<value>1</value>
</uniform>
<!-- END fog include --> <!-- END fog include -->
</pass> </pass>
</technique> </technique>
@ -925,6 +930,11 @@
<use>sea_b</use> <use>sea_b</use>
</value> </value>
</uniform> </uniform>
<uniform>
<name>ocean_flag</name>
<type>int</type>
<value>1</value>
</uniform>
<!-- END fog include --> <!-- END fog include -->
</pass> </pass>
</technique> </technique>

View file

@ -30,6 +30,7 @@ varying vec3 rawPos;
varying float earthShade; varying float earthShade;
varying float yprime_alt; varying float yprime_alt;
varying float mie_angle; varying float mie_angle;
varying float steepness;
uniform float WaveFreq ; uniform float WaveFreq ;
uniform float WaveAmp ; uniform float WaveAmp ;
@ -57,6 +58,7 @@ uniform float sea_g;
uniform float sea_b; uniform float sea_b;
uniform int quality_level; uniform int quality_level;
uniform int ocean_flag;
vec3 specular_light; vec3 specular_light;
@ -525,11 +527,18 @@ void main(void)
float waveSlope = N.g; float waveSlope = N.g;
float surfFact = 0.0;
if (windEffect >= 8.0) if ((windEffect >= 8.0) || (steepness < 0.999))
if (waveSlope >= foamSlope){ {
finalColor = mix(finalColor, max(finalColor, finalColor + foam_texel), smoothstep(0.01, 0.50, N.g)); if ((waveSlope > 0.0) && (ocean_flag ==1))
{
surfFact = surfFact +(1.0 -smoothstep(0.97,1.0,steepness));
waveSlope = waveSlope + 2.0 * surfFact;
} }
if (waveSlope >= foamSlope){
finalColor = mix(finalColor, max(finalColor, finalColor + foam_texel), smoothstep(0.01, 0.50, N.g+0.2 * surfFact));
}
}
} }

View file

@ -15,6 +15,7 @@ varying vec3 rawPos;
varying vec3 viewerdir; varying vec3 viewerdir;
varying vec3 lightdir; varying vec3 lightdir;
varying float steepness;
varying float earthShade; varying float earthShade;
@ -31,6 +32,8 @@ uniform float visibility;
uniform float overcast; uniform float overcast;
uniform float ground_scattering; uniform float ground_scattering;
uniform int ocean_flag;
uniform mat4 osg_ViewMatrixInverse; uniform mat4 osg_ViewMatrixInverse;
vec3 specular_light; vec3 specular_light;
@ -79,6 +82,11 @@ void main(void)
viewerdir = vec3(gl_ModelViewMatrixInverse[3]) - vec3(gl_Vertex); viewerdir = vec3(gl_ModelViewMatrixInverse[3]) - vec3(gl_Vertex);
lightdir = normalize(vec3(gl_ModelViewMatrixInverse * gl_LightSource[0].position)); lightdir = normalize(vec3(gl_ModelViewMatrixInverse * gl_LightSource[0].position));
if (ocean_flag == 1)
{steepness = dot(normalize(gl_Normal), vec3 (0.0, 0.0, 1.0));}
else
{steepness = 0.0;}
waterTex4 = vec4( ecPosition.xzy, 0.0 ); waterTex4 = vec4( ecPosition.xzy, 0.0 );