1
0
Fork 0

ALS: Add display effect - dust overlay texture provided under GPL 2+ by Martin Litzenberger

This commit is contained in:
Thorsten Renk 2018-09-01 09:54:42 +03:00
parent a91bb4caa0
commit 7552c2921e
3 changed files with 1080 additions and 0 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.3 MiB

View file

@ -0,0 +1,717 @@
<?xml version="1.0" encoding="utf-8"?>
<PropertyList>
<name>Effects/model-interior-display</name>
<inherits-from>Effects/model-interior</inherits-from>
<parameters>
<texture n="5">
<type>2d</type>
<filter>linear-mipmap-linear</filter>
<wrap-s>clamp</wrap-s>
<wrap-t>clamp</wrap-t>
<internal-format>normalized</internal-format>
<image>Aircraft/Generic/Effects/dust-effect-overlay.png</image>
</texture>
<sample-res>0.0007</sample-res>
<dirt-factor>3.0</dirt-factor>
<contrast>1.0</contrast>
</parameters>
<technique n="2">
<predicate>
<and>
<property>/sim/rendering/shaders/skydome</property>
<less-equal>
<value type="float">2.0</value>
<float-property>/sim/rendering/shaders/model</float-property>
</less-equal>
<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>
<rendering-hint><use>rendering-hint</use></rendering-hint>
<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>
<wrap-s><use>texture[0]/wrap-s</use></wrap-s>
<wrap-t><use>texture[0]/wrap-t</use></wrap-t>
</texture-unit>
<texture-unit>
<unit>3</unit>
<type><use>texture[3]/type</use></type>
<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>
</texture-unit>
<texture-unit>
<unit>4</unit>
<type><use>texture[4]/type</use></type>
<images><use>texture[4]/images</use></images>
</texture-unit>
<texture-unit>
<unit>5</unit>
<type><use>texture[5]/type</use></type>
<image><use>texture[5]/image</use></image>
<filter><use>texture[5]/filter</use></filter>
<wrap-s><use>texture[5]/wrap-s</use></wrap-s>
<wrap-t><use>texture[5]/wrap-t</use></wrap-t>
</texture-unit>
<texture-unit>
<unit>7</unit>
<type><use>texture[7]/type</use></type>
<image><use>texture[7]/image</use></image>
<filter><use>texture[7]/filter</use></filter>
<wrap-s><use>texture[7]/wrap-s</use></wrap-s>
<wrap-t><use>texture[7]/wrap-t</use></wrap-t>
</texture-unit>
<vertex-program-two-side>
<use>vertex-program-two-side</use>
</vertex-program-two-side>
<program>
<vertex-shader>Shaders/model-interior-ALS-detailed.vert</vertex-shader>
<fragment-shader>Shaders/model-interior-display-ALS.frag</fragment-shader>
<fragment-shader>Shaders/secondary_lights.frag</fragment-shader>
<fragment-shader>Shaders/noise.frag</fragment-shader>
<fragment-shader>Shaders/filters-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>offset_vec</name>
<type>float-vec3</type>
<value><use>opacity-cube-center</use></value>
</uniform>
<uniform>
<name>scale_vec</name>
<type>float-vec3</type>
<value><use>opacity-cube-scale</use></value>
</uniform>
<uniform>
<name>angle</name>
<type>float</type>
<value><use>opacity-cube-angle</use></value>
</uniform>
<uniform>
<name>tag_color</name>
<type>float-vec3</type>
<value><use>implicit-lightmap-tag-color</use></value>
</uniform>
<uniform>
<name>emit_color</name>
<type>float-vec3</type>
<value><use>implicit-lightmap-emit-color</use></value>
</uniform>
<uniform>
<name>light_filter_one</name>
<type>float-vec3</type>
<value><use>light-filter-one</use></value>
</uniform>
<uniform>
<name>light_filter_two</name>
<type>float-vec3</type>
<value><use>light-filter-two</use></value>
</uniform>
<uniform>
<name>light_radius</name>
<type>float</type>
<value><use>light-radius</use></value>
</uniform>
<uniform>
<name>threshold_low</name>
<type>float</type>
<value><use>implicit-lightmap-threshold-low</use></value>
</uniform>
<uniform>
<name>threshold_high</name>
<type>float</type>
<value><use>implicit-lightmap-threshold-high</use></value>
</uniform>
<uniform>
<name>emit_intensity</name>
<type>float</type>
<value><use>implicit-lightmap-intensity</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>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>
<uniform>
<name>lightmap_r_factor</name>
<type>float</type>
<value><use>lightmap-factor[0]</use></value>
</uniform>
<uniform>
<name>lightmap_r_color</name>
<type>float-vec3</type>
<value><use>lightmap-color[0]</use></value>
</uniform>
<uniform>
<name>lightmap_g_factor</name>
<type>float</type>
<value><use>lightmap-factor[1]</use></value>
</uniform>
<uniform>
<name>lightmap_g_color</name>
<type>float-vec3</type>
<value><use>lightmap-color[1]</use></value>
</uniform>
<uniform>
<name>lightmap_b_factor</name>
<type>float</type>
<value><use>lightmap-factor[2]</use></value>
</uniform>
<uniform>
<name>lightmap_b_color</name>
<type>float-vec3</type>
<value><use>lightmap-color[2]</use></value>
</uniform>
<uniform>
<name>lightmap_a_factor</name>
<type>float</type>
<value><use>lightmap-factor[3]</use></value>
</uniform>
<uniform>
<name>lightmap_a_color</name>
<type>float-vec3</type>
<value><use>lightmap-color[3]</use></value>
</uniform>
<uniform>
<name>grain_magnification</name>
<type>float</type>
<value><use>grain-magnification</use></value>
</uniform>
<uniform>
<name>irradiance_map_strength</name>
<type>float</type>
<value><use>irradiance-map-strength</use></value>
</uniform>
<uniform>
<name>ra_irradiance_map_strength</name>
<type>float</type>
<value><use>ra-irradiance-map-strength</use></value>
</uniform>
<uniform>
<name>residual_ambience_r</name>
<type>float</type>
<value><use>residual-ambience-r</use></value>
</uniform>
<uniform>
<name>residual_ambience_g</name>
<type>float</type>
<value><use>residual-ambience-g</use></value>
</uniform>
<uniform>
<name>residual_ambience_b</name>
<type>float</type>
<value><use>residual-ambience-b</use></value>
</uniform>
<uniform>
<name>sample_res</name>
<type>float</type>
<value><use>sample-res</use></value>
</uniform>
<uniform>
<name>dirt_factor</name>
<type>float</type>
<value><use>dirt-factor</use></value>
</uniform>
<uniform>
<name>contrast</name>
<type>float</type>
<value><use>contrast</use></value>
</uniform>
<!-- filtering -->
<uniform>
<name>gamma</name>
<type>float</type>
<value><use>gamma</use></value>
</uniform>
<uniform>
<name>brightness</name>
<type>float</type>
<value><use>brightness</use></value>
</uniform>
<uniform>
<name>use_filtering</name>
<type>bool</type>
<value><use>use_filtering</use></value>
</uniform>
<uniform>
<name>use_night_vision</name>
<type>bool</type>
<value><use>use_night_vision</use></value>
</uniform>
<uniform>
<name>use_IR_vision</name>
<type>bool</type>
<value><use>use_IR_vision</use></value>
</uniform>
<uniform>
<name>delta_T</name>
<type>float</type>
<value><use>delta_T</use></value>
</uniform>
<uniform>
<name>texture</name>
<type>sampler-2d</type>
<value type="int">0</value>
</uniform>
<uniform>
<name>lightmap_texture</name>
<type>sampler-2d</type>
<value type="int">3</value>
</uniform>
<uniform>
<name>cube_texture</name>
<type>sampler-cube</type>
<value type="int">4</value>
</uniform>
<uniform>
<name>dust_texture</name>
<type>sampler-2d</type>
<value type="int">5</value>
</uniform>
<uniform>
<name>grain_texture</name>
<type>sampler-2d</type>
<value type="int">7</value>
</uniform>
<uniform>
<name>colorMode</name>
<type>int</type>
<value><use>material/color-mode-uniform</use></value>
</uniform>
<uniform>
<name>quality_level</name>
<type>int</type>
<value><use>quality_level</use></value>
</uniform>
<uniform>
<name>tquality_level</name>
<type>int</type>
<value><use>tquality_level</use></value>
</uniform>
<uniform>
<name>implicit_lightmap_enabled</name>
<type>int</type>
<value><use>implicit-lightmap-enabled</use></value>
</uniform>
<uniform>
<name>use_flashlight</name>
<type>int</type>
<value><use>use-flashlight</use></value>
</uniform>
<uniform>
<name>lightmap_enabled</name>
<type>int</type>
<value><use>lightmap-enabled</use></value>
</uniform>
<uniform>
<name>lightmap_multi</name>
<type>int</type>
<value><use>lightmap-multi</use></value>
</uniform>
<uniform>
<name>irradiance_map_type</name>
<type>int</type>
<value><use>irradiance-map-type</use></value>
</uniform>
<uniform>
<name>ra_irradiance_map_type</name>
<type>int</type>
<value><use>ra-irradiance-map-type</use></value>
</uniform>
<uniform>
<name>grain_texture_enabled</name>
<type>int</type>
<value><use>grain-texture-enabled</use></value>
</uniform>
</pass>
</technique>
<!-- <technique n="4">
<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>
<rendering-hint><use>rendering-hint</use></rendering-hint>
<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>
<wrap-s><use>texture[0]/wrap-s</use></wrap-s>
<wrap-t><use>texture[0]/wrap-t</use></wrap-t>
</texture-unit>
<texture-unit>
<unit>4</unit>
<type><use>texture[4]/type</use></type>
<images><use>texture[4]/images</use></images>
</texture-unit>
<vertex-program-two-side>
<use>vertex-program-two-side</use>
</vertex-program-two-side>
<program>
<vertex-shader>Shaders/generic-ALS-base.vert</vertex-shader>
<fragment-shader>Shaders/model-interior-ALS-base.frag</fragment-shader>
<fragment-shader>Shaders/hazes.frag</fragment-shader>
<fragment-shader>Shaders/secondary_lights.frag</fragment-shader>
<fragment-shader>Shaders/noise.frag</fragment-shader>
<fragment-shader>Shaders/filters-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>offset_vec</name>
<type>float-vec3</type>
<value><use>opacity-cube-center</use></value>
</uniform>
<uniform>
<name>scale_vec</name>
<type>float-vec3</type>
<value><use>opacity-cube-scale</use></value>
</uniform>
<uniform>
<name>angle</name>
<type>float</type>
<value><use>opacity-cube-angle</use></value>
</uniform>
<uniform>
<name>tag_color</name>
<type>float-vec3</type>
<value><use>implicit-lightmap-tag-color</use></value>
</uniform>
<uniform>
<name>emit_color</name>
<type>float-vec3</type>
<value><use>implicit-lightmap-emit-color</use></value>
</uniform>
<uniform>
<name>light_filter_one</name>
<type>float-vec3</type>
<value><use>light-filter-one</use></value>
</uniform>
<uniform>
<name>light_filter_two</name>
<type>float-vec3</type>
<value><use>light-filter-two</use></value>
</uniform>
<uniform>
<name>light_radius</name>
<type>float</type>
<value><use>light-radius</use></value>
</uniform>
<uniform>
<name>threshold_low</name>
<type>float</type>
<value><use>implicit-lightmap-threshold-low</use></value>
</uniform>
<uniform>
<name>threshold_high</name>
<type>float</type>
<value><use>implicit-lightmap-threshold-high</use></value>
</uniform>
<uniform>
<name>emit_intensity</name>
<type>float</type>
<value><use>implicit-lightmap-intensity</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>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> -->
<!-- filtering -->
<!--<uniform>
<name>gamma</name>
<type>float</type>
<value><use>gamma</use></value>
</uniform>
<uniform>
<name>brightness</name>
<type>float</type>
<value><use>brightness</use></value>
</uniform>
<uniform>
<name>use_filtering</name>
<type>bool</type>
<value><use>use_filtering</use></value>
</uniform>
<uniform>
<name>use_night_vision</name>
<type>bool</type>
<value><use>use_night_vision</use></value>
</uniform>
<uniform>
<name>use_IR_vision</name>
<type>bool</type>
<value><use>use_IR_vision</use></value>
</uniform>
<uniform>
<name>delta_T</name>
<type>float</type>
<value><use>delta_T</use></value>
</uniform>
<uniform>
<name>texture</name>
<type>sampler-2d</type>
<value type="int">0</value>
</uniform>
<uniform>
<name>cube_texture</name>
<type>sampler-cube</type>
<value type="int">4</value>
</uniform>
<uniform>
<name>colorMode</name>
<type>int</type>
<value><use>material/color-mode-uniform</use></value>
</uniform>
<uniform>
<name>quality_level</name>
<type>int</type>
<value><use>quality_level</use></value>
</uniform>
<uniform>
<name>tquality_level</name>
<type>int</type>
<value><use>tquality_level</use></value>
</uniform>
<uniform>
<name>implicit_lightmap_enabled</name>
<type>int</type>
<value><use>implicit-lightmap-enabled</use></value>
</uniform>
<uniform>
<name>use_flashlight</name>
<type>int</type>
<value><use>use-flashlight</use></value>
</uniform>
</pass>
</technique>-->
</PropertyList>

