1
0
Fork 0

Merge branch 'master' of git://gitorious.org/fg/fgdata

This commit is contained in:
BARANGER Emmanuel 2012-05-07 18:55:44 +02:00
commit 7b20bf2d04
6 changed files with 225 additions and 217 deletions

View file

@ -2,6 +2,10 @@
// 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
// © Emilian Huminiuc and Vivian Meazza
// Optimisation - 2012-5-05
// © Emilian Huminiuc and Vivian Meazza
#version 120 #version 120
#define fps2kts 0.5925 #define fps2kts 0.5925
@ -20,8 +24,8 @@ uniform int Status;
varying vec4 waterTex1; //moving texcoords varying vec4 waterTex1; //moving texcoords
varying vec4 waterTex2; //moving texcoords varying vec4 waterTex2; //moving texcoords
varying vec4 waterTex4; //viewts //varying vec4 waterTex4; //viewts
varying vec4 ecPosition; //varying vec4 ecPosition;
varying vec3 viewerdir; varying vec3 viewerdir;
varying vec3 lightdir; varying vec3 lightdir;
varying vec3 normal; varying vec3 normal;
@ -124,7 +128,8 @@ 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) * 2.0 - 1.0; vec4 disdis = texture2D(water_dudvmap, vec2(waterTex2 * tscale)* windScale * 2.0) * 2.0 - 1.0;
vec4 dist = texture2D(water_dudvmap, vec2(waterTex1 + disdis*sca2)* windScale * 2.0) * 2.0 - 1.0; vec4 dist = texture2D(water_dudvmap, vec2(waterTex1 + disdis*sca2)* windScale * 2.0) * 2.0 - 1.0;

View file

@ -2,14 +2,18 @@
// 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
// © Emilian Huminiuc and Vivian Meazza
// Optimisation - 2012-5-05
// © Emilian Huminiuc and Vivian Meazza
#version 120 #version 120
#define fps2kts 0.5925 #define fps2kts 0.5925
varying vec4 waterTex1; varying vec4 waterTex1;
varying vec4 waterTex2; varying vec4 waterTex2;
varying vec4 waterTex4; //varying vec4 waterTex4;
varying vec4 ecPosition; //varying vec4 ecPosition;
varying vec3 viewerdir; varying vec3 viewerdir;
varying vec3 lightdir; varying vec3 lightdir;
varying vec3 normal; varying vec3 normal;
@ -54,12 +58,12 @@ void main(void)
vec3 N = normalize(gl_Normal); vec3 N = normalize(gl_Normal);
normal = N; normal = N;
ecPosition = gl_ModelViewMatrix * gl_Vertex; // ecPosition = gl_ModelViewMatrix * gl_Vertex;
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));
waterTex4 = vec4( ecPosition.xzy, 0.0 ); // waterTex4 = vec4( ecPosition.xzy, 0.0 );
vec4 t1 = vec4(osg_SimulationTime*0.005217, 0.0, 0.0, 0.0); vec4 t1 = vec4(osg_SimulationTime*0.005217, 0.0, 0.0, 0.0);
vec4 t2 = vec4(osg_SimulationTime*-0.0012, 0.0, 0.0, 0.0); vec4 t2 = vec4(osg_SimulationTime*-0.0012, 0.0, 0.0, 0.0);

View file

