Local Weather 1.36 by Thorsten Renk
This commit is contained in:
parent
928789a0d5
commit
a2b26f8d59
7 changed files with 177 additions and 37 deletions
|
@ -479,6 +479,18 @@ if (features.can_set_scattering == 1)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
####################################
|
||||||
|
# set skydome scattering parameters
|
||||||
|
####################################
|
||||||
|
|
||||||
|
var setSkydomeShader = func (r, m, d) {
|
||||||
|
|
||||||
|
setprop("/sim/rendering/rayleigh", r);
|
||||||
|
setprop("/sim/rendering/mie", m);
|
||||||
|
setprop("/sim/rendering/dome-density",d);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
###########################################################
|
###########################################################
|
||||||
# set wind to given direction and speed
|
# set wind to given direction and speed
|
||||||
###########################################################
|
###########################################################
|
||||||
|
|
|
@ -594,12 +594,14 @@ var alt1 = vis_alt1;
|
||||||
var alt2 = alt1 + 1500.0;
|
var alt2 = alt1 + 1500.0;
|
||||||
|
|
||||||
|
|
||||||
#var inc1 = 0.15;
|
|
||||||
#var inc2 = 5.0;
|
|
||||||
#var inc3 = 0.7;
|
|
||||||
|
|
||||||
# compute the visibility gradients
|
# compute the visibility gradients
|
||||||
|
|
||||||
|
if (realistic_visibility_flag == 1)
|
||||||
|
{
|
||||||
|
vis_aloft = vis_aloft * 2.0;
|
||||||
|
vis_ovcst = vis_ovcst * 3.0;
|
||||||
|
}
|
||||||
|
|
||||||
var inc1 = 0.1 * (vis_aloft - vis)/(vis_alt1 - ialt);
|
var inc1 = 0.1 * (vis_aloft - vis)/(vis_alt1 - ialt);
|
||||||
var inc2 = 0.9 * (vis_aloft - vis)/1500.0;
|
var inc2 = 0.9 * (vis_aloft - vis)/1500.0;
|
||||||
var inc3 = (vis_ovcst - vis_aloft)/(ovcst_alt_high - vis_alt1+1500);
|
var inc3 = (vis_ovcst - vis_aloft)/(ovcst_alt_high - vis_alt1+1500);
|
||||||
|
@ -607,7 +609,7 @@ var inc4 = 0.5;
|
||||||
|
|
||||||
|
|
||||||
if (realistic_visibility_flag == 1)
|
if (realistic_visibility_flag == 1)
|
||||||
{inc4 = inc4 * 8.0;}
|
{inc4 = inc4 * 3.0;}
|
||||||
|
|
||||||
# compute the visibility
|
# compute the visibility
|
||||||
|
|
||||||
|
@ -628,35 +630,67 @@ else if (altitude > ovcst_alt_high)
|
||||||
|
|
||||||
# limit visibility (otherwise memory consumption is very bad...)
|
# limit visibility (otherwise memory consumption is very bad...)
|
||||||
|
|
||||||
if (vis > 140000.0)
|
if (vis > 120000.0)
|
||||||
{vis = 140000.0;}
|
{vis = 120000.0;}
|
||||||
|
|
||||||
# compute the horizon shading
|
# determine scattering shader parameters if scattering shader is on
|
||||||
|
|
||||||
if (altitude < scatt_alt_low)
|
if (scattering_shader_flag == 1)
|
||||||
{
|
{
|
||||||
var scatt = scatt_max;
|
var rayleigh = 0.0003 ;
|
||||||
}
|
var mie = 0.003;
|
||||||
else if (altitude < scatt_alt_high)
|
var density = 0.3;
|
||||||
{
|
|
||||||
var scatt = scatt_max + (0.95 - scatt_max) * (altitude - scatt_alt_low)/(scatt_alt_high-scatt_alt_low);
|
if (altitude < 30000.0)
|
||||||
|
{
|
||||||
|
rayleigh = 0.0004 - altitude/30000.0 * 0.0001;
|
||||||
|
mie = 0.004 - altitude/30000.0 * 0.001;
|
||||||
|
}
|
||||||
|
else if (altitude < 60000.0)
|
||||||
|
{
|
||||||
|
rayleigh = 0.0003 - (altitude-30000.0)/30000.0 * 0.0001;
|
||||||
|
mie = 0.003 - (altitude-30000.0)/30000.0 * 0.001;
|
||||||
|
}
|
||||||
|
else if (altitude < 85000.0)
|
||||||
|
{
|
||||||
|
rayleigh = 0.0002 - (altitude-60000.0)/25000.0 * 0.0001;
|
||||||
|
mie = 0.002;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{rayleigh = 0.0001; mie = 0.002;}
|
||||||
}
|
}
|
||||||
|
# otherwise compute normal skydome shader parameters
|
||||||
else
|
else
|
||||||
{var scatt = 0.95;}
|
{
|
||||||
|
|
||||||
|
# compute the horizon shading
|
||||||
|
|
||||||
|
if (altitude < scatt_alt_low)
|
||||||
|
{
|
||||||
|
var scatt = scatt_max;
|
||||||
|
}
|
||||||
|
else if (altitude < scatt_alt_high)
|
||||||
|
{
|
||||||
|
var scatt = scatt_max + (0.95 - scatt_max) * (altitude - scatt_alt_low)/(scatt_alt_high-scatt_alt_low);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{var scatt = 0.95;}
|
||||||
|
|
||||||
|
|
||||||
# compute the overcast haze
|
# compute the overcast haze
|
||||||
|
|
||||||
if (altitude < ovcst_alt_low)
|
if (altitude < ovcst_alt_low)
|
||||||
{
|
{
|
||||||
var ovcst = ovcst_max;
|
var ovcst = ovcst_max;
|
||||||
|
}
|
||||||
|
else if (altitude < ovcst_alt_high)
|
||||||
|
{
|
||||||
|
var ovcst = ovcst_max - ovcst_max * (altitude - ovcst_alt_low)/(ovcst_alt_high-ovcst_alt_low);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{var ovcst = 0.0;}
|
||||||
|
|
||||||
}
|
}
|
||||||
else if (altitude < ovcst_alt_high)
|
|
||||||
{
|
|
||||||
var ovcst = ovcst_max - ovcst_max * (altitude - ovcst_alt_low)/(ovcst_alt_high-ovcst_alt_low);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{var ovcst = 0.0;}
|
|
||||||
|
|
||||||
|
|
||||||
# limit relative changes of the visibility, will make for gradual transitions
|
# limit relative changes of the visibility, will make for gradual transitions
|
||||||
|
@ -678,8 +712,16 @@ setprop(lwi~"dewpoint-degc",D);
|
||||||
if (p > 10.0) {setprop(lwi~"pressure-sea-level-inhg",p);}
|
if (p > 10.0) {setprop(lwi~"pressure-sea-level-inhg",p);}
|
||||||
setprop(lwi~"turbulence",0.0);
|
setprop(lwi~"turbulence",0.0);
|
||||||
|
|
||||||
compat_layer.setScattering(scatt);
|
|
||||||
compat_layer.setOvercast(ovcst);
|
if (scattering_shader_flag == 1)
|
||||||
|
{
|
||||||
|
local_weather.setSkydomeShader(rayleigh, mie, density);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
local_weather.setScattering(scatt);
|
||||||
|
local_weather.setOvercast(ovcst);
|
||||||
|
}
|
||||||
|
|
||||||
# now check if an effect volume writes the property and set only if not
|
# now check if an effect volume writes the property and set only if not
|
||||||
|
|
||||||
|
@ -3479,6 +3521,7 @@ debug_output_flag = getprop(lw~"config/debug-output-flag");
|
||||||
fps_control_flag = getprop(lw~"config/fps-control-flag");
|
fps_control_flag = getprop(lw~"config/fps-control-flag");
|
||||||
realistic_visibility_flag = getprop(lw~"config/realistic-visibility-flag");
|
realistic_visibility_flag = getprop(lw~"config/realistic-visibility-flag");
|
||||||
detailed_terrain_interaction_flag = getprop(lw~"config/detailed-terrain-interaction-flag");
|
detailed_terrain_interaction_flag = getprop(lw~"config/detailed-terrain-interaction-flag");
|
||||||
|
scattering_shader_flag = getprop("/sim/rendering/scattering-shader");
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -4103,6 +4146,7 @@ setlistener(lw~"config/target-framerate", func {target_framerate = getprop(lw~"c
|
||||||
|
|
||||||
setlistener(lw~"config/small-scale-persistence", func {weather_tiles.small_scale_persistence = getprop(lw~"config/small-scale-persistence");});
|
setlistener(lw~"config/small-scale-persistence", func {weather_tiles.small_scale_persistence = getprop(lw~"config/small-scale-persistence");});
|
||||||
|
|
||||||
|
setlistener("/sim/rendering/scattering-shader", func {scattering_shader_flag = getprop("/sim/rendering/scattering-shader"); });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -4525,8 +4569,9 @@ var local_weather_startup_flag = 0;
|
||||||
var fps_control_flag = 0;
|
var fps_control_flag = 0;
|
||||||
var buffer_flag = 1;
|
var buffer_flag = 1;
|
||||||
var detailed_terrain_interaction_flag = 1;
|
var detailed_terrain_interaction_flag = 1;
|
||||||
var hardcoded_clouds_flag = 0;
|
var hardcoded_clouds_flag = 1;
|
||||||
var realistic_visibility_flag = 0;
|
var realistic_visibility_flag = 0;
|
||||||
|
var scattering_shader_flag = 0;
|
||||||
|
|
||||||
# globals for framerate controlled cloud management
|
# globals for framerate controlled cloud management
|
||||||
|
|
||||||
|
|
6
Shaders/road.frag
Normal file
6
Shaders/road.frag
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
#version 120
|
||||||
|
|
||||||
|
uniform sampler2d BaseTex;
|
||||||
|
|
||||||
|
void main() {
|
||||||
|
}
|
30
Shaders/road.geom
Normal file
30
Shaders/road.geom
Normal file
|
@ -0,0 +1,30 @@
|
||||||
|
#version 120
|
||||||
|
#extension GL_EXT_geometry_shader4 : enable
|
||||||
|
|
||||||
|
varying in vec4 ecPositionIn[];
|
||||||
|
varying in vec3 ecNormalIn[];
|
||||||
|
|
||||||
|
varying out vec4 ecPosition;
|
||||||
|
varying out vec3 ecNormal;
|
||||||
|
|
||||||
|
void main() {
|
||||||
|
gl_Position = gl_PositionIn[0];
|
||||||
|
gl_TexCoord[0] = gl_TexCoordIn[0][0];
|
||||||
|
ecPosition = ecPositionIn[0];
|
||||||
|
ecNormal = ecNormalIn[0];
|
||||||
|
EmitVertex();
|
||||||
|
|
||||||
|
gl_Position = gl_PositionIn[1];
|
||||||
|
gl_TexCoord[0] = gl_TexCoordIn[1][0];
|
||||||
|
ecPosition = ecPositionIn[1];
|
||||||
|
ecNormal = ecNormalIn[1];
|
||||||
|
EmitVertex();
|
||||||
|
|
||||||
|
gl_Position = gl_PositionIn[2];
|
||||||
|
gl_TexCoord[0] = gl_TexCoordIn[2][0];
|
||||||
|
ecPosition = ecPositionIn[2];
|
||||||
|
ecNormal = ecNormalIn[2];
|
||||||
|
EmitVertex();
|
||||||
|
|
||||||
|
EndPrimitive();
|
||||||
|
}
|
11
Shaders/road.vert
Normal file
11
Shaders/road.vert
Normal file
|
@ -0,0 +1,11 @@
|
||||||
|
#version 120
|
||||||
|
|
||||||
|
varying vec4 ecPositionIn;
|
||||||
|
varying vec3 ecNormalIn;
|
||||||
|
|
||||||
|
void main() {
|
||||||
|
ecPositionIn = gl_ModelViewMatrix * gl_Vertex;
|
||||||
|
ecNormalIn = gl_NormalMatrix * gl_Normal;
|
||||||
|
gl_TexCoord[0] = gl_TextureMatrix[0] * gl_MultiTexCoord0;
|
||||||
|
gl_Position = ftransform();
|
||||||
|
}
|
|
@ -6,7 +6,8 @@
|
||||||
|
|
||||||
varying vec3 rayleigh;
|
varying vec3 rayleigh;
|
||||||
varying vec3 mie;
|
varying vec3 mie;
|
||||||
varying vec3 eye;
|
varying vec3 eye;
|
||||||
|
varying float ct;
|
||||||
|
|
||||||
float miePhase(in float cosTheta, in float g)
|
float miePhase(in float cosTheta, in float g)
|
||||||
{
|
{
|
||||||
|
@ -30,9 +31,35 @@ float rayleighPhase(in float cosTheta)
|
||||||
void main()
|
void main()
|
||||||
{
|
{
|
||||||
float cosTheta = dot(normalize(eye), gl_LightSource[0].position.xyz);
|
float cosTheta = dot(normalize(eye), gl_LightSource[0].position.xyz);
|
||||||
|
|
||||||
|
|
||||||
vec3 color = rayleigh * rayleighPhase(cosTheta);
|
vec3 color = rayleigh * rayleighPhase(cosTheta);
|
||||||
color += mie * miePhase(cosTheta, -0.8);
|
color += mie * miePhase(cosTheta, -0.8);
|
||||||
|
|
||||||
|
vec3 white = vec3(1.0,1.0,1.0);
|
||||||
|
|
||||||
|
|
||||||
|
//float scale = dot(normalize(white),normalize(color));
|
||||||
|
//float scale1 = 1.0 - exp(-5.0 * length(color));
|
||||||
|
//float scale2 = length(color)/length(white);
|
||||||
|
|
||||||
|
//if (scale1>1.0) color = color/scale1;
|
||||||
|
|
||||||
|
//color = color/scale1;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
if (color.x > 0.8) color.x = 0.8 + 0.8* log(color.x/0.8);
|
||||||
|
if (color.y > 0.8) color.y = 0.8 + 0.8* log(color.y/0.8);
|
||||||
|
if (color.z > 0.8) color.z = 0.8 + 0.8* log(color.z/0.8);
|
||||||
|
|
||||||
|
vec3 fogColor = vec3 (gl_Fog.color.x, gl_Fog.color.y, gl_Fog.color.z);
|
||||||
|
|
||||||
|
|
||||||
|
if (ct > -0.03) color = mix(color, fogColor ,smoothstep(0.2, -0.2, ct));
|
||||||
|
else color = mix (color, fogColor, smoothstep(0.2,-0.2,-0.03));
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
gl_FragColor = vec4(color, 1.0);
|
gl_FragColor = vec4(color, 1.0);
|
||||||
gl_FragDepth = 0.1;
|
gl_FragDepth = 0.1;
|
||||||
|
|
|
@ -10,7 +10,8 @@ uniform mat4 osg_ViewMatrixInverse;
|
||||||
|
|
||||||
varying vec3 rayleigh;
|
varying vec3 rayleigh;
|
||||||
varying vec3 mie;
|
varying vec3 mie;
|
||||||
varying vec3 eye;
|
varying vec3 eye;
|
||||||
|
varying float ct;
|
||||||
|
|
||||||
// Dome parameters from FG and screen
|
// Dome parameters from FG and screen
|
||||||
const float domeSize = 80000.0;
|
const float domeSize = 80000.0;
|
||||||
|
@ -48,7 +49,10 @@ float intersection (in float cheight, in vec3 ray, in float rad2)
|
||||||
|
|
||||||
// Return the scale function at height = 0 for different thetas
|
// Return the scale function at height = 0 for different thetas
|
||||||
float outscatterscale(in float costheta)
|
float outscatterscale(in float costheta)
|
||||||
{
|
{
|
||||||
|
|
||||||
|
if (costheta < -0.12) costheta = -0.12 - 4.0* (costheta+0.12) ;
|
||||||
|
|
||||||
float x = 1.0 - costheta;
|
float x = 1.0 - costheta;
|
||||||
|
|
||||||
float a = 1.16941;
|
float a = 1.16941;
|
||||||
|
@ -98,7 +102,8 @@ void main()
|
||||||
// We are in space, calculate correct positiondelta!
|
// We are in space, calculate correct positiondelta!
|
||||||
relativePosition -= space * normalize(relativePosition);
|
relativePosition -= space * normalize(relativePosition);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
vec3 positionDelta = relativePosition / fSamples;
|
vec3 positionDelta = relativePosition / fSamples;
|
||||||
float deltaLength = length(positionDelta); // Should multiply by something?
|
float deltaLength = length(positionDelta); // Should multiply by something?
|
||||||
|
|
||||||
|
@ -111,7 +116,9 @@ void main()
|
||||||
// If sample is above camera, reverse ray direction
|
// If sample is above camera, reverse ray direction
|
||||||
if(positionDelta.z < 0.0) cameraCosTheta = -positionDelta.z / deltaLength;
|
if(positionDelta.z < 0.0) cameraCosTheta = -positionDelta.z / deltaLength;
|
||||||
else cameraCosTheta = positionDelta.z / deltaLength;
|
else cameraCosTheta = positionDelta.z / deltaLength;
|
||||||
|
|
||||||
|
float cameraCosTheta1 = -positionDelta.z / deltaLength;
|
||||||
|
|
||||||
// Total attenuation from camera to skydome
|
// Total attenuation from camera to skydome
|
||||||
float totalCameraScatter = outscatter(cameraCosTheta, scaledAltitude);
|
float totalCameraScatter = outscatter(cameraCosTheta, scaledAltitude);
|
||||||
|
|
||||||
|
@ -135,7 +142,8 @@ void main()
|
||||||
// Again, reverse the direction if vertex is over the camera
|
// Again, reverse the direction if vertex is over the camera
|
||||||
float cameraScatter;
|
float cameraScatter;
|
||||||
if(relativePosition.z < 0.0) { // Vertex is over the camera
|
if(relativePosition.z < 0.0) { // Vertex is over the camera
|
||||||
cameraCosTheta = -dot(normalize(positionDelta), normalize(sample));
|
cameraCosTheta = -dot(normalize(positionDelta), normalize(sample));
|
||||||
|
|
||||||
cameraScatter = totalCameraScatter - outscatter(cameraCosTheta, sampleAltitude);
|
cameraScatter = totalCameraScatter - outscatter(cameraCosTheta, sampleAltitude);
|
||||||
} else { // Vertex is below camera
|
} else { // Vertex is below camera
|
||||||
cameraCosTheta = dot(normalize(positionDelta), normalize(sample));
|
cameraCosTheta = dot(normalize(positionDelta), normalize(sample));
|
||||||
|
@ -151,12 +159,13 @@ void main()
|
||||||
sample += positionDelta;
|
sample += positionDelta;
|
||||||
}
|
}
|
||||||
|
|
||||||
color *= sunIntensity;
|
color *= sunIntensity;
|
||||||
|
ct = cameraCosTheta1;
|
||||||
rayleigh = rayleighK * color;
|
rayleigh = rayleighK * color;
|
||||||
mie = mieK * color;
|
mie = mieK * color;
|
||||||
eye = gl_NormalMatrix * positionDelta;
|
eye = gl_NormalMatrix * positionDelta;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// We need to move the camera so that the dome appears to be centered around earth
|
// We need to move the camera so that the dome appears to be centered around earth
|
||||||
|
|
Loading…
Add table
Reference in a new issue