1
0
Fork 0

Optimise water shaders after ideas and suggestions by Thorsten Renk

Signed-off-by: Vivian Meazza <vivian.meazza@lineone.net>
This commit is contained in:
Vivian Meazza 2012-05-05 19:59:22 +01:00
parent 7e1ed19307
commit 9657518663
6 changed files with 277 additions and 349 deletions

View file

@ -11,9 +11,6 @@
<internal-format>normalized</internal-format>
</texture>
<texture n="2">
<!--<image>Textures/Water/water-normalmap.png</image>-->
<!--<image>Textures/Water/water-normalmap2.dds</image>-->
<!--<image>Textures/Water/water_sine_nmap.dds</image>-->
<image>Textures/Water/waves-ver10-nm.dds</image>
<filter>linear-mipmap-linear</filter>
<wrap-s>repeat</wrap-s>
@ -21,11 +18,7 @@
<internal-format>normalized</internal-format>
</texture>
<texture n="3">
<!--<image>Textures/Water/water-dudv.png</image>-->
<!--<image>Textures/Water/dudvmap2.png</image>-->
<!--<image>Textures/Water/waves-ver10-dudv.dds</image>-->
<!--<image>Textures/Water/water-reflection-grey.png</image>-->
<image>Textures/Water/water_sine_nmap.dds</image>
<image>Textures/Water/water_sine_nmap.dds</image>
<filter>linear-mipmap-linear</filter>
<wrap-s>repeat</wrap-s>
<wrap-t>repeat</wrap-t>
@ -47,7 +40,6 @@
</texture>
<texture n="6">
<image>Textures/Water/perlin-noise-nm.dds</image>
<!-- <image>Textures/Water/water_sine_nmap.dds</image> -->
<filter>linear-mipmap-linear</filter>
<wrap-s>repeat</wrap-s>
<wrap-t>repeat</wrap-t>
@ -77,18 +69,12 @@
<cloud-cover n="4">
<use>/environment/clouds/layer[4]/coverage-type</use>
</cloud-cover>
<!--<wind>
<use>/environment/wind-speed-kt</use>
</wind>-->
<windE>
<use>/environment/sea/surface/wind-from-east-fps</use>
</windE>
<windN>
<use>/environment/sea/surface/wind-from-north-fps</use>
</windN>
<!--wind-from> unused?
<use>/environment/config/boundary/entry[0]/wind-from-heading-deg</use>
</wind-from-->
<WaveFreq>
<use>/environment/wave/freq</use>
</WaveFreq>
@ -109,49 +95,73 @@
</WaveDAngle>
<!-- fog include -->
<visibility><use>/environment/ground-visibility-m</use></visibility>
<avisibility><use>/environment/visibility-m</use></avisibility>
<lthickness><use>/environment/ground-haze-thickness-m</use></lthickness>
<scattering><use>/rendering/scene/scattering</use></scattering>
<ground_scattering><use>/environment/surface/scattering</use></ground_scattering>
<terminator><use>/environment/terminator-relative-position-m</use></terminator>
<terrain_alt><use>/environment/mean-terrain-elevation-m</use></terrain_alt>
<overcast><use>/rendering/scene/overcast</use></overcast>
<eye_alt><use>/sim/rendering/eye-altitude-m</use></eye_alt>
<visibility>
<use>/environment/ground-visibility-m</use>
</visibility>
<avisibility>
<use>/environment/visibility-m</use>
</avisibility>
<lthickness>
<use>/environment/ground-haze-thickness-m</use>
</lthickness>
<scattering>
<use>/rendering/scene/scattering</use>
</scattering>
<ground_scattering>
<use>/environment/surface/scattering</use>
</ground_scattering>
<terminator>
<use>/environment/terminator-relative-position-m</use>
</terminator>
<terrain_alt>
<use>/environment/mean-terrain-elevation-m</use>
</terrain_alt>
<overcast>
<use>/rendering/scene/overcast</use>
</overcast>
<eye_alt>
<use>/sim/rendering/eye-altitude-m</use>
</eye_alt>
<fogtype>
<use>/sim/rendering/shaders/skydome</use>
</fogtype>
<!-- sea colors -->
<sea_r><use>/environment/sea/color_r</use></sea_r>
<sea_g><use>/environment/sea/color_g</use></sea_g>
<sea_b><use>/environment/sea/color_b</use></sea_b>
<sea_r>
<use>/environment/sea/color_r</use>
</sea_r>
<sea_g>
<use>/environment/sea/color_g</use>
</sea_g>
<sea_b>
<use>/environment/sea/color_b</use>
</sea_b>
<!-- END fog include -->
<!-- END fog include -->
</parameters>
<technique n="3">
<predicate>
<and>
<property>/sim/rendering/shaders/skydome</property>
<less-equal>
<value type="float">4.0</value>
<float-property>/sim/rendering/shaders/water</float-property>
</less-equal>
<or>
<less-equal>
<value type="float">2.0</value>
<glversion/>
</less-equal>
<and>
<extension-supported>GL_ARB_shader_objects</extension-supported>
<extension-supported>GL_ARB_shading_language_100</extension-supported>
<extension-supported>GL_ARB_vertex_shader</extension-supported>
<extension-supported>GL_ARB_fragment_shader</extension-supported>
</and>
</or>
</and>
</predicate>
<technique n="3">
<predicate>
<and>
<property>/sim/rendering/shaders/skydome</property>
<less-equal>
<value type="float">4.0</value>
<float-property>/sim/rendering/shaders/water</float-property>
</less-equal>
<or>
<less-equal>
<value type="float">2.0</value>
<glversion/>
</less-equal>
<and>
<extension-supported>GL_ARB_shader_objects</extension-supported>
<extension-supported>GL_ARB_shading_language_100</extension-supported>
<extension-supported>GL_ARB_vertex_shader</extension-supported>
<extension-supported>GL_ARB_fragment_shader</extension-supported>
</and>
</or>
</and>
</predicate>
<pass>
<lighting>true</lighting>
@ -201,10 +211,6 @@
<use>texture[0]/internal-format</use>
</internal-format>
</texture-unit>-->
<!--<texture-unit>
<unit>1</unit>
<type>noise</type>
</texture-unit>-->
<texture-unit>
<unit>2</unit>
<image>
@ -297,9 +303,7 @@
</texture-unit>
<program>
<!-- <vertex-shader>Shaders/include_fog.vert</vertex-shader> -->
<vertex-shader>Shaders/water_lightfield.vert</vertex-shader>
<!--<fragment-shader>Shaders/include_fog.frag</fragment-shader>-->
<fragment-shader>Shaders/water_lightfield.frag</fragment-shader>
</program>
<!--<uniform>
@ -307,11 +311,6 @@
<type>sampler-2d</type>
<value type="int">0</value>
</uniform>-->
<!--<uniform>
<name>Noise</name>
<type>sampler-3d</type>
<value type="int">1</value>
</uniform>-->
<uniform>
<name>water_normalmap</name>
<type>sampler-2d</type>
@ -322,11 +321,6 @@
<type>sampler-2d</type>
<value type="int">3</value>
</uniform>
<!--<uniform>
<name>water_reflection_grey</name>
<type>sampler-2d</type>
<value type="int">4</value>
</uniform>-->
<uniform>
<name>sea_foam</name>
<type>sampler-2d</type>
@ -341,57 +335,10 @@
<name>saturation</name>
<type>float</type>
<!--<value>0.4</value>-->
<value><use>saturation</use></value>
</uniform>
<!--<uniform>
<name>CloudCover0</name>
<type>float</type>
<value>
<use>cloud-cover[0]</use>
<use>saturation</use>
</value>
</uniform>
<uniform>
<name>CloudCover1</name>
<type>float</type>
<value>
<use>cloud-cover[1]</use>
</value>
</uniform>
<uniform>
<name>CloudCover2</name>
<type>float</type>
<value>
<use>cloud-cover[2]</use>
</value>
</uniform>
<uniform>
<name>CloudCover3</name>
<type>float</type>
<value>
<use>cloud-cover[3]</use>
</value>
</uniform>
<uniform>
<name>CloudCover4</name>
<type>float</type>
<value>
<use>cloud-cover[4]</use>
</value>
</uniform>
<uniform>
<name>Status</name>
<type>int</type>
<value>
<use>status</use>
</value>
</uniform>-->
<!--<uniform>
<name>Overcast</name>
<type>float</type>
<value>
<use>overcast</use>
</value>
</uniform>-->
<uniform>
<name>WindE</name>
<type>float</type>
@ -406,13 +353,6 @@
<use>windN</use>
</value>
</uniform>
<!-- uniform> unused?
<name>WindFrom</name>
<type>float</type>
<value>
<use>wind-from</use>
</value>
</uniform-->
<uniform>
<name>WaveFreq</name>
<type>float</type>
@ -458,7 +398,7 @@
<!-- BEGIN fog include -->
<!-- BEGIN fog include -->
<uniform>
<name>visibility</name>
<type>float</type>
@ -488,10 +428,12 @@
</value>
</uniform>
<uniform>
<name>ground_scattering</name>
<type>float</type>
<value><use>ground_scattering</use></value>
</uniform>
<name>ground_scattering</name>
<type>float</type>
<value>
<use>ground_scattering</use>
</value>
</uniform>
<uniform>
<name>terminator</name>
<type>float</type>
@ -500,47 +442,49 @@
</value>
</uniform>
<uniform>
<name>terrain_alt</name>
<type>float</type>
<value><use>terrain_alt</use></value>
</uniform>
<uniform>
<name>overcast</name>
<type>float</type>
<value><use>overcast</use></value>
</uniform>
<uniform>
<name>eye_alt</name>
<type>float</type>
<value><use>eye_alt</use></value>
</uniform>
<name>terrain_alt</name>
<type>float</type>
<value>
<use>terrain_alt</use>
</value>
</uniform>
<uniform>
<name>overcast</name>
<type>float</type>
<value>
<use>overcast</use>
</value>
</uniform>
<uniform>
<name>eye_alt</name>
<type>float</type>
<value>
<use>eye_alt</use>
</value>
</uniform>
<!-- sea colors -->
<uniform>
<name>sea_r</name>
<type>float</type>
<value><use>sea_r</use></value>
</uniform>
<uniform>
<name>sea_g</name>
<type>float</type>
<value><use>sea_g</use></value>
</uniform>
<uniform>
<name>sea_b</name>
<type>float</type>
<value><use>sea_b</use></value>
</uniform>
<!--<uniform>
<name>fogType</name>
<type>int</type>
<name>sea_r</name>
<type>float</type>
<value>
<use>fogtype</use>
<use>sea_r</use>
</value>
</uniform>-->
<!-- END fog include -->
</uniform>
<uniform>
<name>sea_g</name>
<type>float</type>
<value>
<use>sea_g</use>
</value>
</uniform>
<uniform>
<name>sea_b</name>
<type>float</type>
<value>
<use>sea_b</use>
</value>
</uniform>
<!-- END fog include -->
</pass>
</technique>
@ -598,6 +542,7 @@
<use>render-bin/bin-name</use>
</bin-name>
</render-bin>
<texture-unit>
<unit>0</unit>
<image>
@ -616,7 +561,6 @@
<use>texture[0]/internal-format</use>
</internal-format>
</texture-unit>
<texture-unit>
<unit>2</unit>
<image>
@ -709,7 +653,6 @@
</texture-unit>
<program>
<!-- <vertex-shader>Shaders/include_fog.vert</vertex-shader> -->
<vertex-shader>Shaders/water.vert</vertex-shader>
<fragment-shader>Shaders/include_fog.frag</fragment-shader>
<fragment-shader>Shaders/water_sine.frag</fragment-shader>
@ -719,7 +662,6 @@
<type>sampler-2d</type>
<value type="int">0</value>
</uniform>
<uniform>
<name>water_normalmap</name>
<type>sampler-2d</type>
@ -749,7 +691,9 @@
<name>saturation</name>
<type>float</type>
<!--<value>0.4</value>-->
<value><use>saturation</use></value>
<value>
<use>saturation</use>
</value>
</uniform>
<uniform>
<name>CloudCover0</name>
@ -815,13 +759,6 @@
<use>windN</use>
</value>
</uniform>
<!-- uniform> unused?
<name>WindFrom</name>
<type>float</type>
<value>
<use>wind-from</use>
</value>
</uniform-->
<uniform>
<name>WaveFreq</name>
<type>float</type>
@ -865,9 +802,7 @@
</value>
</uniform>
<!-- BEGIN fog include -->
<!-- BEGIN fog include -->
<uniform>
<name>visibility</name>
<type>float</type>
@ -910,7 +845,7 @@
<use>fogtype</use>
</value>
</uniform>
<!-- END fog include -->
<!-- END fog include -->
</pass>
</technique>
<technique n="9">
@ -1075,7 +1010,6 @@
</texture-unit>
<program>
<!-- <vertex-shader>Shaders/include_fog.vert</vertex-shader> -->
<vertex-shader>Shaders/water.vert</vertex-shader>
<fragment-shader>Shaders/include_fog.frag</fragment-shader>
<fragment-shader>Shaders/water.frag</fragment-shader>