View file

@ -0,0 +1,363 @@
// -*-C++-*-
#version 120
// written by Thorsten Renk, Oct 2017
varying vec4 diffuse_term;
varying vec3 normal;
varying vec3 relPos;
uniform sampler2D texture;
uniform sampler2D dust_texture;
uniform sampler2D lightmap_texture;
uniform sampler2D grain_texture;
uniform samplerCube cube_texture;
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;
uniform float angle;
uniform float threshold_low;
uniform float threshold_high;
uniform float emit_intensity;
uniform float light_radius;
uniform float dirt_factor;
uniform float lightmap_r_factor;
uniform float lightmap_g_factor;
uniform float lightmap_b_factor;
uniform float lightmap_a_factor;
uniform float grain_magnification;
uniform float sample_res;
uniform float contrast;
uniform vec3 offset_vec;
uniform vec3 scale_vec;
uniform vec3 tag_color;
uniform vec3 emit_color;
uniform vec3 light_filter_one;
uniform vec3 light_filter_two;
uniform vec3 lightmap_r_color;
uniform vec3 lightmap_g_color;
uniform vec3 lightmap_b_color;
uniform vec3 lightmap_a_color;
uniform int quality_level;
uniform int tquality_level;
uniform int use_searchlight;
uniform int implicit_lightmap_enabled;
uniform int use_flashlight;
uniform int lightmap_enabled;
uniform int lightmap_multi;
uniform int grain_texture_enabled;
const float EarthRadius = 5800000.0;
const float terminator_width = 200000.0;
float alt;
float eShade;
float fog_func (in float targ, in float 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 addLights(in vec3 color1, in vec3 color2);
vec3 flashlight(in vec3 color, in float radius);
vec3 filter_combined (in vec3 color) ;
float luminance(vec3 color)
{
return dot(vec3(0.212671, 0.715160, 0.072169), color);
}
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 > 30.0) {return e;}
if (x < -15.0) {return 0.0;}
return e / pow((1.0 + a * exp(-b * (x-c)) ),(1.0/d));
}
// bloom effect on the display texture
vec4 find_max (in vec4 texel1, in vec4 texel2, in vec4 texel3, in vec4 texel4)
{
float r = max(texel1.r, texel2.r);
r = max(r, texel3.r);
r = max(r, texel4.r);
float g = max(texel1.g, texel2.g);
g = max(g, texel3.g);
g = max(g, texel4.g);
float b = max(texel1.b, texel2.b);
b = max(b, texel3.b);
b = max(b, texel4.b);
float a = max(texel1.a, texel2.a);
a = max(a, texel3.a);
a = max(a, texel4.a);
//float a = (texel1.a + texel2.a + texel3.a + texel4.a)/4.0;
return vec4 (r,g,b,a);
}
vec4 get_blurred_texel (in vec4 direct_light)
{
float fade0 = smoothstep(0.5, 1.0,contrast);
float fade1 = 0.25 * contrast * contrast;
float fade2 = 0.25 * contrast * contrast;
//fade0 = 1.0;
//fade1 = 1.0;
//fade2 = 1.0;
float desaturation_brightness = 1.0;
float sample_far = 2.0;
float curr_sample_res = sample_res * contrast;
vec4 texel = texture2D(texture, gl_TexCoord[0].st);
vec4 texel1 = texture2D(texture, vec2 (gl_TexCoord[0].s + curr_sample_res, gl_TexCoord[0].t));
vec4 texel2 = texture2D(texture, vec2 (gl_TexCoord[0].s - curr_sample_res, gl_TexCoord[0].t));
vec4 texel3 = texture2D(texture, vec2 (gl_TexCoord[0].s, gl_TexCoord[0].t + curr_sample_res));
vec4 texel4 = texture2D(texture, vec2 (gl_TexCoord[0].s, gl_TexCoord[0].t - curr_sample_res));
vec4 sample_texel = find_max (texel1, texel2, texel3, texel4);
texel.rgb += fade0 * sample_texel.rgb;
texel1 = texture2D(texture, vec2 (gl_TexCoord[0].s + sample_far * curr_sample_res, gl_TexCoord[0].t+ sample_far * curr_sample_res));
texel2 = texture2D(texture, vec2 (gl_TexCoord[0].s - sample_far * curr_sample_res, gl_TexCoord[0].t+ sample_far * curr_sample_res));
texel3 = texture2D(texture, vec2 (gl_TexCoord[0].s + sample_far * curr_sample_res, gl_TexCoord[0].t- sample_far * curr_sample_res));
texel4 = texture2D(texture, vec2 (gl_TexCoord[0].s - sample_far * curr_sample_res, gl_TexCoord[0].t- sample_far * curr_sample_res));
sample_texel = find_max (texel1, texel2, texel3, texel4);
texel.rgb += fade1 * sample_texel.rgb;
texel1 = texture2D(texture, vec2 (gl_TexCoord[0].s + 2.0 * sample_far * curr_sample_res, gl_TexCoord[0].t - curr_sample_res));
texel2 = texture2D(texture, vec2 (gl_TexCoord[0].s - 2.0 * sample_far * curr_sample_res, gl_TexCoord[0].t + curr_sample_res));
texel3 = texture2D(texture, vec2 (gl_TexCoord[0].s - curr_sample_res, gl_TexCoord[0].t + 2.0 * sample_far * curr_sample_res));
texel4 = texture2D(texture, vec2 (gl_TexCoord[0].s + curr_sample_res, gl_TexCoord[0].t - 2.0 * sample_far * curr_sample_res));
sample_texel = find_max (texel1, texel2, texel3, texel4);
texel.rgb += fade2 * sample_texel.rgb;
texel1 = texture2D(texture, vec2 (gl_TexCoord[0].s + 2.5 * sample_far * curr_sample_res, gl_TexCoord[0].t + 2.5 * sample_far * curr_sample_res));
texel2 = texture2D(texture, vec2 (gl_TexCoord[0].s - 2.5 * sample_far * curr_sample_res, gl_TexCoord[0].t + 2.5 * sample_far * curr_sample_res));
texel3 = texture2D(texture, vec2 (gl_TexCoord[0].s + 2.5 * sample_far * curr_sample_res, gl_TexCoord[0].t - 2.5 * sample_far * curr_sample_res));
texel4 = texture2D(texture, vec2 (gl_TexCoord[0].s - 2.5 * sample_far * curr_sample_res, gl_TexCoord[0].t - 2.5 * sample_far * curr_sample_res));
sample_texel = find_max (texel1, texel2, texel3, texel4);
texel.rgb += fade2 * sample_texel.rgb;
texel.rgb/= (1.0 + 1.0 * fade0 + 1.0 * fade1 + 2.0 * fade2);
texel.a = smoothstep(0.0, 0.1, length(texel.rgb));
texel.a *= (1.0 - 0.9 * smoothstep(0.0, 1.0, length(direct_light.rgb)/1.73 * 4.0 *( 0.5 - contrast)) );
float threshold_high = max(desaturation_brightness, 0.05) * 1.0;
float threshold_mid = max(desaturation_brightness, 0.05) * 0.6;
float pixel_brightness = max(texel.r, texel.g);
pixel_brightness = max(pixel_brightness, texel.b);
pixel_brightness *= contrast;
texel.rgb = mix(texel.rgb, vec3 (1.0, 1.0, 1.0), 0.9 * smoothstep(threshold_mid, threshold_high, pixel_brightness));
return texel;
}
void main()
{
vec3 shadedFogColor = vec3(0.55, 0.67, 0.88);
// this is taken from default.frag
vec3 n;
float NdotL, NdotHV, fogFactor;
vec4 color = gl_Color;
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 effective_scattering = min(scattering, cloud_self_shading);
eShade = 1.0 - 0.9 * smoothstep(-terminator_width+ terminator, terminator_width + terminator, yprime_alt);
vec4 light_specular = gl_LightSource[0].specular * (eShade - 0.1);
// 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);
// lookup on the opacity map
vec3 light_vec = normalize((gl_ModelViewMatrixInverse * gl_LightSource[0].position).xyz);
//vec3 light_vec = vec3 (-1.0,0.0,0.0);
vec4 ep = gl_ModelViewMatrixInverse * vec4(0.0,0.0,0.0,1.0);
vec3 scaled_pos = relPos + ep.xyz;
//vec3 lookup_vec = normalize(- normalize(light_vec) + relPos);
scaled_pos -= offset_vec;
float rangle = radians(angle);
mat2 rotMat = mat2 (cos(rangle), -sin(rangle), sin(rangle), cos(rangle));
scaled_pos.xy *=rotMat;
scaled_pos /= scale_vec;
//vec3 lookup_pos = dot(base1,scaled_pos) * base1 + dot(base2,scaled_pos) * base2;
vec3 lookup_pos = scaled_pos - light_vec * dot(light_vec, scaled_pos);
vec3 lookup_vec = normalize(normalize(light_vec) + lookup_pos);
vec4 opacity = textureCube(cube_texture, lookup_vec);
vec4 diffuse = diffuse_term;
NdotL = dot(n, lightDir);
//NdotL = dot(n, (gl_ModelViewMatrix * vec4 (light_vec,0.0)).xyz);
if (NdotL > 0.0) {
diffuse.rgb += 2.0 * diffuse.rgb * (1.0 - opacity.a);
color += diffuse * NdotL * opacity;
NdotHV = max(dot(n, halfVector), 0.0);
if (gl_FrontMaterial.shininess > 0.0)
specular.rgb = (gl_FrontMaterial.specular.rgb
* light_specular.rgb
* pow(NdotHV, gl_FrontMaterial.shininess));
}
color.a = diffuse.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);
vec3 secondary_light = vec3 (0.0,0.0,0.0);
if (use_flashlight == 1)
{
secondary_light.rgb += flashlight(light_filter_one, light_radius);
}
if (use_flashlight == 2)
{
secondary_light.rgb += flashlight(light_filter_two, light_radius);
}
float dist = length(relPos);
color.rgb += secondary_light * light_distance_fading(dist);
//texel = texture2D(texture, gl_TexCoord[0].st);
texel = get_blurred_texel(diffuse * max(0.0, NdotL) * opacity);
if (grain_texture_enabled ==1)
{
vec4 grainTexel = texture2D(grain_texture, gl_TexCoord[0].st * grain_magnification);
texel.rgb = mix(texel.rgb, grainTexel.rgb, grainTexel.a );
}
fragColor = color * texel + specular;
// explicit lightmap
vec3 lightmapcolor = vec3(0.0, 0.0, 0.0);
if (lightmap_enabled == 1)
{
vec4 lightmapTexel = texture2D(lightmap_texture, gl_TexCoord[0].st);
vec4 lightmapFactor = vec4(lightmap_r_factor, lightmap_g_factor, lightmap_b_factor, lightmap_a_factor);
lightmapFactor = lightmapFactor * lightmapTexel;
if (lightmap_multi > 0 )
{
lightmapcolor = lightmap_r_color * lightmapFactor.r;
lightmapcolor = addLights(lightmapcolor, lightmap_g_color * lightmapFactor.g);
lightmapcolor = addLights(lightmapcolor, lightmap_b_color * lightmapFactor.b);
lightmapcolor = addLights(lightmapcolor, lightmap_a_color * lightmapFactor.a);
}
else
{
lightmapcolor = lightmapTexel.rgb * lightmap_r_color * lightmapFactor.r;
}
// implicit lightmap - the user gets to select a color which is then made emissive
if (implicit_lightmap_enabled == 1)
{
float cdiff = (length(texel.rgb - tag_color));
float enhance = 1.0 - smoothstep(threshold_low, threshold_high, cdiff);
enhance *= (1.0 - length(lightmapcolor.rgb)/1.73);
fragColor.rgb = fragColor.rgb + enhance * emit_color * emit_intensity;
}
fragColor.rgb = max(fragColor.rgb, lightmapcolor.rgb * gl_FrontMaterial.diffuse.rgb * smoothstep(0.0, 1.0, texel.rgb*.5 + lightmapcolor.rgb*.5));
}
// add visible dust for glancing sun angle
vec4 dustTexel = texture2D(dust_texture, gl_TexCoord[0].st);
dustTexel.rgb *= diffuse.rgb;
dustTexel.a = clamp(dustTexel.a * dirt_factor * (1.0 - 0.4 * max(0.0,NdotL)) * (length(opacity.rgb)/1.76),0.0,1.0);
fragColor.rgb = mix(fragColor.rgb, dustTexel.rgb, dustTexel.a );
fragColor.a = max(fragColor.a, dustTexel.a);
fragColor.rgb = filter_combined(fragColor.rgb);
gl_FragColor = fragColor;
}