1
0
Fork 0

WS30: Add basic shaders

This commit is contained in:
Stuart Buchanan 2021-01-23 17:15:12 +00:00
parent 9355d464c1
commit d058b514f2
5 changed files with 778 additions and 906 deletions

View file

@ -2,7 +2,6 @@
<!-- World Scenery 3.0 Effect -->
<PropertyList>
<name>Effects/ws30</name>
<!-- <inherits-from>another-effect</inherits-from> -->
<parameters>
<material>
<ambient type="vec4d">
@ -83,279 +82,99 @@
<dust_resistance>1.0</dust_resistance>
<rock_strata>0</rock_strata>
<raise_vertex type="bool">false</raise_vertex>
<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>
<snow_level>
<use>/environment/snow-level-m</use>
</snow_level>
<snow_thickness_factor>
<use>/environment/surface/snow-thickness-factor</use>
</snow_thickness_factor>
<dust_cover_factor>
<use>/environment/surface/dust-cover-factor</use>
</dust_cover_factor>
<lichen_cover_factor>
<use>/environment/surface/lichen-cover-factor</use>
</lichen_cover_factor>
<wetness>
<use>/environment/surface/wetness</use>
</wetness>
<fogtype>
<use>/sim/rendering/shaders/skydome</use>
</fogtype>
<fogstructure>
<use>/environment/fog-structure</use>
</fogstructure>
<cloud_self_shading>
<use>/environment/cloud-self-shading</use>
</cloud_self_shading>
<moonlight>
<use>/environment/moonlight</use>
</moonlight>
<season>
<use>/environment/season</use>
</season>
<air_pollution>
<use>/environment/air-pollution-norm</use>
</air_pollution>
<delta_T>
<use>/environment/surface/delta-T-soil</use>
</delta_T>
<wind_effects>
<use>/sim/rendering/shaders/wind-effects</use>
</wind_effects>
<windE>
<use>/environment/sea/surface/wind-from-east-fps</use>
</windE>
<windN>
<use>/environment/sea/surface/wind-from-north-fps</use>
</windN>
<display_xsize>
<use>/sim/startup/xsize</use>
</display_xsize>
<display_ysize>
<use>/sim/startup/ysize</use>
</display_ysize>
<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>
<snow_level><use>/environment/snow-level-m</use></snow_level>
<snow_thickness_factor><use>/environment/surface/snow-thickness-factor</use></snow_thickness_factor>
<dust_cover_factor><use>/environment/surface/dust-cover-factor</use></dust_cover_factor>
<lichen_cover_factor><use>/environment/surface/lichen-cover-factor</use></lichen_cover_factor>
<wetness><use>/environment/surface/wetness</use></wetness>
<fogtype><use>/sim/rendering/shaders/skydome</use></fogtype>
<fogstructure><use>/environment/fog-structure</use></fogstructure>
<cloud_self_shading><use>/environment/cloud-self-shading</use></cloud_self_shading>
<moonlight><use>/environment/moonlight</use></moonlight>
<season><use>/environment/season</use></season>
<air_pollution><use>/environment/air-pollution-norm</use></air_pollution>
<delta_T><use>/environment/surface/delta-T-soil</use></delta_T>
<wind_effects><use>/sim/rendering/shaders/wind-effects</use></wind_effects>
<windE><use>/environment/sea/surface/wind-from-east-fps</use></windE>
<windN><use>/environment/sea/surface/wind-from-north-fps</use></windN>
<display_xsize><use>/sim/startup/xsize</use></display_xsize>
<display_ysize><use>/sim/startup/ysize</use></display_ysize>
<!--
<tile_width>
<use>/sim/rendering/texture-factor</use>
</tile_width>
<tile_width><use>/sim/rendering/texture-factor</use></tile_width>
-->
<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>
<landing_light3_offset>
<use>/sim/rendering/als-secondary-lights/landing-light3-offset-deg</use>
</landing_light3_offset>
<quality_level>
<use>/sim/rendering/shaders/landmass</use>
</quality_level>
<tquality_level>
<use>/sim/rendering/shaders/transition</use>
</tquality_level>
<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>
<fact_grey>
<use>/sim/rendering/als-filters/grey-factor</use>
</fact_grey>
<fact_black>
<use>/sim/rendering/als-filters/black-factor</use>
</fact_black>
<use_night_vision>
<use>/sim/rendering/als-filters/use-night-vision</use>
</use_night_vision>
<use_IR_vision>
<use>/sim/rendering/als-filters/use-IR-vision</use>
</use_IR_vision>
<cloudpos1_x>
<use>/local-weather/cloud-shadows/cloudpos-x[0]</use>
</cloudpos1_x>
<cloudpos1_y>
<use>/local-weather/cloud-shadows/cloudpos-y[0]</use>
</cloudpos1_y>
<cloudpos2_x>
<use>/local-weather/cloud-shadows/cloudpos-x[1]</use>
</cloudpos2_x>
<cloudpos2_y>
<use>/local-weather/cloud-shadows/cloudpos-y[1]</use>
</cloudpos2_y>
<cloudpos3_x>
<use>/local-weather/cloud-shadows/cloudpos-x[2]</use>
</cloudpos3_x>
<cloudpos3_y>
<use>/local-weather/cloud-shadows/cloudpos-y[2]</use>
</cloudpos3_y>
<cloudpos4_x>
<use>/local-weather/cloud-shadows/cloudpos-x[3]</use>
</cloudpos4_x>
<cloudpos4_y>
<use>/local-weather/cloud-shadows/cloudpos-y[3]</use>
</cloudpos4_y>
<cloudpos5_x>
<use>/local-weather/cloud-shadows/cloudpos-x[4]</use>
</cloudpos5_x>
<cloudpos5_y>
<use>/local-weather/cloud-shadows/cloudpos-y[4]</use>
</cloudpos5_y>
<cloudpos6_x>
<use>/local-weather/cloud-shadows/cloudpos-x[5]</use>
</cloudpos6_x>
<cloudpos6_y>
<use>/local-weather/cloud-shadows/cloudpos-y[5]</use>
</cloudpos6_y>
<cloudpos7_x>
<use>/local-weather/cloud-shadows/cloudpos-x[6]</use>
</cloudpos7_x>
<cloudpos7_y>
<use>/local-weather/cloud-shadows/cloudpos-y[6]</use>
</cloudpos7_y>
<cloudpos8_x>
<use>/local-weather/cloud-shadows/cloudpos-x[7]</use>
</cloudpos8_x>
<cloudpos8_y>
<use>/local-weather/cloud-shadows/cloudpos-y[7]</use>
</cloudpos8_y>
<cloudpos9_x>
<use>/local-weather/cloud-shadows/cloudpos-x[8]</use>
</cloudpos9_x>
<cloudpos9_y>
<use>/local-weather/cloud-shadows/cloudpos-y[8]</use>
</cloudpos9_y>
<cloudpos10_x>
<use>/local-weather/cloud-shadows/cloudpos-x[9]</use>
</cloudpos10_x>
<cloudpos10_y>
<use>/local-weather/cloud-shadows/cloudpos-y[9]</use>
</cloudpos10_y>
<cloudpos11_x>
<use>/local-weather/cloud-shadows/cloudpos-x[10]</use>
</cloudpos11_x>
<cloudpos11_y>
<use>/local-weather/cloud-shadows/cloudpos-y[10]</use>
</cloudpos11_y>
<cloudpos12_x>
<use>/local-weather/cloud-shadows/cloudpos-x[11]</use>
</cloudpos12_x>
<cloudpos12_y>
<use>/local-weather/cloud-shadows/cloudpos-y[11]</use>
</cloudpos12_y>
<cloudpos13_x>
<use>/local-weather/cloud-shadows/cloudpos-x[12]</use>
</cloudpos13_x>
<cloudpos13_y>
<use>/local-weather/cloud-shadows/cloudpos-y[12]</use>
</cloudpos13_y>
<cloudpos14_x>
<use>/local-weather/cloud-shadows/cloudpos-x[13]</use>
</cloudpos14_x>
<cloudpos14_y>
<use>/local-weather/cloud-shadows/cloudpos-y[13]</use>
</cloudpos14_y>
<cloudpos15_x>
<use>/local-weather/cloud-shadows/cloudpos-x[14]</use>
</cloudpos15_x>
<cloudpos15_y>
<use>/local-weather/cloud-shadows/cloudpos-y[14]</use>
</cloudpos15_y>
<cloudpos16_x>
<use>/local-weather/cloud-shadows/cloudpos-x[15]</use>
</cloudpos16_x>
<cloudpos16_y>
<use>/local-weather/cloud-shadows/cloudpos-y[15]</use>
</cloudpos16_y>
<cloudpos17_x>
<use>/local-weather/cloud-shadows/cloudpos-x[16]</use>
</cloudpos17_x>
<cloudpos17_y>
<use>/local-weather/cloud-shadows/cloudpos-y[16]</use>
</cloudpos17_y>
<cloudpos18_x>
<use>/local-weather/cloud-shadows/cloudpos-x[17]</use>
</cloudpos18_x>
<cloudpos18_y>
<use>/local-weather/cloud-shadows/cloudpos-y[17]</use>
</cloudpos18_y>
<cloudpos19_x>
<use>/local-weather/cloud-shadows/cloudpos-x[18]</use>
</cloudpos19_x>
<cloudpos19_y>
<use>/local-weather/cloud-shadows/cloudpos-y[18]</use>
</cloudpos19_y>
<cloudpos20_x>
<use>/local-weather/cloud-shadows/cloudpos-x[19]</use>
</cloudpos20_x>
<cloudpos20_y>
<use>/local-weather/cloud-shadows/cloudpos-y[19]</use>
</cloudpos20_y>
<cloudpos_n_x>
<use>/local-weather/cloud-shadows/nearest-cloudpos-x</use>
</cloudpos_n_x>
<cloudpos_n_y>
<use>/local-weather/cloud-shadows/nearest-cloudpos-y</use>
</cloudpos_n_y>
<cloud_shadow_flag>
<use>/local-weather/cloud-shadows/cloud-shadow-flag</use>
</cloud_shadow_flag>
<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>
<landing_light3_offset><use>/sim/rendering/als-secondary-lights/landing-light3-offset-deg</use></landing_light3_offset>
<quality_level><use>/sim/rendering/shaders/landmass</use></quality_level>
<tquality_level><use>/sim/rendering/shaders/transition</use></tquality_level>
<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>
<fact_grey><use>/sim/rendering/als-filters/grey-factor</use></fact_grey>
<fact_black><use>/sim/rendering/als-filters/black-factor</use></fact_black>
<use_night_vision><use>/sim/rendering/als-filters/use-night-vision</use></use_night_vision>
<use_IR_vision><use>/sim/rendering/als-filters/use-IR-vision</use></use_IR_vision>
<cloudpos1_x><use>/local-weather/cloud-shadows/cloudpos-x[0]</use></cloudpos1_x>
<cloudpos1_y><use>/local-weather/cloud-shadows/cloudpos-y[0]</use></cloudpos1_y>
<cloudpos2_x><use>/local-weather/cloud-shadows/cloudpos-x[1]</use></cloudpos2_x>
<cloudpos2_y><use>/local-weather/cloud-shadows/cloudpos-y[1]</use></cloudpos2_y>
<cloudpos3_x><use>/local-weather/cloud-shadows/cloudpos-x[2]</use></cloudpos3_x>
<cloudpos3_y><use>/local-weather/cloud-shadows/cloudpos-y[2]</use></cloudpos3_y>
<cloudpos4_x><use>/local-weather/cloud-shadows/cloudpos-x[3]</use></cloudpos4_x>
<cloudpos4_y><use>/local-weather/cloud-shadows/cloudpos-y[3]</use></cloudpos4_y>
<cloudpos5_x><use>/local-weather/cloud-shadows/cloudpos-x[4]</use></cloudpos5_x>
<cloudpos5_y><use>/local-weather/cloud-shadows/cloudpos-y[4]</use></cloudpos5_y>
<cloudpos6_x><use>/local-weather/cloud-shadows/cloudpos-x[5]</use></cloudpos6_x>
<cloudpos6_y><use>/local-weather/cloud-shadows/cloudpos-y[5]</use></cloudpos6_y>
<cloudpos7_x><use>/local-weather/cloud-shadows/cloudpos-x[6]</use></cloudpos7_x>
<cloudpos7_y><use>/local-weather/cloud-shadows/cloudpos-y[6]</use></cloudpos7_y>
<cloudpos8_x><use>/local-weather/cloud-shadows/cloudpos-x[7]</use></cloudpos8_x>
<cloudpos8_y><use>/local-weather/cloud-shadows/cloudpos-y[7]</use></cloudpos8_y>
<cloudpos9_x><use>/local-weather/cloud-shadows/cloudpos-x[8]</use></cloudpos9_x>
<cloudpos9_y><use>/local-weather/cloud-shadows/cloudpos-y[8]</use></cloudpos9_y>
<cloudpos10_x><use>/local-weather/cloud-shadows/cloudpos-x[9]</use></cloudpos10_x>
<cloudpos10_y><use>/local-weather/cloud-shadows/cloudpos-y[9]</use></cloudpos10_y>
<cloudpos11_x><use>/local-weather/cloud-shadows/cloudpos-x[10]</use></cloudpos11_x>
<cloudpos11_y><use>/local-weather/cloud-shadows/cloudpos-y[10]</use></cloudpos11_y>
<cloudpos12_x><use>/local-weather/cloud-shadows/cloudpos-x[11]</use></cloudpos12_x>
<cloudpos12_y><use>/local-weather/cloud-shadows/cloudpos-y[11]</use></cloudpos12_y>
<cloudpos13_x><use>/local-weather/cloud-shadows/cloudpos-x[12]</use></cloudpos13_x>
<cloudpos13_y><use>/local-weather/cloud-shadows/cloudpos-y[12]</use></cloudpos13_y>
<cloudpos14_x><use>/local-weather/cloud-shadows/cloudpos-x[13]</use></cloudpos14_x>
<cloudpos14_y><use>/local-weather/cloud-shadows/cloudpos-y[13]</use></cloudpos14_y>
<cloudpos15_x><use>/local-weather/cloud-shadows/cloudpos-x[14]</use></cloudpos15_x>
<cloudpos15_y><use>/local-weather/cloud-shadows/cloudpos-y[14]</use></cloudpos15_y>
<cloudpos16_x><use>/local-weather/cloud-shadows/cloudpos-x[15]</use></cloudpos16_x>
<cloudpos16_y><use>/local-weather/cloud-shadows/cloudpos-y[15]</use></cloudpos16_y>
<cloudpos17_x><use>/local-weather/cloud-shadows/cloudpos-x[16]</use></cloudpos17_x>
<cloudpos17_y><use>/local-weather/cloud-shadows/cloudpos-y[16]</use></cloudpos17_y>
<cloudpos18_x><use>/local-weather/cloud-shadows/cloudpos-x[17]</use></cloudpos18_x>
<cloudpos18_y><use>/local-weather/cloud-shadows/cloudpos-y[17]</use></cloudpos18_y>
<cloudpos19_x><use>/local-weather/cloud-shadows/cloudpos-x[18]</use></cloudpos19_x>
<cloudpos19_y><use>/local-weather/cloud-shadows/cloudpos-y[18]</use></cloudpos19_y>
<cloudpos20_x><use>/local-weather/cloud-shadows/cloudpos-x[19]</use></cloudpos20_x>
<cloudpos20_y><use>/local-weather/cloud-shadows/cloudpos-y[19]</use></cloudpos20_y>
<cloudpos_n_x><use>/local-weather/cloud-shadows/nearest-cloudpos-x</use></cloudpos_n_x>
<cloudpos_n_y><use>/local-weather/cloud-shadows/nearest-cloudpos-y</use></cloudpos_n_y>
<cloud_shadow_flag><use>/local-weather/cloud-shadows/cloud-shadow-flag</use></cloud_shadow_flag>
<!-- BEGIN shadows include -->
<shadows_enabled>
<use>/sim/rendering/als/shadows/enabled</use>
</shadows_enabled>
<sun_atlas_size>
<use>/sim/rendering/als/shadows/sun-atlas-size</use>
</sun_atlas_size>
<shadows_enabled><use>/sim/rendering/als/shadows/enabled</use></shadows_enabled>
<sun_atlas_size><use>/sim/rendering/als/shadows/sun-atlas-size</use></sun_atlas_size>
<!-- END shadows include -->
</parameters>
<!-- put techniques at a "high" index to allow derived effects to
@ -363,6 +182,7 @@
<technique n="5">
<predicate>
<and>
<property>/sim/rendering/shaders/quality-level</property>
<or>
<less-equal>
<value type="float">2.0</value>
@ -377,7 +197,7 @@
</or>
</and>
</predicate>
<!--
<pass>
<lighting>true</lighting>
<material>
@ -388,87 +208,23 @@
<shininess><use>material/shininess</use></shininess>
<color-mode>ambient-and-diffuse</color-mode>
</material>
<blend><use>transparent</use></blend>
<alpha-test><use>transparent</use></alpha-test>
<shade-model>smooth</shade-model>
<cull-face>back</cull-face>
<render-bin>
<bin-number>-1</bin-number>
<bin-name>RenderBin</bin-name>
<bin-number><use>render-bin/bin-number</use></bin-number>
<bin-name><use>render-bin/bin-name</use></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>
<filter>nearest</filter>
<mag-filter>nearest</mag-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>
<program>
<vertex-shader n="0">Shaders/Default/include_fog.vert</vertex-shader>
<vertex-shader n="1">Shaders/Default/default.vert</vertex-shader>
<fragment-shader n="0">Shaders/Default/include_fog.frag</fragment-shader>
<fragment-shader n="1">Shaders/Default/terrain-nocolor.frag</fragment-shader>
</program>
<uniform>
<name>texture</name>
<type>sampler-2d</type>
<value type="int">0</value>
</uniform>
<color-mask type="vec4d">0 0 0 0</color-mask>
</pass> -->
<pass>
<lighting>true</lighting>
<material>
<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>ambient-and-diffuse</color-mode>
</material>
<blend>
<use>transparent</use>
</blend>
<alpha-test>
<use>transparent</use>
</alpha-test>
<shade-model>smooth</shade-model>
<cull-face>back</cull-face>
<render-bin>
<bin-number>
<use>render-bin/bin-number</use>
</bin-number>
<bin-name>
<use>render-bin/bin-name</use>
</bin-name>
</render-bin>
<texture-unit>
<unit>0</unit>
<image>
<use>texture[0]/image</use>
</image>
<filter>nearest</filter>
<mag-filter>nearest</mag-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>
<mipmap-control>
<r>max</r>
<g>max</g>
@ -478,82 +234,45 @@
<texture-unit>
<unit>1</unit>
<image>
<use>texture[1]/image</use>
</image>
<image><use>texture[1]/image</use></image>
<filter>nearest-mipmap-nearest</filter>
<mag-filter>nearest-mipmap-nearest</mag-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>
<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>
<texture-unit>
<unit>2</unit>
<image>
<use>texture[2]/image</use>
</image>
<filter>
<use>texture[2]/filter</use>
</filter>
<wrap-s>
<use>texture[2]/wrap-s</use>
</wrap-s>
<wrap-t>
<use>texture[2]/wrap-t</use>
</wrap-t>
<internal-format>
<use>texture[2]/internal-format</use>
</internal-format>
<image><use>texture[2]/image</use></image>
<filter><use>texture[2]/filter</use></filter>
<wrap-s><use>texture[2]/wrap-s</use></wrap-s>
<wrap-t><use>texture[2]/wrap-t</use></wrap-t>
<internal-format><use>texture[2]/internal-format</use></internal-format>
</texture-unit>
<texture-unit>
<unit>3</unit>
<image>
<use>texture[3]/image</use>
</image>
<filter>
<use>texture[3]/filter</use>
</filter>
<wrap-s>
<use>texture[3]/wrap-s</use>
</wrap-s>
<wrap-t>
<use>texture[3]/wrap-t</use>
</wrap-t>
<internal-format>
<use>texture[3]/internal-format</use>
</internal-format>
<image><use>texture[3]/image</use></image>
<filter><use>texture[3]/filter</use></filter>
<wrap-s><use>texture[3]/wrap-s</use></wrap-s>
<wrap-t><use>texture[3]/wrap-t</use></wrap-t>
<internal-format><use>texture[3]/internal-format</use></internal-format>
</texture-unit>
<texture-unit>
<unit>4</unit>
<image>
<use>texture[4]/image</use>
</image>
<filter>
<use>texture[4]/filter</use>
</filter>
<wrap-s>
<use>texture[4]/wrap-s</use>
</wrap-s>
<wrap-t>
<use>texture[4]/wrap-t</use>
</wrap-t>
<internal-format>
<use>texture[4]/internal-format</use>
</internal-format>
<image><use>texture[4]/image</use></image>
<filter><use>texture[4]/filter</use></filter>
<wrap-s><use>texture[4]/wrap-s</use></wrap-s>
<wrap-t><use>texture[4]/wrap-t</use></wrap-t>
<internal-format><use>texture[4]/internal-format</use></internal-format>
</texture-unit>
<program>
<vertex-shader>Shaders/ws30.vert</vertex-shader>
<vertex-shader>Shaders/ws30-ALS.vert</vertex-shader>
<vertex-shader>Shaders/shadows-include.vert</vertex-shader>
<fragment-shader>Shaders/ws30.frag</fragment-shader>
<fragment-shader>Shaders/ws30-ALS.frag</fragment-shader>
<fragment-shader>Shaders/hazes.frag</fragment-shader>
<fragment-shader>Shaders/noise.frag</fragment-shader>
<fragment-shader>Shaders/filters-ALS.frag</fragment-shader>
@ -562,157 +281,113 @@
<uniform>
<name>visibility</name>
<type>float</type>
<value>
<use>visibility</use>
</value>
<value><use>visibility</use></value>
</uniform>
<uniform>
<name>avisibility</name>
<type>float</type>
<value>
<use>avisibility</use>
</value>
<value><use>avisibility</use></value>
</uniform>
<uniform>
<name>hazeLayerAltitude</name>
<type>float</type>
<value>
<use>lthickness</use>
</value>
<value><use>lthickness</use></value>
</uniform>
<uniform>
<name>scattering</name>
<type>float</type>
<value>
<use>scattering</use>
</value>
<value><use>scattering</use></value>
</uniform>
<uniform>
<name>ground_scattering</name>
<type>float</type>
<value>
<use>ground_scattering</use>
</value>
<value><use>ground_scattering</use></value>
</uniform>
<uniform>
<name>terminator</name>
<type>float</type>
<value>
<use>terminator</use>
</value>
<value><use>terminator</use></value>
</uniform>
<uniform>
<name>terrain_alt</name>
<type>float</type>
<value>
<use>terrain_alt</use>
</value>
<value><use>terrain_alt</use></value>
</uniform>
<uniform>
<name>overcast</name>
<type>float</type>
<value>
<use>overcast</use>
</value>
<value><use>overcast</use></value>
</uniform>
<uniform>
<name>eye_alt</name>
<type>float</type>
<value>
<use>eye_alt</use>
</value>
<value><use>eye_alt</use></value>
</uniform>
<uniform>
<name>cloud_self_shading</name>
<type>float</type>
<value>
<use>cloud_self_shading</use>
</value>
<value><use>cloud_self_shading</use></value>
</uniform>
<uniform>
<name>moonlight</name>
<type>float</type>
<value>
<use>moonlight</use>
</value>
<value><use>moonlight</use></value>
</uniform>
<uniform>
<name>air_pollution</name>
<type>float</type>
<value>
<use>air_pollution</use>
</value>
<value><use>air_pollution</use></value>
</uniform>
<!-- filtering -->
<uniform>
<name>gamma</name>
<type>float</type>
<value>
<use>gamma</use>
</value>
<value><use>gamma</use></value>
</uniform>
<uniform>
<name>brightness</name>
<type>float</type>
<value>
<use>brightness</use>
</value>
<value><use>brightness</use></value>
</uniform>
<uniform>
<name>use_night_vision</name>
<type>bool</type>
<value>
<use>use_night_vision</use>
</value>
<value><use>use_night_vision</use></value>
</uniform>
<uniform>
<name>use_IR_vision</name>
<type>bool</type>
<value>
<use>use_IR_vision</use>
</value>
<value><use>use_IR_vision</use></value>
</uniform>
<uniform>
<name>use_filtering</name>
<type>bool</type>
<value>
<use>use_filtering</use>
</value>
<value><use>use_filtering</use></value>
</uniform>
<uniform>
<name>delta_T</name>
<type>float</type>
<value>
<use>delta_T</use>
</value>
<value><use>delta_T</use></value>
</uniform>
<uniform>
<name>fact_grey</name>
<type>float</type>
<value>
<use>fact_grey</use>
</value>
<value><use>fact_grey</use></value>
</uniform>
<uniform>
<name>fact_black</name>
<type>float</type>
<value>
<use>fact_black</use>
</value>
<value><use>fact_black</use></value>
</uniform>
<uniform>
<name>display_xsize</name>
<type>int</type>
<value>
<use>display_xsize</use>
</value>
<value><use>display_xsize</use></value>
</uniform>
<uniform>
<name>display_ysize</name>
<type>int</type>
<value>
<use>display_ysize</use>
</value>
<value><use>display_ysize</use></value>
</uniform>
<uniform>
<name>landclass</name>
@ -754,22 +429,127 @@
<uniform>
<name>shadows_enabled</name>
<type>bool</type>
<value>
<use>shadows_enabled</use>
</value>
<value><use>shadows_enabled</use></value>
</uniform>
<uniform>
<name>sun_atlas_size</name>
<type>int</type>
<value>
<use>sun_atlas_size</use>
</value>
<value><use>sun_atlas_size</use></value>
</uniform>
<!-- END shadows include -->
<depth>
<function>lequal</function>
<!-- <write-mask type="bool">false</write-mask> -->
<!-- <write-mask type="bool">false</write-mask> -->
</depth>
</pass>
</technique>
<!-- Minimal technique -->
<technique n="12">
<pass>
<lighting>true</lighting>
<material>
<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>ambient-and-diffuse</color-mode>
</material>
<blend><use>transparent</use></blend>
<alpha-test><use>transparent</use></alpha-test>
<shade-model>smooth</shade-model>
<cull-face>back</cull-face>
<render-bin>
<bin-number><use>render-bin/bin-number</use></bin-number>
<bin-name><use>render-bin/bin-name</use></bin-name>
</render-bin>
<texture-unit>
<unit>0</unit>
<image><use>texture[0]/image</use></image>
<filter>nearest</filter>
<mag-filter>nearest</mag-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>
<mipmap-control>
<r>max</r>
<g>max</g>
<b>max</b>
</mipmap-control>
</texture-unit>
<texture-unit>
<unit>1</unit>
<image><use>texture[1]/image</use></image>
<filter>nearest-mipmap-nearest</filter>
<mag-filter>nearest-mipmap-nearest</mag-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>
<texture-unit>
<unit>2</unit>
<image><use>texture[2]/image</use></image>
<filter><use>texture[2]/filter</use></filter>
<wrap-s><use>texture[2]/wrap-s</use></wrap-s>
<wrap-t><use>texture[2]/wrap-t</use></wrap-t>
<internal-format><use>texture[2]/internal-format</use></internal-format>
</texture-unit>
<texture-unit>
<unit>3</unit>
<image><use>texture[3]/image</use></image>
<filter><use>texture[3]/filter</use></filter>
<wrap-s><use>texture[3]/wrap-s</use></wrap-s>
<wrap-t><use>texture[3]/wrap-t</use></wrap-t>
<internal-format><use>texture[3]/internal-format</use></internal-format>
</texture-unit>
<texture-unit>
<unit>4</unit>
<image><use>texture[4]/image</use></image>
<filter><use>texture[4]/filter</use></filter>
<wrap-s><use>texture[4]/wrap-s</use></wrap-s>
<wrap-t><use>texture[4]/wrap-t</use></wrap-t>
<internal-format><use>texture[4]/internal-format</use></internal-format>
</texture-unit>
<program>
<vertex-shader>Shaders/ws30.vert</vertex-shader>
<fragment-shader n="0">Shaders/include_fog.frag</fragment-shader>
<fragment-shader n="1">Shaders/ws30.frag</fragment-shader>
</program>
<uniform>
<name>landclass</name>
<type>sampler-2d</type>
<value type="int">0</value>
</uniform>
<uniform>
<name>atlas</name>
<type>sampler-2d</type>
<value type="int">1</value>
</uniform>
<uniform>
<name>dimensionsArray</name>
<type>sampler-1d</type>
<value type="int">2</value>
</uniform>
<uniform>
<name>diffuseArray</name>
<type>sampler-1d</type>
<value type="int">3</value>
</uniform>
<uniform>
<name>specularArray</name>
<type>sampler-1d</type>
<value type="int">4</value>
</uniform>
</pass>
</technique>
</PropertyList>

