MR269 - Added the Milky Way onto the night sky
from Chris RINGEVAL https://sourceforge.net/p/flightgear/fgdata/merge-requests/269/ Squashed commit of the following: commit 23194c0fed49609999b4da67b2990af774f7df03 Author: Chris Ringeval <eatdirt@protonmail.com> Date: Sun Jan 30 23:52:09 2022 +0100 Remove CC-BY-SA 3.0 texture provided by EAS and replace it with one made by myself commit cb30c7972ba3db6b4cb4ad5f9dcd12d7e0ddbc1a Author: Chris Ringeval <eatdirt@protonmail.com> Date: Sun Dec 5 15:49:31 2021 +0100 Optimize shaders for vram usage and use new uniforms commit 7541e49c6757a23b08684f1c4354e84b9af3bcc3 Author: Chris Ringeval <eatdirt@protonmail.com> Date: Thu Dec 2 17:22:55 2021 +0100 Reduce the oversized galaxy texture to 400kB commit 0e6591907a9978077dc6dff1b53dea7c439a6cc4 Author: Chris Ringeval <eatdirt@protonmail.com> Date: Tue Nov 30 23:49:24 2021 +0100 Add Milky Way onto the night sky
This commit is contained in:
parent
ff3c6f2509
commit
a06298055a
5 changed files with 418 additions and 1 deletions
168
Effects/galaxy.eff
Normal file
168
Effects/galaxy.eff
Normal file
|
@ -0,0 +1,168 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
|
||||
<PropertyList>
|
||||
<name>Effects/galaxy</name>
|
||||
|
||||
<parameters>
|
||||
<display_xsize><use>/sim/startup/xsize</use></display_xsize>
|
||||
<display_ysize><use>/sim/startup/ysize</use></display_ysize>
|
||||
<use_filtering><use>/sim/rendering/als-filters/use-filtering</use></use_filtering>
|
||||
<gamma><use>/sim/rendering/als-filters/gamma</use></gamma>
|
||||
<brightness><use>/sim/rendering/als-filters/brightness</use></brightness>
|
||||
<use_night_vision><use>/sim/rendering/als-filters/use-night-vision</use></use_night_vision>
|
||||
<use_IR_vision><use>/sim/rendering/als-filters/use-IR-vision</use></use_IR_vision>
|
||||
<!--use_CCTV_vision><use>/sim/rendering/als-filters/use-CCTV-vision</use></use_CCTV_vision-->
|
||||
<fact_grey><use>/sim/rendering/als-filters/grey-factor</use></fact_grey>
|
||||
<fact_black><use>/sim/rendering/als-filters/black-factor</use></fact_black>
|
||||
<delta_T>-50.0</delta_T>
|
||||
<moonlight><use>/environment/moonlight</use></moonlight>
|
||||
<darksky_magnitude><use>/environment/darksky-brightness-magnitude</use></darksky_magnitude>
|
||||
<galaxy_magnitude><use>/environment/galaxy-bulge-brightness-magnitude</use></galaxy_magnitude>
|
||||
<atmosphere_top><use>/environment/atmosphere/altitude-troposphere-top</use></atmosphere_top>
|
||||
<eye_altitude_m><use>/sim/rendering/eye-altitude-m</use></eye_altitude_m>
|
||||
|
||||
</parameters>
|
||||
|
||||
<technique n="10">
|
||||
<predicate>
|
||||
<and>
|
||||
<property>/sim/rendering/shader-effects</property>
|
||||
<less-equal>
|
||||
<value type="float">3.0</value>
|
||||
<float-property>/sim/rendering/shaders/quality-level</float-property>
|
||||
</less-equal>
|
||||
<or>
|
||||
<less-equal>
|
||||
<value type="float">2.0</value>
|
||||
<glversion/>
|
||||
</less-equal>
|
||||
<and>
|
||||
<extension-supported>GL_ARB_shader_objects</extension-supported>
|
||||
<extension-supported>GL_ARB_shading_language_100</extension-supported>
|
||||
<extension-supported>GL_ARB_vertex_shader</extension-supported>
|
||||
<extension-supported>GL_ARB_fragment_shader</extension-supported>
|
||||
</and>
|
||||
</or>
|
||||
</and>
|
||||
</predicate>
|
||||
|
||||
<pass>
|
||||
|
||||
|
||||
<program>
|
||||
<vertex-shader>Shaders/galaxy.vert</vertex-shader>
|
||||
<vertex-shader>Shaders/filters-ALS.vert</vertex-shader>
|
||||
<fragment-shader>Shaders/galaxy.frag</fragment-shader>
|
||||
<fragment-shader>Shaders/noise.frag</fragment-shader>
|
||||
<fragment-shader>Shaders/filters-ALS.frag</fragment-shader>
|
||||
</program>
|
||||
|
||||
|
||||
<uniform>
|
||||
<name>milkyway</name>
|
||||
<type>sampler-2d</type>
|
||||
<value type="int">0</value>
|
||||
</uniform>
|
||||
|
||||
|
||||
|
||||
<uniform>
|
||||
<name>gamma</name>
|
||||
<type>float</type>
|
||||
<value><use>gamma</use></value>
|
||||
</uniform>
|
||||
<uniform>
|
||||
<name>brightness</name>
|
||||
<type>float</type>
|
||||
<value><use>brightness</use></value>
|
||||
</uniform>
|
||||
<uniform>
|
||||
<name>use_filtering</name>
|
||||
<type>bool</type>
|
||||
<value><use>use_filtering</use></value>
|
||||
</uniform>
|
||||
<uniform>
|
||||
<name>use_night_vision</name>
|
||||
<type>bool</type>
|
||||
<value><use>use_night_vision</use></value>
|
||||
</uniform>
|
||||
<uniform>
|
||||
<name>delta_T</name>
|
||||
<type>float</type>
|
||||
<value><use>delta_T</use></value>
|
||||
</uniform>
|
||||
<uniform>
|
||||
<name>fact_grey</name>
|
||||
<type>float</type>
|
||||
<value><use>fact_grey</use></value>
|
||||
</uniform>
|
||||
<uniform>
|
||||
<name>fact_black</name>
|
||||
<type>float</type>
|
||||
<value><use>fact_black</use></value>
|
||||
</uniform>
|
||||
<uniform>
|
||||
<name>use_IR_vision</name>
|
||||
<type>bool</type>
|
||||
<value><use>use_IR_vision</use></value>
|
||||
</uniform>
|
||||
<!--
|
||||
<uniform>
|
||||
<name>use_CCTV_vision</name>
|
||||
<type>bool</type>
|
||||
<value><use>use_CCTV_vision</use></value>
|
||||
</uniform>
|
||||
-->
|
||||
<uniform>
|
||||
<name>field_of_view</name>
|
||||
<type>float</type>
|
||||
<value><use>view_fov</use></value>
|
||||
</uniform>
|
||||
<uniform>
|
||||
<name>display_xsize</name>
|
||||
<type>int</type>
|
||||
<value><use>display_xsize</use></value>
|
||||
</uniform>
|
||||
<uniform>
|
||||
<name>display_ysize</name>
|
||||
<type>int</type>
|
||||
<value><use>display_ysize</use></value>
|
||||
</uniform>
|
||||
<uniform>
|
||||
<name>moonlight</name>
|
||||
<type>float</type>
|
||||
<value><use>moonlight</use></value>
|
||||
</uniform>
|
||||
<uniform>
|
||||
<name>mudarksky</name>
|
||||
<type>float</type>
|
||||
<value><use>darksky_magnitude</use></value>
|
||||
</uniform>
|
||||
<uniform>
|
||||
<name>mugxybulge</name>
|
||||
<type>float</type>
|
||||
<value><use>galaxy_magnitude</use></value>
|
||||
</uniform>
|
||||
<uniform>
|
||||
<name>altitude</name>
|
||||
<type>float</type>
|
||||
<value><use>eye_altitude_m</use></value>
|
||||
</uniform>
|
||||
<uniform>
|
||||
<name>atmosphere_top</name>
|
||||
<type>float</type>
|
||||
<value><use>atmosphere_top</use></value>
|
||||
</uniform>
|
||||
</pass>
|
||||
</technique>
|
||||
|
||||
|
||||
<!-- minimal technique -->
|
||||
<technique n="11">
|
||||
|
||||
</technique>
|
||||
|
||||
<technique n="109">
|
||||
<scheme>hdr-geometry</scheme>
|
||||
</technique>
|
||||
</PropertyList>
|
|
@ -532,5 +532,7 @@
|
|||
<!-- definitions for vocanic activity -->
|
||||
<volcanoes include="volcanoes.xml"/>
|
||||
|
||||
<star-magnitude-cutoff type="float">4.5</star-magnitude-cutoff>
|
||||
<darksky-brightness-magnitude type="float">22.0</darksky-brightness-magnitude>
|
||||
<galaxy-bulge-brightness-magnitude type="float">20.3</galaxy-bulge-brightness-magnitude>
|
||||
|
||||
</PropertyList>
|
||||
|
|
218
Shaders/galaxy.frag
Normal file
218
Shaders/galaxy.frag
Normal file
|
@ -0,0 +1,218 @@
|
|||
// -*-C++-*-
|
||||
//
|
||||
// Chris Ringeval (November 2021)
|
||||
//
|
||||
|
||||
#version 120
|
||||
|
||||
|
||||
varying vec3 eye2VertInEyeSpace;
|
||||
varying vec3 eye2ZenithInEyeSpace;
|
||||
varying vec3 eye2MoonInEyeSpace;
|
||||
|
||||
uniform sampler2D milkyway;
|
||||
|
||||
uniform float moonlight;
|
||||
uniform float mudarksky;
|
||||
uniform float altitude;
|
||||
uniform float atmosphere_top;
|
||||
|
||||
uniform float fg_ZenithSkyBrightness;
|
||||
uniform float mugxybulge;
|
||||
|
||||
|
||||
// conversion factor to recover moon logI in lux
|
||||
const float max_loglux = -0.504030345621;
|
||||
const float min_loglux = -4.399646345620;
|
||||
// conversion factor to recover moon logI in footcandle
|
||||
const float luxtofootcandle = -1.0319696543787917;
|
||||
|
||||
// the log10 of Mie + Rayleight scattering function at minimum,
|
||||
// i.e., for a Moon-Sky distance of 90 degrees
|
||||
const float logf90 = 5.399285;
|
||||
|
||||
//extinction coefficient at Maunea Kea (2800m asl), in mag/airmass
|
||||
const float k2800 = 0.172;
|
||||
|
||||
|
||||
// cos(3pi/5), at asl 0m, any light source < -18 degrees above the horizon does
|
||||
// not light-up atmosphere -> zenital angle > 108 degrees.
|
||||
const float cosUnvisible = -0.309016994374947;
|
||||
|
||||
|
||||
// D65 white multiplied by rhodopic response function and converted
|
||||
// to linear sRGB is [-0.321, 0.656, 0.455], i.e. out of gammut. We
|
||||
// desaturate along red to mimic night vision color blindness
|
||||
// (see https://github.com/eatdust/spectroll)
|
||||
const vec4 nightColor = vec4(0.0,0.977,0.776,1.0);
|
||||
|
||||
|
||||
|
||||
vec3 filter_combined (in vec3 color) ;
|
||||
|
||||
|
||||
float log10(in float x){
|
||||
return 0.434294481903252*log(x);
|
||||
}
|
||||
|
||||
|
||||
//Rayleight + Mie scattering in unit of the minimal scattering at
|
||||
//90 degrees (const f90)
|
||||
float scattering_angular_dependency(in float cosMoonSep) {
|
||||
|
||||
float fR = 0.913514*(1.06 + cosMoonSep*cosMoonSep);
|
||||
|
||||
float moonSepRad = acos(cosMoonSep);
|
||||
|
||||
float fM = 5.63268*pow(10.0,-moonSepRad*1.432394);
|
||||
|
||||
return fR + fM;
|
||||
|
||||
}
|
||||
|
||||
float airmass_angular_dependency(in float sineZenithDistanceSquare) {
|
||||
|
||||
return 1.0/sqrt(1.0 - 0.96*sineZenithDistanceSquare);
|
||||
|
||||
}
|
||||
|
||||
|
||||
//log10 of the moon illuminance in footcandles
|
||||
float log10_moon_illuminance_fc(in float Inorm){
|
||||
|
||||
return (max_loglux-min_loglux)*(Inorm-1.0) + max_loglux + luxtofootcandle ;
|
||||
}
|
||||
|
||||
|
||||
//in mag/arcsec^2 from flux in nano Lambert
|
||||
float magnitude_from_lognL(in float logBnL){
|
||||
return 26.3313 - 2.5*logBnL;
|
||||
}
|
||||
|
||||
|
||||
void main()
|
||||
{
|
||||
|
||||
|
||||
//unit vectors
|
||||
vec3 uViewDir = normalize(eye2VertInEyeSpace);
|
||||
vec3 uZenithDir = normalize(eye2ZenithInEyeSpace);
|
||||
vec3 uMoonDir = normalize(eye2MoonInEyeSpace);
|
||||
|
||||
|
||||
// the intrinsic sky brightness without the Moon at
|
||||
// zenith set in simgear and propagated as uniform
|
||||
|
||||
float muzenithsky = fg_ZenithSkyBrightness;
|
||||
|
||||
|
||||
vec4 fragColor;
|
||||
|
||||
|
||||
|
||||
// the galaxy is visible only if
|
||||
if (muzenithsky >= mugxybulge) {
|
||||
|
||||
|
||||
|
||||
// texture look-up
|
||||
vec4 texel = texture2D(milkyway, gl_TexCoord[0].st);
|
||||
|
||||
|
||||
|
||||
float cosZenithView = max(dot(uZenithDir,uViewDir),0.0);
|
||||
|
||||
float sineZenithDist2 = 1.0 - pow(cosZenithView,2);
|
||||
|
||||
float Xview = airmass_angular_dependency(sineZenithDist2);
|
||||
|
||||
|
||||
float k = k2800 * max(0.0,(atmosphere_top - altitude)/(atmosphere_top - 2800.0));
|
||||
|
||||
|
||||
|
||||
// add angular dependence from scattering within the atmosphere
|
||||
|
||||
float musky = muzenithsky + k*(Xview-1.0);
|
||||
|
||||
// main effect: airglow coming from the van Rhijn layer (height 130km)
|
||||
//
|
||||
// https://ui.adsabs.harvard.edu/abs/1986PASP...98..364G/abstract
|
||||
//
|
||||
// We smoothstep airglow to zero while approaching 130km of altitude
|
||||
|
||||
musky = musky - 2.5*log10(0.4+0.6*Xview) * (1.0 - smoothstep(0.0,130000.0,altitude));
|
||||
|
||||
|
||||
|
||||
// Moon illumination of the atmosphere, we use the same model as in
|
||||
// simgear (see moonpos.cxx), based on Publ. Astron. Soc. Pacif.
|
||||
// 103(667), 1033-1039 (DOI: http://dx.doi.org/10.1086/132921).
|
||||
//
|
||||
// https://ui.adsabs.harvard.edu/abs/1991PASP..103.1033K/abstract
|
||||
//
|
||||
// The altitude damping effect is encoded in k and the moon
|
||||
// scattering smoothly disappears with altitude as k->0. Only smoothstep added to
|
||||
// smooth the moon rising effects
|
||||
|
||||
float cosZenithMoon = dot(uZenithDir,uMoonDir);
|
||||
float dmumoon = 0.0;
|
||||
|
||||
// Include values under the horizon to smooth the Moon rising jumps effect
|
||||
if (cosZenithMoon >= cosUnvisible) {
|
||||
|
||||
//however, we use the math only with sane input: cosZenithMoon >= 0
|
||||
float sineZenithMoon2 = 1.0 - pow(max(cosZenithMoon,0.0),2.0);
|
||||
|
||||
float Xmoon = airmass_angular_dependency(sineZenithMoon2);
|
||||
|
||||
float cosMoonView = dot(uMoonDir,uViewDir);
|
||||
|
||||
float moon_logI = log10_moon_illuminance_fc(moonlight);
|
||||
|
||||
// log10(Bmoon) with Bmoon in nanoLambert
|
||||
float logBnL = logf90 + log10(scattering_angular_dependency(cosMoonView)) \
|
||||
+ moon_logI - 0.4*k*Xmoon + log10(1.0-pow(10.0,-0.4*k*Xview));
|
||||
|
||||
// sky brightness from the moon in mag/arcsec^2
|
||||
float mumoon = magnitude_from_lognL(logBnL);
|
||||
|
||||
//relative flux w.r.t background
|
||||
float Brel = pow(10.0,0.4*(musky-mumoon));
|
||||
|
||||
// artificial smoothing for the moon between -18 degrees and 0
|
||||
Brel = Brel*smoothstep(cosUnvisible,0.0,cosZenithMoon);
|
||||
|
||||
dmumoon = - 2.5*log10(1.0 + Brel);
|
||||
|
||||
|
||||
}
|
||||
|
||||
// final angle dependent sky brightness
|
||||
musky = musky + dmumoon;
|
||||
|
||||
// we put the damping in the colors as to keep alpha channel to 1
|
||||
// for the ALS filters to not being affected
|
||||
|
||||
fragColor.rgb = texel.rgb * nightColor.rgb * (musky-mugxybulge)/musky;
|
||||
fragColor.a = 1.0;
|
||||
|
||||
//For debugging and testing, uncomment. The red shows sky low surface brightness
|
||||
//fragColor.r = 8*(musky-mugxybulge)/musky;
|
||||
|
||||
}
|
||||
|
||||
else {
|
||||
// galaxy is invisible, too much sky brightness, color the night sphere is black
|
||||
|
||||
fragColor = vec4(0.0,0.0,0.0,1.0);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
fragColor.rgb = filter_combined(fragColor.rgb);
|
||||
|
||||
gl_FragColor = clamp(fragColor,0.0,1.0);
|
||||
|
||||
}
|
29
Shaders/galaxy.vert
Normal file
29
Shaders/galaxy.vert
Normal file
|
@ -0,0 +1,29 @@
|
|||
// -*-C++-*-
|
||||
//
|
||||
// Chris Ringeval (Novermber 2021)
|
||||
//
|
||||
|
||||
#version 120
|
||||
|
||||
|
||||
uniform vec3 fg_CameraWorldUp;
|
||||
uniform mat4 osg_ViewMatrix;
|
||||
|
||||
varying vec3 eye2VertInEyeSpace;
|
||||
varying vec3 eye2ZenithInEyeSpace;
|
||||
varying vec3 eye2MoonInEyeSpace;
|
||||
|
||||
uniform vec3 fg_MoonDirection;
|
||||
|
||||
|
||||
void main()
|
||||
{
|
||||
|
||||
eye2VertInEyeSpace = (gl_ModelViewMatrix * gl_Vertex - vec4(0.0,0.0,0.0,1.0)).xyz;
|
||||
eye2ZenithInEyeSpace = (osg_ViewMatrix * vec4(fg_CameraWorldUp,0.0)).xyz;
|
||||
eye2MoonInEyeSpace = fg_MoonDirection;
|
||||
|
||||
gl_Position = ftransform();
|
||||
gl_TexCoord[0] = gl_TextureMatrix[0] * gl_MultiTexCoord0;
|
||||
}
|
||||
|
BIN
Textures/Sky/allsky_brightness_magten.png
Normal file
BIN
Textures/Sky/allsky_brightness_magten.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 383 KiB |
Loading…
Add table
Reference in a new issue