1
0
Fork 0

Aurora Borealis shader effects for Earthview - not yet used

This commit is contained in:
Thorsten Renk 2015-12-23 13:39:45 +02:00
parent 2822505f08
commit 88bc96d346
3 changed files with 239 additions and 0 deletions

151
Effects/planet-aurora.eff Normal file
View file

@ -0,0 +1,151 @@
<?xml version="1.0" encoding="utf-8"?>
<PropertyList>
<name>Effects/aurora</name>
<!-- <inherits-from>Effects/shadow</inherits-from> -->
<parameters>
<texture n ="0">
<type>white</type>
</texture>
<vertex-program-two-side type="bool">true</vertex-program-two-side>
<material>
<color-mode-uniform>1</color-mode-uniform>
<!-- DIFFUSE -->
</material>
<strength><use>/environment/aurora/strength</use></strength>
<ray_factor><use>/environment/aurora/ray-factor</use></ray_factor>
<upper_alt_factor><use>/environment/aurora/upper-alt-factor</use></upper_alt_factor>
<penetration_factor><use>/environment/aurora/penetration-factor</use></penetration_factor>
<patchiness><use>/environment/aurora/patchiness</use></patchiness>
<afterglow><use>/environment/aurora/afterglow</use></afterglow>
</parameters>
<technique n="10">
<predicate>
<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>
<property>/sim/rendering/shaders/skydome</property>
</and>
</or>
</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>
<source>src-alpha</source>
<destination>one-minus-src-alpha</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>
<depth>
<write-mask>false</write-mask>
</depth>
<render-bin>
<bin-number>10</bin-number>
<bin-name>DepthSortedBin</bin-name>
</render-bin>
<texture-unit>
<!-- The texture unit is always active because the shaders expect
that. -->
<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>
<vertex-program-two-side>
<use>vertex-program-two-side</use>
</vertex-program-two-side>
<program>
<vertex-shader>Shaders/planet-aurora.vert</vertex-shader>
<fragment-shader>Shaders/planet-aurora.frag</fragment-shader>
<fragment-shader>Shaders/noise.frag</fragment-shader>
</program>
<uniform>
<name>texture</name>
<type>sampler-2d</type>
<value type="int">0</value>
</uniform>
<uniform>
<name>strength</name>
<type>float</type>
<value><use>strength</use></value>
</uniform>
<uniform>
<name>ray_factor</name>
<type>float</type>
<value><use>ray_factor</use></value>
</uniform>
<uniform>
<name>upper_alt_factor</name>
<type>float</type>
<value><use>upper_alt_factor</use></value>
</uniform>
<uniform>
<name>penetration_factor</name>
<type>float</type>
<value><use>penetration_factor</use></value>
</uniform>
<uniform>
<name>patchiness</name>
<type>float</type>
<value><use>patchiness</use></value>
</uniform>
<uniform>
<name>afterglow</name>
<type>float</type>
<value><use>afterglow</use></value>
</uniform>
</pass>
</technique>
</PropertyList>

View file

@ -0,0 +1,73 @@
// -*-C++-*-
// Ambient term comes in gl_Color.rgb.
#version 120
varying vec3 vertex;
varying vec3 relVec;
varying vec3 normal;
uniform float strength;
uniform float ray_factor;
uniform float upper_alt_factor;
uniform float penetration_factor;
uniform float patchiness;
uniform float afterglow;
uniform float osg_SimulationTime;
float Noise2D(in vec2 coord, in float wavelength);
void main()
{
float vCoord = abs(vertex.z);
float aurora_time = 0.001 * osg_SimulationTime;
float noise_01 = Noise2D( vec2(vertex.x +aurora_time, vertex.y), 0.05);
float blend_factor = smoothstep(0.935, 0.955, vCoord - 0.001 * noise_01 - 0.02 * (1.0-upper_alt_factor));
float blend_low = smoothstep(0.915, 0.925, vCoord - 0.001 * noise_01-0.00250 * penetration_factor);
noise_01 = smoothstep(0.0 + 0.25 * patchiness, 1.0 - 0.25 *patchiness, noise_01 - 0.5 * (1.0-strength) * patchiness);
float noise_02 = 0.7 + 0.3 * Noise2D( vec2 (vertex.x +vertex.y, aurora_time), 0.002);
noise_02 = mix(0.85, noise_02 , min((1.0-blend_factor) * ray_factor, 1.0));
float smoothness = 0.01 + 0.02 * (1.0 - ray_factor);
float noise_03 = 0.05 * (0.5 - Noise2D ( vec2 (vertex.x + vertex.y, 2.0 * aurora_time), smoothness));
noise_03 = mix(0.0, noise_03, upper_alt_factor);
vCoord += 0.00250 * penetration_factor;
float vStrength = smoothstep(0.92, 0.94, vCoord) * (1.0 - smoothstep(0.94, 0.95 + 0.1 * upper_alt_factor, vCoord+noise_03));
vec3 auroraColor1 = vec3 (0.0, 0.2, 0.1);
vec3 auroraColor2 = vec3 (0.2, 0.0, 0.05);
vec3 auroraColor3 = vec3 (0.8, 0.3, 0.4);
vec3 auroraColor = mix(auroraColor1, auroraColor2, blend_factor);
auroraColor = mix(auroraColor3, auroraColor, blend_low);
float fade_factor = smoothstep(0.94, 0.97, vCoord - 0.001 * noise_01 - 0.02 * (1.0-upper_alt_factor));
fade_factor = mix(1.0, fade_factor, afterglow);
float view_angle = abs(dot(normalize(relVec), normalize(normal)));
float angStrength = smoothstep(0.2, 0.6, view_angle);
float auroraStrength = vStrength * angStrength * noise_01 * noise_02 * strength * fade_factor;
gl_FragColor = vec4 (auroraColor.x, auroraColor.y, auroraColor.z, auroraStrength);
}

View file

@ -0,0 +1,15 @@
#version 120
varying vec3 vertex;
varying vec3 normal;
varying vec3 relVec;
void main()
{
normal = gl_Normal;
vertex = gl_Vertex.xyz;
vec3 ep = (gl_ModelViewMatrixInverse * vec4 (0.0, 0.0, 0.0, 1.0)).xyz;
relVec = vertex - ep;
gl_Position = ftransform();
}