1
0
Fork 0

Model ubershader for Atmospheric Light Scattering

This commit is contained in:
Thorsten Renk 2013-01-31 14:15:18 +02:00
parent db546a6fd6
commit 9c95d09f60
6 changed files with 1228 additions and 4 deletions

View file

@ -98,6 +98,91 @@
<fogstructure><use>/environment/fog-structure</use></fogstructure>
<!-- END fog include -->
</parameters>
<!-- Atmospheric scattering technique with model shader-->
<technique n="4">
<predicate>
<and>
<property>/sim/rendering/shaders/skydome</property>
<property>/sim/rendering/shaders/quality-level</property>
<property>/sim/rendering/shaders/model</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>
<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>
<alpha-test>false</alpha-test>
<shade-model>flat</shade-model>
<cull-face>back</cull-face>
<render-bin>
<bin-number>-1</bin-number>
<bin-name>RenderBin</bin-name>
</render-bin>
<texture-unit>
<unit>0</unit>
<image><use>texture[0]/image</use></image>
<filter><use>texture[0]/filter</use></filter>
<wrap-s><use>texture[0]/wrap-s</use></wrap-s>
<wrap-t><use>texture[0]/wrap-t</use></wrap-t>
<internal-format>
<use>texture[0]/internal-format</use>
</internal-format>
</texture-unit>
<program>
<vertex-shader>Shaders/building-default.vert</vertex-shader>
<fragment-shader>Shaders/trivial.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>
<texture-unit n="4">
<unit>4</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>
<program>
<vertex-shader n="1">Shaders/building-ubershader.vert</vertex-shader>
<fragment-shader n="1">Shaders/ubershader-lightfield.frag</fragment-shader>
</program>
</pass>
</technique>
<!-- Atmospheric scattering technique -->
<technique n="5">

View file