273
Shaders/ws30-ALS.frag Normal file
View file

@ -0,0 +1,273 @@
// WS30 FRAGMENT SHADER
// -*-C++-*-
#version 130
#extension GL_EXT_texture_array : enable
// written by Thorsten Renk, Oct 2011, based on default.frag
// Ambient term comes in gl_Color.rgb.
varying vec4 diffuse_term;
varying vec3 normal;
varying vec3 relPos;
uniform sampler2D landclass;
uniform sampler2DArray atlas;
uniform sampler1D dimensionsArray;
uniform sampler1D diffuseArray;
uniform sampler1D specularArray;
varying float yprime_alt;
varying float mie_angle;
uniform float visibility;
uniform float avisibility;
uniform float scattering;
uniform float terminator;
uniform float terrain_alt;
uniform float hazeLayerAltitude;
uniform float overcast;
uniform float eye_alt;
uniform float cloud_self_shading;
// Passed from VPBTechnique, not the Effect
uniform int tile_level;
uniform float tile_width;
uniform float tile_height;
const float EarthRadius = 5800000.0;
const float terminator_width = 200000.0;
float alt;
float eShade;
float fog_func (in float targ, in float alt);
vec3 get_hazeColor(in float light_arg);
vec3 filter_combined (in vec3 color) ;
float getShadowing();
float luminance(vec3 color)
{
return dot(vec3(0.212671, 0.715160, 0.072169), color);
}
void main()
{
// The Landclass for this particular fragment. This can be used to
// index into the atlas textures.
int lc = int(texture2D(landclass, gl_TexCoord[0].st).g * 255.0 + 0.5);
vec3 shadedFogColor = vec3(0.55, 0.67, 0.88);
// this is taken from default.frag
vec3 n;
float NdotL, NdotHV, fogFactor;
vec3 lightDir = gl_LightSource[0].position.xyz;
vec3 halfVector = gl_LightSource[0].halfVector.xyz;
vec4 texel;
vec4 fragColor;
vec4 specular = vec4(0.0);
float intensity;
float mat_index = float(lc)/512.0;
float mat_shininess = texture(dimensionsArray, mat_index).z;
vec4 mat_diffuse = texture(diffuseArray, mat_index);
vec4 mat_specular = texture(specularArray, mat_index);
vec4 color = mat_diffuse;
float effective_scattering = min(scattering, cloud_self_shading);
vec4 light_specular = gl_LightSource[0].specular;
// If gl_Color.a == 0, this is a back-facing polygon and the
// normal should be reversed.
n = (2.0 * gl_Color.a - 1.0) * normal;
n = normalize(n);
NdotL = dot(n, lightDir);
if (NdotL > 0.0) {
float shadowmap = getShadowing();
color += diffuse_term * NdotL * shadowmap;
NdotHV = max(dot(n, halfVector), 0.0);
if (mat_shininess > 0.0)
specular.rgb = (mat_specular.rgb
* light_specular.rgb
* pow(NdotHV, gl_FrontMaterial.shininess)
* shadowmap);
}
color.a = diffuse_term.a;
// This shouldn't be necessary, but our lighting becomes very
// saturated. Clamping the color before modulating by the texture
// is closer to what the OpenGL fixed function pipeline does.
color = clamp(color, 0.0, 1.0);
// Different textures have different have different dimensions.
// Dimensions array is scaled to fit in [0...1.0] in the texture1D, so has to be scaled back up here.
vec2 atlas_dimensions = 10000.0 * texture(dimensionsArray, float(lc)/512.0).st;
vec2 atlas_scale = vec2(tile_width / atlas_dimensions.s, tile_height / atlas_dimensions.t );
texel = texture(atlas, vec3(atlas_scale * gl_TexCoord[0].st, lc));
fragColor = color * texel + specular;
// here comes the terrain haze model
float delta_z = hazeLayerAltitude - eye_alt;
float dist = length(relPos);
float mvisibility = min(visibility,avisibility);
if (dist > 0.04 * mvisibility)
{
alt = eye_alt;
float transmission;
float vAltitude;
float delta_zv;
float H;
float distance_in_layer;
float transmission_arg;
// angle with horizon
float ct = dot(vec3(0.0, 0.0, 1.0), relPos)/dist;
// we solve the geometry what part of the light path is attenuated normally and what is through the haze layer
if (delta_z > 0.0) // we're inside the layer
{
if (ct < 0.0) // we look down
{
distance_in_layer = dist;
vAltitude = min(distance_in_layer,mvisibility) * ct;
delta_zv = delta_z - vAltitude;
}
else // we may look through upper layer edge
{
H = dist * ct;
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;
}
}
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;
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
transmission_arg = (dist-distance_in_layer)/avisibility;
float eqColorFactor;
if (visibility < avisibility)
{
transmission_arg = transmission_arg + (distance_in_layer/visibility);
// this combines the Weber-Fechner intensity
eqColorFactor = 1.0 - 0.1 * delta_zv/visibility - (1.0 -effective_scattering);
}
else
{
transmission_arg = transmission_arg + (distance_in_layer/avisibility);
// this combines the Weber-Fechner intensity
eqColorFactor = 1.0 - 0.1 * delta_zv/avisibility - (1.0 -effective_scattering);
}
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;}
float lightArg = (terminator-yprime_alt)/100000.0;
vec3 hazeColor = get_hazeColor(lightArg);
// now dim the light for haze
eShade = 1.0 - 0.9 * smoothstep(-terminator_width+ terminator, terminator_width + terminator, yprime_alt);
// Mie-like factor
if (lightArg < 10.0)
{intensity = length(hazeColor);
float mie_magnitude = 0.5 * smoothstep(350000.0, 150000.0, terminator-sqrt(2.0 * EarthRadius * terrain_alt));
hazeColor = intensity * ((1.0 - mie_magnitude) + mie_magnitude * mie_angle) * normalize(mix(hazeColor, vec3 (0.5, 0.58, 0.65), mie_magnitude * (0.5 - 0.5 * mie_angle)) );
}
// high altitude desaturation of the haze color
intensity = length(hazeColor);
hazeColor = intensity * normalize (mix(hazeColor, intensity * vec3 (1.0,1.0,1.0), 0.7* smoothstep(5000.0, 50000.0, alt)));
// blue hue of haze
hazeColor.x = hazeColor.x * 0.83;
hazeColor.y = hazeColor.y * 0.9;
// additional blue in indirect light
float fade_out = max(0.65 - 0.3 *overcast, 0.45);
intensity = length(hazeColor);
hazeColor = intensity * normalize(mix(hazeColor, 1.5* shadedFogColor, 1.0 -smoothstep(0.25, fade_out,eShade) ));
// change haze color to blue hue for strong fogging
//intensity = length(hazeColor);
hazeColor = intensity * normalize(mix(hazeColor, shadedFogColor, (1.0-smoothstep(0.5,0.9,eqColorFactor))));
// reduce haze intensity when looking at shaded surfaces, only in terminator region
float shadow = mix( min(1.0 + dot(normal,lightDir),1.0), 1.0, 1.0-smoothstep(0.1, 0.4, transmission));
hazeColor = mix(shadow * hazeColor, hazeColor, 0.3 + 0.7* smoothstep(250000.0, 400000.0, terminator));
// don't let the light fade out too rapidly
lightArg = (terminator + 200000.0)/100000.0;
float minLightIntensity = min(0.2,0.16 * lightArg + 0.5);
vec3 minLight = minLightIntensity * vec3 (0.2, 0.3, 0.4);
hazeColor *= eqColorFactor * eShade;
hazeColor.rgb = max(hazeColor.rgb, minLight.rgb);
// determine the right mix of transmission and haze
fragColor.rgb = mix(hazeColor, fragColor.rgb,transmission);
}
fragColor.rgb = filter_combined(fragColor.rgb);
gl_FragColor = fragColor;
}

