ALS: Detailed scattering model for light on Cirrus clouds
This commit is contained in:
parent
3ebc1af5ac
commit
a4960e14fa
6 changed files with 358 additions and 2 deletions
|
@ -8,6 +8,8 @@
|
|||
<altitude><use>/sim/rendering/eye-altitude-m</use></altitude>
|
||||
<cloud_self_shading><use>/environment/cloud-self-shading</use></cloud_self_shading>
|
||||
<moonlight><use>/environment/moonlight</use></moonlight>
|
||||
<ring-factor><use>/environment/scattering-phenomena/ring-factor</use></ring-factor>
|
||||
<rainbow-factor><use>/environment/scattering-phenomena/rainbow-factor</use></rainbow-factor>
|
||||
<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>
|
||||
|
@ -20,6 +22,150 @@
|
|||
<display_ysize><use>/sim/startup/ysize</use></display_ysize>
|
||||
</parameters>
|
||||
|
||||
<technique n="8">
|
||||
<predicate>
|
||||
<and>
|
||||
<property>/sim/rendering/shaders/skydome</property>
|
||||
<property>/sim/rendering/clouds3d-enable</property>
|
||||
<less-equal>
|
||||
<value type="float">1.0</value>
|
||||
<shader-language/>
|
||||
</less-equal>
|
||||
<less-equal>
|
||||
<value type="float">1.0</value>
|
||||
<float-property>/sim/rendering/shaders/clouds</float-property>
|
||||
</less-equal>
|
||||
</and>
|
||||
</predicate>
|
||||
<pass n="0">
|
||||
<!-- This is apparently not used, so maybe we'll blow it way soon. -->
|
||||
<lighting>true</lighting>
|
||||
<material>
|
||||
<ambient type="vec4d">0.5 0.5 0.5 1.0</ambient>
|
||||
<diffuse type="vec4d">0.5 0.5 0.5 1.0</diffuse>
|
||||
<color-mode>off</color-mode>
|
||||
</material>
|
||||
<alpha-test>
|
||||
<comparison>greater</comparison>
|
||||
<reference type="float">0.01</reference>
|
||||
</alpha-test>
|
||||
<shade-model>smooth</shade-model>
|
||||
<blend>
|
||||
<source>src-alpha</source>
|
||||
<destination>one-minus-src-alpha</destination>
|
||||
</blend>
|
||||
<depth>
|
||||
<write-mask>false</write-mask>
|
||||
</depth>
|
||||
<render-bin>
|
||||
<bin-number>9</bin-number>
|
||||
<bin-name>DepthSortedBin</bin-name>
|
||||
</render-bin>
|
||||
<texture-unit>
|
||||
<unit>0</unit>
|
||||
<type><use>texture[0]/type</use></type>
|
||||
<image><use>texture[0]/image</use></image>
|
||||
<filter><use>texture[0]/filter</use></filter>
|
||||
<wrap-s><use>texture[0]/wrap-s</use></wrap-s>
|
||||
<wrap-t><use>texture[0]/wrap-t</use></wrap-t>
|
||||
<!--<wrap-s>clamp</wrap-s>
|
||||
<wrap-t>clamp</wrap-t>-->
|
||||
</texture-unit>
|
||||
<program>
|
||||
<vertex-shader>Shaders/cloud-static-ALS-detailed.vert</vertex-shader>
|
||||
<fragment-shader>Shaders/cloud-static-ALS-detailed.frag</fragment-shader>
|
||||
<fragment-shader>Shaders/noise.frag</fragment-shader>
|
||||
<fragment-shader>Shaders/filters-ALS.frag</fragment-shader>
|
||||
</program>
|
||||
<uniform>
|
||||
<name>baseTexture</name>
|
||||
<type>sampler-2d</type>
|
||||
<value type="int">0</value>
|
||||
</uniform>
|
||||
<uniform>
|
||||
<name>terminator</name>
|
||||
<type>float</type>
|
||||
<value><use>terminator</use></value>
|
||||
</uniform>
|
||||
<uniform>
|
||||
<name>altitude</name>
|
||||
<type>float</type>
|
||||
<value><use>altitude</use></value>
|
||||
</uniform>
|
||||
<uniform>
|
||||
<name>cloud_self_shading</name>
|
||||
<type>float</type>
|
||||
<value><use>cloud_self_shading</use></value>
|
||||
</uniform>
|
||||
<uniform>
|
||||
<name>moonlight</name>
|
||||
<type>float</type>
|
||||
<value><use>moonlight</use></value>
|
||||
</uniform>
|
||||
<uniform>
|
||||
<name>ring_factor</name>
|
||||
<type>float</type>
|
||||
<value><use>ring-factor</use></value>
|
||||
</uniform>
|
||||
<uniform>
|
||||
<name>rainbow_factor</name>
|
||||
<type>float</type>
|
||||
<value><use>rainbow-factor</use></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>use_IR_vision</name>
|
||||
<type>bool</type>
|
||||
<value><use>use_IR_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>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>
|
||||
<vertex-program-two-side>true</vertex-program-two-side>
|
||||
</pass>
|
||||
</technique>
|
||||
|
||||
<technique n="9">
|
||||
<predicate>
|
||||
<and>
|
||||
|
|
|
@ -13,11 +13,12 @@
|
|||
<ice_hex_col><use>/environment/scattering-phenomena/ice-hexagonal-column-factor</use></ice_hex_col>
|
||||
<ice_hex_sheet><use>/environment/scattering-phenomena/ice-hexagonal-sheet-factor</use></ice_hex_sheet>
|
||||
<parhelic><use>/environment/scattering-phenomena/parhelic-factor</use></parhelic>
|
||||
<ring><use>/environment/scattering-phenomena/ring-factor</use></ring>
|
||||
<aurora_strength><use>/environment/aurora/strength</use></aurora_strength>
|
||||
<aurora_vsize><use>/environment/aurora/vsize</use></aurora_vsize>
|
||||
<aurora_hsize><use>/environment/aurora/hsize</use></aurora_hsize>
|
||||
<aurora_ray_factor><use>/environment/aurora/ray-factor</use></aurora_ray_factor>
|
||||
<aurora_penetration_factor><use>/environment/aurora/penetration-factor</use></aurora_penetration_factor>
|
||||
<aurora_penetration_factor><use>/environment/aurora/penetration-factor</use></aurora_penetration_factor>
|
||||
<lthickness><use>/environment/ground-haze-thickness-m</use></lthickness>
|
||||
<terminator><use>/environment/terminator-relative-position-m</use></terminator>
|
||||
<terrain_alt><use>/environment/mean-terrain-elevation-m</use></terrain_alt>
|
||||
|
@ -149,6 +150,11 @@
|
|||
<type>float</type>
|
||||
<value><use>parhelic</use></value>
|
||||
</uniform>
|
||||
<uniform>
|
||||
<name>ring</name>
|
||||
<type>float</type>
|
||||
<value><use>ring</use></value>
|
||||
</uniform>
|
||||
<uniform>
|
||||
<name>ice_hex_sheet</name>
|
||||
<type>float</type>
|
||||
|
|
|
@ -436,6 +436,8 @@
|
|||
<ice-hexagonal-column-factor type="double" userarchive="n">0.0</ice-hexagonal-column-factor>
|
||||
<ice-hexagonal-sheet-factor type="double" userarchive="n">0.0</ice-hexagonal-sheet-factor>
|
||||
<parhelic-factor type="double" userarchive="n">0.0</parhelic-factor>
|
||||
<ring-factor type="double" userarchive="n">0.0</ring-factor>
|
||||
<rainbow-factor type="double" userarchive="n">0.0</rainbow-factor>
|
||||
</scattering-phenomena>
|
||||
|
||||
<!-- definitions for aurorae -->
|
||||
|
|
59
Shaders/cloud-static-ALS-detailed.frag
Normal file
59
Shaders/cloud-static-ALS-detailed.frag
Normal file
|
@ -0,0 +1,59 @@
|
|||
// -*-C++-*-
|
||||
#version 120
|
||||
|
||||
uniform sampler2D baseTexture;
|
||||
|
||||
uniform float ring_factor;
|
||||
uniform float rainbow_factor;
|
||||
|
||||
varying float fogFactor;
|
||||
varying float mie_frag;
|
||||
varying float eShade;
|
||||
|
||||
varying vec3 hazeColor;
|
||||
|
||||
vec3 filter_combined (in vec3 color) ;
|
||||
|
||||
void main(void)
|
||||
{
|
||||
vec4 base = texture2D( baseTexture, gl_TexCoord[0].st);
|
||||
|
||||
float fwd_enhancement = smoothstep(0.8, 1.0, mie_frag) * eShade;
|
||||
float light_intensity = length(gl_Color.rgb)/1.76;
|
||||
|
||||
|
||||
//22 deg ring
|
||||
|
||||
float halo_ring_enhancement = smoothstep (0.88, 0.927, mie_frag) * (1.0 - smoothstep(0.927, 0.94, mie_frag)) * eShade * 1.5 * ring_factor;
|
||||
|
||||
|
||||
float halo_ring_enhancement_r = smoothstep (0.88, 0.90, mie_frag) * (1.0 - smoothstep(0.90, 0.92, mie_frag)) * eShade * ring_factor;
|
||||
float halo_ring_enhancement_b = smoothstep (0.91, 0.93, mie_frag) * (1.0 - smoothstep(0.93, 0.955, mie_frag)) * eShade * ring_factor;
|
||||
|
||||
|
||||
vec4 finalColor = base * gl_Color;
|
||||
|
||||
float reduction = 0.16 * light_intensity * rainbow_factor;
|
||||
|
||||
finalColor.g *= (1.0 - reduction * halo_ring_enhancement_r);
|
||||
finalColor.b *= (1.0 - reduction * halo_ring_enhancement_r);
|
||||
|
||||
finalColor.r *= (1.0 - reduction * halo_ring_enhancement_b);
|
||||
finalColor.g *= (1.0 - reduction * halo_ring_enhancement_b);
|
||||
|
||||
fwd_enhancement *=(1.0-smoothstep(0.8, 1.0, light_intensity));
|
||||
finalColor.rgb *= (1.0 + fwd_enhancement) * (1.0 + 0.5 * halo_ring_enhancement * (1.0-smoothstep(0.8, 1.0, light_intensity))) ;
|
||||
finalColor.a *= (1.0 + 0.5 * halo_ring_enhancement);
|
||||
|
||||
|
||||
|
||||
finalColor.rgb = clamp(finalColor.rgb, 0.0, 1.0);
|
||||
finalColor.a = clamp(finalColor.a, 0.0, 1.0);
|
||||
|
||||
vec4 fragColor = vec4 (mix(hazeColor, finalColor.rgb, fogFactor ), mix(0.0, finalColor.a, 1.0 - 0.5 * (1.0 - fogFactor)));
|
||||
|
||||
|
||||
fragColor.rgb = filter_combined(fragColor.rgb);
|
||||
//fragColor.rgb = vec3 (1.0, 0.0, 0.0);
|
||||
gl_FragColor = fragColor;
|
||||
}
|
142
Shaders/cloud-static-ALS-detailed.vert
Normal file
142
Shaders/cloud-static-ALS-detailed.vert
Normal file
|
@ -0,0 +1,142 @@
|
|||
// -*-C++-*-
|
||||
#version 120
|
||||
|
||||
varying float fogFactor;
|
||||
varying float mie_frag;
|
||||
varying float eShade;
|
||||
varying vec3 hazeColor;
|
||||
|
||||
uniform float terminator;
|
||||
uniform float altitude;
|
||||
uniform float cloud_self_shading;
|
||||
uniform float moonlight;
|
||||
|
||||
const float shade = 1.0;
|
||||
const float cloud_height = 1000.0;
|
||||
const float EarthRadius = 5800000.0;
|
||||
|
||||
// light_func is a generalized logistic function fit to the light intensity as a function
|
||||
// of scaled terminator position obtained from Flightgear core
|
||||
|
||||
float light_func (in float x, in float a, in float b, in float c, in float d, in float e)
|
||||
{
|
||||
x = x-0.5;
|
||||
|
||||
// use the asymptotics to shorten computations
|
||||
if (x > 30.0) {return e;}
|
||||
if (x < -15.0) {return 0.03;}
|
||||
|
||||
|
||||
return e / pow((1.0 + a * exp(-b * (x-c)) ),(1.0/d));
|
||||
}
|
||||
|
||||
void main(void)
|
||||
{
|
||||
|
||||
vec3 shadedFogColor = vec3 (0.55, 0.67, 0.88);
|
||||
vec3 moonLightColor = vec3 (0.095, 0.095, 0.15) * moonlight;
|
||||
|
||||
gl_TexCoord[0] = gl_TextureMatrix[0] * gl_MultiTexCoord0;
|
||||
//gl_TexCoord[0] = gl_MultiTexCoord0 + vec4(textureIndexX, textureIndexY, 0.0, 0.0);
|
||||
vec4 ep = gl_ModelViewMatrixInverse * vec4(0.0,0.0,0.0,1.0);
|
||||
vec4 l = gl_ModelViewMatrixInverse * vec4(0.0,0.0,1.0,1.0);
|
||||
vec3 u = normalize(ep.xyz - l.xyz);
|
||||
|
||||
gl_Position = vec4(0.0, 0.0, 0.0, 1.0);
|
||||
gl_Position.x = gl_Vertex.x;
|
||||
gl_Position.y += gl_Vertex.y;
|
||||
gl_Position.z += gl_Vertex.z;
|
||||
gl_Position.xyz += gl_Color.xyz;
|
||||
|
||||
|
||||
// Determine a lighting normal based on the vertex position from the
|
||||
// center of the cloud, so that sprite on the opposite side of the cloud to the sun are darker.
|
||||
float n = dot(normalize(-gl_LightSource[0].position.xyz),
|
||||
normalize(mat3x3(gl_ModelViewMatrix) * (- gl_Position.xyz)));;
|
||||
|
||||
// Determine the position - used for fog and shading calculations
|
||||
vec3 ecPosition = vec3(gl_ModelViewMatrix * gl_Position);
|
||||
float fogCoord = abs(ecPosition.z);
|
||||
float fract = smoothstep(0.0, cloud_height, gl_Position.z + cloud_height);
|
||||
|
||||
vec3 relVector = gl_Position.xyz - ep.xyz;
|
||||
gl_Position = gl_ModelViewProjectionMatrix * gl_Position;
|
||||
|
||||
// Light at the final position
|
||||
|
||||
// first obtain normal to sun position
|
||||
|
||||
vec3 lightFull = (gl_ModelViewMatrixInverse * gl_LightSource[0].position).xyz;
|
||||
vec3 lightHorizon = normalize(vec3(lightFull.x,lightFull.y, 0.0));
|
||||
|
||||
|
||||
mie_frag = dot(normalize(lightFull), normalize(relVector));
|
||||
|
||||
|
||||
// yprime is the distance of the vertex into sun direction, corrected for altitude
|
||||
//float vertex_alt = max(altitude * 0.30480 + relVector.z,100.0);
|
||||
float vertex_alt = altitude + relVector.z;
|
||||
float yprime = -dot(relVector, lightHorizon);
|
||||
float yprime_alt = yprime -sqrt(2.0 * EarthRadius * vertex_alt);
|
||||
|
||||
// compute the light at the position
|
||||
vec4 light_diffuse;
|
||||
|
||||
float lightArg = (terminator-yprime_alt)/100000.0;
|
||||
|
||||
light_diffuse.b = light_func(lightArg, 1.330e-05, 0.264, 2.227, 1.08e-05, 1.0);
|
||||
light_diffuse.g = light_func(lightArg, 3.931e-06, 0.264, 3.827, 7.93e-06, 1.0);
|
||||
light_diffuse.r = light_func(lightArg, 8.305e-06, 0.161, 3.827, 3.04e-05, 1.0);
|
||||
light_diffuse.a = 1.0;
|
||||
|
||||
float intensity = length(light_diffuse.rgb);
|
||||
light_diffuse.rgb = intensity * normalize(mix(light_diffuse.rgb, shadedFogColor, (1.0 - smoothstep(0.5,0.9, cloud_self_shading ))));
|
||||
|
||||
// Determine the shading of the sprite based on its vertical position and position relative to the sun.
|
||||
n = min(smoothstep(-0.5, 0.0, n), fract);
|
||||
// Determine the shading based on a mixture from the backlight to the front
|
||||
vec4 backlight = light_diffuse * shade;
|
||||
|
||||
gl_FrontColor = mix(backlight, light_diffuse, n);
|
||||
gl_FrontColor += gl_FrontLightModelProduct.sceneColor;
|
||||
|
||||
// As we get within 100m of the sprite, it is faded out. Equally at large distances it also fades out.
|
||||
gl_FrontColor.a = min(smoothstep(100.0, 250.0, fogCoord), 1.0 - smoothstep(70000.0, 75000.0, fogCoord));
|
||||
|
||||
// Fog doesn't affect rain as much as other objects.
|
||||
//fogFactor = exp( -gl_Fog.density * fogCoord * 0.4);
|
||||
//fogFactor = clamp(fogFactor, 0.0, 1.0);
|
||||
|
||||
float fadeScale = 0.05 + 0.2 * log(fogCoord/1000.0);
|
||||
if (fadeScale < 0.05) fadeScale = 0.05;
|
||||
fogFactor = exp( -gl_Fog.density * fogCoord * fadeScale);
|
||||
|
||||
hazeColor = light_diffuse.rgb;
|
||||
hazeColor.r = hazeColor.r * 0.83;
|
||||
hazeColor.g = hazeColor.g * 0.9;
|
||||
|
||||
// in sunset or sunrise conditions, do extra shading of clouds
|
||||
|
||||
|
||||
|
||||
// two times terminator width governs how quickly light fades into shadow
|
||||
float terminator_width = 200000.0;
|
||||
|
||||
// now dim the light
|
||||
float earthShade = 0.9 * smoothstep(terminator_width+ terminator, -terminator_width + terminator, yprime_alt) + 0.1;
|
||||
|
||||
eShade = earthShade;
|
||||
|
||||
if (earthShade < 0.8)
|
||||
{
|
||||
intensity = length(light_diffuse.rgb);
|
||||
gl_FrontColor.rgb = intensity * normalize(mix(gl_FrontColor.rgb, shadedFogColor, 1.0 -smoothstep(0.1, 0.8,earthShade ) ));
|
||||
}
|
||||
|
||||
hazeColor = hazeColor * earthShade;
|
||||
gl_FrontColor.rgb = gl_FrontColor.rgb * earthShade;
|
||||
gl_FrontColor.rgb = gl_FrontColor.rgb + moonLightColor * (1.0 - smoothstep(0.4, 0.5, earthShade));
|
||||
hazeColor.rgb = hazeColor.rgb + moonLightColor * (1.0 - smoothstep(0.4, 0.5, earthShade));
|
||||
gl_BackColor = gl_FrontColor;
|
||||
|
||||
}
|
|
@ -31,6 +31,7 @@ uniform float horizon_roughness;
|
|||
uniform float ice_hex_col;
|
||||
uniform float ice_hex_sheet;
|
||||
uniform float parhelic;
|
||||
uniform float ring;
|
||||
uniform float aurora_strength;
|
||||
uniform float aurora_hsize;
|
||||
uniform float aurora_vsize;
|
||||
|
@ -258,7 +259,7 @@ float view_altitude = dot(nView, vec3 (0.0, 0.0, 1.0));
|
|||
//float halo_ring_enhancement = smoothstep (0.88, 0.927, calpha) * (1.0 - smoothstep(0.927, 0.98, calpha));
|
||||
float halo_ring_enhancement = smoothstep (0.88, 0.927, calpha) * (1.0 - smoothstep(0.927, 0.94, calpha));
|
||||
halo_ring_enhancement *= halo_ring_enhancement;
|
||||
|
||||
halo_ring_enhancement *= ring;
|
||||
|
||||
// parhelic circle
|
||||
|
||||
|
|
Loading…
Reference in a new issue