Shader support for aircraft shadows
This commit is contained in:
parent
1ad83ec6e5
commit
c1e7703d78
3 changed files with 355 additions and 0 deletions
261
Effects/shadow.eff
Normal file
261
Effects/shadow.eff
Normal file
|
@ -0,0 +1,261 @@
|
||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<PropertyList>
|
||||||
|
<name>Effects/shadow</name>
|
||||||
|
<!-- <inherits-from>Effects/shadow</inherits-from> -->
|
||||||
|
<parameters>
|
||||||
|
<texture n ="0">
|
||||||
|
<type>white</type>
|
||||||
|
</texture>
|
||||||
|
<vertex-program-two-side type="bool">false</vertex-program-two-side>
|
||||||
|
<material>
|
||||||
|
<color-mode-uniform>1</color-mode-uniform>
|
||||||
|
<!-- DIFFUSE -->
|
||||||
|
</material>
|
||||||
|
<material-id>0</material-id>
|
||||||
|
<!-- BEGIN fog include -->
|
||||||
|
<visibility><use>/environment/ground-visibility-m</use></visibility>
|
||||||
|
<avisibility><use>/environment/visibility-m</use></avisibility>
|
||||||
|
<lthickness><use>/environment/ground-haze-thickness-m</use></lthickness>
|
||||||
|
<scattering><use>/rendering/scene/scattering</use></scattering>
|
||||||
|
<ground_scattering><use>/environment/surface/scattering</use></ground_scattering>
|
||||||
|
<terminator><use>/environment/terminator-relative-position-m</use></terminator>
|
||||||
|
<terrain_alt><use>/environment/mean-terrain-elevation-m</use></terrain_alt>
|
||||||
|
<overcast><use>/rendering/scene/overcast</use></overcast>
|
||||||
|
<eye_alt><use>/sim/rendering/eye-altitude-m</use></eye_alt>
|
||||||
|
<cloud_self_shading><use>/environment/cloud-self-shading</use></cloud_self_shading>
|
||||||
|
<moonlight><use>/environment/moonlight</use></moonlight>
|
||||||
|
<alt_agl><use>/position/gear-agl-m</use></alt_agl>
|
||||||
|
<gear_clearance>1.5</gear_clearance>
|
||||||
|
<!-- END fog include -->
|
||||||
|
</parameters>
|
||||||
|
|
||||||
|
<technique n="5">
|
||||||
|
<predicate>
|
||||||
|
<and>
|
||||||
|
<property>/sim/rendering/shaders/skydome</property>
|
||||||
|
<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>
|
||||||
|
<lighting>true</lighting>
|
||||||
|
<material>
|
||||||
|
<active><use>material/active</use></active>
|
||||||
|
<ambient><use>material/ambient</use></ambient>
|
||||||
|
<diffuse><use>material/diffuse</use></diffuse>
|
||||||
|
<specular><use>material/specular</use></specular>
|
||||||
|
<emissive><use>material/emissive</use></emissive>
|
||||||
|
<shininess><use>material/shininess</use></shininess>
|
||||||
|
<color-mode><use>material/color-mode</use></color-mode>
|
||||||
|
</material>
|
||||||
|
<blend>
|
||||||
|
<active><use>blend/active</use></active>
|
||||||
|
<source><use>blend/source</use></source>
|
||||||
|
<destination><use>blend/destination</use></destination>
|
||||||
|
</blend>
|
||||||
|
<shade-model><use>shade-model</use></shade-model>
|
||||||
|
<cull-face><use>cull-face</use></cull-face>
|
||||||
|
<render-bin>
|
||||||
|
<bin-number>10</bin-number>
|
||||||
|
<bin-name>DepthSortedBin</bin-name>
|
||||||
|
</render-bin>
|
||||||
|
<rendering-hint><use>rendering-hint</use></rendering-hint>
|
||||||
|
<texture-unit>
|
||||||
|
<!-- The texture unit is always active because the shaders expect
|
||||||
|
that. -->
|
||||||
|
<unit>0</unit>
|
||||||
|
<!-- If there is a texture, the type in the derived effect
|
||||||
|
will be "2d". -->
|
||||||
|
<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>
|
||||||
|
<!--
|
||||||
|
<internal-format>
|
||||||
|
<use>texture[0]/internal-format</use>
|
||||||
|
</internal-format>
|
||||||
|
-->
|
||||||
|
</texture-unit>
|
||||||
|
<vertex-program-two-side>
|
||||||
|
<use>vertex-program-two-side</use>
|
||||||
|
</vertex-program-two-side>
|
||||||
|
<program>
|
||||||
|
<vertex-shader>Shaders/shadow-ALS.vert</vertex-shader>
|
||||||
|
<fragment-shader>Shaders/shadow-ALS.frag</fragment-shader>
|
||||||
|
</program>
|
||||||
|
<uniform>
|
||||||
|
<name>visibility</name>
|
||||||
|
<type>float</type>
|
||||||
|
<value><use>visibility</use></value>
|
||||||
|
</uniform>
|
||||||
|
<uniform>
|
||||||
|
<name>avisibility</name>
|
||||||
|
<type>float</type>
|
||||||
|
<value><use>avisibility</use></value>
|
||||||
|
</uniform>
|
||||||
|
<uniform>
|
||||||
|
<name>hazeLayerAltitude</name>
|
||||||
|
<type>float</type>
|
||||||
|
<value><use>lthickness</use></value>
|
||||||
|
</uniform>
|
||||||
|
<uniform>
|
||||||
|
<name>scattering</name>
|
||||||
|
<type>float</type>
|
||||||
|
<value><use>scattering</use></value>
|
||||||
|
</uniform>
|
||||||
|
<uniform>
|
||||||
|
<name>terminator</name>
|
||||||
|
<type>float</type>
|
||||||
|
<value><use>terminator</use></value>
|
||||||
|
</uniform>
|
||||||
|
<uniform>
|
||||||
|
<name>ground_scattering</name>
|
||||||
|
<type>float</type>
|
||||||
|
<value><use>ground_scattering</use></value>
|
||||||
|
</uniform>
|
||||||
|
<uniform>
|
||||||
|
<name>terminator</name>
|
||||||
|
<type>float</type>
|
||||||
|
<value><use>terminator</use></value>
|
||||||
|
</uniform>
|
||||||
|
<uniform>
|
||||||
|
<name>terrain_alt</name>
|
||||||
|
<type>float</type>
|
||||||
|
<value><use>terrain_alt</use></value>
|
||||||
|
</uniform>
|
||||||
|
<uniform>
|
||||||
|
<name>overcast</name>
|
||||||
|
<type>float</type>
|
||||||
|
<value><use>overcast</use></value>
|
||||||
|
</uniform>
|
||||||
|
<uniform>
|
||||||
|
<name>eye_alt</name>
|
||||||
|
<type>float</type>
|
||||||
|
<value><use>eye_alt</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>alt_agl</name>
|
||||||
|
<type>float</type>
|
||||||
|
<value><use>alt_agl</use></value>
|
||||||
|
</uniform>
|
||||||
|
<uniform>
|
||||||
|
<name>gear_clearance</name>
|
||||||
|
<type>float</type>
|
||||||
|
<value><use>gear_clearance</use></value>
|
||||||
|
</uniform>
|
||||||
|
<alpha-test>
|
||||||
|
<comparison>greater</comparison>
|
||||||
|
<reference type="float">0.01</reference>
|
||||||
|
</alpha-test>
|
||||||
|
<depth>
|
||||||
|
<function>lequal</function>
|
||||||
|
<write-mask type="bool">true</write-mask>
|
||||||
|
</depth>
|
||||||
|
</pass>
|
||||||
|
</technique>
|
||||||
|
|
||||||
|
|
||||||
|
<technique n="13">
|
||||||
|
<pass>
|
||||||
|
<lighting>true</lighting>
|
||||||
|
<material>
|
||||||
|
<active>
|
||||||
|
<use>material/active</use>
|
||||||
|
</active>
|
||||||
|
<ambient>
|
||||||
|
<use>material/ambient</use>
|
||||||
|
</ambient>
|
||||||
|
<diffuse>
|
||||||
|
<use>material/diffuse</use>
|
||||||
|
</diffuse>
|
||||||
|
<specular>
|
||||||
|
<use>material/specular</use>
|
||||||
|
</specular>
|
||||||
|
<emissive>
|
||||||
|
<use>material/emissive</use>
|
||||||
|
</emissive>
|
||||||
|
<shininess>
|
||||||
|
<use>material/shininess</use>
|
||||||
|
</shininess>
|
||||||
|
<color-mode>
|
||||||
|
<use>material/color-mode</use>
|
||||||
|
</color-mode>
|
||||||
|
</material>
|
||||||
|
<blend>
|
||||||
|
<active>
|
||||||
|
<use>blend/active</use>
|
||||||
|
</active>
|
||||||
|
<source>
|
||||||
|
<use>blend/source</use>
|
||||||
|
</source>
|
||||||
|
<destination>
|
||||||
|
<use>blend/destination</use>
|
||||||
|
</destination>
|
||||||
|
</blend>
|
||||||
|
<shade-model>
|
||||||
|
<use>shade-model</use>
|
||||||
|
</shade-model>
|
||||||
|
<cull-face>
|
||||||
|
<use>cull-face</use>
|
||||||
|
</cull-face>
|
||||||
|
<rendering-hint>
|
||||||
|
<use>rendering-hint</use>
|
||||||
|
</rendering-hint>
|
||||||
|
<texture-unit>
|
||||||
|
<active>
|
||||||
|
<use>texture[0]/active</use>
|
||||||
|
</active>
|
||||||
|
<unit>0</unit>
|
||||||
|
<image>
|
||||||
|
<use>texture[0]/image</use>
|
||||||
|
</image>
|
||||||
|
<type>
|
||||||
|
<use>texture[0]/type</use>
|
||||||
|
</type>
|
||||||
|
<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>
|
||||||
|
<!--
|
||||||
|
<internal-format>
|
||||||
|
<use>texture[0]/internal-format</use>
|
||||||
|
</internal-format>
|
||||||
|
-->
|
||||||
|
<environment>
|
||||||
|
<mode>modulate</mode>
|
||||||
|
</environment>
|
||||||
|
</texture-unit>
|
||||||
|
<!-- A two-sided lighting model is set by default near the root
|
||||||
|
of the scene graph. Perhaps that ought to be set in this
|
||||||
|
effect?
|
||||||
|
-->
|
||||||
|
</pass>
|
||||||
|
</technique>
|
||||||
|
</PropertyList>
|
19
Shaders/shadow-ALS.frag
Normal file
19
Shaders/shadow-ALS.frag
Normal file
|
@ -0,0 +1,19 @@
|
||||||
|
#version 120
|
||||||
|
|
||||||
|
uniform sampler2D texture;
|
||||||
|
uniform float scattering;
|
||||||
|
|
||||||
|
void main()
|
||||||
|
{
|
||||||
|
vec4 texel = texture2D(texture, gl_TexCoord[0].st);
|
||||||
|
texel.a = smoothstep(0.0,0.1, texel.a);
|
||||||
|
|
||||||
|
float illumination = length(gl_Color.rgb);
|
||||||
|
texel = vec4 (0.1,0.1,0.1,texel.a);
|
||||||
|
texel.a *= illumination;
|
||||||
|
texel.a *=0.6 * smoothstep(0.5,0.8,scattering);
|
||||||
|
texel.a = min(0.8, texel.a);
|
||||||
|
|
||||||
|
vec4 fragColor = texel;
|
||||||
|
gl_FragColor = fragColor;
|
||||||
|
}
|
75
Shaders/shadow-ALS.vert
Normal file
75
Shaders/shadow-ALS.vert
Normal file
|
@ -0,0 +1,75 @@
|
||||||
|
// -*-C++-*-
|
||||||
|
|
||||||
|
|
||||||
|
#version 120
|
||||||
|
|
||||||
|
uniform float hazeLayerAltitude;
|
||||||
|
uniform float terminator;
|
||||||
|
uniform float terrain_alt;
|
||||||
|
uniform float avisibility;
|
||||||
|
uniform float visibility;
|
||||||
|
uniform float overcast;
|
||||||
|
uniform float ground_scattering;
|
||||||
|
uniform float eye_alt;
|
||||||
|
uniform float moonlight;
|
||||||
|
uniform float alt_agl;
|
||||||
|
uniform float gear_clearance;
|
||||||
|
|
||||||
|
const float EarthRadius = 5800000.0;
|
||||||
|
const float terminator_width = 200000.0;
|
||||||
|
|
||||||
|
float light_func (in float x, in float a, in float b, in float c, in float d, in float e)
|
||||||
|
{
|
||||||
|
|
||||||
|
if (x < -15.0) {return 0.0;}
|
||||||
|
|
||||||
|
return e / pow((1.0 + a * exp(-b * (x-c)) ),(1.0/d));
|
||||||
|
}
|
||||||
|
|
||||||
|
void main()
|
||||||
|
{
|
||||||
|
|
||||||
|
|
||||||
|
gl_TexCoord[0] = gl_TextureMatrix[0] * gl_MultiTexCoord0;
|
||||||
|
|
||||||
|
vec4 ep = gl_ModelViewMatrixInverse * vec4(0.0,0.0,0.0,1.0);
|
||||||
|
vec3 relPos = gl_Vertex.xyz - ep.xyz;
|
||||||
|
|
||||||
|
|
||||||
|
// compute the strength of light
|
||||||
|
float vertex_alt = max(gl_Vertex.z,100.0);
|
||||||
|
float scattering = ground_scattering + (1.0 - ground_scattering) * smoothstep(hazeLayerAltitude -100.0, hazeLayerAltitude + 100.0, vertex_alt);
|
||||||
|
vec3 lightFull = (gl_ModelViewMatrixInverse * gl_LightSource[0].position).xyz;
|
||||||
|
vec3 lightHorizon = normalize(vec3(lightFull.x,lightFull.y, 0.0));
|
||||||
|
float yprime = -dot(relPos, lightHorizon);
|
||||||
|
float yprime_alt = yprime - sqrt(2.0 * EarthRadius * vertex_alt);
|
||||||
|
float earthShade = 0.6 * (1.0 - smoothstep(-terminator_width+ terminator, terminator_width + terminator, yprime_alt)) + 0.4;
|
||||||
|
float lightArg = (terminator-yprime_alt)/100000.0;
|
||||||
|
vec4 light_diffuse;
|
||||||
|
light_diffuse.b = light_func(lightArg, 1.330e-05, 0.264, 3.827, 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;
|
||||||
|
light_diffuse = light_diffuse * scattering;
|
||||||
|
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_diffuse.rgb = light_diffuse.rgb * (1.0 + 1.2 * shade_depth);
|
||||||
|
|
||||||
|
|
||||||
|
// project the shadow onto the ground
|
||||||
|
vec4 pos = gl_Vertex;
|
||||||
|
pos.z-=0.95 * alt_agl-0.1;
|
||||||
|
pos.xy -= lightFull.xy * 0.95* alt_agl/lightFull.z;
|
||||||
|
|
||||||
|
// enlargen the shadow for low light
|
||||||
|
if (dot(pos.xy, lightHorizon.xy)<0.0)
|
||||||
|
{
|
||||||
|
pos.xy -= lightFull.xy * gear_clearance/lightFull.z;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
gl_Position = gl_ModelViewProjectionMatrix * pos;
|
||||||
|
|
||||||
|
gl_FrontColor = light_diffuse;
|
||||||
|
gl_BackColor = gl_FrontColor;
|
||||||
|
}
|
Loading…
Reference in a new issue