233
Shaders/ws30-ALS.vert Normal file
View file

@ -0,0 +1,233 @@
// WS30 VERTEX SHADER
// -*-C++-*-
#version 120
// Shader that uses OpenGL state values to do per-pixel lighting
//
// The only light used is gl_LightSource[0], which is assumed to be
// directional.
//
// Colors are not assigned in this shader, as they will come from
// the landclass lookup in the fragment shader.
// Haze part added by Thorsten Renk, Oct. 2011
#define MODE_OFF 0
#define MODE_DIFFUSE 1
#define MODE_AMBIENT_AND_DIFFUSE 2
attribute vec2 orthophotoTexCoord;
// The constant term of the lighting equation that doesn't depend on
// the surface normal is passed in gl_{Front,Back}Color. The alpha
// component is set to 1 for front, 0 for back in order to work around
// bugs with gl_FrontFacing in the fragment shader.
varying vec4 diffuse_term;
varying vec3 normal;
varying vec3 relPos;
varying vec2 orthoTexCoord;
varying float yprime_alt;
varying float mie_angle;
uniform int colorMode;
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 moonlight;
void setupShadows(vec4 eyeSpacePos);
// This is the value used in the skydome scattering shader - use the same here for consistency?
const float EarthRadius = 5800000.0;
const float terminator_width = 200000.0;
float earthShade;
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 < -15.0) {return 0.0;}
return e / pow((1.0 + a * exp(-b * (x-c)) ),(1.0/d));
}
void main()
{
vec4 light_diffuse;
vec4 light_ambient;
vec3 shadedFogColor = vec3(0.55, 0.67, 0.88);
vec3 moonLightColor = vec3 (0.095, 0.095, 0.15) * moonlight;
//float yprime_alt;
float yprime;
float lightArg;
float intensity;
float vertex_alt;
float scattering;
// this code is copied from default.vert
//vec4 ecPosition = gl_ModelViewMatrix * gl_Vertex;
gl_Position = ftransform();
gl_TexCoord[0] = gl_TextureMatrix[0] * gl_MultiTexCoord0;
orthoTexCoord = orthophotoTexCoord;
normal = gl_NormalMatrix * gl_Normal;
// here start computations for the haze layer
// we need several geometrical quantities
// first current altitude of eye position in model space
vec4 ep = gl_ModelViewMatrixInverse * vec4(0.0,0.0,0.0,1.0);
// and relative position to vector
relPos = gl_Vertex.xyz - ep.xyz;
// unfortunately, we need the distance in the vertex shader, although the more accurate version
// is later computed in the fragment shader again
float dist = length(relPos);
// altitude of the vertex in question, somehow zero leads to artefacts, so ensure it is at least 100m
vertex_alt = max(gl_Vertex.z,100.0);
scattering = ground_scattering + (1.0 - ground_scattering) * smoothstep(hazeLayerAltitude -100.0, hazeLayerAltitude + 100.0, vertex_alt);
// branch dependent on daytime
if (terminator < 1000000.0) // the full, sunrise and sunset computation
{
// establish coordinates relative to sun position
vec3 lightFull = (gl_ModelViewMatrixInverse * gl_LightSource[0].position).xyz;
vec3 lightHorizon = normalize(vec3(lightFull.x,lightFull.y, 0.0));
// yprime is the distance of the vertex into sun direction
yprime = -dot(relPos, lightHorizon);
// this gets an altitude correction, higher terrain gets to see the sun earlier
yprime_alt = yprime - sqrt(2.0 * EarthRadius * vertex_alt);
// two times terminator width governs how quickly light fades into shadow
// now the light-dimming factor
earthShade = 0.6 * (1.0 - smoothstep(-terminator_width+ terminator, terminator_width + terminator, yprime_alt)) + 0.4;
// parametrized version of the Flightgear ground lighting function
lightArg = (terminator-yprime_alt)/100000.0;
// directional scattering for low sun
if (lightArg < 10.0)
{mie_angle = (0.5 * dot(normalize(relPos), normalize(lightFull)) ) + 0.5;}
else
{mie_angle = 1.0;}
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;
light_ambient.r = light_func(lightArg, 0.236, 0.253, 1.073, 0.572, 0.33);
light_ambient.g = light_ambient.r * 0.4/0.33;
light_ambient.b = light_ambient.r * 0.5/0.33;
light_ambient.a = 1.0;
// correct ambient light intensity and hue before sunrise
if (earthShade < 0.5)
{
//light_ambient = light_ambient * (0.7 + 0.3 * smoothstep(0.2, 0.5, earthShade));
intensity = length(light_ambient.xyz);
light_ambient.rgb = intensity * normalize(mix(light_ambient.rgb, shadedFogColor, 1.0 -smoothstep(0.4, 0.8,earthShade) ));
light_ambient.rgb = light_ambient.rgb + moonLightColor * (1.0 - smoothstep(0.4, 0.5, earthShade));
intensity = length(light_diffuse.xyz);
light_diffuse.rgb = intensity * normalize(mix(light_diffuse.rgb, shadedFogColor, 1.0 -smoothstep(0.4, 0.7,earthShade) ));
}
// the haze gets the light at the altitude of the haze top if the vertex in view is below
// but the light at the vertex if the vertex is above
vertex_alt = max(vertex_alt,hazeLayerAltitude);
if (vertex_alt > hazeLayerAltitude)
{
if (dist > 0.8 * avisibility)
{
vertex_alt = mix(vertex_alt, hazeLayerAltitude, smoothstep(0.8*avisibility, avisibility, dist));
yprime_alt = yprime -sqrt(2.0 * EarthRadius * vertex_alt);
}
}
else
{
vertex_alt = hazeLayerAltitude;
yprime_alt = yprime -sqrt(2.0 * EarthRadius * vertex_alt);
}
}
else // the faster, full-day version without lightfields
{
//vertex_alt = max(gl_Vertex.z,100.0);
earthShade = 1.0;
mie_angle = 1.0;
if (terminator > 3000000.0)
{light_diffuse = vec4 (1.0, 1.0, 1.0, 0.0);
light_ambient = vec4 (0.33, 0.4, 0.5, 0.0); }
else
{
lightArg = (terminator/100000.0 - 10.0)/20.0;
light_diffuse.b = 0.78 + lightArg * 0.21;
light_diffuse.g = 0.907 + lightArg * 0.091;
light_diffuse.r = 0.904 + lightArg * 0.092;
light_diffuse.a = 1.0;
light_ambient.r = 0.316 + lightArg * 0.016;
light_ambient.g = light_ambient.r * 0.4/0.33;
light_ambient.b = light_ambient.r * 0.5/0.33;
light_ambient.a = 1.0;
}
light_diffuse = light_diffuse * scattering;
yprime_alt = -sqrt(2.0 * EarthRadius * hazeLayerAltitude);
}
// default lighting based on texture and material using the light we have just computed
diffuse_term = light_diffuse;
vec4 constant_term = (gl_LightModel.ambient + light_ambient);
// Another hack for supporting two-sided lighting without using
// gl_FrontFacing in the fragment shader.
gl_FrontColor.rgb = constant_term.rgb; gl_FrontColor.a = 1.0;
gl_BackColor.rgb = constant_term.rgb; gl_BackColor.a = 0.0;
setupShadows(gl_ModelViewMatrix * gl_Vertex);
}

