Fixed directional lighting.
This commit is contained in:
parent
da1316a74c
commit
281469611b
3 changed files with 312 additions and 26 deletions
286
Effects/surface-lights-directional.eff
Normal file
286
Effects/surface-lights-directional.eff
Normal file
|
@ -0,0 +1,286 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<PropertyList>
|
||||
<name>Effects/surface-lights-directional</name>
|
||||
<parameters>
|
||||
<!-- min-size, max-size, size, attenuation, cull-face parameters filled in by C++ code -->
|
||||
<texture n="0">
|
||||
<type>light-sprite</type>
|
||||
<wrap-s>clamp</wrap-s>
|
||||
<wrap-t>clamp</wrap-t>
|
||||
</texture>
|
||||
<visibility><use>/environment/ground-visibility-m</use></visibility>
|
||||
<avisibility><use>/environment/visibility-m</use></avisibility>
|
||||
<lthickness><use>/environment/ground-haze-thickness-m</use></lthickness>
|
||||
<eye_alt><use>/sim/rendering/eye-altitude-m</use></eye_alt>
|
||||
<terminator><use>/environment/terminator-relative-position-m</use></terminator>
|
||||
</parameters>
|
||||
|
||||
<technique n="10">
|
||||
<!-- ALS -->
|
||||
<predicate>
|
||||
<and>
|
||||
<property>/sim/rendering/point-sprites</property>
|
||||
<property>/sim/rendering/shaders/skydome</property>
|
||||
<or>
|
||||
<less-equal>
|
||||
<value type="float">2.0</value>
|
||||
<glversion/>
|
||||
</less-equal>
|
||||
<and>
|
||||
<extension-supported>GL_ARB_point_sprite</extension-supported>
|
||||
<extension-supported>GL_ARB_point_parameters</extension-supported>
|
||||
<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>
|
||||
<render-bin>
|
||||
<bin-number>8</bin-number>
|
||||
<bin-name>DepthSortedBin</bin-name>
|
||||
</render-bin>
|
||||
<lighting>false</lighting>
|
||||
<blend>
|
||||
<source>src-alpha</source>
|
||||
<destination>one-minus-src-alpha</destination>
|
||||
</blend>
|
||||
<depth>
|
||||
<write-mask>false</write-mask>
|
||||
</depth>
|
||||
<!--<alpha-test>
|
||||
<comparison>gequal</comparison>
|
||||
<reference type="float">0.03</reference>
|
||||
</alpha-test>-->
|
||||
<cull-face>back</cull-face>
|
||||
<polygon-mode>
|
||||
<front>point</front>
|
||||
</polygon-mode>
|
||||
<point>
|
||||
<min-size><use>min-size</use></min-size>
|
||||
<max-size><use>max-size</use></max-size>
|
||||
<size><use>size</use></size>
|
||||
<attenuation><use>attenuation</use></attenuation>
|
||||
</point>
|
||||
<texture-unit>
|
||||
<unit>0</unit>
|
||||
<point-sprite>true</point-sprite>
|
||||
<type><use>texture[0]/type</use></type>
|
||||
<wrap-s><use>texture[0]/wrap-s</use></wrap-s>
|
||||
<wrap-t><use>texture[0]/wrap-t</use></wrap-t>
|
||||
</texture-unit>
|
||||
<program>
|
||||
<vertex-shader>Shaders/surface-light-ALS.vert</vertex-shader>
|
||||
<fragment-shader>Shaders/surface-light-ALS.frag</fragment-shader>
|
||||
<fragment-shader>Shaders/noise.frag</fragment-shader>
|
||||
</program>
|
||||
<uniform>
|
||||
<name>size</name>
|
||||
<type>float</type>
|
||||
<value><use>size</use></value>
|
||||
</uniform>
|
||||
<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>eye_alt</name>
|
||||
<type>float</type>
|
||||
<value><use>eye_alt</use></value>
|
||||
</uniform>
|
||||
<uniform>
|
||||
<name>max_size</name>
|
||||
<type>float</type>
|
||||
<value><use>max-size</use></value>
|
||||
</uniform>
|
||||
<uniform>
|
||||
<name>is_directional</name>
|
||||
<type>bool</type>
|
||||
<value><use>light-directional</use></value>
|
||||
</uniform>
|
||||
<uniform>
|
||||
<name>texture</name>
|
||||
<type>sampler-2d</type>
|
||||
<value type="int">0</value>
|
||||
</uniform>
|
||||
<uniform>
|
||||
<name>terminator</name>
|
||||
<type>float</type>
|
||||
<value><use>terminator</use></value>
|
||||
</uniform>
|
||||
<vertex-program-point-size>true</vertex-program-point-size>
|
||||
</pass>
|
||||
</technique>
|
||||
|
||||
|
||||
|
||||
|
||||
<technique n="17">
|
||||
<!-- Combined technique -->
|
||||
<predicate>
|
||||
<and>
|
||||
<property>/sim/rendering/point-sprites</property>
|
||||
<or>
|
||||
<less-equal>
|
||||
<value type="float">2.0</value>
|
||||
<glversion/>
|
||||
</less-equal>
|
||||
<and>
|
||||
<extension-supported>GL_ARB_point_sprite</extension-supported>
|
||||
<extension-supported>GL_ARB_point_parameters</extension-supported>
|
||||
</and>
|
||||
</or>
|
||||
</and>
|
||||
</predicate>
|
||||
<pass>
|
||||
<render-bin>
|
||||
<bin-number>8</bin-number>
|
||||
<bin-name>DepthSortedBin</bin-name>
|
||||
</render-bin>
|
||||
<lighting>false</lighting>
|
||||
<depth>
|
||||
<write-mask>false</write-mask>
|
||||
</depth>
|
||||
<blend>
|
||||
<source>src-alpha</source>
|
||||
<destination>one-minus-src-alpha</destination>
|
||||
</blend>
|
||||
<alpha-test>
|
||||
<comparison>gequal</comparison>
|
||||
<reference type="float">0.1</reference>
|
||||
</alpha-test>
|
||||
<cull-face>back</cull-face>
|
||||
<polygon-mode>
|
||||
<front>point</front>
|
||||
</polygon-mode>
|
||||
<point>
|
||||
<min-size><use>min-size</use></min-size>
|
||||
<max-size><use>max-size</use></max-size>
|
||||
<size><use>size</use></size>
|
||||
<attenuation><use>attenuation</use></attenuation>
|
||||
</point>
|
||||
<texture-unit>
|
||||
<unit>0</unit>
|
||||
<point-sprite>true</point-sprite>
|
||||
<type><use>texture[0]/type</use></type>
|
||||
<wrap-s><use>texture[0]/wrap-s</use></wrap-s>
|
||||
<wrap-t><use>texture[0]/wrap-t</use></wrap-t>
|
||||
</texture-unit>
|
||||
</pass>
|
||||
</technique>
|
||||
|
||||
<technique n="18">
|
||||
<!-- Sprite technique -->
|
||||
<predicate>
|
||||
<and>
|
||||
<property>/sim/rendering/point-sprites</property>
|
||||
<or>
|
||||
<less-equal>
|
||||
<value type="float">2.0</value>
|
||||
<glversion/>
|
||||
</less-equal>
|
||||
<extension-supported>GL_ARB_point_sprite</extension-supported>
|
||||
</or>
|
||||
</and>
|
||||
</predicate>
|
||||
<pass>
|
||||
<render-bin>
|
||||
<bin-number>8</bin-number>
|
||||
<bin-name>DepthSortedBin</bin-name>
|
||||
</render-bin>
|
||||
<lighting>false</lighting>
|
||||
<depth>
|
||||
<write-mask>false</write-mask>
|
||||
</depth>
|
||||
<blend>
|
||||
<source>src-alpha</source>
|
||||
<destination>one-minus-src-alpha</destination>
|
||||
</blend>
|
||||
<cull-face>back</cull-face>
|
||||
<polygon-mode>
|
||||
<front>point</front>
|
||||
</polygon-mode>
|
||||
<texture-unit>
|
||||
<unit>0</unit>
|
||||
<point-sprite>true</point-sprite>
|
||||
<type><use>texture[0]/type</use></type>
|
||||
<wrap-s><use>texture[0]/wrap-s</use></wrap-s>
|
||||
<wrap-t><use>texture[0]/wrap-t</use></wrap-t>
|
||||
</texture-unit>
|
||||
</pass>
|
||||
</technique>
|
||||
|
||||
<technique n="19">
|
||||
<!-- Attenuation technique -->
|
||||
<predicate>
|
||||
<and>
|
||||
<or>
|
||||
<less-equal>
|
||||
<value type="float">2.0</value>
|
||||
<glversion/>
|
||||
</less-equal>
|
||||
<extension-supported>GL_ARB_point_parameters</extension-supported>
|
||||
</or>
|
||||
</and>
|
||||
</predicate>
|
||||
<pass>
|
||||
<point>
|
||||
<min-size><use>min-size</use></min-size>
|
||||
<max-size><use>max-size</use></max-size>
|
||||
<size><use>size</use></size>
|
||||
<attenuation><use>attenuation</use></attenuation>
|
||||
</point>
|
||||
<render-bin>
|
||||
<bin-number>8</bin-number>
|
||||
<bin-name>DepthSortedBin</bin-name>
|
||||
</render-bin>
|
||||
<depth>
|
||||
<write-mask>false</write-mask>
|
||||
</depth>
|
||||
<blend>
|
||||
<source>src-alpha</source>
|
||||
<destination>one-minus-src-alpha</destination>
|
||||
</blend>
|
||||
<lighting>false</lighting>
|
||||
<cull-face>back</cull-face>
|
||||
<polygon-mode>
|
||||
<front>point</front>
|
||||
</polygon-mode>
|
||||
</pass>
|
||||
</technique>
|
||||
|
||||
<technique n="20">
|
||||
<!-- Basic technique -->
|
||||
<pass>
|
||||
<render-bin>
|
||||
<bin-number>8</bin-number>
|
||||
<bin-name>DepthSortedBin</bin-name>
|
||||
</render-bin>
|
||||
<lighting>false</lighting>
|
||||
<depth>
|
||||
<write-mask>false</write-mask>
|
||||
</depth>
|
||||
<blend>
|
||||
<source>src-alpha</source>
|
||||
<destination>one-minus-src-alpha</destination>
|
||||
</blend>
|
||||
<cull-face>back</cull-face>
|
||||
<polygon-mode>
|
||||
<front>point</front>
|
||||
</polygon-mode>
|
||||
</pass>
|
||||
</technique>
|
||||
</PropertyList>
|
|
@ -54,7 +54,7 @@
|
|||
<comparison>gequal</comparison>
|
||||
<reference type="float">0.03</reference>
|
||||
</alpha-test>-->
|
||||
<cull-face><use>directional</use></cull-face>
|
||||
<cull-face><use>cull-face</use></cull-face>
|
||||
<polygon-mode>
|
||||
<front>point</front>
|
||||
<back>point</back>
|
||||
|
@ -125,7 +125,7 @@
|
|||
<vertex-program-point-size>true</vertex-program-point-size>
|
||||
</pass>
|
||||
</technique>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
@ -163,10 +163,9 @@
|
|||
<comparison>gequal</comparison>
|
||||
<reference type="float">0.1</reference>
|
||||
</alpha-test>
|
||||
<cull-face><use>directional</use></cull-face>
|
||||
<cull-face>back</cull-face>
|
||||
<polygon-mode>
|
||||
<front>point</front>
|
||||
<back>point</back>
|
||||
</polygon-mode>
|
||||
<point>
|
||||
<min-size><use>min-size</use></min-size>
|
||||
|
@ -211,10 +210,9 @@
|
|||
<source>src-alpha</source>
|
||||
<destination>one-minus-src-alpha</destination>
|
||||
</blend>
|
||||
<cull-face><use>directional</use></cull-face>
|
||||
<cull-face><use>cull-face</use></cull-face>
|
||||
<polygon-mode>
|
||||
<front>point</front>
|
||||
<back>point</back>
|
||||
</polygon-mode>
|
||||
<texture-unit>
|
||||
<unit>0</unit>
|
||||
|
@ -258,7 +256,7 @@
|
|||
<destination>one-minus-src-alpha</destination>
|
||||
</blend>
|
||||
<lighting>false</lighting>
|
||||
<cull-face><use>directional</use></cull-face>
|
||||
<cull-face><use>cull-face</use></cull-face>
|
||||
<polygon-mode>
|
||||
<front>point</front>
|
||||
<back>point</back>
|
||||
|
@ -281,10 +279,9 @@
|
|||
<source>src-alpha</source>
|
||||
<destination>one-minus-src-alpha</destination>
|
||||
</blend>
|
||||
<cull-face><use>directional</use></cull-face>
|
||||
<cull-face><use>cull-face</use></cull-face>
|
||||
<polygon-mode>
|
||||
<front>point</front>
|
||||
<back>point</back>
|
||||
</polygon-mode>
|
||||
</pass>
|
||||
</technique>
|
||||
|
|
|
@ -35,9 +35,9 @@ if (alt < 30000.0)
|
|||
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));
|
||||
return fade_mix * exp(-targ*targ - pow(targ,4.0)) + (1.0 - fade_mix) * exp(-targ - pow(targ,4.0));
|
||||
}
|
||||
else
|
||||
else
|
||||
{
|
||||
return exp(- targ * targ - pow(targ,4.0));
|
||||
}
|
||||
|
@ -56,13 +56,13 @@ float r = length(coord);
|
|||
if (pixelSize<1.3) {return vec4 (1.0,1.0,1.0,1.0) * 0.08;}
|
||||
|
||||
float angle = noise * 6.2832;
|
||||
|
||||
|
||||
float sinphi = dot(vec2 (sin(angle),cos(angle)), normalize(coord));
|
||||
float sinterm = sin(mod((sinphi-3.0) * (sinphi-3.0),6.2832));
|
||||
float ray = 0.0;
|
||||
if (sinterm == 0.0)
|
||||
{ray = 0.0;}
|
||||
else
|
||||
{ray = 0.0;}
|
||||
else
|
||||
{ray = clamp(pow(sinterm,10.0),0.0,1.0);}
|
||||
|
||||
float fogEffect = (1.0-smoothstep(0.4,0.8,transmission));
|
||||
|
@ -76,7 +76,7 @@ return vec4 (1.0,1.0,1.0,1.0) * intensity;
|
|||
|
||||
void main()
|
||||
{
|
||||
|
||||
|
||||
float dist = length(relPos);
|
||||
float delta_z = hazeLayerAltitude - eye_alt;
|
||||
float transmission;
|
||||
|
@ -86,7 +86,10 @@ void main()
|
|||
float distance_in_layer;
|
||||
float transmission_arg;
|
||||
|
||||
float noise = Noise2D(rawPos.xy ,1.0);
|
||||
// Discard the second and third vertex, which are used for directional lighting
|
||||
if (gl_Color.a == 0.0) {discard;}
|
||||
|
||||
float noise = Noise2D(rawPos.xy ,1.0);
|
||||
|
||||
// angle with horizon
|
||||
float ct = dot(vec3(0.0, 0.0, 1.0), relPos)/dist;
|
||||
|
@ -96,7 +99,7 @@ void main()
|
|||
|
||||
if (delta_z > 0.0) // we're inside the layer
|
||||
{
|
||||
if (ct < 0.0) // we look down
|
||||
if (ct < 0.0) // we look down
|
||||
{
|
||||
distance_in_layer = dist;
|
||||
vAltitude = min(distance_in_layer,min(visibility, avisibility)) * ct;
|
||||
|
@ -108,26 +111,26 @@ void main()
|
|||
if (H > delta_z) {distance_in_layer = dist/H * delta_z;}
|
||||
else {distance_in_layer = dist;}
|
||||
vAltitude = min(distance_in_layer,visibility) * ct;
|
||||
delta_zv = delta_z - vAltitude;
|
||||
delta_zv = delta_z - vAltitude;
|
||||
}
|
||||
}
|
||||
else // we see the layer from above, delta_z < 0.0
|
||||
{
|
||||
{
|
||||
H = dist * -ct;
|
||||
if (H < (-delta_z)) // we don't see into the layer at all, aloft visibility is the only fading
|
||||
{
|
||||
distance_in_layer = 0.0;
|
||||
delta_zv = 0.0;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
vAltitude = H + delta_z;
|
||||
distance_in_layer = vAltitude/H * dist;
|
||||
distance_in_layer = vAltitude/H * dist;
|
||||
vAltitude = min(distance_in_layer,visibility) * (-ct);
|
||||
delta_zv = vAltitude;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
// ground haze cannot be thinner than aloft visibility in the model,
|
||||
// so we need to use aloft visibility otherwise
|
||||
|
@ -138,7 +141,7 @@ void main()
|
|||
{
|
||||
transmission_arg = transmission_arg + (distance_in_layer/visibility);
|
||||
}
|
||||
else
|
||||
else
|
||||
{
|
||||
transmission_arg = transmission_arg + (distance_in_layer/avisibility);
|
||||
}
|
||||
|
@ -153,7 +156,7 @@ void main()
|
|||
|
||||
//vec4 texel = texture2D(texture,gl_TexCoord[0].st);
|
||||
vec4 texel = light_sprite(gl_TexCoord[0].st,transmission, noise);
|
||||
gl_FragColor = vec4 (clamp(gl_Color.rgb,0.0,1.0), texel.a * transmission * dist_att);
|
||||
|
||||
gl_FragColor = vec4 (clamp(gl_Color.rgb,0.0,1.0), texel.a * transmission * dist_att);
|
||||
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue