1
0
Fork 0

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

This commit is contained in:
Stuart Buchanan 2011-10-08 19:40:15 +01:00
commit f695fd4679
13 changed files with 279 additions and 61 deletions

View file

@ -83,6 +83,12 @@ Jan 30 2003
<layer>
<name>HDG Knob</name>
<condition>
<equals>
<property>/sim/instrument-options/omit-knobs</property>
<value></value>
</equals>
</condition>
<w>88</w>
<h>88</h>
<texture>

View file

@ -23,9 +23,9 @@
<object-name>PtrTipL</object-name>
<property>systems/electrical/amps</property>
<interpolation>
<entry><ind>-40</ind><dep>-45</dep></entry>
<entry><ind>-40</ind><dep>-30</dep></entry>
<entry><ind>0</ind><dep>0</dep></entry>
<entry><ind>40</ind><dep>45</dep></entry>
<entry><ind>40</ind><dep>33</dep></entry>
</interpolation>
<axis>
<x>1</x>

View file

@ -12,7 +12,9 @@
</texture>
<texture n="2">
<!--<image>Textures/Water/water-normalmap.png</image>-->
<image>Textures/Water/normalmap2.png</image>
<!--<image>Textures/Water/water-normalmap2.dds</image>-->
<image>Textures/Water/waves-ver10-nm.dds</image>
<!--<image>Textures/Water/caustic-nm.png</image>-->
<filter>linear-mipmap-linear</filter>
<wrap-s>repeat</wrap-s>
<wrap-t>repeat</wrap-t>
@ -20,7 +22,9 @@
</texture>
<texture n="3">
<!--<image>Textures/Water/water-dudv.png</image>-->
<image>Textures/Water/dudvmap2.png</image>
<!--<image>Textures/Water/dudvmap2.png</image>-->
<image>Textures/Water/waves-ver10-dudv.dds</image>
<!--<image>Textures/Water/water-reflection-grey.png</image>-->
<filter>linear-mipmap-linear</filter>
<wrap-s>repeat</wrap-s>
<wrap-t>repeat</wrap-t>
@ -34,7 +38,14 @@
<internal-format>normalized</internal-format>
</texture>
<texture n="5">
<image>Textures/Water/sea_foam.png</image>
<image>Textures/Water/sea_foam.dds</image>
<filter>linear-mipmap-linear</filter>
<wrap-s>repeat</wrap-s>
<wrap-t>repeat</wrap-t>
<internal-format>normalized</internal-format>
</texture>
<texture n="6">
<image>Textures/Water/perlin-noise-nm.dds</image>
<filter>linear-mipmap-linear</filter>
<wrap-s>repeat</wrap-s>
<wrap-t>repeat</wrap-t>
@ -73,6 +84,10 @@
<windN>
<use>/environment/config/boundary/entry[0]/wind-from-north-fps</use>
</windN>
<wind-from>
<use>/environment/config/boundary/entry[0]/wind-from-heading-deg</use>
</wind-from>
</parameters>
<technique n="8">
@ -218,6 +233,28 @@
<use>texture[5]/internal-format</use>
</internal-format>
</texture-unit>
<texture-unit>
<unit>6</unit>
<image>
<use>texture[6]/image</use>
</image>
<filter>
<use>texture[6]/filter</use>
</filter>
<wrap-s>
<use>texture[6]/wrap-s</use>
</wrap-s>
<wrap-t>
<use>texture[6]/wrap-t</use>
</wrap-t>
<internal-format>
<use>texture[6]/internal-format</use>
</internal-format>
</texture-unit>
<texture-unit>
<unit>9</unit>
<type>noise</type>
</texture-unit>
<program>
<vertex-shader>Shaders/water.vert</vertex-shader>
<fragment-shader>Shaders/water.frag</fragment-shader>
@ -247,6 +284,11 @@
<type>sampler-2d</type>
<value type="int">5</value>
</uniform>
<uniform>
<name>perlin_normalmap</name>
<type>sampler-2d</type>
<value type="int">6</value>
</uniform>
<uniform>
<name>saturation</name>
<type>float</type>
@ -317,6 +359,18 @@
<use>windN</use>
</value>
</uniform>
<uniform>
<name>WindFrom</name>
<type>float</type>
<value>
<use>wind-from</use>
</value>
</uniform>
<uniform>
<name>Noise</name>
<type>sampler-3d</type>
<value type="int">9</value>
</uniform>
</pass>
</technique>
<technique n="9">

View file

