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
|
||||
###########################################################
|
||||
|
|
|
@ -594,12 +594,14 @@ var alt1 = vis_alt1;
|
|||
var alt2 = alt1 + 1500.0;
|
||||
|
||||
|
||||
#var inc1 = 0.15;
|
||||
#var inc2 = 5.0;
|
||||
#var inc3 = 0.7;
|
||||
|
||||
# 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 inc2 = 0.9 * (vis_aloft - vis)/1500.0;
|
||||
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)
|
||||
{inc4 = inc4 * 8.0;}
|
||||
{inc4 = inc4 * 3.0;}
|
||||
|
||||
# compute the visibility
|
||||
|
||||
|
@ -628,8 +630,38 @@ else if (altitude > ovcst_alt_high)
|
|||
|
||||
# limit visibility (otherwise memory consumption is very bad...)
|
||||
|
||||
if (vis > 140000.0)
|
||||
{vis = 140000.0;}
|
||||
if (vis > 120000.0)
|
||||
{vis = 120000.0;}
|
||||
|
||||
# determine scattering shader parameters if scattering shader is on
|
||||
|
||||
if (scattering_shader_flag == 1)
|
||||
{
|
||||
var rayleigh = 0.0003 ;
|
||||
var mie = 0.003;
|
||||
var density = 0.3;
|
||||
|
||||
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
|
||||
{
|
||||
|
||||
# compute the horizon shading
|
||||
|
||||
|
@ -658,6 +690,8 @@ else if (altitude < ovcst_alt_high)
|
|||
else
|
||||
{var ovcst = 0.0;}
|
||||
|
||||
}
|
||||
|
||||
|
||||
# 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);}
|
||||
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
|
||||
|
||||
|
@ -3479,6 +3521,7 @@ debug_output_flag = getprop(lw~"config/debug-output-flag");
|
|||
fps_control_flag = getprop(lw~"config/fps-control-flag");
|
||||
realistic_visibility_flag = getprop(lw~"config/realistic-visibility-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("/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 buffer_flag = 1;
|
||||
var detailed_terrain_interaction_flag = 1;
|
||||
var hardcoded_clouds_flag = 0;
|
||||
var hardcoded_clouds_flag = 1;
|
||||
var realistic_visibility_flag = 0;
|
||||
var scattering_shader_flag = 0;
|
||||
|
||||
# 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();
|
||||
}
|
|
@ -7,6 +7,7 @@
|
|||
varying vec3 rayleigh;
|
||||
varying vec3 mie;
|
||||
varying vec3 eye;
|
||||
varying float ct;
|
||||
|
||||
float miePhase(in float cosTheta, in float g)
|
||||
{
|
||||
|
@ -31,9 +32,35 @@ void main()
|
|||
{
|
||||
float cosTheta = dot(normalize(eye), gl_LightSource[0].position.xyz);
|
||||
|
||||
|
||||
vec3 color = rayleigh * rayleighPhase(cosTheta);
|
||||
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_FragDepth = 0.1;
|
||||
}
|
||||
|
|
|
@ -11,6 +11,7 @@ uniform mat4 osg_ViewMatrixInverse;
|
|||
varying vec3 rayleigh;
|
||||
varying vec3 mie;
|
||||
varying vec3 eye;
|
||||
varying float ct;
|
||||
|
||||
// Dome parameters from FG and screen
|
||||
const float domeSize = 80000.0;
|
||||
|
@ -49,6 +50,9 @@ float intersection (in float cheight, in vec3 ray, in float rad2)
|
|||
// Return the scale function at height = 0 for different thetas
|
||||
float outscatterscale(in float costheta)
|
||||
{
|
||||
|
||||
if (costheta < -0.12) costheta = -0.12 - 4.0* (costheta+0.12) ;
|
||||
|
||||
float x = 1.0 - costheta;
|
||||
|
||||
float a = 1.16941;
|
||||
|
@ -99,6 +103,7 @@ void main()
|
|||
relativePosition -= space * normalize(relativePosition);
|
||||
}
|
||||
|
||||
|
||||
vec3 positionDelta = relativePosition / fSamples;
|
||||
float deltaLength = length(positionDelta); // Should multiply by something?
|
||||
|
||||
|
@ -112,6 +117,8 @@ void main()
|
|||
if(positionDelta.z < 0.0) cameraCosTheta = -positionDelta.z / deltaLength;
|
||||
else cameraCosTheta = positionDelta.z / deltaLength;
|
||||
|
||||
float cameraCosTheta1 = -positionDelta.z / deltaLength;
|
||||
|
||||
// Total attenuation from camera to skydome
|
||||
float totalCameraScatter = outscatter(cameraCosTheta, scaledAltitude);
|
||||
|
||||
|
@ -136,6 +143,7 @@ void main()
|
|||
float cameraScatter;
|
||||
if(relativePosition.z < 0.0) { // Vertex is over the camera
|
||||
cameraCosTheta = -dot(normalize(positionDelta), normalize(sample));
|
||||
|
||||
cameraScatter = totalCameraScatter - outscatter(cameraCosTheta, sampleAltitude);
|
||||
} else { // Vertex is below camera
|
||||
cameraCosTheta = dot(normalize(positionDelta), normalize(sample));
|
||||
|
@ -152,13 +160,14 @@ void main()
|
|||
}
|
||||
|
||||
color *= sunIntensity;
|
||||
|
||||
ct = cameraCosTheta1;
|
||||
rayleigh = rayleighK * color;
|
||||
mie = mieK * color;
|
||||
eye = gl_NormalMatrix * positionDelta;
|
||||
|
||||
|
||||
|
||||
|
||||
// We need to move the camera so that the dome appears to be centered around earth
|
||||
// to make the dome render correctly!
|
||||
float moveDown = -altitude; // Center dome on camera
|
||||
|
|
Loading…
Add table
Reference in a new issue