1
0
Fork 0

Sea colour effect by Emilian Huminiuc

Signed-off-by: Vivian Meazza <vivian.meazza@lineone.net>
This commit is contained in:
Vivian Meazza 2013-11-03 18:38:31 +00:00
parent cad41c4eff
commit af22245993
4 changed files with 542 additions and 418 deletions

View file

@ -18,13 +18,27 @@ varying vec3 rawNormal;
varying vec3 VTangent; varying vec3 VTangent;
varying vec3 VBinormal; varying vec3 VBinormal;
uniform float osg_SimulationTime; varying vec3 WorldPos;
varying vec2 TopoUV;
uniform float WindE, WindN; uniform float WindE, WindN;
uniform int rembrandt_enabled; uniform int rembrandt_enabled;
uniform float osg_SimulationTime;
uniform mat4 osg_ViewMatrixInverse;
attribute vec3 tangent; attribute vec3 tangent;
attribute vec3 binormal; attribute vec3 binormal;
// constants for the cartezian to geodetic conversion.
const float a = 6378137.0; //float a = equRad;
const float squash = 0.9966471893352525192801545;
const float latAdjust = 0.9999074159800018; //geotiff source for the depth map
const float lonAdjust = 0.9999537058469516; //actual extents: +-180.008333333333326/+-90.008333333333340
/////// functions ///////// /////// functions /////////
void rotationmatrix(in float angle, out mat4 rotmat) void rotationmatrix(in float angle, out mat4 rotmat)
@ -64,6 +78,46 @@ void main(void)
rotationmatrix(Angle, RotationMatrix); rotationmatrix(Angle, RotationMatrix);
waterTex2 = gl_MultiTexCoord0 * RotationMatrix - t2 * windFactor; waterTex2 = gl_MultiTexCoord0 * RotationMatrix - t2 * windFactor;
// fog_Func(fogType); WorldPos = (osg_ViewMatrixInverse *gl_ModelViewMatrix * gl_Vertex).xyz;
///FIXME: convert cartezian coordinates to geodetic, this
///FIXME: duplicates parts of code in SGGeodesy.cxx
////////////////////////////////////////////////////////////////////////////
float e2 = abs(1.0 - squash * squash);
float ra2 = 1.0/(a * a);
float e4 = e2 * e2;
float XXpYY = WorldPos.x * WorldPos.x + WorldPos.y * WorldPos.y;
float Z = WorldPos.z;
float sqrtXXpYY = sqrt(XXpYY);
float p = XXpYY * ra2;
float q = Z*Z*(1.0-e2)*ra2;
float r = 1.0/6.0*(p + q - e4);
float s = e4 * p * q/(4.0*r*r*r);
if ( s >= 2.0 && s <= 0.0)
s = 0.0;
float t = pow(1.0+s+sqrt(s*2.0+s*s), 1.0/3.0);
float u = r + r*t + r/t;
float v = sqrt(u*u + e4*q);
float w = (e2*u+ e2*v-e2*q)/(2.0*v);
float k = sqrt(u+v+w*w)-w;
float D = k*sqrtXXpYY/(k+e2);
vec2 NormPosXY = normalize(WorldPos.xy);
vec2 NormPosXZ = normalize(vec2(D, WorldPos.z));
float signS = sign(WorldPos.y);
if (-0.00015 <= WorldPos.y && WorldPos.y<=.00015)
signS = 1.0;
float signT = sign(WorldPos.z);
if (-0.0002 <= WorldPos.z && WorldPos.z<=.0002)
signT = 1.0;
float cosLon = dot(NormPosXY, vec2(1.0,0.0));
float cosLat = dot(abs(NormPosXZ), vec2(1.0,0.0));
TopoUV.s = signS * lonAdjust * degrees(acos(cosLon))/180.;
TopoUV.t = signT * latAdjust * degrees(acos(cosLat))/90.;
TopoUV.s = TopoUV.s * 0.5 + 0.5;
TopoUV.t = TopoUV.t * 0.5 + 0.5;
//FIXME end/////////////////////////////////////////////////////////////////
gl_Position = ftransform(); gl_Position = ftransform();
} }

View file

@ -14,9 +14,20 @@ varying vec3 viewerdir;
varying vec3 lightdir; varying vec3 lightdir;
varying vec3 normal; varying vec3 normal;
varying vec3 WorldPos;
varying vec2 TopoUV;
uniform float osg_SimulationTime; uniform float osg_SimulationTime;
uniform mat4 osg_ViewMatrixInverse;
uniform float WindE, WindN; uniform float WindE, WindN;
// constants for the cartezian to geodetic conversion.
const float a = 6378137.0; //float a = equRad;
const float squash = 0.9966471893352525192801545;
const float latAdjust = 0.9999074159800018; //geotiff source for the depth map
const float lonAdjust = 0.9999537058469516; //actual extents: +-180.008333333333326/+-90.008333333333340
/////// functions ///////// /////// functions /////////
void rotationmatrix(in float angle, out mat4 rotmat) void rotationmatrix(in float angle, out mat4 rotmat)
@ -54,5 +65,48 @@ void main(void)
waterTex2 = gl_MultiTexCoord0 * RotationMatrix - t2 * windFactor; waterTex2 = gl_MultiTexCoord0 * RotationMatrix - t2 * windFactor;
// fog_Func(fogType); // fog_Func(fogType);
WorldPos = (osg_ViewMatrixInverse *gl_ModelViewMatrix * gl_Vertex).xyz;
///FIXME: convert cartezian coordinates to geodetic, this
///FIXME: duplicates parts of code in SGGeodesy.cxx
////////////////////////////////////////////////////////////////////////////
float e2 = abs(1.0 - squash * squash);
float ra2 = 1.0/(a * a);
float e4 = e2 * e2;
float XXpYY = WorldPos.x * WorldPos.x + WorldPos.y * WorldPos.y;
float Z = WorldPos.z;
float sqrtXXpYY = sqrt(XXpYY);
float p = XXpYY * ra2;
float q = Z*Z*(1.0-e2)*ra2;
float r = 1.0/6.0*(p + q - e4);
float s = e4 * p * q/(4.0*r*r*r);
if ( s >= 2.0 && s <= 0.0)
s = 0.0;
float t = pow(1.0+s+sqrt(s*2.0+s*s), 1.0/3.0);
float u = r + r*t + r/t;
float v = sqrt(u*u + e4*q);
float w = (e2*u+ e2*v-e2*q)/(2.0*v);
float k = sqrt(u+v+w*w)-w;
float D = k*sqrtXXpYY/(k+e2);
vec2 NormPosXY = normalize(WorldPos.xy);
vec2 NormPosXZ = normalize(vec2(D, WorldPos.z));
float signS = sign(WorldPos.y);
if (-0.00015 <= WorldPos.y && WorldPos.y<=.00015)
signS = 1.0;
float signT = sign(WorldPos.z);
if (-0.0002 <= WorldPos.z && WorldPos.z<=.0002)
signT = 1.0;
float cosLon = dot(NormPosXY, vec2(1.0,0.0));
float cosLat = dot(abs(NormPosXZ), vec2(1.0,0.0));
TopoUV.s = signS * lonAdjust * degrees(acos(cosLon))/180.;
TopoUV.t = signT * latAdjust * degrees(acos(cosLat))/90.;
TopoUV.s = TopoUV.s * 0.5 + 0.5;
TopoUV.t = TopoUV.t * 0.5 + 0.5;
//FIXME end/////////////////////////////////////////////////////////////////
gl_Position = ftransform(); gl_Position = ftransform();
} }

