1
0
Fork 0

ALS secondary lights and Rayleigh haze for model ubershader and random buildings

This commit is contained in:
Thorsten Renk 2014-10-11 16:12:19 +03:00
parent 77e5cc4c9f
commit 20dda77d6f
4 changed files with 125 additions and 28 deletions

View file

@ -183,8 +183,10 @@
</texture-unit>
<program>
<vertex-shader n="1">Shaders/building-ubershader.vert</vertex-shader>
<fragment-shader n="1">Shaders/ubershader-lightfield.frag</fragment-shader>
<fragment-shader n="1">Shaders/model-ALS-ultra.frag</fragment-shader>
<fragment-shader n="2">Shaders/cloud-shadowfunc.frag</fragment-shader>
<fragment-shader n="3">Shaders/hazes.frag</fragment-shader>
<fragment-shader n="4">Shaders/secondary_lights.frag</fragment-shader>
</program>
</pass>
</technique>

View file

@ -422,9 +422,11 @@ please see Docs/README.model-combined.eff for documentation
</vertex-program-two-side>
<program>
<vertex-shader n="1">Shaders/ubershader.vert</vertex-shader>
<fragment-shader n="1">Shaders/ubershader-lightfield.frag</fragment-shader>
<fragment-shader n="2">Shaders/cloud-shadowfunc.frag</fragment-shader>
<vertex-shader n="1">Shaders/ubershader.vert</vertex-shader>
<fragment-shader n="1">Shaders/model-ALS-ultra.frag</fragment-shader>
<fragment-shader n="2">Shaders/cloud-shadowfunc.frag</fragment-shader>
<fragment-shader n="3">Shaders/hazes.frag</fragment-shader>
<fragment-shader n="4">Shaders/secondary_lights.frag</fragment-shader>
</program>
<uniform>
@ -842,6 +844,36 @@ please see Docs/README.model-combined.eff for documentation
<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>
@ -1047,6 +1079,32 @@ please see Docs/README.model-combined.eff for documentation
<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>
<name>rembrandt_enabled</name>

View file

@ -25,6 +25,17 @@
<cloud_self_shading><use>/environment/cloud-self-shading</use></cloud_self_shading>
<moonlight><use>/environment/moonlight</use></moonlight>
<fogtype><use>/sim/rendering/shaders/skydome</use></fogtype>
<air_pollution><use>/environment/air-pollution-norm</use></air_pollution>
<display_xsize><use>/sim/startup/xsize</use></display_xsize>
<display_ysize><use>/sim/startup/ysize</use></display_ysize>
<view_pitch_offset><use>/sim/current-view/pitch-offset-deg</use></view_pitch_offset>
<view_heading_offset><use>/sim/current-view/heading-offset-deg</use></view_heading_offset>
<view_fov><use>/sim/current-view/field-of-view</use></view_fov>
<use_searchlight><use>/sim/rendering/als-secondary-lights/use-searchlight</use></use_searchlight>
<use_landing_light><use>/sim/rendering/als-secondary-lights/use-landing-light</use></use_landing_light>
<use_alt_landing_light><use>/sim/rendering/als-secondary-lights/use-alt-landing-light</use></use_alt_landing_light>
<landing_light1_offset><use>/sim/rendering/als-secondary-lights/landing-light1-offset-deg</use></landing_light1_offset>
<landing_light2_offset><use>/sim/rendering/als-secondary-lights/landing-light2-offset-deg</use></landing_light2_offset>
<!-- END fog include -->
</parameters>

View file

@ -38,6 +38,9 @@ uniform int refl_enabled;
uniform int refl_map;
uniform int grain_texture_enabled;
uniform int cloud_shadow_flag;
uniform int use_searchlight;
uniform int use_landing_light;
uniform int use_alt_landing_light;
uniform float amb_correction;
uniform float dirt_b_factor;
@ -54,7 +57,6 @@ uniform float refl_noise;
uniform float refl_rainbow;
uniform float grain_magnification;
uniform float avisibility;
uniform float cloud_self_shading;
uniform float eye_alt;
@ -66,6 +68,10 @@ uniform float scattering;
uniform float terminator;
uniform float terrain_alt;
uniform float visibility;
uniform float air_pollution;
uniform float landing_light1_offset;
uniform float landing_light2_offset;
// constants needed by the light and fog computations ###################################################
@ -82,9 +88,17 @@ uniform vec3 dirt_g_color;
uniform vec3 dirt_b_color;
float shadow_func (in float x, in float y, in float noise, in float dist);
float fog_func (in float targ, in float altitude);
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);
vec3 rayleigh_out_shift(in vec3 color, in float outscatter);
vec3 searchlight();
vec3 landing_light(in float offset);
// uniform mat4 osg_ViewMatrixInverse;
// uniform mat4 osg_ViewMatrix;
float light_func (in float x, in float a, in float b, in float c, in float d, in float e)
{
@ -93,25 +107,8 @@ float light_func (in float x, in float a, in float b, in float c, in float d, in
return e / pow((1.0 + a * exp(-b * (x-c)) ),(1.0/d));
}
float fog_func (in float targ, in float altitude)
{
float fade_mix;
targ = 1.25 * targ * smoothstep(0.04,0.06,targ); // need to sync with the distance to which objects are drawn unfogged
if (altitude < 30000.0)
{return exp(-targ - targ * targ * targ * targ);}
else if (altitude < 50000.0)
{
fade_mix = (altitude - 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));
}
}
void main (void)
@ -265,15 +262,32 @@ void main (void)
{pf1 = pow(nDotHV1, 0.5*gl_FrontMaterial.shininess);}
vec3 relPos;
vec3 relPos = (gl_ModelViewMatrixInverse * vec4 (vertVec,0.0)).xyz;
if (cloud_shadow_flag == 1)
{
relPos = (gl_ModelViewMatrixInverse * vec4 (vertVec,0.0)).xyz;
light_diffuse = light_diffuse * shadow_func(relPos.x, relPos.y, 1.0, dist);
}
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);
}
vec4 Diffuse = light_diffuse * nDotVP;
Diffuse.rgb += secondary_light * light_distance_fading(dist);
vec4 Specular = gl_FrontMaterial.specular * light_diffuse * pf + gl_FrontMaterial.specular * light_ambient * pf1;
Specular+= gl_FrontMaterial.specular * pow(max(0.0,-dot(N,normalize(vertVec))),gl_FrontMaterial.shininess) * vec4(secondary_light,1.0);
vec4 color = gl_Color + Diffuse * gl_FrontMaterial.diffuse;
color = clamp( color, 0.0, 1.0 );
@ -481,7 +495,19 @@ void main (void)
/// END fog color
fragColor = clamp(fragColor, 0.0, 1.0);
///BEGIN Rayleigh fog ///
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);
fragColor.rgb = mix(fragColor.rgb, rayleighColor,rayleighStrength);
/// END Rayleigh fog
//fragColor = fragColor * smoothstep(-0.05, 0.05, ct);
fragColor.rgb = mix(eqColorFactor * hazeColor * fog_earthShade, fragColor.rgb,transmission);
fragColor.rgb = mix(eqColorFactor * hazeColor * fog_earthShade +secondary_light * fog_backscatter(avisibility), fragColor.rgb,transmission);
gl_FragColor = fragColor;
}