@ -151,7 +151,659 @@ please see Docs/README.model-combined.eff for documentation
<binormal type="int">7</binormal>
</generate>-->
<technique n="4">
<predicate>
<and>
<property>/sim/rendering/shaders/skydome</property>
<property>/sim/rendering/shaders/quality-level</property>
<property>/sim/rendering/shaders/model</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>
<blend>
<use>transparent</use>
</blend>
<alpha-test>
<use>transparent</use>
</alpha-test>
<render-bin>
<bin-number>
<use>render-bin/bin-number</use>
</bin-number>
<bin-name>
<use>render-bin/bin-name</use>
</bin-name>
</render-bin>
<!-- Diffuse texture unit-->
<texture-unit>
<unit>0</unit>
<image>
<use>texture[0]/image</use>
</image>
<filter>
<use>texture[0]/filter</use>
</filter>
<wrap-s>
<use>texture[0]/wrap-s</use>
</wrap-s>
<wrap-t>
<use>texture[0]/wrap-t</use>
</wrap-t>
<internal-format>
<use>texture[0]/internal-format</use>
</internal-format>
</texture-unit>
<!-- Reflection Noise texture unit-->
<texture-unit>
<unit>1</unit>
<type>noise</type>
</texture-unit>
<!-- NormalMap 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>
<!-- LightMap 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>
<!-- ReflectMap 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>
<!-- Reflection CubeMap texture unit-->
<texture-unit>
<unit>5</unit>
<type>
<use>texture[5]/type</use>
</type>
<!-- use this form for a cube cross -->
<!--<image>
<use>texture[5]/image</use>
</image>-->
<!-- END CubeCross -->
<!-- use this form for a 6 image cube map -->
<images>
<use>texture[5]/images</use>
</images>
<!-- END 6 image cube map -->
</texture-unit>
<!-- Reflection fresnel texture unit-->
<texture-unit>
<unit>6</unit>
<image>
<use>texture[6]/image</use>
</image>
<filter>
<use>texture[6]/filter</use>
</filter>
<wrap-s>
<use>texture[6]/wrap-s</use>
</wrap-s>
<wrap-t>
<use>texture[6]/wrap-t</use>
</wrap-t>
<internal-format>
<use>texture[6]/internal-format</use>
</internal-format>
</texture-unit>
<!-- Reflection rainbow texture unit-->
<texture-unit>
<unit>7</unit>
<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>
<internal-format>
<use>texture[7]/internal-format</use>
</internal-format>
</texture-unit>
<vertex-program-two-side>
<use>vertex-program-two-side</use>
</vertex-program-two-side>
<program>
<!-- <vertex-shader n="0">Shaders/include_fog.vert</vertex-shader> -->
<vertex-shader n="1">Shaders/ubershader.vert</vertex-shader>
<!-- <fragment-shader n="0">Shaders/include_fog.frag</fragment-shader> -->
<fragment-shader n="1">Shaders/ubershader-lightfield.frag</fragment-shader>
<!--<attribute>
<name>tangent</name>
<index>6</index>
</attribute>
<attribute>
<name>binormal</name>
<index>7</index>
</attribute>-->
</program>
<uniform>
<name>BaseTex</name>
<type>sampler-2d</type>
<value type="int">0</value>
</uniform>
<uniform>
<name>ReflNoiseTex</name>
<type>sampler-3d</type>
<value type="int">1</value>
</uniform>
<uniform>
<name>NormalTex</name>
<type>sampler-2d</type>
<value type="int">2</value>
</uniform>
<uniform>
<name>LightMapTex</name>
<type>sampler-2d</type>
<value type="int">3</value>
</uniform>
<uniform>
<name>ReflMapTex</name>
<type>sampler-2d</type>
<value type="int">4</value>
</uniform>
<uniform>
<name>Environment</name>
<type>sampler-cube</type>
<value type="int">5</value>
</uniform>
<uniform>
<name>ReflFresnelTex</name>
<type>sampler-2d</type>
<value type="int">6</value>
</uniform>
<uniform>
<name>ReflRainbowTex</name>
<type>sampler-2d</type>
<value type="int">7</value>
</uniform>
<!-- NORMAL MAP -->
<!-- normalmap is used-->
<uniform>
<name>nmap_enabled</name>
<type>int</type>
<value>
<use>normalmap-enabled</use>
</value>
</uniform>
<!-- normalmap is .dds-->
<uniform>
<name>nmap_dds</name>
<type>int</type>
<value>
<use>normalmap-dds</use>
</value>
</uniform>
<uniform>
<name>nmap_tile</name>
<type>float</type>
<value>
<use>normalmap-tiling</use>
</value>
</uniform>
<!-- LIGHTMAP -->
<!-- lightmap is used -->
<uniform>
<name>lightmap_enabled</name>
<type>int</type>
<value>
<use>lightmap-enabled</use>
</value>
</uniform>
<!-- lightmap is multichannel -->
<uniform>
<name>lightmap_multi</name>
<type>int</type>
<value>
<use>lightmap-multi</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>
<!-- reflection is used -->
<uniform>
<name>refl_enabled</name>
<type>int</type>
<value>
<use>reflection-enabled</use>
</value>
</uniform>
<!-- reflection correction -->
<uniform>
<name>refl_correction</name>
<type>float</type>
<value>
<use>reflection-correction</use>
</value>
</uniform>
<!-- use a reflection map-->
<uniform>
<name>refl_map</name>
<type>int</type>
<value>
<use>reflect-map-enabled</use>
</value>
</uniform>
<!-- reflection is dynamic -->
<uniform>
<name>refl_dynamic</name>
<type>int</type>
<value>
<use>reflection-dynamic</use>
</value>
</uniform>
<!-- set the amount of fringing colour 0.0 - 1.0 -->
<uniform>
<name>refl_rainbow</name>
<type>float</type>
<value>
<use>reflection-rainbow</use>
</value>
</uniform>
<!-- set the amount of fresnel effect colour 0.0 - 1.0 -->
<uniform>
<name>refl_fresnel</name>
<type>float</type>
<value>
<use>reflection-fresnel</use>
</value>
</uniform>
<!-- set the amount of noisiness 0.0 - 1.0 -->
<uniform>
<name>refl_noise</name>
<type>float</type>
<value>
<use>reflection-noise</use>
</value>
</uniform>
<!-- dirt -->
<uniform>
<name>dirt_enabled</name>
<type>int</type>
<value>
<use>dirt-enabled</use>
</value>
</uniform>
<uniform>
<name>dirt_multi</name>
<type>int</type>
<value>
<use>dirt-multi</use>
</value>
</uniform>
<uniform>
<name>dirt_r_color</name>
<type>float-vec3</type>
<value>
<use>dirt-color[0]</use>
</value>
</uniform>
<uniform>
<name>dirt_r_factor</name>
<type>float</type>
<value>
<use>dirt-factor[0]</use>
</value>
</uniform>
<uniform>
<name>dirt_g_color</name>
<type>float-vec3</type>
<value>
<use>dirt-color[1]</use>
</value>
</uniform>
<uniform>
<name>dirt_g_factor</name>
<type>float</type>
<value>
<use>dirt-factor[1]</use>
</value>
</uniform>
<uniform>
<name>dirt_b_color</name>
<type>float-vec3</type>
<value>
<use>dirt-color[2]</use>
</value>
</uniform>
<uniform>
<name>dirt_b_factor</name>
<type>float</type>
<value>
<use>dirt-factor[2]</use>
</value>
</uniform>
<!-- set the amount of ambient light correction 0.0 - 1.0 -->
<uniform>
<name>amb_correction</name>
<type>float</type>
<value>
<use>ambient-correction</use>
</value>
</uniform>
<!-- shader quality -->
<uniform>
<name>shader_qual</name>
<type>int</type>
<value>
<use>shader-quality</use>
</value>
</uniform>
<uniform>
<name>hdg</name>
<type>float</type>
<value>
<use>model-hdg</use>
</value>
</uniform>
<uniform>
<name>pitch</name>
<type>float</type>
<value>
<use>model-pitch</use>
</value>
</uniform>
<uniform>
<name>roll</name>
<type>float</type>
<value>
<use>model-roll</use>
</value>
</uniform>
<!-- BEGIN fog include -->
<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>
<!-- END fog include -->
<uniform>
<name>rembrandt_enabled</name>
<type>int</type>
<value>
<use>rembrandt</use>
</value>
</uniform>
</pass>
</technique>
<!-- Default rendering -->
<technique n="9">
@ -768,4 +1420,4 @@ please see Docs/README.model-combined.eff for documentation
</uniform>
</pass>
</technique>
</PropertyList>
</PropertyList>