View file

@ -4,11 +4,7 @@
#version 130
#extension GL_EXT_texture_array : enable
// written by Thorsten Renk, Oct 2011, based on default.frag
// Ambient term comes in gl_Color.rgb.
varying vec4 diffuse_term;
varying vec3 normal;
varying vec3 relPos;
uniform sampler2D landclass;
uniform sampler2DArray atlas;
@ -16,258 +12,42 @@ uniform sampler1D dimensionsArray;
uniform sampler1D diffuseArray;
uniform sampler1D specularArray;
varying float yprime_alt;
varying float mie_angle;
uniform float visibility;
uniform float avisibility;
uniform float scattering;
uniform float terminator;
uniform float terrain_alt;
uniform float hazeLayerAltitude;
uniform float overcast;
uniform float eye_alt;
uniform float cloud_self_shading;
// Passed from VPBTechnique, not the Effect
uniform int tile_level;
uniform float tile_width;
uniform float tile_height;
const float EarthRadius = 5800000.0;
const float terminator_width = 200000.0;
float alt;
float eShade;
float fog_func (in float targ, in float alt);
vec3 get_hazeColor(in float light_arg);
vec3 filter_combined (in vec3 color) ;
float getShadowing();
float luminance(vec3 color)
{
return dot(vec3(0.212671, 0.715160, 0.072169), color);
}
// See include_fog.frag
uniform int fogType;
vec3 fog_Func(vec3 color, int type);
void main()
{
vec3 lightDir = gl_LightSource[0].position.xyz;
vec3 halfVector = gl_LightSource[0].halfVector.xyz;
vec4 texel;
vec4 fragColor;
// The Landclass for this particular fragment. This can be used to
// index into the atlas textures.
int lc = int(texture2D(landclass, gl_TexCoord[0].st).g * 255.0 + 0.5);
vec3 shadedFogColor = vec3(0.55, 0.67, 0.88);
// this is taken from default.frag
vec3 n;
float NdotL, NdotHV, fogFactor;
vec3 lightDir = gl_LightSource[0].position.xyz;
vec3 halfVector = gl_LightSource[0].halfVector.xyz;
vec4 texel;
vec4 fragColor;
vec4 specular = vec4(0.0);
float intensity;
float mat_index = float(lc)/512.0;
float mat_shininess = texture(dimensionsArray, mat_index).z;
vec4 mat_diffuse = texture(diffuseArray, mat_index);
vec4 mat_specular = texture(specularArray, mat_index);
vec4 color = mat_diffuse;
float effective_scattering = min(scattering, cloud_self_shading);
vec4 light_specular = gl_LightSource[0].specular;
// If gl_Color.a == 0, this is a back-facing polygon and the
// normal should be reversed.
n = (2.0 * gl_Color.a - 1.0) * normal;
vec3 n = (2.0 * gl_Color.a - 1.0) * normal;
n = normalize(n);
NdotL = dot(n, lightDir);
if (NdotL > 0.0) {
float shadowmap = getShadowing();
color += diffuse_term * NdotL * shadowmap;
NdotHV = max(dot(n, halfVector), 0.0);
if (mat_shininess > 0.0)
specular.rgb = (mat_specular.rgb
* light_specular.rgb
* pow(NdotHV, gl_FrontMaterial.shininess)
* shadowmap);
}
color.a = diffuse_term.a;
// This shouldn't be necessary, but our lighting becomes very
// saturated. Clamping the color before modulating by the texture
// is closer to what the OpenGL fixed function pipeline does.
color = clamp(color, 0.0, 1.0);
float NdotL = dot(n, lightDir);
float NdotHV = max(dot(n, halfVector), 0.0);
// Different textures have different have different dimensions.
// Dimensions array is scaled to fit in [0...1.0] in the texture1D, so has to be scaled back up here.
vec4 color = texture(diffuseArray, float(lc)/512.0) * NdotL;
vec4 specular = texture(specularArray, float(lc)/512.0);
vec2 atlas_dimensions = 10000.0 * texture(dimensionsArray, float(lc)/512.0).st;
vec2 atlas_scale = vec2(tile_width / atlas_dimensions.s, tile_height / atlas_dimensions.t );
texel = texture(atlas, vec3(atlas_scale * gl_TexCoord[0].st, lc));
fragColor = color * texel + specular;
fragColor = texel + pow(NdotHV, gl_FrontMaterial.shininess) * gl_LightSource[0].specular * specular;
// here comes the terrain haze model
float delta_z = hazeLayerAltitude - eye_alt;
float dist = length(relPos);
float mvisibility = min(visibility,avisibility);
if (dist > 0.04 * mvisibility)
{
alt = eye_alt;
float transmission;
float vAltitude;
float delta_zv;
float H;
float distance_in_layer;
float transmission_arg;
// angle with horizon
float ct = dot(vec3(0.0, 0.0, 1.0), relPos)/dist;
// we solve the geometry what part of the light path is attenuated normally and what is through the haze layer
if (delta_z > 0.0) // we're inside the layer
{
if (ct < 0.0) // we look down
{
distance_in_layer = dist;
vAltitude = min(distance_in_layer,mvisibility) * ct;
delta_zv = delta_z - vAltitude;
}
else // we may look through upper layer edge
{
H = dist * ct;
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;
}
}
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;
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
transmission_arg = (dist-distance_in_layer)/avisibility;
float eqColorFactor;
if (visibility < avisibility)
{
transmission_arg = transmission_arg + (distance_in_layer/visibility);
// this combines the Weber-Fechner intensity
eqColorFactor = 1.0 - 0.1 * delta_zv/visibility - (1.0 -effective_scattering);
}
else
{
transmission_arg = transmission_arg + (distance_in_layer/avisibility);
// this combines the Weber-Fechner intensity
eqColorFactor = 1.0 - 0.1 * delta_zv/avisibility - (1.0 -effective_scattering);
}
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;}
float lightArg = (terminator-yprime_alt)/100000.0;
vec3 hazeColor = get_hazeColor(lightArg);
// now dim the light for haze
eShade = 1.0 - 0.9 * smoothstep(-terminator_width+ terminator, terminator_width + terminator, yprime_alt);
// Mie-like factor
if (lightArg < 10.0)
{intensity = length(hazeColor);
float mie_magnitude = 0.5 * smoothstep(350000.0, 150000.0, terminator-sqrt(2.0 * EarthRadius * terrain_alt));
hazeColor = intensity * ((1.0 - mie_magnitude) + mie_magnitude * mie_angle) * normalize(mix(hazeColor, vec3 (0.5, 0.58, 0.65), mie_magnitude * (0.5 - 0.5 * mie_angle)) );
}
// high altitude desaturation of the haze color
intensity = length(hazeColor);
hazeColor = intensity * normalize (mix(hazeColor, intensity * vec3 (1.0,1.0,1.0), 0.7* smoothstep(5000.0, 50000.0, alt)));
// blue hue of haze
hazeColor.x = hazeColor.x * 0.83;
hazeColor.y = hazeColor.y * 0.9;
// additional blue in indirect light
float fade_out = max(0.65 - 0.3 *overcast, 0.45);
intensity = length(hazeColor);
hazeColor = intensity * normalize(mix(hazeColor, 1.5* shadedFogColor, 1.0 -smoothstep(0.25, fade_out,eShade) ));
// change haze color to blue hue for strong fogging
//intensity = length(hazeColor);
hazeColor = intensity * normalize(mix(hazeColor, shadedFogColor, (1.0-smoothstep(0.5,0.9,eqColorFactor))));
// reduce haze intensity when looking at shaded surfaces, only in terminator region
float shadow = mix( min(1.0 + dot(normal,lightDir),1.0), 1.0, 1.0-smoothstep(0.1, 0.4, transmission));
hazeColor = mix(shadow * hazeColor, hazeColor, 0.3 + 0.7* smoothstep(250000.0, 400000.0, terminator));
// don't let the light fade out too rapidly
lightArg = (terminator + 200000.0)/100000.0;
float minLightIntensity = min(0.2,0.16 * lightArg + 0.5);
vec3 minLight = minLightIntensity * vec3 (0.2, 0.3, 0.4);
hazeColor *= eqColorFactor * eShade;
hazeColor.rgb = max(hazeColor.rgb, minLight.rgb);
// determine the right mix of transmission and haze
fragColor.rgb = mix(hazeColor, fragColor.rgb,transmission);
}
fragColor.rgb = filter_combined(fragColor.rgb);
gl_FragColor = fragColor;
fragColor.rgb = fog_Func(fragColor.rgb, fogType);
gl_FragColor = fragColor;
}