View file

@ -1,12 +1,13 @@
// FRAGMENT SHADER
// This shader is mostly an adaptation of the shader found at // This shader is mostly an adaptation of the shader found at
// http://www.bonzaisoftware.com/water_tut.html and its glsl conversion // http://www.bonzaisoftware.com/water_tut.html and its glsl conversion
// available at http://forum.bonzaisoftware.com/viewthread.php?tid=10 // available at http://forum.bonzaisoftware.com/viewthread.php?tid=10
// Michael Horsch - 2005 // ©Michael Horsch - 2005
// Major update and revisions - 2011-10-07 // Major update and revisions - 2011-10-07
// Emilian Huminiuc and Vivian Meazza // ©Emilian Huminiuc and Vivian Meazza
// Optimisation - 2012-5-05 // Optimisation - 2012-5-05
// Based on ideas by Thorsten Renk // Based on ideas by Thorsten Renk
// Emilian Huminiuc and Vivian Meazza // ©Emilian Huminiuc and Vivian Meazza
#version 120 #version 120
@ -17,6 +18,8 @@ uniform sampler2D water_reflection_grey ;
uniform sampler2D sea_foam ; uniform sampler2D sea_foam ;
uniform sampler2D perlin_normalmap ; uniform sampler2D perlin_normalmap ;
uniform sampler2D topo_map;
uniform sampler3D Noise ; uniform sampler3D Noise ;
@ -43,6 +46,9 @@ uniform int Status ;
varying vec4 waterTex1 ; //moving texcoords varying vec4 waterTex1 ; //moving texcoords
varying vec4 waterTex2 ; //moving texcoords varying vec4 waterTex2 ; //moving texcoords
varying vec3 WorldPos ;
varying vec2 TopoUV ;
varying vec3 viewerdir ; varying vec3 viewerdir ;
varying vec3 lightdir ; varying vec3 lightdir ;
varying vec3 normal ; varying vec3 normal ;
@ -51,6 +57,10 @@ varying vec3 VTangent ;
varying vec3 VBinormal ; varying vec3 VBinormal ;
const vec4 AllOnes = vec4(1.0); const vec4 AllOnes = vec4(1.0);
const vec4 sca = vec4(0.005, 0.005, 0.005, 0.005) ;
const vec4 sca2 = vec4(0.02, 0.02, 0.02, 0.02) ;
const vec4 tscale = vec4(0.25, 0.25, 0.25, 0.25) ;
const float water_shininess = 240.0 ;
/////// functions ///////// /////// functions /////////
void encode_gbuffer(vec3 normal, vec3 color, int mId, float specular, float shininess, float emission, float depth); void encode_gbuffer(vec3 normal, vec3 color, int mId, float specular, float shininess, float emission, float depth);
@ -100,7 +110,7 @@ float evaluateWaveDerivSharp(Wave w, vec2 pos, float t, float k)
return k*w.freq*w.amp * pow(sin( dot(w.dir, pos)*w.freq + t*w.phase)* 0.5 + 0.5 , k - 1.0) * cos( dot(w.dir, pos)*w.freq + t*w.phase) ; return k*w.freq*w.amp * pow(sin( dot(w.dir, pos)*w.freq + t*w.phase)* 0.5 + 0.5 , k - 1.0) * cos( dot(w.dir, pos)*w.freq + t*w.phase) ;
} }
void sumWaves(float angle, float dangle, float windScale, float factor, out float ddx, float ddy) void sumWaves(float angle, float dangle, float windScale, float factor, out float ddx, out float ddy)
{ {
mat4 RotationMatrix ; mat4 RotationMatrix ;
float deriv ; float deriv ;
@ -132,9 +142,6 @@ void sumWaves(float angle, float dangle, float windScale, float factor, out floa
void main(void) void main(void)
{ {
const vec4 sca = vec4(0.005, 0.005, 0.005, 0.005) ;
const vec4 sca2 = vec4(0.02, 0.02, 0.02, 0.02) ;
const vec4 tscale = vec4(0.25, 0.25, 0.25, 0.25) ;
mat4 RotationMatrix ; mat4 RotationMatrix ;
@ -148,22 +155,33 @@ void main(void)
vec3 Normal = normalize(normal) ; vec3 Normal = normalize(normal) ;
vec3 vNormal = normalize(rawNormal) ; vec3 vNormal = normalize(rawNormal) ;
const float water_shininess = 240.0 ;
// float range = gl_ProjectionMatrix[3].z/(gl_FragCoord.z * -2.0 + 1.0 - gl_ProjectionMatrix[2].z);
// approximate cloud cover // approximate cloud cover
float cover = 0.0 ; float cover = 0.0 ;
//bool Status = true; //bool Status = true;
// Global bathymetry texture
vec4 topoTexel = texture2D(topo_map, TopoUV);
vec4 mixNoise = texture3D(Noise, WorldPos.xyz * 0.00005);
vec4 mixNoise1 = texture3D(Noise, WorldPos.xyz * 0.00008);
float mixNoiseFactor = mixNoise.r * mixNoise.g * mixNoise.b;
float mixNoise1Factor = mixNoise1.r * mixNoise1.g * mixNoise1.b;
mixNoiseFactor *= 300.0;
mixNoise1Factor *= 300.0;
mixNoiseFactor = 0.8 + 0.2 * smoothstep(0.0,1.0, mixNoiseFactor)* smoothstep(0.0,1.0, mixNoise1Factor);
float floorMixFactor = smoothstep(0.3, 0.985, topoTexel.a * mixNoiseFactor);
vec3 floorColour = mix(topoTexel.rgb, mixNoise.rgb * mixNoise1.rgb, 0.3);
float windFloorFactor = 1.0 + 0.5 * smoothstep(0.8, 0.985, topoTexel.a);
float windEffect = sqrt( WindE*WindE + WindN*WindN ) * 0.6; //wind speed in kt float windEffect = sqrt( WindE*WindE + WindN*WindN ) * 0.6; //wind speed in kt
float windFloorEffect = windEffect * windFloorFactor;
float windScale = 15.0/(3.0 + windEffect); //wave scale float windScale = 15.0/(3.0 + windEffect); //wave scale
float windEffect_low = 0.3 + 0.7 * smoothstep(0.0, 5.0, windEffect); //low windspeed wave filter float windEffect_low = 0.3 + 0.7 * smoothstep(0.0, 5.0, windEffect); //low windspeed wave filter
float waveRoughness = 0.01 + smoothstep(0.0, 40.0, windEffect); //wave roughness filter float waveRoughness = 0.01 + smoothstep(0.0, 40.0, windEffect); //wave roughness filter
float mixFactor = 0.2 + 0.02 * smoothstep(0.0, 50.0, windEffect); float mixFactor = 0.2 + 0.02 * smoothstep(0.0, 50.0, windFloorEffect);
mixFactor = clamp(mixFactor, 0.3, 0.8); mixFactor = clamp(mixFactor, 0.3, 0.95);
// sine waves // sine waves
// Test data // Test data
@ -173,12 +191,6 @@ void main(void)
vec4 ddxVec = vec4(0.0) ; vec4 ddxVec = vec4(0.0) ;
vec4 ddyVec = vec4(0.0) ; vec4 ddyVec = vec4(0.0) ;
int detailFlag = 0 ;
//uncomment to test
//range = -20000;
// if (range > -15000 || dot(Normal,H) > 0.95 ) {
float ddx = 0.0, ddy = 0.0 ; float ddx = 0.0, ddy = 0.0 ;
float ddx1 = 0.0, ddy1 = 0.0 ; float ddx1 = 0.0, ddy1 = 0.0 ;
@ -187,25 +199,30 @@ void main(void)
float waveamp ; float waveamp ;
float angle = 0.0 ; float angle = 0.0 ;
float WaveAmpFromDepth = WaveAmp * (1.0 + 0.5 * smoothstep(0.8, 0.9, topoTexel.a));
float phaseFloorFactor = 1.0 - 0.2 * smoothstep(0.8, 0.9, topoTexel.a);
wave0.freq = WaveFreq ; wave0.freq = WaveFreq ;
wave0.amp = WaveAmp ; wave0.amp = WaveAmpFromDepth ;
wave0.dir = vec2(cos(radians(angle)), sin(radians(angle))) ; wave0.dir = vec2(cos(radians(angle)), sin(radians(angle))) ;
wave0.phase *= phaseFloorFactor;
angle -= 45.0 ; angle -= 45.0 ;
wave1.freq = WaveFreq * 2.0 ; wave1.freq = WaveFreq * 2.0 ;
wave1.amp = WaveAmp * 1.25 ; wave1.amp = WaveAmpFromDepth * 1.25 ;
wave1.dir = vec2(cos(radians(angle)), sin(radians(angle))) ; wave1.dir = vec2(cos(radians(angle)), sin(radians(angle))) ;
wave1.phase *= phaseFloorFactor;
angle += 30.0; angle += 30.0;
wave2.freq = WaveFreq * 3.5 ; wave2.freq = WaveFreq * 3.5 ;
wave2.amp = WaveAmp * 0.75 ; wave2.amp = WaveAmpFromDepth * 0.75 ;
wave2.dir = vec2(cos(radians(angle)), sin(radians(angle))) ; wave2.dir = vec2(cos(radians(angle)), sin(radians(angle))) ;
wave2.phase *= phaseFloorFactor;
angle -= 50.0 ; angle -= 50.0 ;
wave3.freq = WaveFreq * 3.0 ; wave3.freq = WaveFreq * 3.0 ;
wave3.amp = WaveAmp * 0.75 ; wave3.amp = WaveAmpFromDepth * 0.75 ;
wave3.dir = vec2(cos(radians(angle)), sin(radians(angle))) ; wave3.dir = vec2(cos(radians(angle)), sin(radians(angle))) ;
wave3.phase *= phaseFloorFactor;
// sum waves // sum waves
@ -217,7 +234,7 @@ void main(void)
//reset the waves //reset the waves
angle = 0.0 ; angle = 0.0 ;
waveamp = WaveAmp * 0.75 ; waveamp = WaveAmpFromDepth * 0.75 ;
wave0.freq = WaveFreq ; wave0.freq = WaveFreq ;
wave0.amp = waveamp ; wave0.amp = waveamp ;
@ -248,10 +265,6 @@ void main(void)
ddxVec = vec4(ddx, ddx1, ddx2, ddx3) ; ddxVec = vec4(ddx, ddx1, ddx2, ddx3) ;
ddyVec = vec4(ddy, ddy1, ddy2, ddy3) ; ddyVec = vec4(ddy, ddy1, ddy2, ddy3) ;
//toggle detailFlag
//detailFlag = 1 ;
// } // end sine stuff
float ddxSum = dot(ddxVec, AllOnes) ; float ddxSum = dot(ddxVec, AllOnes) ;
float ddySum = dot(ddyVec, AllOnes) ; float ddySum = dot(ddyVec, AllOnes) ;
@ -266,73 +279,73 @@ void main(void)
} }
} }
// vec4 viewt = normalize(waterTex4);
vec4 viewt = vec4(-E, 0.0) * 0.6 ; vec4 viewt = vec4(-E, 0.0) * 0.6 ;
vec4 disdis = texture2D(water_dudvmap, vec2(waterTex2 * tscale)* windScale) * 2.0 - 1.0 ; vec4 disdis = texture2D(water_dudvmap, vec2(waterTex2 * tscale)* windScale) * 2.0 - 1.0 ;
vec2 uvAnimSca2 = (waterTex1 + disdis * sca2).st * windScale;
//normalmaps //normalmaps
vec4 nmap = texture2D(water_normalmap, vec2(waterTex1 + disdis * sca2) * windScale) * 2.0 - 1.0 ; vec4 nmap = texture2D(water_normalmap, uvAnimSca2) * 2.0 - 1.0;
vec4 nmap1 = texture2D(perlin_normalmap, vec2(waterTex1 + disdis * sca2) * windScale) * 2.0 - 1.0 ; vec4 nmap1 = texture2D(perlin_normalmap, uvAnimSca2) * 2.0 - 1.0;
rotationmatrix(radians(3.0 * sin(osg_SimulationTime * 0.0075)), RotationMatrix); rotationmatrix(radians(3.0 * sin(osg_SimulationTime * 0.0075)), RotationMatrix);
nmap += texture2D(water_normalmap, vec2(waterTex2 * RotationMatrix * tscale) * windScale) * 2.0 - 1.0 ; vec2 uvAnimTscale = (waterTex2 * RotationMatrix * tscale).st * windScale;
nmap1 += texture2D(perlin_normalmap, vec2(waterTex2 * RotationMatrix * tscale) * windScale) * 2.0 - 1.0 ;
nmap *= windEffect_low ; nmap += texture2D(water_normalmap, uvAnimTscale) * 2.0 - 1.0;
nmap1 *= windEffect_low ; nmap1 += texture2D(perlin_normalmap, uvAnimTscale) * 2.0 - 1.0;
// mix water and noise, modulated by factor // mix water and noise, modulated by factor
vec4 vNorm = normalize(mix(nmap, nmap1, mixFactor) * waveRoughness) ; vec4 vNorm = normalize(mix(nmap, nmap1, mixFactor) * waveRoughness) ;
vNorm.r += ddxSum ; vNorm.r += ddxSum ;
vNorm.y += ddySum ;
if (normalmap_dds > 0)//dds fix if (normalmap_dds > 0)//dds fix
vNorm = -vNorm ; vNorm = -vNorm ;
//load reflection //load reflection
//vec4 tmp = vec4(lightdir, 0.0); //vec4 tmp = vec4(lightdir, 0.0);
vec4 tmp = vec4(0.0); //vec4 tmp = vec4(0.0);
vec4 refTex = texture2D(water_reflection, vec2(tmp + waterTex1) * 32.0) ; vec2 refTexUV = waterTex1.st * 32.0;
vec4 refTexGrey = texture2D(water_reflection_grey, vec2(tmp + waterTex1) * 32.0) ; vec4 refTex = texture2D(water_reflection, refTexUV) ;
vec4 refl ; vec4 refTexGrey = texture2D(water_reflection_grey, refTexUV) ;
vec4 refl = vec4(0.0,0.0,0.0,1.0) ;
// Test data // Test data
// cover = 0; // cover = 0;
if(cover >= 1.5){ if(cover >= 1.5){
refl = normalize(refTex); refl.rgb = normalize(refTex).rgb;
refl.a = 1.0;
} }
else else
{ {
refl = normalize(refTexGrey); refl.rgb = normalize(refTexGrey).rgb;
refl.r *= (0.75 + 0.15 * cover); refl.r *= (0.75 + 0.15 * cover);
refl.g *= (0.80 + 0.15 * cover); refl.g *= (0.80 + 0.15 * cover);
refl.b *= (0.875 + 0.125 * cover); refl.b *= (0.875 + 0.125 * cover);
refl.a = 1.0;
} }
vec3 N0 = vec3(texture2D(water_normalmap, vec2(waterTex1 + disdis * sca2) * windScale) * 2.0 - 1.0); vec4 N0 = texture2D(water_normalmap, uvAnimSca2) * 2.0 - 1.0;
vec3 N1 = vec3(texture2D(perlin_normalmap, vec2(waterTex1 + disdis * sca) * windScale) * 2.0 - 1.0); vec4 N1 = texture2D(perlin_normalmap, vec2(waterTex1 + disdis * sca) * windScale) * 2.0 - 1.0;
N0 += texture2D(water_normalmap, vec2(waterTex1 * tscale) * windScale) * 2.0 - 1.0;
N1 += texture2D(perlin_normalmap, vec2(waterTex2 * tscale) * windScale) * 2.0 - 1.0;
N0 += vec3(texture2D(water_normalmap, vec2(waterTex1 * tscale) * windScale) * 2.0 - 1.0);
N1 += vec3(texture2D(perlin_normalmap, vec2(waterTex2 * tscale) * windScale) * 2.0 - 1.0);
rotationmatrix(radians(2.0 * sin(osg_SimulationTime * 0.005)), RotationMatrix); rotationmatrix(radians(2.0 * sin(osg_SimulationTime * 0.005)), RotationMatrix);
N0 += vec3(texture2D(water_normalmap, vec2(waterTex2 * RotationMatrix * (tscale + sca2)) * windScale) * 2.0 - 1.0); vec2 uvAnimTscaleSca2 = (waterTex2 * RotationMatrix * (tscale + sca2)).st * windScale;
N1 += vec3(texture2D(perlin_normalmap, vec2(waterTex2 * RotationMatrix * (tscale + sca2)) * windScale) * 2.0 - 1.0); N0 += texture2D(water_normalmap, uvAnimTscaleSca2) * 2.0 - 1.0;
N1 += texture2D(perlin_normalmap, uvAnimTscaleSca2) * 2.0 - 1.0;
rotationmatrix(radians(-4.0 * sin(osg_SimulationTime * 0.003)), RotationMatrix); rotationmatrix(radians(-4.0 * sin(osg_SimulationTime * 0.003)), RotationMatrix);
N0 += vec3(texture2D(water_normalmap, vec2(waterTex1 * RotationMatrix + disdis * sca2) * windScale) * 2.0 - 1.0); N0 += texture2D(water_normalmap, vec2(waterTex1 * RotationMatrix + disdis * sca2) * windScale) * 2.0 - 1.0;
N1 += vec3(texture2D(perlin_normalmap, vec2(waterTex1 * RotationMatrix + disdis * sca) * windScale) * 2.0 - 1.0); N1 += texture2D(perlin_normalmap, vec2(waterTex1 * RotationMatrix + disdis * sca) * windScale) * 2.0 - 1.0;
// if(detailFlag > 0)
// {
N0 *= windEffect_low; N0 *= windEffect_low;
N1 *= windEffect_low; N1 *= windEffect_low;
N0.r += ddxSum; N0.r += ddxSum;
N0.g += ddySum; N0.g += ddySum;
vec3 N2 = normalize(mix(N0, N1, mixFactor) * waveRoughness); vec3 N2 = normalize(mix(N0.rgb, N1.rgb, mixFactor) * waveRoughness);
Normal = normalize(N2.x * VTangent + N2.y * VBinormal + N2.z * Normal); Normal = normalize(N2.x * VTangent + N2.y * VBinormal + N2.z * Normal);
//vNormal = normalize(mix(vNormal + N0, vNormal + N1, mixFactor) * waveRoughness); //vNormal = normalize(mix(vNormal + N0, vNormal + N1, mixFactor) * waveRoughness);
vNormal = normalize(N2.x * vec3(1.0, 0.0, 0.0) + N2.y * vec3(0.0, 1., 0.0) + N2.z * vNormal); vNormal = normalize(N2.x * vec3(1.0, 0.0, 0.0) + N2.y * vec3(0.0, 1., 0.0) + N2.z * vNormal);
@ -340,7 +353,6 @@ void main(void)
Normal = -Normal; Normal = -Normal;
vNormal = -vNormal; vNormal = -vNormal;
} }
// }
// specular // specular
@ -350,35 +362,33 @@ void main(void)
// float specular = saturation * 0.3; // float specular = saturation * 0.3;
//calculate fresnel //calculate fresnel
vec4 invfres = vec4( dot(vNorm, viewt) ); float vNormDotViewT = dot(vNorm, viewt);
vec4 invfres = vec4( vNormDotViewT );
vec4 fres = vec4(1.0) + invfres; vec4 fres = vec4(1.0) + invfres;
refl *= fres; refl *= fres;
refl.rgb = mix(refl.rgb, floorColour, floorMixFactor);
//calculate final colour //calculate final colour
vec4 finalColor = refl; vec4 finalColor = refl;
//add foam //add foam
vec4 foam_texel = texture2D(sea_foam, vec2(waterTex2 * tscale) * 25.0); vec4 foam_texel = texture2D(sea_foam, (waterTex2 * tscale).st * 50.0);
// if (range > -10000.0){
float foamSlope = 0.1 + 0.1 * windScale; float foamSlope = 0.1 + 0.1 * windScale;
float waveSlope = vNormal.g;
if (windEffect >= 8.0)
if (waveSlope >= foamSlope){
finalColor = mix( finalColor,
max(finalColor, finalColor + foam_texel),
smoothstep(0.01, 0.50, vNormal.g)
);
}
// } // end range float waveSlope1 = vNormal.g * windFloorFactor * 0.96 ; //0.6; Normals values seem to be .25 of those in the classic pipeline
float waveSlope2 = vNorm.r * windFloorFactor * 0.4; //0.25;
float waveSlope = waveSlope1 + waveSlope2 ;
finalColor = mix(finalColor, max(finalColor, finalColor + foam_texel),
smoothstep(7.0, 8.0, windFloorEffect)
* step(foamSlope, waveSlope)
* smoothstep(0.01, 0.50, waveSlope));
float emission = dot( gl_FrontLightModelProduct.sceneColor.rgb + gl_FrontMaterial.emission.rgb, float emission = dot( gl_FrontLightModelProduct.sceneColor.rgb + gl_FrontMaterial.emission.rgb,
vec3( 0.3, 0.59, 0.11 ) vec3( 0.3, 0.59, 0.11 )
); );
float specular = smoothstep(0.0, 3.5, cover); float specular = smoothstep(0.0, 3.5, cover);
encode_gbuffer(Normal, finalColor.rgb, 254, specular, water_shininess, emission, gl_FragCoord.z); encode_gbuffer(Normal, finalColor.rgb, 254, specular, water_shininess, emission, gl_FragCoord.z);
} }

