1
0
Fork 0
fgdata/Shaders/rain-layer-ALS.frag

67 lines
1.4 KiB
GLSL
Raw Normal View History

#version 120
2012-03-08 22:20:39 +00:00
uniform sampler2D baseTexture;
varying float fogFactor;
varying vec3 hazeColor;
varying vec3 relVector;
2012-03-08 22:20:39 +00:00
2016-04-08 12:57:59 +00:00
vec3 filter_combined (in vec3 color) ;
uniform bool is_lightning;
vec3 rainbow (in float index)
{
float red = max(1.0 - 2.0 * index,0.0);
float green;
if (index < 0.5)
{green = 2.0 * index;}
else
{green = 1.0 - 2.0 *(index - 0.5);}
float blue = max(2.0 * (index - 0.5), 0.0);
red *= 1.3;
green *=0.6;
return vec3 (red, green, blue) * hazeColor;
}
2012-03-08 22:20:39 +00:00
void main(void)
{
vec4 base = texture2D( baseTexture, gl_TexCoord[0].st);
vec4 finalColor = base * gl_Color;
2016-04-08 12:57:59 +00:00
vec4 fragColor;
if (is_lightning==false)
{
vec3 nView = normalize(relVector);
vec3 lightFull = normalize((gl_ModelViewMatrixInverse * gl_LightSource[0].position).xyz);
float calpha = dot(-lightFull, nView);
float rainbow_shape = smoothstep(0.743 -0.03, 0.743, calpha) * (1.0 - smoothstep(0.743, 0.743+0.03, calpha));
float color_index = clamp((calpha - 0.713)/ 0.06,0.0,1.0);
vec3 rainbow_color = rainbow(color_index);
finalColor.rgb = mix(finalColor.rgb, rainbow_color, 0.5* rainbow_shape);
2016-04-08 12:57:59 +00:00
fragColor.rgb = mix(hazeColor, finalColor.rgb, fogFactor );
}
else
{fragColor.rgb = finalColor.rgb;}
2016-04-08 12:57:59 +00:00
fragColor.a = mix(0.0, finalColor.a, fogFactor);
fragColor.rgb = filter_combined(fragColor.rgb);
gl_FragColor = fragColor;
2012-03-08 22:20:39 +00:00
}