Optimise water shaders after ideas and suggestions by Thorsten Renk
Signed-off-by: Vivian Meazza <vivian.meazza@lineone.net>
This commit is contained in:
parent
7e1ed19307
commit
9657518663
6 changed files with 277 additions and 349 deletions
|
@ -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,10 +18,6 @@
|
|||
<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>
|
||||
<filter>linear-mipmap-linear</filter>
|
||||
<wrap-s>repeat</wrap-s>
|
||||
|
@ -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,28 +95,52 @@
|
|||
</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 -->
|
||||
</parameters>
|
||||
|
||||
|
||||
<technique n="3">
|
||||
<technique n="3">
|
||||
<predicate>
|
||||
<and>
|
||||
<property>/sim/rendering/shaders/skydome</property>
|
||||
|
@ -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>
|
||||
|
@ -490,7 +430,9 @@
|
|||
<uniform>
|
||||
<name>ground_scattering</name>
|
||||
<type>float</type>
|
||||
<value><use>ground_scattering</use></value>
|
||||
<value>
|
||||
<use>ground_scattering</use>
|
||||
</value>
|
||||
</uniform>
|
||||
<uniform>
|
||||
<name>terminator</name>
|
||||
|
@ -502,44 +444,46 @@
|
|||
<uniform>
|
||||
<name>terrain_alt</name>
|
||||
<type>float</type>
|
||||
<value><use>terrain_alt</use></value>
|
||||
<value>
|
||||
<use>terrain_alt</use>
|
||||
</value>
|
||||
</uniform>
|
||||
<uniform>
|
||||
<name>overcast</name>
|
||||
<type>float</type>
|
||||
<value><use>overcast</use></value>
|
||||
<value>
|
||||
<use>overcast</use>
|
||||
</value>
|
||||
</uniform>
|
||||
<uniform>
|
||||
<name>eye_alt</name>
|
||||
<type>float</type>
|
||||
<value><use>eye_alt</use></value>
|
||||
<value>
|
||||
<use>eye_alt</use>
|
||||
</value>
|
||||
</uniform>
|
||||
<!-- sea colors -->
|
||||
<uniform>
|
||||
<name>sea_r</name>
|
||||
<type>float</type>
|
||||
<value><use>sea_r</use></value>
|
||||
<value>
|
||||
<use>sea_r</use>
|
||||
</value>
|
||||
</uniform>
|
||||
<uniform>
|
||||
<name>sea_g</name>
|
||||
<type>float</type>
|
||||
<value><use>sea_g</use></value>
|
||||
<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>
|
||||
<value>
|
||||
<use>fogtype</use>
|
||||
<use>sea_b</use>
|
||||
</value>
|
||||
</uniform>-->
|
||||
</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,8 +802,6 @@
|
|||
</value>
|
||||
</uniform>
|
||||
|
||||
|
||||
|
||||
<!-- BEGIN fog include -->
|
||||
<uniform>
|
||||
<name>visibility</name>
|
||||
|
@ -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>
|
||||
|
|
|
@ -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;
|
||||
|
@ -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;
|
||||
|
|
|
@ -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,34 +18,28 @@ 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 );
|
||||
}
|
||||
}
|
||||
|
||||
void main(void)
|
||||
{
|
||||
{
|
||||
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));
|
||||
|
||||
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);
|
||||
|
@ -54,6 +47,7 @@ void main(void)
|
|||
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{
|
||||
|
@ -66,6 +60,6 @@ void main(void)
|
|||
rotationmatrix(Angle, RotationMatrix);
|
||||
waterTex2 = gl_MultiTexCoord0 * RotationMatrix - t2 * windFactor;
|
||||
|
||||
// fog_Func(fogType);
|
||||
// fog_Func(fogType);
|
||||
gl_Position = ftransform();
|
||||
}
|
||||
}
|
|
@ -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,6 +143,8 @@ 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;
|
||||
|
@ -154,9 +160,26 @@ void main(void)
|
|||
|
||||
// sine waves
|
||||
|
||||
// Test data
|
||||
//float WaveFreq =1.0;
|
||||
//float WaveAmp = 1000.0;
|
||||
//float WaveSharp = 10.0;
|
||||
|
||||
vec4 ddxVec = 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 ddx1 = 0.0, ddy1 = 0.0;
|
||||
float ddx2 = 0.0, ddy2 = 0.0;
|
||||
float ddx3 = 0.0, ddy3 = 0.0;
|
||||
float waveamp;
|
||||
|
||||
float angle = 0.0;
|
||||
|
||||
wave0.freq = WaveFreq ;
|
||||
|
@ -180,15 +203,15 @@ void main(void)
|
|||
|
||||
// sum waves
|
||||
|
||||
float ddx = 0.0, ddy = 0.0;
|
||||
ddx = 0.0, ddy = 0.0;
|
||||
sumWaves(WaveAngle, -1.5, windScale, WaveFactor, ddx, ddy);
|
||||
|
||||
float ddx1 = 0.0, ddy1 = 0.0;
|
||||
ddx1 = 0.0, ddy1 = 0.0;
|
||||
sumWaves(WaveAngle, 1.5, windScale, WaveFactor, ddx1, ddy1);
|
||||
|
||||
//reset the waves
|
||||
angle = 0.0;
|
||||
float waveamp = WaveAmp * 0.75;
|
||||
waveamp = WaveAmp * 0.75;
|
||||
|
||||
wave0.freq = WaveFreq ;
|
||||
wave0.amp = waveamp;
|
||||
|
@ -209,13 +232,22 @@ void main(void)
|
|||
wave3.amp = waveamp * 0.75;
|
||||
wave3.dir = vec2(cos(radians(angle)), sin(radians(angle)));
|
||||
|
||||
float ddx2 = 0.0, ddy2 = 0.0;
|
||||
// sum waves
|
||||
ddx2 = 0.0, ddy2 = 0.0;
|
||||
sumWaves(WaveAngle + WaveDAngle, -1.5, windScale, WaveFactor, ddx2, ddy2);
|
||||
|
||||
float ddx3 = 0.0, ddy3 = 0.0;
|
||||
ddx3 = 0.0, ddy3 = 0.0;
|
||||
sumWaves(WaveAngle + WaveDAngle, 1.5, windScale, WaveFactor, ddx3, ddy3);
|
||||
|
||||
// end sine stuff
|
||||
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 ;
|
||||
|
||||
// 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);
|
||||
|
||||
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,36 +355,21 @@ 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){
|
||||
|
||||
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, N.g));
|
||||
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;
|
||||
|
|
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 |
Loading…
Reference in a new issue