@ -21,7 +21,7 @@
# EventChannel.register(event_hash, handler)
# Register a handler for the event identified by the hash event_hash.
# event_hash - hash value for the event : a unique 4 character string
# handler - a handler function for the event : func (msg)
# handler - a handler function for the event : func (sender, msg)
#
# EventChannel.deregister(event_hash)
# Deregister the handler for the event identified by the hash event_hash.
@ -62,7 +62,7 @@ EventChannel.send = func (event_hash,
EventChannel._process = func (n, msg) {
var event_hash = Binary.readHash(msg);
if (contains(me.events, event_hash)) {
me.events[event_hash](substr(msg, Binary.sizeOf["Hash"]));
me.events[event_hash](n, substr(msg, Binary.sizeOf["Hash"]));
}
}
@ -226,11 +226,64 @@ BroadcastChannel._loop_ = func (id) {
}
######################################################################
###############################################################################
# Lamport clock. Useful for creating a total order for events or messages.
# The users' callsigns are used to break ties.
#
# LamportClock.new()
# Creates a new lamport clock for this user.
#
# LamportClock.merge(sender, sender_timestamp)
# Merges the timestamp from the sender with the local clock.
# sender : base node of the senders property tree
# sender_timestamp : the timestamp received from the sender.
# Returns 1 if the local clock was advanced; 0 otherwise.
#
# LamportClock.advance()
# Advances the local clock one tick.
#
# LamportClock.timestamp()
# Returns an encoded 4 character long timestamp from the local clock.
#
var LamportClock = {
# LamportClock.new()
# Creates a new lamport clock for this user.
new : func {
var obj = {
parents : [LamportClock],
callsign : getprop("/sim/multiplay/callsign"),
time : 0
};
return obj;
},
merge : func (sender, sender_timestamp) {
var sender_time = Binary.decodeInt28(sender_timestamp);
if (sender_time > me.time) {
me.time = sender_time;
return 1;
} elsif ((sender_time == me.time) and
(cmp(sender.getNode("callsign").getValue(), me.callsign) > 0)) {
return 1;
} else {
# The received timestamp is old and should be ignored.
return 0;
}
},
advance : func {
me.time += 1;
},
timestamp : func {
return Binary.encodeInt28(me.time);
}
};
###############################################################################
# Some routines for encoding/decoding values into/from a string.
# NOTE: MP is picky about what it sends in a string propery.
# Encode 7 bits as a printable 8 bit character.
var Binary = {};
Binary.TWOTO27 = 134217728;
Binary.TWOTO28 = 268435456;
Binary.TWOTO31 = 2147483648;
Binary.TWOTO32 = 4294967296;
@ -275,6 +328,31 @@ Binary.decodeByte = func (str) {
return int(v);
}
############################################################
# NOTE: This encodes a 28 bit integer.
Binary.sizeOf["int28"] = 4;
Binary.encodeInt28 = func (int) {
var bf = bits.buf(4);
if (int < 0) int += Binary.TWOTO32;
var r = int;
for (var i = 0; i < 4; i += 1) {
var c = math.mod(r, 128);
bf[3-i] = c + `A`;
r = (r - c)/128;
}
return bf;
}
############################################################
Binary.decodeInt28 = func (str) {
var v = 0;
var b = 1;
for (var i = 0; i < 4; i += 1) {
v += (str[3-i] - `A`) * b;
b *= 128;
}
if (v / Binary.TWOTO27 >= 1) v -= Binary.TWOTO28;
return int(v);
}
############################################################
# NOTE: This can neither handle huge values nor really tiny.
Binary.sizeOf["double"] = 2*Binary.sizeOf["int"];
Binary.encodeDouble = func (d) {
@ -318,6 +396,8 @@ Binary.stringHash = func (str) {
Binary.readHash = func (str) {
return substr(str, 0, Binary.sizeOf["Hash"]);
}
############################################################
Binary.sizeOf["LamportTS"] = 4;
######################################################################
###############################################################################

View file

@ -23,20 +23,42 @@ var sharedDoor = {
obj.parents = [sharedDoor] ~ obj.parents;
obj.event_hash = mp_broadcast.Binary.stringHash
(isa(node, props.Node) ? node.getPath() : node);
events.register(obj.event_hash, func (msg) { obj._process(msg) });
obj.clock = mp_broadcast.LamportClock.new();
obj.loopid = 0;
events.register(obj.event_hash,
func (sender, msg) { obj._process(sender, msg) });
return obj;
},
toggle: func {
events.send(me.event_hash, mp_broadcast.Binary.encodeByte(me.target));
# Send current time, current position and target position.
me.clock.advance();
me.move(me.target);
me._loop(me.loopid += 1);
},
destroy : func {
me.loopid += 1;
events.deregister(me.event_hash);
},
_process : func (msg) {
me.target = mp_broadcast.Binary.decodeByte(msg);
_process : func (sender, msg) {
if (me.clock.merge(sender, msg)) {
me.setpos(mp_broadcast.Binary.decodeDouble
(substr(msg, mp_broadcast.Binary.sizeOf["LamportTS"])));
me.target = mp_broadcast.Binary.decodeByte
(substr(msg,
mp_broadcast.Binary.sizeOf["LamportTS"] +
mp_broadcast.Binary.sizeOf["double"]));
me.move(me.target);
}
},
_loop : func (id) {
id == me.loopid or return;
# Send current time, current position and target position.
events.send(me.event_hash,
me.clock.timestamp() ~
mp_broadcast.Binary.encodeDouble(me.positionN.getValue()) ~
mp_broadcast.Binary.encodeByte(!me.target));
settimer(func { me._loop(id); }, 17, 1);
}
};
###############################################################################

View file

@ -2,18 +2,23 @@
// http://www.bonzaisoftware.com/water_tut.html and its glsl conversion
// available at http://forum.bonzaisoftware.com/viewthread.php?tid=10
// © Michael Horsch - 2005
// Major update and revisions - 2011-10-07
// © Emilian Huminiuc and Vivian Meazza
#version 120
#pragma debug(on)
uniform sampler2D water_normalmap;
uniform sampler2D water_reflection;
uniform sampler2D water_dudvmap;
uniform sampler2D water_reflection_grey;
uniform sampler2D sea_foam;
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
@ -24,12 +29,23 @@ varying vec3 viewerdir;
varying vec3 lightdir;
varying vec3 normal;
/////// 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)
{
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;
// compute direction to viewer
vec3 E = normalize(viewerdir);
@ -39,40 +55,55 @@ void main(void)
// half vector
vec3 H = normalize(L + E);
const float water_shininess = 240.0;
vec3 Normal = normalize(normal);
// calculate wind effects
float windEffect = sqrt(pow(abs(WindE),2)+pow(abs(WindN),2)) * 0.6;
float windScale = 10.0/(6.0 + 8.0 * smoothstep(0.0,0.8,windEffect * 0.05));
const float water_shininess = 240.0;
// approximate cloud cover
float cover = 0.0;
//bool Status = true;
float windEffect = sqrt(pow(abs(WindE),2)+pow(abs(WindN),2)) * 0.6; //wind speed in kt
float windScale = 15.0/(3.0 + windEffect); //wave scale
float windEffect_low = 0.4 + 0.6 * smoothstep(0.0, 5.0, windEffect); //low windspeed wave filter
float waveRoughness = 0.15 + smoothstep(0.0, 15.0, windEffect); //wave roughness filter
//float noise_factor = 0.2 + 0.15 * smoothstep(0.0, 40.0, windEffect);
if (Status == 1){
cover = min(min(min(min(CloudCover0, CloudCover1),CloudCover2),CloudCover3),CloudCover4);
} else {
// hack to allow for Overcast not to be set by Local Weather
if (Overcast == 0){
cover = 5;
} else {
cover = Overcast * 5;
}
}
vec4 viewt = normalize(waterTex4);
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;
//normalmap
vec4 nmap0 = texture2D(water_normalmap, vec2(waterTex1+ disdis*sca2) * windScale) * 2.0 - 1.0;
vec4 nmap2 = texture2D(water_normalmap, vec2(waterTex2 * tscale) * windScale) * 2.0 - 1.0;
vec4 vNorm = normalize(nmap0 + nmap2);
//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;
rotationmatrix(radians(3.0 * sin(osg_SimulationTime * 0.0075)), RotationMatrix);
nmap += texture2D(water_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;
nmap1 *= windEffect_low;
// mix water and noise, modulated by factor
vec4 vNorm = normalize(mix(nmap, nmap1, 0.3) * waveRoughness);
vNorm = -vNorm; //dds fix
//load reflection
vec4 tmp = vec4(lightdir, 0.0);
@ -93,15 +124,31 @@ void main(void)
}
vec3 N0 = vec3(texture2D(water_normalmap, vec2(waterTex1 + disdis * sca2) * windScale) * 2.0 - 1.0);
vec3 N1 = vec3(texture2D(water_normalmap, vec2(waterTex2 * tscale) * windScale) * 2.0 - 1.0);
vec3 N = normalize(normal+N0+N1);
vec3 N1 = vec3(texture2D(perlin_normalmap, vec2(waterTex1 + disdis * sca) * windScale) * 2.0 - 1.0);
N0 += vec3(texture2D(water_normalmap, vec2(waterTex2 * 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);
N0 += vec3(texture2D(water_normalmap, vec2(waterTex2 * RotationMatrix * (tscale + sca2)) * windScale) * 2.0 - 1.0);
N1 += vec3(texture2D(perlin_normalmap, vec2(waterTex2 * RotationMatrix * (tscale + sca2)) * windScale) * 2.0 - 1.0);
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);
N1 += vec3(texture2D(perlin_normalmap, vec2(waterTex1 * RotationMatrix + disdis * sca) * windScale) * 2.0 - 1.0);
N0 *= windEffect_low;
N1 *= windEffect_low;
vec3 N = normalize(mix(Normal + N0 , Normal + N1, 0.3) * waveRoughness);
N = -N; //dds fix
// specular
vec3 specular_color = vec3(gl_LightSource[0].diffuse)
* pow(max(0.0, dot(N, H)), water_shininess) * 6.0;
vec4 specular = vec4(specular_color, 0.5);
specular = specular * saturation * 0.4;
specular = specular * saturation * 0.3 ;
//calculate fresnel
vec4 invfres = vec4( dot(vNorm, viewt) );
@ -121,25 +168,20 @@ void main(void)
vec4 ambient_light = gl_LightSource[0].diffuse;
vec4 finalColor;
// cover = 0;
if(cover >= 1.5){
finalColor = refl + specular;
} else {
finalColor = refl;
}
if (windEffect >= 10.0){
float windScale3 = pow(windScale, 3);
if (N.g >= 0.0005 + 0.085 * windScale3){
vec4 foam_texel = texture2D(sea_foam, vec2(waterTex1+ disdis*sca2) * windScale3 * 50.0);
finalColor = mix(finalColor, max(finalColor, foam_texel), smoothstep(0.0005 + 0.085 * windScale3, 0.1, N.g));
float foamSlope = 0.1 + 0.1 * windScale;
if (windEffect >= 10.0)
if (N.g >= foamSlope){
vec4 foam_texel = texture2D(sea_foam, vec2(waterTex2 * tscale) * 30.0);
finalColor = mix(finalColor, max(finalColor, finalColor + foam_texel), smoothstep(foamSlope, 0.25, N.g));
}
}
finalColor *= ambient_light;
gl_FragColor = mix(gl_Fog.color, finalColor, fogFactor);
}

View file

@ -2,6 +2,8 @@
// http://www.bonzaisoftware.com/water_tut.html and its glsl conversion
// available at http://forum.bonzaisoftware.com/viewthread.php?tid=10
// © Michael Horsch - 2005
// Major update and revisions - 2011-10-07
// © Emilian Huminiuc and Vivian Meazza
#version 120
@ -9,14 +11,27 @@ varying vec4 waterTex1;
varying vec4 waterTex2;
varying vec4 waterTex4;
varying vec4 ecPosition;
uniform float osg_SimulationTime;
uniform float WindE, WindN;
varying vec3 viewerdir;
varying vec3 lightdir;
varying vec3 normal;
uniform float osg_SimulationTime;
uniform float WindE, WindN;
/////// 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;
@ -30,15 +45,14 @@ 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);
//float windFactor = sqrt(pow(abs(WindE),2)+pow(abs(WindN),2)) * 0.3;
float windFactor = 0.001;
float windFactor = sqrt(pow(abs(WindE),2)+pow(abs(WindN),2)) * 0.01;
float Angle = atan(-WindN + 0.001, WindE + 0.001) - atan(1.0);
waterTex1 = gl_MultiTexCoord0 + t1;
waterTex1.x += WindE * windFactor;
waterTex1.y += WindN * windFactor;
waterTex2 = gl_MultiTexCoord0 + t2;
waterTex2.x += WindE * windFactor;
waterTex2.y += WindN * windFactor;
rotationmatrix(Angle, RotationMatrix);
waterTex1 = gl_MultiTexCoord0 * RotationMatrix - t1 * windFactor;
rotationmatrix(Angle, RotationMatrix);
waterTex2 = gl_MultiTexCoord0 * RotationMatrix - t2 * windFactor;
gl_Position = ftransform();
}

Binary file not shown.

BIN
Textures/Water/sea_foam.dds Normal file

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

BIN
Textures/Water/waves2.dds Normal file

Binary file not shown.