1
0
Fork 0

Glow effect for ALS space shader, converting a temperature into surface blackbody radiation color

This commit is contained in:
Thorsten Renk 2017-05-26 12:19:06 +03:00
parent 8f7ab7e725
commit 0b6ef218b1
3 changed files with 89 additions and 4 deletions

View file

@ -4,7 +4,7 @@
<name>Effects/space-combined</name>
<inherits-from>Effects/model-combined</inherits-from>
<!--<parameters>
<parameters>
<geo_light_r type="float">0.0</geo_light_r>
<geo_light_g type="float">0.0</geo_light_g>
<geo_light_b type="float">0.0</geo_light_b>
@ -13,13 +13,15 @@
<geo_light_z type="float">0.0</geo_light_z>
<geo_light_radius type="float">0.0</geo_light_radius>
<geo_ambience type="float">0.0</geo_ambience>
</parameters> -->
<use_geo_light type="int">0</use_geo_light>
</parameters>
<technique n="4">
<pass>
<program>
<vertex-shader n="0">Shaders/space-ALS-ultra.vert</vertex-shader>
<fragment-shader n="0">Shaders/space-ALS-ultra.frag</fragment-shader>
<fragment-shader n="6">Shaders/color_temperature.frag</fragment-shader>
</program>
<uniform>
@ -816,6 +818,11 @@
<type>float</type>
<value><use>geo_ambience</use></value>
</uniform>
<uniform>
<name>use_geo_light</name>
<type>int</type>
<value><use>use_geo_light</use></value>
</uniform>
</pass>
</technique>

51
Shaders/color_temperature.frag Executable file
View file

@ -0,0 +1,51 @@
// -*-C++-*-
#version 120
vec4 color_temperature (in float T)
{
T *=0.01;
float red;
float green;
float blue;
float alpha;
red = 1.0;
if (T<66.0)
{
red = 255.0;
green = T;
green = 99.4708025 * log(green) - 161.11956;
if (T <=19)
{blue = 0.0;}
else
{
blue = T-10;
blue = 138.517731 * log(blue) - 305.044792;
}
}
else
{
red = T - 60.0;
red = 329.6987 * pow(red, -0.1332047);
green = T - 60.0;
green = 288.122169 * pow(green, -0.075514);
blue = 255.0;
}
alpha = 0.8 * smoothstep(5.0, 15.0, T);
vec3 color = vec3 (red, green, blue);
color /= 255.0;
color = clamp(color, 0.0, 1.0);
return vec4 (color, alpha);
}

View file

@ -41,6 +41,7 @@ uniform int cloud_shadow_flag;
uniform int use_searchlight;
uniform int use_landing_light;
uniform int use_alt_landing_light;
uniform int use_geo_light;
uniform float amb_correction;
uniform float dirt_b_factor;
@ -59,6 +60,7 @@ uniform float grain_magnification;
uniform float wetness;
uniform float rain_norm;
uniform float darkmap_factor;
uniform float delta_T;
uniform float avisibility;
uniform float cloud_self_shading;
@ -116,7 +118,7 @@ vec3 get_hazeColor(in float lightArg);
vec3 searchlight();
vec3 landing_light(in float offset, in float offsetv);
vec3 addLights(in vec3 color1, in vec3 color2);
vec4 color_temperature (in float T);
float light_func (in float x, in float a, in float b, in float c, in float d, in float e)
{
@ -346,12 +348,14 @@ void main (void)
//Diffuse.rgb += secondary_light * light_distance_fading(dist) + geo_light;
Diffuse.rgb = addLights(Diffuse.rgb, secondary_light * light_distance_fading(dist));
Diffuse.rgb = addLights(Diffuse.rgb, geo_light * diffuse_reduction );
//if (use_geo_light == 1)
{Diffuse.rgb = addLights(Diffuse.rgb, geo_light * diffuse_reduction );}
vec4 Specular = gl_FrontMaterial.specular * light_diffuse * pf + gl_FrontMaterial.specular * light_ambient * pf1;
Specular+= gl_FrontMaterial.specular * pow(max(0.0,-dot(N,normalize(vertVec))),gl_FrontMaterial.shininess) * vec4(secondary_light,1.0);
vec4 color = gl_Color * light_ambient + gl_FrontMaterial.emission;
color = color + Diffuse * gl_FrontMaterial.diffuse;
color = clamp( color, 0.0, 1.0 );
@ -444,6 +448,8 @@ void main (void)
ambient_Correction = vec4 (0.0, 0.0, 0.0, 1.0);
color.a = texel.a * alpha;
vec4 fragColor = vec4(color.rgb * mixedcolor + ambient_Correction.rgb, color.a);
@ -479,6 +485,24 @@ void main (void)
// END lightmap
/////////////////////////////////////////////////////////////////////
/// BEGIN glow
float temperature = delta_T;
if (darkmap_enabled == 2)
{
temperature *= (1.0 - darkmap_factor * lightmapTexel.a);
}
vec4 glow = color_temperature(temperature);
float glowFactor = 0.3 + 0.6 * (1.0 - length(texel.rgb)/1.73);
glowFactor *= glow.a;
fragColor.rgb = mix(fragColor.rgb, glow.rgb, glowFactor);
//////////////////////////////////////////////////////////////////////
// END glow
/////////////////////////////////////////////////////////////////////
/// BEGIN fog amount
@ -616,8 +640,11 @@ void main (void)
hazeColor *= eqColorFactor * fog_earthShade;
hazeColor.rgb = max(hazeColor.rgb, minLight.rgb);
fragColor.rgb = mix(hazeColor +secondary_light * fog_backscatter(mvisibility), fragColor.rgb,transmission);
gl_FragColor = fragColor;