diff --git a/Nasal/local_weather/compat_layer.nas b/Nasal/local_weather/compat_layer.nas index 1df26b60b..4038a9a0e 100644 --- a/Nasal/local_weather/compat_layer.nas +++ b/Nasal/local_weather/compat_layer.nas @@ -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 ########################################################### diff --git a/Nasal/local_weather/local_weather.nas b/Nasal/local_weather/local_weather.nas index d6f7e31e5..185945f77 100644 --- a/Nasal/local_weather/local_weather.nas +++ b/Nasal/local_weather/local_weather.nas @@ -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,35 +630,67 @@ 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;} -# 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; - } -else if (altitude < scatt_alt_high) - { - var scatt = scatt_max + (0.95 - scatt_max) * (altitude - scatt_alt_low)/(scatt_alt_high-scatt_alt_low); + 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 - {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 -if (altitude < ovcst_alt_low) - { - var ovcst = ovcst_max; + if (altitude < ovcst_alt_low) + { + 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 @@ -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 diff --git a/Shaders/road.frag b/Shaders/road.frag new file mode 100644 index 000000000..0b60098e3 --- /dev/null +++ b/Shaders/road.frag @@ -0,0 +1,6 @@ +#version 120 + +uniform sampler2d BaseTex; + +void main() { +} diff --git a/Shaders/road.geom b/Shaders/road.geom new file mode 100644 index 000000000..ba686d0aa --- /dev/null +++ b/Shaders/road.geom @@ -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(); +} diff --git a/Shaders/road.vert b/Shaders/road.vert new file mode 100644 index 000000000..8783af590 --- /dev/null +++ b/Shaders/road.vert @@ -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(); +} diff --git a/Shaders/skydome.frag b/Shaders/skydome.frag index a120eb2aa..c50309fc5 100644 --- a/Shaders/skydome.frag +++ b/Shaders/skydome.frag @@ -6,7 +6,8 @@ varying vec3 rayleigh; varying vec3 mie; -varying vec3 eye; +varying vec3 eye; +varying float ct; float miePhase(in float cosTheta, in float g) { @@ -30,9 +31,35 @@ float rayleighPhase(in float cosTheta) 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; diff --git a/Shaders/skydome.vert b/Shaders/skydome.vert index 917aba508..5c3505f01 100644 --- a/Shaders/skydome.vert +++ b/Shaders/skydome.vert @@ -10,7 +10,8 @@ uniform mat4 osg_ViewMatrixInverse; varying vec3 rayleigh; varying vec3 mie; -varying vec3 eye; +varying vec3 eye; +varying float ct; // Dome parameters from FG and screen 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 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; @@ -98,7 +102,8 @@ void main() // We are in space, calculate correct positiondelta! relativePosition -= space * normalize(relativePosition); } - + + vec3 positionDelta = relativePosition / fSamples; float deltaLength = length(positionDelta); // Should multiply by something? @@ -111,7 +116,9 @@ void main() // If sample is above camera, reverse ray direction 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); @@ -135,7 +142,8 @@ void main() // Again, reverse the direction if vertex is over the camera float cameraScatter; 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); } else { // Vertex is below camera cameraCosTheta = dot(normalize(positionDelta), normalize(sample)); @@ -151,12 +159,13 @@ void main() sample += positionDelta; } - color *= sunIntensity; - + 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