ALS secondary lights and Rayleigh haze for urban effect
This commit is contained in:
parent
a790930acd
commit
dfb8073607
3 changed files with 192 additions and 114 deletions
|
@ -172,9 +172,12 @@
|
|||
<type>noise</type>
|
||||
</texture-unit>
|
||||
<program>
|
||||
<vertex-shader>Shaders/urban-lightfield.vert</vertex-shader>
|
||||
<fragment-shader>Shaders/urban-lightfield.frag</fragment-shader>
|
||||
<vertex-shader>Shaders/urban-ALS.vert</vertex-shader>
|
||||
<fragment-shader>Shaders/urban-ALS.frag</fragment-shader>
|
||||
<fragment-shader>Shaders/cloud-shadowfunc.frag</fragment-shader>
|
||||
<fragment-shader>Shaders/noise.frag</fragment-shader>
|
||||
<fragment-shader>Shaders/hazes.frag</fragment-shader>
|
||||
<fragment-shader>Shaders/secondary_lights.frag</fragment-shader>
|
||||
<attribute>
|
||||
<name>tangent</name>
|
||||
<index>6</index>
|
||||
|
@ -343,6 +346,36 @@
|
|||
<type>float</type>
|
||||
<value><use>moonlight</use></value>
|
||||
</uniform>
|
||||
<uniform>
|
||||
<name>air_pollution</name>
|
||||
<type>float</type>
|
||||
<value><use>air_pollution</use></value>
|
||||
</uniform>
|
||||
<uniform>
|
||||
<name>view_pitch_offset</name>
|
||||
<type>float</type>
|
||||
<value><use>view_pitch_offset</use></value>
|
||||
</uniform>
|
||||
<uniform>
|
||||
<name>view_heading_offset</name>
|
||||
<type>float</type>
|
||||
<value><use>view_heading_offset</use></value>
|
||||
</uniform>
|
||||
<uniform>
|
||||
<name>field_of_view</name>
|
||||
<type>float</type>
|
||||
<value><use>view_fov</use></value>
|
||||
</uniform>
|
||||
<uniform>
|
||||
<name>landing_light1_offset</name>
|
||||
<type>float</type>
|
||||
<value><use>landing_light1_offset</use></value>
|
||||
</uniform>
|
||||
<uniform>
|
||||
<name>landing_light2_offset</name>
|
||||
<type>float</type>
|
||||
<value><use>landing_light2_offset</use></value>
|
||||
</uniform>
|
||||
<uniform>
|
||||
<name>cloudpos1_x</name>
|
||||
<type>float</type>
|
||||
|
@ -548,6 +581,31 @@
|
|||
<type>int</type>
|
||||
<value><use>cloud_shadow_flag</use></value>
|
||||
</uniform>
|
||||
<uniform>
|
||||
<name>use_searchlight</name>
|
||||
<type>int</type>
|
||||
<value><use>use_searchlight</use></value>
|
||||
</uniform>
|
||||
<uniform>
|
||||
<name>use_landing_light</name>
|
||||
<type>int</type>
|
||||
<value><use>use_landing_light</use></value>
|
||||
</uniform>
|
||||
<uniform>
|
||||
<name>use_alt_landing_light</name>
|
||||
<type>int</type>
|
||||
<value><use>use_alt_landing_light</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>
|
||||
|
||||
|
||||
|
||||
|
@ -657,10 +715,12 @@
|
|||
<type>noise</type>
|
||||
</texture-unit>
|
||||
<program>
|
||||
<vertex-shader>Shaders/urban-lightfield.vert</vertex-shader>
|
||||
<fragment-shader>Shaders/urban-lightfield.frag</fragment-shader>
|
||||
<vertex-shader>Shaders/urban-ALS.vert</vertex-shader>
|
||||
<fragment-shader>Shaders/urban-ALS.frag</fragment-shader>
|
||||
<fragment-shader>Shaders/cloud-shadowfunc.frag</fragment-shader>
|
||||
|
||||
<fragment-shader>Shaders/noise.frag</fragment-shader>
|
||||
<fragment-shader>Shaders/hazes.frag</fragment-shader>
|
||||
<fragment-shader>Shaders/secondary_lights.frag</fragment-shader>
|
||||
<attribute>
|
||||
<name>tangent</name>
|
||||
<index>6</index>
|
||||
|
@ -750,7 +810,37 @@
|
|||
<name>fogstructure</name>
|
||||
<type>float</type>
|
||||
<value><use>fogstructure</use></value>
|
||||
</uniform>
|
||||
</uniform>
|
||||
<uniform>
|
||||
<name>air_pollution</name>
|
||||
<type>float</type>
|
||||
<value><use>air_pollution</use></value>
|
||||
</uniform>
|
||||
<uniform>
|
||||
<name>view_pitch_offset</name>
|
||||
<type>float</type>
|
||||
<value><use>view_pitch_offset</use></value>
|
||||
</uniform>
|
||||
<uniform>
|
||||
<name>view_heading_offset</name>
|
||||
<type>float</type>
|
||||
<value><use>view_heading_offset</use></value>
|
||||
</uniform>
|
||||
<uniform>
|
||||
<name>field_of_view</name>
|
||||
<type>float</type>
|
||||
<value><use>view_fov</use></value>
|
||||
</uniform>
|
||||
<uniform>
|
||||
<name>landing_light1_offset</name>
|
||||
<type>float</type>
|
||||
<value><use>landing_light1_offset</use></value>
|
||||
</uniform>
|
||||
<uniform>
|
||||
<name>landing_light2_offset</name>
|
||||
<type>float</type>
|
||||
<value><use>landing_light2_offset</use></value>
|
||||
</uniform>
|
||||
<uniform>
|
||||
<name>cloudpos1_x</name>
|
||||
<type>float</type>
|
||||
|
@ -956,6 +1046,32 @@
|
|||
<type>int</type>
|
||||
<value><use>cloud_shadow_flag</use></value>
|
||||
</uniform>
|
||||
<uniform>
|
||||
<name>use_searchlight</name>
|
||||
<type>int</type>
|
||||
<value><use>use_searchlight</use></value>
|
||||
</uniform>
|
||||
<uniform>
|
||||
<name>use_landing_light</name>
|
||||
<type>int</type>
|
||||
<value><use>use_landing_light</use></value>
|
||||
</uniform>
|
||||
<uniform>
|
||||
<name>use_alt_landing_light</name>
|
||||
<type>int</type>
|
||||
<value><use>use_alt_landing_light</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>
|
||||
|
||||
|
||||
<!-- END fog include -->
|
||||
<uniform>
|
||||
|
|
|
@ -18,17 +18,13 @@ varying vec3 worldPos;
|
|||
varying vec4 ecPosition;
|
||||
varying vec3 VNormal;
|
||||
varying vec3 VTangent;
|
||||
//varying vec3 VBinormal;
|
||||
//varying vec3 Normal;
|
||||
varying vec4 constantColor;
|
||||
varying vec3 light_diffuse;
|
||||
varying vec3 relPos;
|
||||
|
||||
varying float yprime_alt;
|
||||
varying float mie_angle;
|
||||
//varying float steepness;
|
||||
|
||||
//uniform sampler3D NoiseTex;
|
||||
uniform sampler2D BaseTex;
|
||||
uniform sampler2D NormalTex;
|
||||
uniform sampler2D QDMTex;
|
||||
|
@ -48,9 +44,19 @@ uniform float dust_cover_factor;
|
|||
uniform float wetness;
|
||||
uniform float fogstructure;
|
||||
uniform float cloud_self_shading;
|
||||
uniform float air_pollution;
|
||||
uniform float landing_light1_offset;
|
||||
uniform float landing_light2_offset;
|
||||
|
||||
|
||||
uniform vec3 night_color;
|
||||
|
||||
uniform bool random_buildings;
|
||||
|
||||
uniform int cloud_shadow_flag;
|
||||
uniform int use_searchlight;
|
||||
uniform int use_landing_light;
|
||||
uniform int use_alt_landing_light;
|
||||
|
||||
const float scale = 1.0;
|
||||
int linear_search_steps = 10;
|
||||
|
@ -64,85 +70,19 @@ float alt;
|
|||
float eShade;
|
||||
|
||||
float shadow_func (in float x, in float y, in float noise, in float dist);
|
||||
float Noise2D(in vec2 coord, in float wavelength);
|
||||
float Noise3D(in vec3 coord, in float wavelength);
|
||||
float fog_func (in float targ, in float alt);
|
||||
float rayleigh_in_func(in float dist, in float air_pollution, in float avisibility, in float eye_alt, in float vertex_alt);
|
||||
float alt_factor(in float eye_alt, in float vertex_alt);
|
||||
float light_distance_fading(in float dist);
|
||||
float fog_backscatter(in float avisibility);
|
||||
|
||||
float rand2D(in vec2 co){
|
||||
return fract(sin(dot(co.xy ,vec2(12.9898,78.233))) * 43758.5453);
|
||||
}
|
||||
|
||||
float rand3D(in vec3 co){
|
||||
return fract(sin(dot(co.xyz ,vec3(12.9898,78.233,144.7272))) * 43758.5453);
|
||||
}
|
||||
vec3 rayleigh_out_shift(in vec3 color, in float outscatter);
|
||||
vec3 searchlight();
|
||||
vec3 landing_light(in float offset);
|
||||
|
||||
|
||||
float simple_interpolate(in float a, in float b, in float x)
|
||||
{
|
||||
return a + smoothstep(0.0,1.0,x) * (b-a);
|
||||
}
|
||||
|
||||
float interpolatedNoise2D(in float x, in float y)
|
||||
{
|
||||
float integer_x = x - fract(x);
|
||||
float fractional_x = x - integer_x;
|
||||
|
||||
float integer_y = y - fract(y);
|
||||
float fractional_y = y - integer_y;
|
||||
|
||||
float v1 = rand2D(vec2(integer_x, integer_y));
|
||||
float v2 = rand2D(vec2(integer_x+1.0, integer_y));
|
||||
float v3 = rand2D(vec2(integer_x, integer_y+1.0));
|
||||
float v4 = rand2D(vec2(integer_x+1.0, integer_y +1.0));
|
||||
|
||||
float i1 = simple_interpolate(v1 , v2 , fractional_x);
|
||||
float i2 = simple_interpolate(v3 , v4 , fractional_x);
|
||||
|
||||
return simple_interpolate(i1 , i2 , fractional_y);
|
||||
}
|
||||
|
||||
|
||||
float interpolatedNoise3D(in float x, in float y, in float z)
|
||||
{
|
||||
float integer_x = x - fract(x);
|
||||
float fractional_x = x - integer_x;
|
||||
|
||||
float integer_y = y - fract(y);
|
||||
float fractional_y = y - integer_y;
|
||||
|
||||
float integer_z = z - fract(z);
|
||||
float fractional_z = z - integer_z;
|
||||
|
||||
float v1 = rand3D(vec3(integer_x, integer_y, integer_z));
|
||||
float v2 = rand3D(vec3(integer_x+1.0, integer_y, integer_z));
|
||||
float v3 = rand3D(vec3(integer_x, integer_y+1.0, integer_z));
|
||||
float v4 = rand3D(vec3(integer_x+1.0, integer_y +1.0, integer_z));
|
||||
|
||||
float v5 = rand3D(vec3(integer_x, integer_y, integer_z+1.0));
|
||||
float v6 = rand3D(vec3(integer_x+1.0, integer_y, integer_z+1.0));
|
||||
float v7 = rand3D(vec3(integer_x, integer_y+1.0, integer_z+1.0));
|
||||
float v8 = rand3D(vec3(integer_x+1.0, integer_y +1.0, integer_z+1.0));
|
||||
|
||||
|
||||
float i1 = simple_interpolate(v1,v5, fractional_z);
|
||||
float i2 = simple_interpolate(v2,v6, fractional_z);
|
||||
float i3 = simple_interpolate(v3,v7, fractional_z);
|
||||
float i4 = simple_interpolate(v4,v8, fractional_z);
|
||||
|
||||
float ii1 = simple_interpolate(i1,i2,fractional_x);
|
||||
float ii2 = simple_interpolate(i3,i4,fractional_x);
|
||||
|
||||
|
||||
return simple_interpolate(ii1 , ii2 , fractional_y);
|
||||
}
|
||||
|
||||
float Noise2D(in vec2 coord, in float wavelength)
|
||||
{
|
||||
return interpolatedNoise2D(coord.x/wavelength, coord.y/wavelength);
|
||||
|
||||
}
|
||||
|
||||
float Noise3D(in vec3 coord, in float wavelength)
|
||||
{
|
||||
return interpolatedNoise3D(coord.x/wavelength, coord.y/wavelength, coord.z/wavelength);
|
||||
}
|
||||
|
||||
|
||||
float light_func (in float x, in float a, in float b, in float c, in float d, in float e)
|
||||
|
@ -160,32 +100,8 @@ return e / pow((1.0 + a * exp(-b * (x-c)) ),(1.0/d));
|
|||
// physically this should be exp(-arg) but for technical reasons we use a sharper cutoff
|
||||
// for distance > visibility
|
||||
|
||||
float fog_func (in float targ)
|
||||
{
|
||||
|
||||
|
||||
float fade_mix;
|
||||
|
||||
// for large altitude > 30 km, we switch to some component of quadratic distance fading to
|
||||
// create the illusion of improved visibility range
|
||||
|
||||
targ = 1.25 * targ * smoothstep(0.04,0.06,targ); // need to sync with the distance to which terrain is drawn
|
||||
|
||||
|
||||
if (alt < 30000.0)
|
||||
{return exp(-targ - targ * targ * targ * targ);}
|
||||
else if (alt < 50000.0)
|
||||
{
|
||||
fade_mix = (alt - 30000.0)/20000.0;
|
||||
return fade_mix * exp(-targ*targ - pow(targ,4.0)) + (1.0 - fade_mix) * exp(-targ - pow(targ,4.0));
|
||||
}
|
||||
else
|
||||
{
|
||||
return exp(- targ * targ - pow(targ,4.0));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
@ -402,12 +318,35 @@ if (quality_level > 2)
|
|||
|
||||
finalColor.rgb = finalColor.rgb * (1.0 - 0.6 * wetness);
|
||||
|
||||
vec3 secondary_light = vec3 (0.0,0.0,0.0);
|
||||
|
||||
if (use_searchlight == 1)
|
||||
{
|
||||
secondary_light += searchlight();
|
||||
}
|
||||
if (use_landing_light == 1)
|
||||
{
|
||||
secondary_light += landing_light(landing_light1_offset);
|
||||
}
|
||||
if (use_alt_landing_light == 1)
|
||||
{
|
||||
secondary_light += landing_light(landing_light2_offset);
|
||||
}
|
||||
ambient_light = clamp(ambient_light,0.0,1.0);
|
||||
ambient_light.rgb +=secondary_light * light_distance_fading(dist);
|
||||
|
||||
|
||||
|
||||
finalColor *= ambient_light;
|
||||
|
||||
vec4 p = vec4( ecPos3 + tile_size * V * (d-1.0) * depthfactor / s.z, 1.0 );
|
||||
|
||||
//finalColor.rgb = fog_Func(finalColor.rgb, fogType);
|
||||
|
||||
// Rayleigh color shift due to out-scattering
|
||||
|
||||
float rayleigh_length = 0.5 * avisibility * (2.5 - 1.9 * air_pollution)/alt_factor(eye_alt, eye_alt+relPos.z);
|
||||
float outscatter = 1.0-exp(-dist/rayleigh_length);
|
||||
finalColor.rgb = rayleigh_out_shift(finalColor.rgb,outscatter);
|
||||
|
||||
// here comes the terrain haze model
|
||||
|
||||
|
@ -415,7 +354,7 @@ if (quality_level > 2)
|
|||
float delta_z = hazeLayerAltitude - eye_alt;
|
||||
|
||||
|
||||
if (dist > max(40.0, 0.04 * min(visibility,avisibility)))
|
||||
if (dist > 0.04 * min(visibility,avisibility))
|
||||
{
|
||||
|
||||
alt = eye_alt;
|
||||
|
@ -513,7 +452,7 @@ else
|
|||
|
||||
|
||||
|
||||
transmission = fog_func(transmission_arg);
|
||||
transmission = fog_func(transmission_arg, alt);
|
||||
|
||||
// there's always residual intensity, we should never be driven to zero
|
||||
if (eqColorFactor < 0.2) eqColorFactor = 0.2;
|
||||
|
@ -578,13 +517,30 @@ if (intensity > 0.0) // this needs to be a condition, because otherwise hazeColo
|
|||
}
|
||||
|
||||
|
||||
// blue Rayleigh scattering with distance
|
||||
|
||||
finalColor.xyz = mix(eqColorFactor * hazeColor * eShade, finalColor.xyz,transmission);
|
||||
float rShade = 0.9 * smoothstep(terminator_width+ terminator, -terminator_width + terminator, yprime_alt-340000.0) + 0.1;
|
||||
float lightIntensity = length(light_diffuse.rgb)/1.73 * rShade;
|
||||
vec3 rayleighColor = vec3 (0.17, 0.52, 0.87) * lightIntensity;
|
||||
float rayleighStrength = rayleigh_in_func(dist, air_pollution, avisibility/max(lightIntensity,0.05), eye_alt, eye_alt + relPos.z);
|
||||
finalColor.rgb = mix(finalColor.rgb, rayleighColor,rayleighStrength);
|
||||
|
||||
|
||||
finalColor.rgb = mix((eqColorFactor * hazeColor * eShade) +secondary_light * fog_backscatter(avisibility), finalColor.rgb,transmission);
|
||||
gl_FragColor = finalColor;
|
||||
|
||||
}
|
||||
else // if dist < threshold no fogging at all
|
||||
{
|
||||
// blue Rayleigh scattering with distance
|
||||
|
||||
float rShade = 0.9 * smoothstep(terminator_width+ terminator, -terminator_width + terminator, yprime_alt-340000.0) + 0.1;
|
||||
float lightIntensity = length(light_diffuse.rgb)/1.73 * rShade;
|
||||
vec3 rayleighColor = vec3 (0.17, 0.52, 0.87) * lightIntensity;
|
||||
float rayleighStrength = rayleigh_in_func(dist, air_pollution, avisibility/max(lightIntensity,0.05), eye_alt, eye_alt + relPos.z);
|
||||
finalColor.rgb = mix(finalColor.rgb, rayleighColor,rayleighStrength);
|
||||
|
||||
|
||||
gl_FragColor = finalColor;
|
||||
}
|
||||
|
|
@ -263,6 +263,12 @@ else // the faster, full-day version without lightfields
|
|||
|
||||
light_ambient = light_ambient * ((1.0+steepness)/2.0 * 1.2 + (1.0-steepness)/2.0 * 0.2);
|
||||
|
||||
// deeper shadows when there is lots of direct light
|
||||
|
||||
float shade_depth = 1.0 * smoothstep (0.6,0.95,ground_scattering) * (1.0-smoothstep(0.1,0.5,overcast)) * smoothstep(0.4,1.5,earthShade);
|
||||
|
||||
light_ambient.rgb = light_ambient.rgb * (1.0 - shade_depth);
|
||||
light_diffuse.rgb = light_diffuse.rgb * (1.0 + 1.2 * shade_depth);
|
||||
|
||||
// default lighting based on texture and material using the light we have just computed
|
||||
|
Loading…
Add table
Reference in a new issue