View file

@ -1,4 +1,4 @@
// WS30 VERTEX SHADER
// WS30 VERTEX SHADER. Very basic
// -*-C++-*-
#version 120
@ -9,223 +9,29 @@
//
// Colors are not assigned in this shader, as they will come from
// the landclass lookup in the fragment shader.
// Haze part added by Thorsten Renk, Oct. 2011
#define MODE_OFF 0
#define MODE_DIFFUSE 1
#define MODE_AMBIENT_AND_DIFFUSE 2
attribute vec2 orthophotoTexCoord;
// The constant term of the lighting equation that doesn't depend on
// the surface normal is passed in gl_{Front,Back}Color. The alpha
// component is set to 1 for front, 0 for back in order to work around
// bugs with gl_FrontFacing in the fragment shader.
varying vec4 diffuse_term;
varying vec3 normal;
varying vec3 relPos;
varying vec2 orthoTexCoord;
varying float yprime_alt;
varying float mie_angle;
uniform int colorMode;
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 moonlight;
void setupShadows(vec4 eyeSpacePos);
// This is the value used in the skydome scattering shader - use the same here for consistency?
const float EarthRadius = 5800000.0;
const float terminator_width = 200000.0;
float earthShade;
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 < -15.0) {return 0.0;}
return e / pow((1.0 + a * exp(-b * (x-c)) ),(1.0/d));
}
void main()
{
vec4 light_diffuse;
vec4 light_ambient;
vec3 shadedFogColor = vec3(0.55, 0.67, 0.88);
vec3 moonLightColor = vec3 (0.095, 0.095, 0.15) * moonlight;
//float yprime_alt;
float yprime;
float lightArg;
float intensity;
float vertex_alt;
float scattering;
// this code is copied from default.vert
//vec4 ecPosition = gl_ModelViewMatrix * gl_Vertex;
gl_Position = ftransform();
gl_TexCoord[0] = gl_TextureMatrix[0] * gl_MultiTexCoord0;
orthoTexCoord = orthophotoTexCoord;
normal = gl_NormalMatrix * gl_Normal;
// here start computations for the haze layer
// we need several geometrical quantities
// first current altitude of eye position in model space
vec4 ep = gl_ModelViewMatrixInverse * vec4(0.0,0.0,0.0,1.0);
// and relative position to vector
relPos = gl_Vertex.xyz - ep.xyz;
// unfortunately, we need the distance in the vertex shader, although the more accurate version
// is later computed in the fragment shader again
float dist = length(relPos);
// altitude of the vertex in question, somehow zero leads to artefacts, so ensure it is at least 100m
vertex_alt = max(gl_Vertex.z,100.0);
scattering = ground_scattering + (1.0 - ground_scattering) * smoothstep(hazeLayerAltitude -100.0, hazeLayerAltitude + 100.0, vertex_alt);
// branch dependent on daytime
if (terminator < 1000000.0) // the full, sunrise and sunset computation
{
// establish coordinates relative to sun position
vec3 lightFull = (gl_ModelViewMatrixInverse * gl_LightSource[0].position).xyz;
vec3 lightHorizon = normalize(vec3(lightFull.x,lightFull.y, 0.0));
// yprime is the distance of the vertex into sun direction
yprime = -dot(relPos, lightHorizon);
// this gets an altitude correction, higher terrain gets to see the sun earlier
yprime_alt = yprime - sqrt(2.0 * EarthRadius * vertex_alt);
// two times terminator width governs how quickly light fades into shadow
// now the light-dimming factor
earthShade = 0.6 * (1.0 - smoothstep(-terminator_width+ terminator, terminator_width + terminator, yprime_alt)) + 0.4;
// parametrized version of the Flightgear ground lighting function
lightArg = (terminator-yprime_alt)/100000.0;
// directional scattering for low sun
if (lightArg < 10.0)
{mie_angle = (0.5 * dot(normalize(relPos), normalize(lightFull)) ) + 0.5;}
else
{mie_angle = 1.0;}
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;
light_ambient.r = light_func(lightArg, 0.236, 0.253, 1.073, 0.572, 0.33);
light_ambient.g = light_ambient.r * 0.4/0.33;
light_ambient.b = light_ambient.r * 0.5/0.33;
light_ambient.a = 1.0;
// correct ambient light intensity and hue before sunrise
if (earthShade < 0.5)
{
//light_ambient = light_ambient * (0.7 + 0.3 * smoothstep(0.2, 0.5, earthShade));
intensity = length(light_ambient.xyz);
light_ambient.rgb = intensity * normalize(mix(light_ambient.rgb, shadedFogColor, 1.0 -smoothstep(0.4, 0.8,earthShade) ));
light_ambient.rgb = light_ambient.rgb + moonLightColor * (1.0 - smoothstep(0.4, 0.5, earthShade));
intensity = length(light_diffuse.xyz);
light_diffuse.rgb = intensity * normalize(mix(light_diffuse.rgb, shadedFogColor, 1.0 -smoothstep(0.4, 0.7,earthShade) ));
}
// the haze gets the light at the altitude of the haze top if the vertex in view is below
// but the light at the vertex if the vertex is above
vertex_alt = max(vertex_alt,hazeLayerAltitude);
if (vertex_alt > hazeLayerAltitude)
{
if (dist > 0.8 * avisibility)
{
vertex_alt = mix(vertex_alt, hazeLayerAltitude, smoothstep(0.8*avisibility, avisibility, dist));
yprime_alt = yprime -sqrt(2.0 * EarthRadius * vertex_alt);
}
}
else
{
vertex_alt = hazeLayerAltitude;
yprime_alt = yprime -sqrt(2.0 * EarthRadius * vertex_alt);
}
}
else // the faster, full-day version without lightfields
{
//vertex_alt = max(gl_Vertex.z,100.0);
earthShade = 1.0;
mie_angle = 1.0;
if (terminator > 3000000.0)
{light_diffuse = vec4 (1.0, 1.0, 1.0, 0.0);
light_ambient = vec4 (0.33, 0.4, 0.5, 0.0); }
else
{
lightArg = (terminator/100000.0 - 10.0)/20.0;
light_diffuse.b = 0.78 + lightArg * 0.21;
light_diffuse.g = 0.907 + lightArg * 0.091;
light_diffuse.r = 0.904 + lightArg * 0.092;
light_diffuse.a = 1.0;
light_ambient.r = 0.316 + lightArg * 0.016;
light_ambient.g = light_ambient.r * 0.4/0.33;
light_ambient.b = light_ambient.r * 0.5/0.33;
light_ambient.a = 1.0;
}
light_diffuse = light_diffuse * scattering;
yprime_alt = -sqrt(2.0 * EarthRadius * hazeLayerAltitude);
}
// default lighting based on texture and material using the light we have just computed
diffuse_term = light_diffuse;
vec4 constant_term = (gl_LightModel.ambient + light_ambient);
// Another hack for supporting two-sided lighting without using
// gl_FrontFacing in the fragment shader.
gl_FrontColor.rgb = constant_term.rgb; gl_FrontColor.a = 1.0;
gl_BackColor.rgb = constant_term.rgb; gl_BackColor.a = 0.0;
setupShadows(gl_ModelViewMatrix * gl_Vertex);
gl_FrontColor.a = 1.0;
gl_BackColor.a = 0.0;
}