View file

@ -4,6 +4,9 @@
// © Michael Horsch - 2005
// Major update and revisions - 2011-10-07
// © Emilian Huminiuc and Vivian Meazza
// Optimisation - 2012-5-05
// Based on ideas by Thorsten Renk
// © Emilian Huminiuc and Vivian Meazza
#version 120
@ -21,8 +24,6 @@ uniform int Status;
varying vec4 waterTex1; //moving texcoords
varying vec4 waterTex2; //moving texcoords
varying vec4 waterTex4; //viewts
varying vec4 ecPosition;
varying vec3 viewerdir;
varying vec3 lightdir;
varying vec3 normal;
@ -72,7 +73,7 @@ void main(void)
//bool Status = true;
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 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 waveRoughness = 0.05 + smoothstep(0.0, 20.0, windEffect); //wave roughness filter
@ -91,7 +92,7 @@ void main(void)
}
}
vec4 viewt = normalize(waterTex4);
vec4 viewt = vec4(-E, 0.0) * 0.6;
vec4 disdis = texture2D(water_dudvmap, vec2(waterTex2 * tscale)* windScale) * 2.0 - 1.0;
@ -122,13 +123,14 @@ void main(void)
nmap1 *= windEffect_low;
// mix water and noise, modulated by factor
vec4 vNorm = normalize(mix(nmap, nmap1, mixFactor) * waveRoughness);
//vNorm.r += ddx;
vNorm = -vNorm; //dds fix
//load reflection
vec4 tmp = vec4(lightdir, 0.0);
vec4 refTex;
vec4 refl;
// cover = 0;
if(cover >= 1.5){
@ -163,8 +165,6 @@ void main(void)
N1 *= windEffect_low;
vec3 N = normalize(mix(Normal + N0, Normal + N1, mixFactor) * waveRoughness);
//N.r += ddx;
//N.g += ddy;
N = -N; //dds fix
@ -180,15 +180,6 @@ void main(void)
vec4 fres = vec4(1.0) + invfres;
refl *= fres;
//calculate the fog factor
// float fogFactor;
// float fogCoord = ecPosition.z;
// const float LOG2 = 1.442695;
// fogFactor = exp2(-gl_Fog.density * gl_Fog.density * fogCoord * fogCoord * LOG2);
//
// if(gl_Fog.density == 1.0)
// fogFactor=1.0;
//calculate final colour
vec4 ambient_light = gl_LightSource[0].diffuse;
vec4 finalColor;
@ -200,7 +191,6 @@ void main(void)
}
float foamSlope = 0.10 + 0.1 * windScale;
//float waveSlope = mix(N0.g, N1.g, 0.25);
vec4 foam_texel = texture2D(sea_foam, vec2(waterTex2 * tscale) * 25.0);
float waveSlope = N.g;