@ -1,209 +1,211 @@
// 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; uniform sampler2D water_normalmap;
uniform sampler2D water_reflection; uniform sampler2D water_reflection;
uniform sampler2D water_dudvmap; uniform sampler2D water_dudvmap;
uniform sampler2D water_reflection_grey; uniform sampler2D water_reflection_grey;
uniform sampler2D sea_foam; uniform sampler2D sea_foam;
uniform sampler2D perlin_normalmap; uniform sampler2D perlin_normalmap;
uniform float saturation, Overcast, WindE, WindN; uniform float saturation, Overcast, WindE, WindN;
uniform float CloudCover0, CloudCover1, CloudCover2, CloudCover3, CloudCover4; uniform float CloudCover0, CloudCover1, CloudCover2, CloudCover3, CloudCover4;
uniform float osg_SimulationTime; uniform float osg_SimulationTime;
uniform int Status; 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; varying vec3 viewerdir;
varying vec3 lightdir; varying vec3 lightdir;
varying vec3 normal; varying vec3 normal;
uniform float WaveFreq ; uniform float WaveFreq ;
uniform float WaveAmp ; uniform float WaveAmp ;
uniform float WaveSharp ; uniform float WaveSharp ;
////fog "include" ///// ////fog "include" /////
uniform int fogType; uniform int fogType;
vec3 fog_Func(vec3 color, int type); vec3 fog_Func(vec3 color, int type);
////////////////////// //////////////////////
/////// functions ///////// /////// functions /////////
void rotationmatrix(in float angle, out mat4 rotmat) void rotationmatrix(in float angle, out mat4 rotmat)
{ {
rotmat = mat4( cos( angle ), -sin( angle ), 0.0, 0.0, rotmat = mat4( cos( angle ), -sin( angle ), 0.0, 0.0,
sin( angle ), cos( 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 , 1.0, 0.0,
0.0 , 0.0 , 0.0, 1.0 ); 0.0 , 0.0 , 0.0, 1.0 );
} }
void main(void) void main(void)
{ {
const vec4 sca = vec4(0.005, 0.005, 0.005, 0.005); 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 sca2 = vec4(0.02, 0.02, 0.02, 0.02);
const vec4 tscale = vec4(0.25, 0.25, 0.25, 0.25); const vec4 tscale = vec4(0.25, 0.25, 0.25, 0.25);
mat4 RotationMatrix; mat4 RotationMatrix;
// compute direction to viewer // compute direction to viewer
vec3 E = normalize(viewerdir); vec3 E = normalize(viewerdir);
// compute direction to light source // compute direction to light source
vec3 L = normalize(lightdir); vec3 L = normalize(lightdir);
// half vector // half vector
vec3 H = normalize(L + E); vec3 H = normalize(L + E);
vec3 Normal = normalize(normal); vec3 Normal = normalize(normal);
const float water_shininess = 240.0; const float water_shininess = 240.0;
// approximate cloud cover // approximate cloud cover
float cover = 0.0; float cover = 0.0;
//bool Status = true; //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 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.05 + smoothstep(0.0, 20.0, windEffect); //wave roughness filter float waveRoughness = 0.05 + smoothstep(0.0, 20.0, windEffect); //wave roughness filter
float mixFactor = 0.75 - 0.15 * smoothstep(0.0, 40.0, windEffect); float mixFactor = 0.75 - 0.15 * smoothstep(0.0, 40.0, windEffect);
mixFactor = clamp(mixFactor, 0.3, 0.8); mixFactor = clamp(mixFactor, 0.3, 0.8);
if (Status == 1){ if (Status == 1){
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){
cover = 5; cover = 5;
} else { } else {
cover = Overcast * 5; cover = Overcast * 5;
} }
} }
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;
vec4 dist = texture2D(water_dudvmap, vec2(waterTex1 + disdis*sca2)* 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)); dist *= (0.6 + 0.5 * smoothstep(0.0, 15.0, windEffect));
vec4 fdist = normalize(dist); vec4 fdist = normalize(dist);
fdist = -fdist; //dds fix fdist = -fdist; //dds fix
fdist *= sca; fdist *= sca;
//normalmaps //normalmaps
rotationmatrix(radians(3.0 * windScale + 0.6 * sin(waterTex1.s * 0.2)), RotationMatrix); rotationmatrix(radians(3.0 * windScale + 0.6 * sin(waterTex1.s * 0.2)), RotationMatrix);
vec4 nmap = texture2D(water_normalmap, vec2(waterTex1* RotationMatrix + disdis * sca2) * windScale) * 2.0 - 1.0; vec4 nmap = texture2D(water_normalmap, vec2(waterTex1* RotationMatrix + disdis * sca2) * windScale) * 2.0 - 1.0;
vec4 nmap1 = texture2D(perlin_normalmap, vec2(waterTex1/** RotationMatrix*/ + disdis * sca2) * windScale) * 2.0 - 1.0; vec4 nmap1 = texture2D(perlin_normalmap, vec2(waterTex1/** RotationMatrix*/ + disdis * sca2) * windScale) * 2.0 - 1.0;
rotationmatrix(radians(-2.0 * windScale -0.4 * sin(waterTex1.s * 0.32)), RotationMatrix); rotationmatrix(radians(-2.0 * windScale -0.4 * sin(waterTex1.s * 0.32)), RotationMatrix);
nmap += texture2D(water_normalmap, vec2(waterTex1* RotationMatrix + disdis * sca2) * windScale * 1.5) * 2.0 - 1.0; nmap += texture2D(water_normalmap, vec2(waterTex1* RotationMatrix + disdis * sca2) * windScale * 1.5) * 2.0 - 1.0;
//nmap1 += texture2D(perlin_normalmap, vec2(waterTex1* RotationMatrix + disdis * sca2) * windScale) * 2.0 - 1.0; //nmap1 += texture2D(perlin_normalmap, vec2(waterTex1* RotationMatrix + disdis * sca2) * windScale) * 2.0 - 1.0;
rotationmatrix(radians(1.5 * windScale + 0.3 * sin(waterTex1.s * 0.16)), RotationMatrix); rotationmatrix(radians(1.5 * windScale + 0.3 * sin(waterTex1.s * 0.16)), RotationMatrix);
nmap += texture2D(water_normalmap, vec2(waterTex1* RotationMatrix + disdis * sca2) * windScale * 2.1) * 2.0 - 1.0; nmap += texture2D(water_normalmap, vec2(waterTex1* RotationMatrix + disdis * sca2) * windScale * 2.1) * 2.0 - 1.0;
rotationmatrix(radians(-0.5 * windScale - 0.45 * sin(waterTex1.s * 0.28)), RotationMatrix); rotationmatrix(radians(-0.5 * windScale - 0.45 * sin(waterTex1.s * 0.28)), RotationMatrix);
nmap += texture2D(water_normalmap, vec2(waterTex1* RotationMatrix + disdis * sca2) * windScale * 0.8) * 2.0 - 1.0; nmap += texture2D(water_normalmap, vec2(waterTex1* RotationMatrix + disdis * sca2) * windScale * 0.8) * 2.0 - 1.0;
rotationmatrix(radians(-1.2 * windScale - 0.35 * sin(waterTex1.s * 0.28)), RotationMatrix); rotationmatrix(radians(-1.2 * windScale - 0.35 * sin(waterTex1.s * 0.28)), RotationMatrix);
nmap += texture2D(water_normalmap, vec2(waterTex2 * RotationMatrix* tscale) * windScale * 1.7) * 2.0 - 1.0; nmap += texture2D(water_normalmap, vec2(waterTex2 * RotationMatrix* tscale) * windScale * 1.7) * 2.0 - 1.0;
nmap1 += texture2D(perlin_normalmap, vec2(waterTex2/** RotationMatrix*/ * tscale) * windScale) * 2.0 - 1.0; nmap1 += texture2D(perlin_normalmap, vec2(waterTex2/** RotationMatrix*/ * tscale) * windScale) * 2.0 - 1.0;
nmap *= windEffect_low; nmap *= windEffect_low;
nmap1 *= windEffect_low; nmap1 *= windEffect_low;
// 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 = -vNorm; //dds fix vNorm = -vNorm; //dds fix
//load reflection //load reflection
vec4 tmp = vec4(lightdir, 0.0); vec4 tmp = vec4(lightdir, 0.0);
vec4 refTex; vec4 refTex = texture2D(water_reflection, vec2(tmp + waterTex1) * 32.0) ;
vec4 refl; vec4 refTexGrey = texture2D(water_reflection_grey, vec2(tmp + waterTex1) * 32.0) ;
vec4 refl ;
// cover = 0;
// cover = 0;
if(cover >= 1.5){
refTex = texture2D(water_reflection, vec2(tmp)); if(cover >= 1.5){
refl= normalize(refTex); refl = normalize(refTex);
} else { refl.a = 1.0;
refTex = texture2D(water_reflection_grey, vec2(tmp)); }
refl = normalize(refTex); else
refl.r *= (0.75 + 0.15 * cover); {
refl.g *= (0.80 + 0.15 * cover); refl = normalize(refTexGrey);
refl.b *= (0.875 + 0.125 * cover); refl.r *= (0.75 + 0.15 * cover);
refl.a *= 1.0; refl.g *= (0.80 + 0.15 * cover);
} refl.b *= (0.875 + 0.125 * cover);
refl.a = 1.0;
rotationmatrix(radians(2.1* windScale + 0.25 * sin(waterTex1.s *0.14)), RotationMatrix); }
vec3 N0 = vec3(texture2D(water_normalmap, vec2(waterTex1* RotationMatrix + disdis * sca2) * windScale * 1.15) * 2.0 - 1.0);
vec3 N1 = vec3(texture2D(perlin_normalmap, vec2(waterTex1/** RotationMatrix*/ + disdis * sca) * windScale) * 2.0 - 1.0); rotationmatrix(radians(2.1* windScale + 0.25 * sin(waterTex1.s *0.14)), RotationMatrix);
vec3 N0 = vec3(texture2D(water_normalmap, vec2(waterTex1* RotationMatrix + disdis * sca2) * windScale * 1.15) * 2.0 - 1.0);
rotationmatrix(radians(-1.5 * windScale -0.32 * sin(waterTex1.s *0.24)), RotationMatrix); vec3 N1 = vec3(texture2D(perlin_normalmap, vec2(waterTex1/** RotationMatrix*/ + disdis * sca) * windScale) * 2.0 - 1.0);
N0 += vec3(texture2D(water_normalmap, vec2(waterTex2* RotationMatrix * tscale) * windScale * 1.8) * 2.0 - 1.0);
N1 += vec3(texture2D(perlin_normalmap, vec2(waterTex2/** RotationMatrix*/ * tscale) * windScale) * 2.0 - 1.0); rotationmatrix(radians(-1.5 * windScale -0.32 * sin(waterTex1.s *0.24)), RotationMatrix);
N0 += vec3(texture2D(water_normalmap, vec2(waterTex2* RotationMatrix * tscale) * windScale * 1.8) * 2.0 - 1.0);
rotationmatrix(radians(3.8 * windScale + 0.45 * sin(waterTex1.s *0.32)), RotationMatrix); N1 += vec3(texture2D(perlin_normalmap, vec2(waterTex2/** RotationMatrix*/ * tscale) * windScale) * 2.0 - 1.0);
N0 += vec3(texture2D(water_normalmap, vec2(waterTex2 * RotationMatrix * (tscale + sca2)) * windScale * 0.85) * 2.0 - 1.0);
N1 += vec3(texture2D(perlin_normalmap, vec2(waterTex2/** RotationMatrix*/ * (tscale + sca2)) * windScale) * 2.0 - 1.0); rotationmatrix(radians(3.8 * windScale + 0.45 * sin(waterTex1.s *0.32)), RotationMatrix);
N0 += vec3(texture2D(water_normalmap, vec2(waterTex2 * RotationMatrix * (tscale + sca2)) * windScale * 0.85) * 2.0 - 1.0);
rotationmatrix(radians(-2.8 * windScale - 0.38 * sin(waterTex1.s * 0.26)), RotationMatrix); N1 += vec3(texture2D(perlin_normalmap, vec2(waterTex2/** RotationMatrix*/ * (tscale + sca2)) * windScale) * 2.0 - 1.0);
N0 += vec3(texture2D(water_normalmap, vec2(waterTex1 * RotationMatrix + disdis * sca2) * windScale * 2.1) * 2.0 - 1.0);
N1 += vec3(texture2D(perlin_normalmap, vec2(waterTex1 /** RotationMatrix*/ + disdis * sca) * windScale) * 2.0 - 1.0); rotationmatrix(radians(-2.8 * windScale - 0.38 * sin(waterTex1.s * 0.26)), RotationMatrix);
N0 += vec3(texture2D(water_normalmap, vec2(waterTex1 * RotationMatrix + disdis * sca2) * windScale * 2.1) * 2.0 - 1.0);
N0 *= windEffect_low; N1 += vec3(texture2D(perlin_normalmap, vec2(waterTex1 /** RotationMatrix*/ + disdis * sca) * windScale) * 2.0 - 1.0);
N1 *= windEffect_low;
N0 *= windEffect_low;
vec3 N = normalize(mix(Normal + N0, Normal + N1, mixFactor) * waveRoughness); N1 *= windEffect_low;
N = -N; //dds fix vec3 N = normalize(mix(Normal + N0, Normal + N1, mixFactor) * waveRoughness);
// specular N = -N; //dds fix
vec3 specular_color = vec3(gl_LightSource[0].diffuse)
* pow(max(0.0, dot(N, H)), water_shininess) * 6.0; // specular
vec4 specular = vec4(specular_color, 0.5); vec3 specular_color = vec3(gl_LightSource[0].diffuse)
* pow(max(0.0, dot(N, H)), water_shininess) * 6.0;
specular = specular * saturation * 0.3 ; vec4 specular = vec4(specular_color, 0.5);
//calculate fresnel specular = specular * saturation * 0.3 ;
vec4 invfres = vec4( dot(vNorm, viewt) );
vec4 fres = vec4(1.0) + invfres; //calculate fresnel
refl *= fres; vec4 invfres = vec4( dot(vNorm, viewt) );
vec4 fres = vec4(1.0) + invfres;
//calculate final colour refl *= fres;
vec4 ambient_light = gl_LightSource[0].diffuse;
vec4 finalColor; //calculate final colour
vec4 ambient_light = gl_LightSource[0].diffuse;
if(cover >= 1.5){ vec4 finalColor;
finalColor = refl + specular;
} else { if(cover >= 1.5){
finalColor = refl; finalColor = refl + specular;
} } else {
finalColor = refl;
float foamSlope = 0.10 + 0.1 * windScale; }
vec4 foam_texel = texture2D(sea_foam, vec2(waterTex2 * tscale) * 25.0); float foamSlope = 0.10 + 0.1 * windScale;
float waveSlope = N.g;
vec4 foam_texel = texture2D(sea_foam, vec2(waterTex2 * tscale) * 25.0);
if (windEffect >= 8.0) float waveSlope = N.g;
if (waveSlope >= foamSlope){
finalColor = mix(finalColor, max(finalColor, finalColor + foam_texel), smoothstep(0.01, 0.50, N.g)); if (windEffect >= 8.0)
} if (waveSlope >= foamSlope){
finalColor = mix(finalColor, max(finalColor, finalColor + foam_texel), smoothstep(0.01, 0.50, N.g));
}
finalColor *= ambient_light;
//gl_FragColor = mix(gl_Fog.color, finalColor, fogFactor); finalColor *= ambient_light;
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: 396 B

After

Width:  |  Height:  |  Size: 30 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 850 KiB

After

Width:  |  Height:  |  Size: 810 KiB

View file

@ -186,9 +186,6 @@ command interface /autopilot/route-manager/input:
var apt = flightplan().destination; var apt = flightplan().destination;
var rwy = flightplan().destination_runway; var rwy = flightplan().destination_runway;
debug.dump("updateAproaches for " ~ rwy.id);
debug.dump(apt.getApproachList(rwy));
if (apt == nil or apt.getApproachList(rwy) == nil) { if (apt == nil or apt.getApproachList(rwy) == nil) {
return; return;
} }