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

58 lines
1.2 KiB
GLSL
Raw Normal View History

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
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;
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);
gl_FragColor.rgb = mix(hazeColor, finalColor.rgb, fogFactor );
}
else
{gl_FragColor.rgb = finalColor;}
2012-03-08 22:20:39 +00:00
gl_FragColor.a = mix(0.0, finalColor.a, fogFactor);
}