View file

@ -9,8 +9,7 @@
varying vec4 waterTex1;
varying vec4 waterTex2;
varying vec4 waterTex4;
varying vec4 ecPosition;
//varying vec4 waterTex4;
varying vec3 viewerdir;
varying vec3 lightdir;
@ -19,53 +18,48 @@ varying vec3 normal;
uniform float osg_SimulationTime;
uniform float WindE, WindN;
////fog "include"////////
// uniform int fogType;
//
// void fog_Func(int type);
/////////////////////////
/////// functions /////////
void rotationmatrix(in float angle, out mat4 rotmat)
{
rotmat = mat4( cos( angle ), -sin( angle ), 0.0, 0.0,
sin( angle ), cos( angle ), 0.0, 0.0,
0.0 , 0.0 , 1.0, 0.0,
0.0 , 0.0 , 0.0, 1.0 );
}
{
rotmat = mat4( cos( angle ), -sin( angle ), 0.0, 0.0,
sin( angle ), cos( angle ), 0.0, 0.0,
0.0 , 0.0 , 1.0, 0.0,
0.0 , 0.0 , 0.0, 1.0 );
}
void main(void)
{
mat4 RotationMatrix;
vec3 N = normalize(gl_Normal);
normal = N;
{
mat4 RotationMatrix;
vec3 N = normalize(gl_Normal);
normal = N;
ecPosition = gl_ModelViewMatrix * gl_Vertex;
vec4 ecPosition = gl_ModelViewMatrix * gl_Vertex;
viewerdir = vec3(gl_ModelViewMatrixInverse[3]) - vec3(gl_Vertex);
lightdir = normalize(vec3(gl_ModelViewMatrixInverse * gl_LightSource[0].position));
viewerdir = vec3(gl_ModelViewMatrixInverse[3]) - vec3(gl_Vertex);
lightdir = normalize(vec3(gl_ModelViewMatrixInverse * gl_LightSource[0].position));
waterTex4 = vec4( ecPosition.xzy, 0.0 );
//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 Angle;
float Angle;
float windFactor = sqrt(pow(abs(WindE),2)+pow(abs(WindN),2)) * 0.05;
if (WindN == 0.0 && WindE == 0.0) {
Angle = 0.0;
}else{
Angle = atan(-WindN, WindE) - atan(1.0);
}
float windFactor = sqrt(pow(abs(WindE),2)+pow(abs(WindN),2)) * 0.05;
rotationmatrix(Angle, RotationMatrix);
waterTex1 = gl_MultiTexCoord0 * RotationMatrix - t1 * windFactor;
if (WindN == 0.0 && WindE == 0.0) {
Angle = 0.0;
}else{
Angle = atan(-WindN, WindE) - atan(1.0);
}
rotationmatrix(Angle, RotationMatrix);
waterTex2 = gl_MultiTexCoord0 * RotationMatrix - t2 * windFactor;
rotationmatrix(Angle, RotationMatrix);
waterTex1 = gl_MultiTexCoord0 * RotationMatrix - t1 * windFactor;
// fog_Func(fogType);
gl_Position = ftransform();
}
rotationmatrix(Angle, RotationMatrix);
waterTex2 = gl_MultiTexCoord0 * RotationMatrix - t2 * windFactor;
// fog_Func(fogType);
gl_Position = ftransform();
}