View file

@ -8,6 +8,7 @@ varying vec3 VNormal;
varying vec3 VTangent;
varying vec3 VBinormal;
varying vec3 vViewVec;
varying vec3 vertVec;
varying vec3 reflVec;
varying float alpha;
@ -83,7 +84,7 @@ void main(void)
alpha = 1.0;
// Vertex in eye coordinates
vec3 vertVec = ecPosition.xyz;
vertVec = ecPosition.xyz;
vViewVec.x = dot(t, vertVec);
vViewVec.y = dot(b, vertVec);
vViewVec.z = dot(n, vertVec);

View file

@ -0,0 +1,461 @@
// -*- mode: C; -*-
// Licence: GPL v2
// Authors: Frederic Bouvier and Gijs de Rooy
// with major additions and revisions by
// Emilian Huminiuc and Vivian Meazza 2011
// ported to Atmospheric Light Scattering
// by Thorsten Renk, 2013
#version 120
varying vec3 rawpos;
varying vec3 VNormal;
varying vec3 VTangent;
varying vec3 VBinormal;
varying vec3 vViewVec;
varying vec3 reflVec;
varying vec3 vertVec;
varying float alpha;
uniform samplerCube Environment;
uniform sampler2D BaseTex;
uniform sampler2D NormalTex;
uniform sampler2D LightMapTex;
uniform sampler2D ReflMapTex;
uniform sampler2D ReflFresnelTex;
uniform sampler2D ReflRainbowTex;
uniform sampler3D ReflNoiseTex;
uniform int nmap_enabled;
uniform int nmap_dds;
uniform int refl_enabled;
uniform int refl_map;
uniform int lightmap_enabled;
uniform int lightmap_multi;
uniform int shader_qual;
uniform int dirt_enabled;
uniform int dirt_multi;
uniform float lightmap_r_factor;
uniform float lightmap_g_factor;
uniform float lightmap_b_factor;
uniform float lightmap_a_factor;
uniform float refl_correction;
uniform float refl_fresnel;
uniform float refl_rainbow;
uniform float refl_noise;
uniform float amb_correction;
uniform float dirt_r_factor;
uniform float dirt_g_factor;
uniform float dirt_b_factor;
uniform float nmap_tile;
uniform float hazeLayerAltitude;
uniform float visibility;
uniform float avisibility;
uniform float terminator;
uniform float terrain_alt;
uniform float overcast;
uniform float ground_scattering;
uniform float scattering;
uniform float moonlight;
uniform float cloud_self_shading;
uniform float eye_alt;
uniform mat4 osg_ViewMatrixInverse;
uniform mat4 osg_ViewMatrix;
// constants needed by the light and fog computations ###################################################
const float EarthRadius = 5800000.0;
const float terminator_width = 200000.0;
uniform vec3 lightmap_r_color;
uniform vec3 lightmap_g_color;
uniform vec3 lightmap_b_color;
uniform vec3 lightmap_a_color;
uniform vec3 dirt_r_color;
uniform vec3 dirt_g_color;
uniform vec3 dirt_b_color;
float alt;
///fog include//////////////////////
uniform int fogType;
vec3 fog_Func(vec3 color, int type);
////////////////////////////////////
float light_func (in float x, in float a, in float b, in float c, in float d, in float e)
{
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));
}
float fog_func (in float targ)
{
float fade_mix;
targ = 1.25 * targ * smoothstep(0.04,0.06,targ); // need to sync with the distance to which objects are drawn unfogged
if (alt < 30000.0)
{return exp(-targ - targ * targ * targ * targ);}
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));
}
else
{
return exp(- targ * targ - pow(targ,4.0));
}
}
void main (void)
{
vec4 texel = texture2D(BaseTex, gl_TexCoord[0].st);
vec4 nmap = texture2D(NormalTex, gl_TexCoord[0].st * nmap_tile);
vec4 reflmap = texture2D(ReflMapTex, gl_TexCoord[0].st);
vec4 noisevec = texture3D(ReflNoiseTex, rawpos.xyz);
vec4 lightmapTexel = texture2D(LightMapTex, gl_TexCoord[0].st);
vec3 mixedcolor;
vec3 N = vec3(0.0,0.0,1.0);
float pf = 0.0;
///some generic light scattering parameters
vec3 shadedFogColor = vec3(0.65, 0.67, 0.78);
vec3 moonLightColor = vec3 (0.095, 0.095, 0.15) * moonlight;
float alt = eye_alt;
float effective_scattering = min(scattering, cloud_self_shading);
/// BEGIN geometry for light
vec3 up = (gl_ModelViewMatrix * vec4(0.0,0.0,1.0,0.0)).xyz;
//vec4 worldPos3D = (osg_ViewMatrixInverse * vec4 (0.0,0.0,0.0, 1.0));
//worldPos3D.a = 0.0;
//vec3 up = (osg_ViewMatrix * worldPos3D).xyz;
float dist = length(vertVec);
float vertex_alt = max(100.0,dot(up, vertVec) + alt);
float vertex_scattering = ground_scattering + (1.0 - ground_scattering) * smoothstep(hazeLayerAltitude -100.0, hazeLayerAltitude + 100.0, vertex_alt);
vec3 lightHorizon = gl_LightSource[0].position.xyz - up * dot(up,gl_LightSource[0].position.xyz);
float yprime = -dot(vertVec, lightHorizon);
float yprime_alt = yprime - sqrt(2.0 * EarthRadius * vertex_alt);
float lightArg = (terminator-yprime_alt)/100000.0;
float earthShade = 0.6 * (1.0 - smoothstep(-terminator_width+ terminator, terminator_width + terminator, yprime_alt)) + 0.4;
float mie_angle;
if (lightArg < 10.0)
{mie_angle = (0.5 * dot(normalize(vertVec), normalize(gl_LightSource[0].position.xyz)) ) + 0.5;}
else
{mie_angle = 1.0;}
float fog_vertex_alt = max(vertex_alt,hazeLayerAltitude);
float fog_yprime_alt = yprime_alt;
if (fog_vertex_alt > hazeLayerAltitude)
{
if (dist > 0.8 * avisibility)
{
fog_vertex_alt = mix(fog_vertex_alt, hazeLayerAltitude, smoothstep(0.8*avisibility, avisibility, dist));
fog_yprime_alt = yprime -sqrt(2.0 * EarthRadius * fog_vertex_alt);
}
}
else
{
fog_vertex_alt = hazeLayerAltitude;
fog_yprime_alt = yprime -sqrt(2.0 * EarthRadius * fog_vertex_alt);
}
float fog_lightArg = (terminator-fog_yprime_alt)/100000.0;
float fog_earthShade = 0.9 * smoothstep(terminator_width+ terminator, -terminator_width + terminator, fog_yprime_alt) + 0.1;
float ct = dot(normalize(up), normalize(vertVec));
/// END geometry for light
/// BEGIN light
vec4 light_diffuse;
vec4 light_ambient;
float intensity;
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 * vertex_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;
if (earthShade < 0.5)
{
intensity = length(light_ambient.rgb);
light_ambient.rgb = intensity * normalize(mix(light_ambient.rgb, shadedFogColor, 1.0 -smoothstep(0.1, 0.8,earthShade) ));
light_ambient.rgb = light_ambient.rgb + moonLightColor * (1.0 - smoothstep(0.4, 0.5, earthShade));
intensity = length(light_diffuse.rgb);
light_diffuse.rgb = intensity * normalize(mix(light_diffuse.rgb, shadedFogColor, 1.0 -smoothstep(0.1, 0.7,earthShade) ));
}
/// END light
///BEGIN bump
if (nmap_enabled > 0 && shader_qual > 2){
N = nmap.rgb * 2.0 - 1.0;
N = normalize(N.x * VTangent + N.y * VBinormal + N.z * VNormal);
if (nmap_dds > 0)
{
N = -N;
}
} else {
N = normalize(VNormal);
}
///END bump
vec4 reflection = textureCube(Environment, reflVec * dot(N,VNormal));
vec3 viewVec = normalize(vViewVec);
float v = abs(dot(viewVec, normalize(VNormal)));// Map a rainbowish color
vec4 fresnel = texture2D(ReflFresnelTex, vec2(v, 0.0));
vec4 rainbow = texture2D(ReflRainbowTex, vec2(v, 0.0));
float nDotVP = max(0.0, dot(N, normalize(gl_LightSource[0].position.xyz)));
float nDotHV = max(0.0, dot(N, normalize(gl_LightSource[0].halfVector.xyz)));
//glare on the backside of tranparent objects
if ((gl_FrontMaterial.diffuse.a < 1.0 || texel.a < 1.0)
&& dot(N, normalize(gl_LightSource[0].position.xyz)) < 0.0) {
nDotVP = max(0.0, dot(-N, normalize(gl_LightSource[0].position.xyz)));
nDotHV = max(0.0, dot(-N, normalize(gl_LightSource[0].halfVector.xyz)));
}
if (nDotVP == 0.0)
pf = 0.0;
else
pf = pow(nDotHV, gl_FrontMaterial.shininess);
//vec4 Diffuse = gl_LightSource[0].diffuse * nDotVP;
vec4 Diffuse = light_diffuse * nDotVP;
//vec4 Specular = gl_FrontMaterial.specular * gl_LightSource[0].specular * pf;
vec4 Specular = gl_FrontMaterial.specular * light_diffuse * pf;
vec4 color = gl_Color + Diffuse * gl_FrontMaterial.diffuse;
color += Specular * gl_FrontMaterial.specular * nmap.a;
color = clamp( color, 0.0, 1.0 );
////////////////////////////////////////////////////////////////////
//BEGIN reflect
////////////////////////////////////////////////////////////////////
if (refl_enabled > 0 && shader_qual > 1){
float reflFactor = 0.0;
float transparency_offset = clamp(refl_correction, -1.0, 1.0);// set the user shininess offset
if(refl_map > 0){
// map the shininess of the object with user input
//float pam = (map.a * -2) + 1; //reverse map
reflFactor = reflmap.a + transparency_offset;
} else if (nmap_enabled > 0 && shader_qual > 2) {
// set the reflectivity proportional to shininess with user input
reflFactor = gl_FrontMaterial.shininess * 0.0078125 * nmap.a + transparency_offset;
} else {
reflFactor = gl_FrontMaterial.shininess* 0.0078125 + transparency_offset;
}
reflFactor = clamp(reflFactor, 0.0, 1.0);
// add fringing fresnel and rainbow effects and modulate by reflection
vec4 reflcolor = mix(reflection, rainbow, refl_rainbow * v);
reflcolor += Specular * nmap.a;
vec4 reflfrescolor = mix(reflcolor, fresnel, refl_fresnel * v);
vec4 noisecolor = mix(reflfrescolor, noisevec, refl_noise);
vec4 raincolor = vec4(noisecolor.rgb * reflFactor, 1.0);
raincolor += Specular * nmap.a;
mixedcolor = mix(texel, raincolor, reflFactor).rgb;
} else {
mixedcolor = texel.rgb;
}
/////////////////////////////////////////////////////////////////////
//END reflect
/////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////
//begin DIRT
//////////////////////////////////////////////////////////////////////
if (dirt_enabled > 0.0){
vec3 dirtFactorIn = vec3 (dirt_r_factor, dirt_g_factor, dirt_b_factor);
vec3 dirtFactor = reflmap.rgb * dirtFactorIn.rgb;
//dirtFactor.r = smoothstep(0.0, 1.0, dirtFactor.r);
mixedcolor.rgb = mix(mixedcolor.rgb, dirt_r_color, smoothstep(0.0, 1.0, dirtFactor.r));
if (dirt_multi > 0) {
//dirtFactor.g = smoothstep(0.0, 1.0, dirtFactor.g);
//dirtFactor.b = smoothstep(0.0, 1.0, dirtFactor.b);
mixedcolor.rgb = mix(mixedcolor.rgb, dirt_g_color, smoothstep(0.0, 1.0, dirtFactor.g));
mixedcolor.rgb = mix(mixedcolor.rgb, dirt_b_color, smoothstep(0.0, 1.0, dirtFactor.b));
}
}
//////////////////////////////////////////////////////////////////////
//END Dirt
//////////////////////////////////////////////////////////////////////
// set ambient adjustment to remove bluiness with user input
float ambient_offset = clamp(amb_correction, -1.0, 1.0);
//vec4 ambient = gl_LightModel.ambient + gl_LightSource[0].ambient;
vec4 ambient = gl_LightModel.ambient + light_ambient;
vec4 ambient_Correction = vec4(ambient.rg, ambient.b * 0.6, 1.0)
* ambient_offset ;
ambient_Correction = clamp(ambient_Correction, -1.0, 1.0);
color.a = texel.a * alpha;
vec4 fragColor = vec4(color.rgb * mixedcolor + ambient_Correction.rgb, color.a);
fragColor += Specular * nmap.a;
//////////////////////////////////////////////////////////////////////
// BEGIN lightmap
//////////////////////////////////////////////////////////////////////
if ( lightmap_enabled >= 1 ) {
vec3 lightmapcolor = vec3(0.0);
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 +
lightmap_g_color * lightmapFactor.g +
lightmap_b_color * lightmapFactor.b +
lightmap_a_color * lightmapFactor.a ;
} else {
lightmapcolor = lightmapTexel.rgb * lightmap_r_color * lightmapFactor.r;
}
fragColor.rgb = max(fragColor.rgb, lightmapcolor * gl_FrontMaterial.diffuse.rgb * mixedcolor);
}
//////////////////////////////////////////////////////////////////////
// END lightmap
/////////////////////////////////////////////////////////////////////
/// BEGIN fog amount
float transmission;
float vAltitude;
float delta_zv;
float H;
float distance_in_layer;
float transmission_arg;
float eqColorFactor;
float delta_z = hazeLayerAltitude - eye_alt;
if (dist > max(40.0, 0.04 * min(visibility,avisibility)))
{
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,min(visibility, avisibility)) * 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;
}
}
transmission_arg = (dist-distance_in_layer)/avisibility;
if (visibility < avisibility)
{
transmission_arg = transmission_arg + (distance_in_layer/visibility);
eqColorFactor = 1.0 - 0.1 * delta_zv/visibility - (1.0 -effective_scattering);
}
else
{
transmission_arg = transmission_arg + (distance_in_layer/avisibility);
eqColorFactor = 1.0 - 0.1 * delta_zv/avisibility - (1.0 -effective_scattering);
}
transmission = fog_func(transmission_arg);
if (eqColorFactor < 0.2) eqColorFactor = 0.2;
}
else
{
eqColorFactor = 1.0;
transmission = 1.0;
}
/// END fog amount
/// BEGIN fog color
vec3 hazeColor;
if (transmission< 1.0)
{
hazeColor.b = light_func(fog_lightArg-0.5, 1.330e-05, 0.264, 2.527, 1.08e-05, 1.0);
hazeColor.g = light_func(fog_lightArg-0.5, 3.931e-06, 0.264, 3.827, 7.93e-06, 1.0);
hazeColor.r = light_func(fog_lightArg-0.5, 8.305e-06, 0.161, 3.827, 3.04e-05, 1.0);
if (fog_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)) );
}
intensity = length(hazeColor);
hazeColor = intensity * normalize (mix(hazeColor, intensity * vec3 (1.0,1.0,1.0), 0.7* smoothstep(5000.0, 50000.0, alt)));
hazeColor.r = hazeColor.r * 0.83;
hazeColor.g = hazeColor.g * 0.9;
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,fog_earthShade) ));
hazeColor = intensity * normalize(mix(hazeColor, shadedFogColor, (1.0-smoothstep(0.5,0.9,eqColorFactor))));
float shadow = mix( min(1.0 + dot(VNormal,gl_LightSource[0].position.xyz),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));
}
else
{
hazeColor = vec3 (1.0, 1.0, 1.0);
}
/// END fog color
fragColor = clamp(fragColor, 0.0, 1.0);
//fragColor = fragColor * smoothstep(-0.05, 0.05, ct);
fragColor.rgb = mix(eqColorFactor * hazeColor * fog_earthShade, fragColor.rgb,transmission);
gl_FragColor = fragColor;
}

View file

@ -9,6 +9,7 @@ varying vec3 VTangent;
varying vec3 VBinormal;
varying vec3 vViewVec;
varying vec3 reflVec;
varying vec3 vertVec;
varying float alpha;
@ -70,7 +71,7 @@ void main(void)
alpha = gl_Color.a;
// Vertex in eye coordinates
vec3 vertVec = ecPosition.xyz;
vertVec = ecPosition.xyz;
vViewVec.x = dot(t, vertVec);
vViewVec.y = dot(b, vertVec);
vViewVec.z = dot(n, vertVec);

View file

@ -148,6 +148,30 @@
<pref-width>55</pref-width>
</empty>
</group>
<group>
<layout>hbox</layout>
<halign>right</halign>
<text>
<label>Model</label>
</text>
<slider>
<name>model</name>
<min>0.0</min>
<max>3.0</max>
<step>1.0</step>
<fraction>0.17</fraction>
<live>true</live>
<property>/sim/rendering/shaders/model</property>
<binding>
<command>dialog-apply</command>
<object-name>model</object-name>
</binding>
</slider>
<empty>
<pref-width>55</pref-width>
</empty>
</group>
<group>
<layout>hbox</layout>