View file

@ -1,42 +1,51 @@
// FRAGMENT SHADER
// This shader is mostly an adaptation of the shader found at // This shader is mostly an adaptation of the shader found at
// http://www.bonzaisoftware.com/water_tut.html and its glsl conversion // http://www.bonzaisoftware.com/water_tut.html and its glsl conversion
// available at http://forum.bonzaisoftware.com/viewthread.php?tid=10 // available at http://forum.bonzaisoftware.com/viewthread.php?tid=10
// © Michael Horsch - 2005 // ©Michael Horsch - 2005
// Major update and revisions - 2011-10-07 // Major update and revisions - 2011-10-07
// © Emilian Huminiuc and Vivian Meazza // ©Emilian Huminiuc and Vivian Meazza
// Optimisation - 2012-5-05 // Optimisation - 2012-5-05
// Based on ideas by Thorsten Renk // Based on ideas by Thorsten Renk
// © Emilian Huminiuc and Vivian Meazza // ©Emilian Huminiuc and Vivian Meazza
#version 120 #version 120
uniform sampler2D water_normalmap; varying vec2 TopoUV;
uniform sampler2D water_reflection; varying vec3 WorldPos;
uniform sampler2D water_dudvmap; varying vec3 lightdir;
uniform sampler2D water_reflection_grey; varying vec3 normal;
uniform sampler2D sea_foam; varying vec3 viewerdir;
uniform sampler2D perlin_normalmap;
uniform sampler3D Noise;
uniform float saturation, Overcast, WindE, WindN;
uniform float CloudCover0, CloudCover1, CloudCover2, CloudCover3, CloudCover4;
uniform float osg_SimulationTime;
uniform int Status;
varying vec4 waterTex1; //moving texcoords varying vec4 waterTex1; //moving texcoords
varying vec4 waterTex2; //moving texcoords varying vec4 waterTex2; //moving texcoords
varying vec3 viewerdir; uniform sampler2D perlin_normalmap;
varying vec3 lightdir; uniform sampler2D sea_foam;
varying vec3 normal; uniform sampler2D topo_map;
uniform sampler2D water_dudvmap;
uniform sampler2D water_normalmap;
uniform sampler2D water_reflection;
uniform sampler2D water_reflection_grey;
uniform sampler3D Noise;
uniform float CloudCover0;
uniform float CloudCover1;
uniform float CloudCover2;
uniform float CloudCover3;
uniform float CloudCover4;
uniform float Overcast;
uniform float WindE;
uniform float WindN;
uniform float osg_SimulationTime;
uniform float saturation;
uniform int Status;
uniform float WaveFreq ;
uniform float WaveAmp; uniform float WaveAmp;
uniform float WaveSharp ;
uniform float WaveAngle; uniform float WaveAngle;
uniform float WaveFactor ;
uniform float WaveDAngle; uniform float WaveDAngle;
uniform float WaveFactor;
uniform float WaveFreq;
uniform float WaveSharp;
uniform float normalmap_dds; uniform float normalmap_dds;
////fog "include" ///// ////fog "include" /////
@ -46,6 +55,10 @@ vec3 fog_Func(vec3 color, int type);
////////////////////// //////////////////////
const vec4 AllOnes = vec4(1.0); const vec4 AllOnes = vec4(1.0);
const vec4 sca = vec4(0.005, 0.005, 0.005, 0.005);
const vec4 sca2 = vec4(0.02, 0.02, 0.02, 0.02);
const vec4 tscale = vec4(0.25, 0.25, 0.25, 0.25);
const float water_shininess = 240.0;
/////// functions ///////// /////// functions /////////
@ -93,7 +106,7 @@ float evaluateWaveDerivSharp(Wave w, vec2 pos, float t, float k)
return k*w.freq*w.amp * pow(sin( dot(w.dir, pos)*w.freq + t*w.phase)* 0.5 + 0.5 , k - 1.0) * cos( dot(w.dir, pos)*w.freq + t*w.phase); return k*w.freq*w.amp * pow(sin( dot(w.dir, pos)*w.freq + t*w.phase)* 0.5 + 0.5 , k - 1.0) * cos( dot(w.dir, pos)*w.freq + t*w.phase);
} }
void sumWaves(float angle, float dangle, float windScale, float factor, out float ddx, float ddy) void sumWaves(float angle, float dangle, float windScale, float factor, out float ddx, out float ddy)
{ {
mat4 RotationMatrix; mat4 RotationMatrix;
float deriv; float deriv;
@ -125,10 +138,6 @@ void sumWaves(float angle, float dangle, float windScale, float factor, out floa
void main(void) void main(void)
{ {
const vec4 sca = vec4(0.005, 0.005, 0.005, 0.005);
const vec4 sca2 = vec4(0.02, 0.02, 0.02, 0.02);
const vec4 tscale = vec4(0.25, 0.25, 0.25, 0.25);
mat4 RotationMatrix; mat4 RotationMatrix;
// compute direction to viewer // compute direction to viewer
@ -142,25 +151,37 @@ void main(void)
vec3 Normal = normalize(normal); vec3 Normal = normalize(normal);
const float water_shininess = 240.0;
float range = gl_ProjectionMatrix[3].z/(gl_FragCoord.z * -2.0 + 1.0 - gl_ProjectionMatrix[2].z);
// approximate cloud cover // approximate cloud cover
float cover = 0.0; float cover = 0.0;
//bool Status = true; //bool Status = true;
// try some aliasing fix for low angles
// float viewAngle = smoothstep(0.0,0.5,abs(dot(E,Normal)));
// Global bathymetry texture
vec4 topoTexel = texture2D(topo_map, TopoUV);
vec4 mixNoise = texture3D(Noise, WorldPos.xyz * 0.00005);
vec4 mixNoise1 = texture3D(Noise, WorldPos.xyz * 0.00008);
float mixNoiseFactor = mixNoise.r * mixNoise.g * mixNoise.b;
float mixNoise1Factor = mixNoise1.r * mixNoise1.g * mixNoise1.b;
mixNoiseFactor *= 300.0;
mixNoise1Factor *= 300.0;
mixNoiseFactor = 0.8 + 0.2 * smoothstep(0.0,1.0, mixNoiseFactor)* smoothstep(0.0,1.0, mixNoise1Factor);
float floorMixFactor = smoothstep(0.3, 0.985, topoTexel.a * mixNoiseFactor);
vec3 floorColour = mix(topoTexel.rgb, mixNoise.rgb * mixNoise1.rgb, 0.3);
float windFloorFactor = 1.0 + 0.5 * smoothstep(0.8, 0.985, topoTexel.a);
float windEffect = sqrt( WindE*WindE + WindN*WindN ) * 0.6; //wind speed in kt float windEffect = sqrt( WindE*WindE + WindN*WindN ) * 0.6; //wind speed in kt
float windFloorEffect = windEffect * windFloorFactor;
float windScale = 15.0/(3.0 + windEffect); //wave scale float windScale = 15.0/(3.0 + windEffect); //wave scale
float windEffect_low = 0.3 + 0.7 * smoothstep(0.0, 5.0, windEffect); //low windspeed wave filter float windEffect_low = 0.3 + 0.7 * smoothstep(0.0, 5.0, windEffect); //low windspeed wave filter
float waveRoughness = 0.01 + smoothstep(0.0, 40.0, windEffect); //wave roughness filter float waveRoughness = 0.01 + smoothstep(0.0, 40.0, windEffect); //wave roughness filter
float mixFactor = 0.2 + 0.02 * smoothstep(0.0, 50.0, windEffect); float mixFactor = 0.2 + 0.02 * smoothstep(0.0, 50.0, windFloorEffect);
//mixFactor = 0.2; mixFactor = clamp(mixFactor, 0.3, 0.95);
mixFactor = clamp(mixFactor, 0.3, 0.8);
// sine waves // sine waves
//
// Test data // Test data
// float WaveFreq =1.0; // float WaveFreq =1.0;
// float WaveAmp = 1000.0; // float WaveAmp = 1000.0;
@ -168,12 +189,6 @@ void main(void)
vec4 ddxVec = vec4(0.0); vec4 ddxVec = vec4(0.0);
vec4 ddyVec = vec4(0.0); vec4 ddyVec = vec4(0.0);
int detailFlag = 0;
//uncomment to test
//range = -20000;
if (range > -15000.0 || dot(Normal,H) > 0.95 ) {
float ddx = 0.0, ddy = 0.0; float ddx = 0.0, ddy = 0.0;
float ddx1 = 0.0, ddy1 = 0.0; float ddx1 = 0.0, ddy1 = 0.0;
@ -182,28 +197,32 @@ void main(void)
float waveamp; float waveamp;
float angle = 0.0; float angle = 0.0;
float WaveAmpFromDepth = WaveAmp * windFloorFactor;
wave0.freq = WaveFreq ; float phaseFloorFactor = 1.0 - 0.2 * smoothstep(0.8, 0.9, topoTexel.a);
wave0.amp = WaveAmp; wave0.freq = WaveFreq; // * (smoothstep(0.8, 0.9, topoTexel.a)*1.5 + 0.25);
wave0.amp = WaveAmpFromDepth;
wave0.dir = vec2(cos(radians(angle)), sin(radians(angle))); wave0.dir = vec2(cos(radians(angle)), sin(radians(angle)));
wave0.phase *= phaseFloorFactor;
angle -= 45.0; angle -= 45.0;
wave1.freq = WaveFreq * 2.0 ; wave1.freq = WaveFreq * 2.0 ;
wave1.amp = WaveAmp * 1.25; wave1.amp = WaveAmpFromDepth * 1.25;
wave1.dir = vec2(cos(radians(angle)), sin(radians(angle))); wave1.dir = vec2(cos(radians(angle)), sin(radians(angle)));
wave1.phase *= phaseFloorFactor;
angle += 30.0; angle += 30.0;
wave2.freq = WaveFreq * 3.5; wave2.freq = WaveFreq * 3.5;
wave2.amp = WaveAmp * 0.75; wave2.amp = WaveAmpFromDepth * 0.75;
wave2.dir = vec2(cos(radians(angle)), sin(radians(angle))); wave2.dir = vec2(cos(radians(angle)), sin(radians(angle)));
wave2.phase *= phaseFloorFactor;
angle -= 50.0; angle -= 50.0;
wave3.freq = WaveFreq * 3.0 ; wave3.freq = WaveFreq * 3.0 ;
wave3.amp = WaveAmp * 0.75; wave3.amp = WaveAmpFromDepth * 0.75;
wave3.dir = vec2(cos(radians(angle)), sin(radians(angle))); wave3.dir = vec2(cos(radians(angle)), sin(radians(angle)));
wave3.phase *= phaseFloorFactor;
// sum waves // sum waves
ddx = 0.0, ddy = 0.0; ddx = 0.0, ddy = 0.0;
sumWaves(WaveAngle, -1.5, windScale, WaveFactor, ddx, ddy); sumWaves(WaveAngle, -1.5, windScale, WaveFactor, ddx, ddy);
@ -212,7 +231,7 @@ void main(void)
//reset the waves //reset the waves
angle = 0.0; angle = 0.0;
waveamp = WaveAmp * 0.75; waveamp = WaveAmpFromDepth * 0.75;
wave0.freq = WaveFreq ; wave0.freq = WaveFreq ;
wave0.amp = waveamp; wave0.amp = waveamp;
@ -243,10 +262,6 @@ void main(void)
ddxVec = vec4(ddx, ddx1, ddx2, ddx3); ddxVec = vec4(ddx, ddx1, ddx2, ddx3);
ddyVec = vec4(ddy, ddy1, ddy2, ddy3); ddyVec = vec4(ddy, ddy1, ddy2, ddy3);
//toggle detailFlag
detailFlag = 1;
} // end sine stuff
float ddxSum = dot(ddxVec, AllOnes); float ddxSum = dot(ddxVec, AllOnes);
float ddySum = dot(ddyVec, AllOnes); float ddySum = dot(ddyVec, AllOnes);
@ -254,25 +269,27 @@ void main(void)
cover = min(min(min(min(CloudCover0, CloudCover1),CloudCover2),CloudCover3),CloudCover4); cover = min(min(min(min(CloudCover0, CloudCover1),CloudCover2),CloudCover3),CloudCover4);
} else { } else {
// hack to allow for Overcast not to be set by Local Weather // hack to allow for Overcast not to be set by Local Weather
if (Overcast == 0){ if (Overcast == 0.0){
cover = 5; cover = 5.0;
} else { } else {
cover = Overcast * 5; cover = Overcast * 5.0;
} }
} }
// vec4 viewt = normalize(waterTex4);
vec4 viewt = vec4(-E, 0.0) * 0.6; vec4 viewt = vec4(-E, 0.0) * 0.6;
vec4 disdis = texture2D(water_dudvmap, vec2(waterTex2 * tscale)* windScale) * 2.0 - 1.0; vec4 disdis = texture2D(water_dudvmap, vec2(waterTex2 * tscale)* windScale) * 2.0 - 1.0;
vec2 uvAnimSca2 = (waterTex1 + disdis * sca2).st * windScale;
//normalmaps //normalmaps
vec4 nmap = texture2D(water_normalmap, vec2(waterTex1 + disdis * sca2) * windScale) * 2.0 - 1.0; vec4 nmap = texture2D(water_normalmap, uvAnimSca2) * 2.0 - 1.0;
vec4 nmap1 = texture2D(perlin_normalmap, vec2(waterTex1 + disdis * sca2) * windScale) * 2.0 - 1.0; vec4 nmap1 = texture2D(perlin_normalmap, uvAnimSca2) * 2.0 - 1.0;
rotationmatrix(radians(3.0 * sin(osg_SimulationTime * 0.0075)), RotationMatrix); rotationmatrix(radians(3.0 * sin(osg_SimulationTime * 0.0075)), RotationMatrix);
nmap += texture2D(water_normalmap, vec2(waterTex2 * RotationMatrix * tscale) * windScale) * 2.0 - 1.0; vec2 uvAnimTscale = (waterTex2 * RotationMatrix * tscale).st * windScale;
nmap1 += texture2D(perlin_normalmap, vec2(waterTex2 * RotationMatrix * tscale) * windScale) * 2.0 - 1.0;
nmap += texture2D(water_normalmap, uvAnimTscale) * 2.0 - 1.0;
nmap1 += texture2D(perlin_normalmap, uvAnimTscale) * 2.0 - 1.0;
nmap *= windEffect_low; nmap *= windEffect_low;
nmap1 *= windEffect_low; nmap1 *= windEffect_low;
@ -286,100 +303,89 @@ void main(void)
//load reflection //load reflection
vec4 tmp = vec4(lightdir, 0.0); vec4 tmp = vec4(lightdir, 0.0);
vec4 refTex = texture2D(water_reflection, vec2(tmp + waterTex1) * 32.0) ; vec2 refTexUV = (tmp + waterTex1).st * 32.0;
vec4 refTexGrey = texture2D(water_reflection_grey, vec2(tmp + waterTex1) * 32.0) ; vec4 refTex = texture2D(water_reflection, refTexUV) ;
vec4 refl ; vec4 refTexGrey = texture2D(water_reflection_grey, refTexUV) ;
vec4 refl = vec4(0.0,0.0,0.0,1.0) ;
// Test data // Test data
// cover = 0; // cover = 0;
if(cover >= 1.5){ if(cover >= 1.5){
refl = normalize(refTex); refl.rgb = normalize(refTex).rgb;
refl.a = 1.0;
} }
else else
{ {
refl = normalize(refTexGrey); refl.rgb = normalize(refTexGrey).rgb;
refl.r *= (0.75 + 0.15 * cover ); refl.r *= (0.75 + 0.15 * cover );
refl.g *= (0.80 + 0.15 * cover ); refl.g *= (0.80 + 0.15 * cover );
refl.b *= (0.875 + 0.125 * cover); refl.b *= (0.875 + 0.125 * cover);
refl.a = 1.0;
} }
vec3 N0 = vec3(texture2D(water_normalmap, vec2(waterTex1 + disdis * sca2) * windScale) * 2.0 - 1.0); // refl.rgb = mix(refl.rgb, floorColour, 0.99 * floorMixFactor);
vec3 N1 = vec3(texture2D(perlin_normalmap, vec2(waterTex1 + disdis * sca) * windScale) * 2.0 - 1.0);
vec4 N0 = texture2D(water_normalmap, uvAnimSca2) * 2.0 - 1.0;
vec4 N1 = texture2D(perlin_normalmap, vec2(waterTex1 + disdis * sca) * windScale) * 2.0 - 1.0;
N0 += texture2D(water_normalmap, vec2(waterTex1 * tscale) * windScale) * 2.0 - 1.0;
N1 += texture2D(perlin_normalmap, vec2(waterTex2 * tscale) * windScale) * 2.0 - 1.0;
N0 += vec3(texture2D(water_normalmap, vec2(waterTex1 * tscale) * windScale) * 2.0 - 1.0);
N1 += vec3(texture2D(perlin_normalmap, vec2(waterTex2 * tscale) * windScale) * 2.0 - 1.0);
rotationmatrix(radians(2.0 * sin(osg_SimulationTime * 0.005)), RotationMatrix); rotationmatrix(radians(2.0 * sin(osg_SimulationTime * 0.005)), RotationMatrix);
N0 += vec3(texture2D(water_normalmap, vec2(waterTex2 * RotationMatrix * (tscale + sca2)) * windScale) * 2.0 - 1.0); vec2 uvAnimTscaleSca2 = (waterTex2 * RotationMatrix * (tscale + sca2)).st * windScale;
N1 += vec3(texture2D(perlin_normalmap, vec2(waterTex2 * RotationMatrix * (tscale + sca2)) * windScale) * 2.0 - 1.0); N0 += texture2D(water_normalmap, uvAnimTscaleSca2) * 2.0 - 1.0;
N1 += texture2D(perlin_normalmap, uvAnimTscaleSca2) * 2.0 - 1.0;
rotationmatrix(radians(-4.0 * sin(osg_SimulationTime * 0.003)), RotationMatrix); rotationmatrix(radians(-4.0 * sin(osg_SimulationTime * 0.003)), RotationMatrix);
N0 += vec3(texture2D(water_normalmap, vec2(waterTex1 * RotationMatrix + disdis * sca2) * windScale) * 2.0 - 1.0); N0 += texture2D(water_normalmap, vec2(waterTex1 * RotationMatrix + disdis * sca2) * windScale) * 2.0 - 1.0;
N1 += vec3(texture2D(perlin_normalmap, vec2(waterTex1 * RotationMatrix + disdis * sca) * windScale) * 2.0 - 1.0); N1 += texture2D(perlin_normalmap, vec2(waterTex1 * RotationMatrix + disdis * sca) * windScale) * 2.0 - 1.0;
if(detailFlag > 0)
{
N0 *= windEffect_low; N0 *= windEffect_low;
N1 *= windEffect_low; N1 *= windEffect_low;
//N0.r += (ddx + ddx1 + ddx2 + ddx3);
//N0.g += (ddy + ddy1 + ddy2 + ddy3);
N0.r += ddxSum; N0.r += ddxSum;
N0.g += ddySum; N0.g += ddySum;
Normal = normalize(mix(Normal + N0, Normal + N1, mixFactor) * waveRoughness); Normal = normalize(mix(Normal + N0.rgb, Normal + N1.rgb, mixFactor) * waveRoughness);
if (normalmap_dds > 0) if (normalmap_dds > 0)
Normal = -Normal; //dds fix Normal = -Normal; //dds fix
}
float NdotH = max(0.0, dot(Normal, H));
// specular
vec3 specular_color = vec3(gl_LightSource[0].diffuse) vec3 specular_color = vec3(gl_LightSource[0].diffuse)
* pow(max(0.0, dot(Normal, H)), water_shininess) * 6.0; * pow(NdotH, water_shininess) * 6.0;
vec4 specular = vec4(specular_color, 0.5); vec4 specular = vec4(specular_color, 0.5);
specular = specular * saturation * 0.3 ; specular = specular * saturation * 0.3 ;
//calculate fresnel //calculate fresnel
vec4 invfres = vec4( dot(vNorm, viewt) ); float vNormDotViewT = dot(vNorm, viewt);
vec4 invfres = vec4( vNormDotViewT);
vec4 fres = vec4(1.0) + invfres; vec4 fres = vec4(1.0) + invfres;
refl *= fres; refl *= fres;
refl.rgb = mix(refl.rgb, floorColour, floorMixFactor);
//calculate final colour //calculate final colour
vec4 ambient_light = gl_LightSource[0].diffuse; vec4 ambient_light = gl_LightSource[0].diffuse;
vec4 finalColor; vec4 finalColor;
if(cover >= 1.5){ finalColor = refl + step(1.5, cover) * specular;
finalColor = refl + specular;
} else {
finalColor = refl;
}
//add foam //add foam
vec4 foam_texel = texture2D(sea_foam, vec2(waterTex2 * tscale) * 25.0); vec4 foam_texel = texture2D(sea_foam, (waterTex2 * tscale).st * 50.0);
if (range > -10000.0){
float foamSlope = 0.1 + 0.1 * windScale; float foamSlope = 0.1 + 0.1 * windScale;
//float waveSlope = mix(N0.g, N1.g, 0.25);
float waveSlope = Normal.g;
if (windEffect >= 8.0) float waveSlope1 = Normal.g * windFloorFactor * 0.65;
float waveSlope2 = vNorm.r * windFloorFactor * 0.3;
float waveSlope = waveSlope1 + waveSlope2;
if (waveSlope >= foamSlope){
finalColor = mix(finalColor, max(finalColor, finalColor + foam_texel), finalColor = mix(finalColor, max(finalColor, finalColor + foam_texel),
smoothstep(0.01, 0.50, Normal.g)); smoothstep(7.0, 8.0, windFloorEffect)
} * step(foamSlope, waveSlope)
* smoothstep(0.01, 0.50, waveSlope)) ;
} // end range
finalColor *= ambient_light ; finalColor *= ambient_light ;
//gl_FragColor = mix(gl_Fog.color, finalColor, fogFactor);
finalColor.rgb = fog_Func(finalColor.rgb, fogType) ; finalColor.rgb = fog_Func(finalColor.rgb, fogType) ;
gl_FragColor = finalColor ; gl_FragColor = finalColor ;
} }