View file

@ -4,6 +4,9 @@
// © Michael Horsch - 2005
// Major update and revisions - 2011-10-07
// © Emilian Huminiuc and Vivian Meazza
// Optimisation - 2012-5-05
// Based on ideas by Thorsten Renk
// © Emilian Huminiuc and Vivian Meazza
#version 120
@ -23,8 +26,7 @@ uniform int Status;
varying vec4 waterTex1; //moving texcoords
varying vec4 waterTex2; //moving texcoords
varying vec4 waterTex4; //viewts
//varying vec4 ecPosition;
varying vec3 viewerdir;
varying vec3 lightdir;
varying vec3 normal;
@ -42,6 +44,8 @@ uniform int fogType;
vec3 fog_Func(vec3 color, int type);
//////////////////////
const vec4 AllOnes = vec4(1.0);
/////// functions /////////
void rotationmatrix(in float angle, out mat4 rotmat)
@ -92,7 +96,7 @@ void sumWaves(float angle, float dangle, float windScale, float factor, out floa
{
mat4 RotationMatrix;
float deriv;
vec4 P = waterTex1 * 1024;
vec4 P = waterTex1 * 1024.0;
rotationmatrix(radians(angle + dangle * windScale + 0.6 * sin(P.x * factor)), RotationMatrix);
P *= RotationMatrix;
@ -139,14 +143,16 @@ void main(void)
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
float cover = 0.0;
//bool Status = true;
float windEffect = sqrt( WindE*WindE + WindN*WindN ) * 0.6; //wind speed in kt
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 waveRoughness = 0.01 + smoothstep(0.0, 40.0, windEffect); //wave roughness filter
float windEffect = sqrt( WindE*WindE + WindN*WindN ) * 0.6; //wind speed in kt
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 waveRoughness = 0.01 + smoothstep(0.0, 40.0, windEffect); //wave roughness filter
float mixFactor = 0.2 + 0.02 * smoothstep(0.0, 50.0, windEffect);
//mixFactor = 0.2;
@ -154,68 +160,94 @@ void main(void)
// sine waves
// Test data
//float WaveFreq =1.0;
//float WaveAmp = 1000.0;
//float WaveSharp = 10.0;
float angle = 0.0;
wave0.freq = WaveFreq ;
wave0.amp = WaveAmp;
wave0.dir = vec2(cos(radians(angle)), sin(radians(angle)));
vec4 ddxVec = vec4(0.0);
vec4 ddyVec = vec4(0.0);
int detailFlag = 0;
angle -= 45;
wave1.freq = WaveFreq * 2.0 ;
wave1.amp = WaveAmp * 1.25;
wave1.dir = vec2(cos(radians(angle)), sin(radians(angle)));
//uncomment to test
//range = -20000;
angle += 30;
wave2.freq = WaveFreq * 3.5;
wave2.amp = WaveAmp * 0.75;
wave2.dir = vec2(cos(radians(angle)), sin(radians(angle)));
if (range > -15000 || dot(Normal,H) > 0.95 ) {
angle -= 50;
wave3.freq = WaveFreq * 3.0 ;
wave3.amp = WaveAmp * 0.75;
wave3.dir = vec2(cos(radians(angle)), sin(radians(angle)));
float ddx = 0.0, ddy = 0.0;
float ddx1 = 0.0, ddy1 = 0.0;
float ddx2 = 0.0, ddy2 = 0.0;
float ddx3 = 0.0, ddy3 = 0.0;
float waveamp;
// sum waves
float angle = 0.0;
float ddx = 0.0, ddy = 0.0;
sumWaves(WaveAngle, -1.5, windScale, WaveFactor, ddx, ddy);
wave0.freq = WaveFreq ;
wave0.amp = WaveAmp;
wave0.dir = vec2(cos(radians(angle)), sin(radians(angle)));
float ddx1 = 0.0, ddy1 = 0.0;
sumWaves(WaveAngle, 1.5, windScale, WaveFactor, ddx1, ddy1);
angle -= 45;
wave1.freq = WaveFreq * 2.0 ;
wave1.amp = WaveAmp * 1.25;
wave1.dir = vec2(cos(radians(angle)), sin(radians(angle)));
//reset the waves
angle = 0.0;
float waveamp = WaveAmp * 0.75;
angle += 30;
wave2.freq = WaveFreq * 3.5;
wave2.amp = WaveAmp * 0.75;
wave2.dir = vec2(cos(radians(angle)), sin(radians(angle)));
wave0.freq = WaveFreq ;
wave0.amp = waveamp;
wave0.dir = vec2(cos(radians(angle)), sin(radians(angle)));
angle -= 50;
wave3.freq = WaveFreq * 3.0 ;
wave3.amp = WaveAmp * 0.75;
wave3.dir = vec2(cos(radians(angle)), sin(radians(angle)));
angle -= 20;
wave1.freq = WaveFreq * 2.0 ;
wave1.amp = waveamp * 1.25;
wave1.dir = vec2(cos(radians(angle)), sin(radians(angle)));
// sum waves
angle += 35;
wave2.freq = WaveFreq * 3.5;
wave2.amp = waveamp * 0.75;
wave2.dir = vec2(cos(radians(angle)), sin(radians(angle)));
ddx = 0.0, ddy = 0.0;
sumWaves(WaveAngle, -1.5, windScale, WaveFactor, ddx, ddy);
angle -= 45;
wave3.freq = WaveFreq * 3.0 ;
wave3.amp = waveamp * 0.75;
wave3.dir = vec2(cos(radians(angle)), sin(radians(angle)));
ddx1 = 0.0, ddy1 = 0.0;
sumWaves(WaveAngle, 1.5, windScale, WaveFactor, ddx1, ddy1);
float ddx2 = 0.0, ddy2 = 0.0;
sumWaves(WaveAngle + WaveDAngle, -1.5, windScale, WaveFactor, ddx2, ddy2);
//reset the waves
angle = 0.0;
waveamp = WaveAmp * 0.75;
float ddx3 = 0.0, ddy3 = 0.0;
sumWaves(WaveAngle + WaveDAngle, 1.5, windScale, WaveFactor, ddx3, ddy3);
wave0.freq = WaveFreq ;
wave0.amp = waveamp;
wave0.dir = vec2(cos(radians(angle)), sin(radians(angle)));
// end sine stuff
angle -= 20;
wave1.freq = WaveFreq * 2.0 ;
wave1.amp = waveamp * 1.25;
wave1.dir = vec2(cos(radians(angle)), sin(radians(angle)));
angle += 35;
wave2.freq = WaveFreq * 3.5;
wave2.amp = waveamp * 0.75;
wave2.dir = vec2(cos(radians(angle)), sin(radians(angle)));
angle -= 45;
wave3.freq = WaveFreq * 3.0 ;
wave3.amp = waveamp * 0.75;
wave3.dir = vec2(cos(radians(angle)), sin(radians(angle)));
// sum waves
ddx2 = 0.0, ddy2 = 0.0;
sumWaves(WaveAngle + WaveDAngle, -1.5, windScale, WaveFactor, ddx2, ddy2);
ddx3 = 0.0, ddy3 = 0.0;
sumWaves(WaveAngle + WaveDAngle, 1.5, windScale, WaveFactor, ddx3, ddy3);
ddxVec = vec4(ddx, ddx1, ddx2, ddx3);
ddyVec = vec4(ddy, ddy1, ddy2, ddy3);
//toggle detailFlag
detailFlag = 1;
} // end sine stuff
float ddxSum = dot(ddxVec, AllOnes);
float ddySum = dot(ddyVec, AllOnes);
if (Status == 1){
cover = min(min(min(min(CloudCover0, CloudCover1),CloudCover2),CloudCover3),CloudCover4);
@ -228,16 +260,11 @@ void main(void)
}
}
vec4 viewt = normalize(waterTex4);
// vec4 viewt = normalize(waterTex4);
vec4 viewt = vec4(-E, 0.0) * 0.6;
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;
//dist *= (0.6 + 0.5 * smoothstep(0.0, 15.0, windEffect));
//vec4 fdist = normalize(dist);
//fdist = -fdist; //dds fix
//fdist *= sca;
//normalmaps
vec4 nmap = texture2D(water_normalmap, vec2(waterTex1 + disdis * sca2) * windScale) * 2.0 - 1.0;
vec4 nmap1 = texture2D(perlin_normalmap, vec2(waterTex1 + disdis * sca2) * windScale) * 2.0 - 1.0;
@ -251,18 +278,21 @@ void main(void)
// mix water and noise, modulated by factor
vec4 vNorm = normalize(mix(nmap, nmap1, mixFactor) * waveRoughness);
vNorm.r += ddx + ddx1 + ddx2 + ddx3;
vNorm.r += ddxSum;
vNorm = -vNorm; //dds fix
//load reflection
vec4 tmp = vec4(lightdir, 0.0);
vec4 refTex = texture2D(water_reflection, vec2(tmp)) ;
vec4 refTexGrey = texture2D(water_reflection_grey, vec2(tmp)) ;
vec4 refTex = texture2D(water_reflection, vec2(tmp + waterTex1) * 32.0) ;
vec4 refTexGrey = texture2D(water_reflection_grey, vec2(tmp * waterTex1)) ;
vec4 refl ;
// cover = 0;
// Test data
// cover = 0;
if(cover >= 1.5){
refl= normalize(refTex);
refl = normalize(refTex);
refl.a = 1.0;
}
else
{
@ -270,10 +300,9 @@ void main(void)
refl.r *= (0.75 + 0.15 * cover);
refl.g *= (0.80 + 0.15 * cover);
refl.b *= (0.875 + 0.125 * cover);
refl.a *= 1.0;
refl.a = 1.0;
}
vec3 N0 = vec3(texture2D(water_normalmap, vec2(waterTex1 + disdis * sca2) * windScale) * 2.0 - 1.0);
vec3 N1 = vec3(texture2D(perlin_normalmap, vec2(waterTex1 + disdis * sca) * windScale) * 2.0 - 1.0);
@ -288,19 +317,24 @@ void main(void)
N0 += vec3(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);
N0 *= windEffect_low;
N1 *= windEffect_low;
if(detailFlag > 0)
{
N0 *= windEffect_low;
N1 *= windEffect_low;
//N0.r += (ddx + ddx1 + ddx2 + ddx3);
//N0.g += (ddy + ddy1 + ddy2 + ddy3);
N0.r += (ddx + ddx1 + ddx2 + ddx3);
N0.g += (ddy + ddy1 + ddy2 + ddy3);
N0.r += ddxSum;
N0.g += ddySum;
vec3 N = normalize(mix(Normal + N0, Normal + N1, mixFactor) * waveRoughness);
Normal = normalize(mix(Normal + N0, Normal + N1, mixFactor) * waveRoughness);
Normal = -Normal; //dds fix
}
N = -N; //dds fix
// specular
vec3 specular_color = vec3(gl_LightSource[0].diffuse)
* pow(max(0.0, dot(N, H)), water_shininess) * 6.0;
* pow(max(0.0, dot(Normal, H)), water_shininess) * 6.0;
vec4 specular = vec4(specular_color, 0.5);
specular = specular * saturation * 0.3 ;
@ -310,15 +344,6 @@ void main(void)
vec4 fres = vec4(1.0) + invfres;
refl *= fres;
//calculate the fog factor
// float fogFactor;
// float fogCoord = ecPosition.z;
// const float LOG2 = 1.442695;
// fogFactor = exp2(-gl_Fog.density * gl_Fog.density * fogCoord * fogCoord * LOG2);
//
// if(gl_Fog.density == 1.0)
// fogFactor=1.0;
//calculate final colour
vec4 ambient_light = gl_LightSource[0].diffuse;
vec4 finalColor;
@ -330,41 +355,26 @@ void main(void)
}
//add foam
float foamSlope = 0.10 + 0.1 * windScale;
//float waveSlope = mix(N0.g, N1.g, 0.25);
vec4 foam_texel = texture2D(sea_foam, vec2(waterTex2 * tscale) * 25.0);
float waveSlope = N.g;
if (range > -10000.0){
if (windEffect >= 8.0)
if (waveSlope >= foamSlope){
finalColor = mix(finalColor, max(finalColor, finalColor + foam_texel), smoothstep(0.01, 0.50, N.g));
float foamSlope = 0.1 + 0.1 * windScale;
//float waveSlope = mix(N0.g, N1.g, 0.25);
float waveSlope = Normal.g;
if (windEffect >= 8.0)
if (waveSlope >= foamSlope){
finalColor = mix(finalColor, max(finalColor, finalColor + foam_texel),
smoothstep(0.01, 0.50, Normal.g));
}
// float deltaN0 = 1.0 - N0.g;
//float deltaN1 = 1.0 - N1.g;
//if (windEffect >= 8.0){
// if (N0.g >= foamSlope){
// if (deltaN0 > 0.8){
// finalColor = mix(finalColor, max(finalColor, finalColor + foam_texel), smoothstep(0.01, 0.50, N0.g));
// } else {
// finalColor = mix(finalColor, max(finalColor, finalColor + foam_texel), smoothstep(0.15, 0.25, deltaN0));
// }
// }
// if (N1.g >= foamSlope){
// if (deltaN1 > 0.85){
// finalColor = mix(finalColor, max(finalColor, finalColor + foam_texel), smoothstep(0.01, 0.13, N1.g));
// } else {
// finalColor = mix(finalColor, max(finalColor, finalColor + foam_texel), smoothstep(0.01, 0.20, deltaN1));
// }
// }
//}
} // end range
finalColor *= ambient_light;
finalColor *= ambient_light;
//gl_FragColor = mix(gl_Fog.color, finalColor, fogFactor);
finalColor.rgb = fog_Func(finalColor.rgb, fogType);
gl_FragColor = finalColor;
//gl_FragColor = mix(gl_Fog.color, finalColor, fogFactor);
finalColor.rgb = fog_Func(finalColor.rgb, fogType);
gl_FragColor = finalColor;
}

Binary file not shown.

Before

Width:  |  Height:  |  Size: 118 KiB

After

Width:  |  Height:  |  Size: 48 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 962 B

After

Width:  |  Height:  |  Size: 274 B