| 1 |
#version 120 |
| 2 |
|
| 3 |
uniform sampler2D baseTexture; |
| 4 |
varying float fogFactor; |
| 5 |
varying vec3 hazeColor; |
| 6 |
varying vec3 relVector; |
| 7 |
|
| 8 |
vec3 filter_combined (in vec3 color) ; |
| 9 |
|
| 10 |
uniform bool is_lightning; |
| 11 |
|
| 12 |
vec3 rainbow (in float index) |
| 13 |
{ |
| 14 |
|
| 15 |
float red = max(1.0 - 2.0 * index,0.0); |
| 16 |
float green; |
| 17 |
|
| 18 |
if (index < 0.5) |
| 19 |
{green = 2.0 * index;} |
| 20 |
else |
| 21 |
{green = 1.0 - 2.0 *(index - 0.5);} |
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
float blue = max(2.0 * (index - 0.5), 0.0); |
| 26 |
|
| 27 |
red *= 1.3; |
| 28 |
green *=0.6; |
| 29 |
|
| 30 |
return vec3 (red, green, blue) * hazeColor; |
| 31 |
} |
| 32 |
|
| 33 |
void main(void) |
| 34 |
{ |
| 35 |
vec4 base = texture2D( baseTexture, gl_TexCoord[0].st); |
| 36 |
vec4 finalColor = base * gl_Color; |
| 37 |
|
| 38 |
vec4 fragColor; |
| 39 |
|
| 40 |
|
| 41 |
if (is_lightning==false) |
| 42 |
{ |
| 43 |
vec3 nView = normalize(relVector); |
| 44 |
vec3 lightFull = normalize((gl_ModelViewMatrixInverse * gl_LightSource[0].position).xyz); |
| 45 |
|
| 46 |
float calpha = dot(-lightFull, nView); |
| 47 |
|
| 48 |
float rainbow_shape = smoothstep(0.743 -0.03, 0.743, calpha) * (1.0 - smoothstep(0.743, 0.743+0.03, calpha)); |
| 49 |
|
| 50 |
float color_index = clamp((calpha - 0.713)/ 0.06,0.0,1.0); |
| 51 |
|
| 52 |
vec3 rainbow_color = rainbow(color_index); |
| 53 |
finalColor.rgb = mix(finalColor.rgb, rainbow_color, 0.5* rainbow_shape); |
| 54 |
|
| 55 |
|
| 56 |
fragColor.rgb = mix(hazeColor, finalColor.rgb, fogFactor ); |
| 57 |
} |
| 58 |
else |
| 59 |
{fragColor.rgb = finalColor.rgb;} |
| 60 |
fragColor.a = mix(0.0, finalColor.a, fogFactor); |
| 61 |
|
| 62 |
fragColor.rgb = filter_combined(fragColor.rgb); |
| 63 |
|
| 64 |
gl_FragColor = fragColor; |
| 65 |
|
| 66 |
} |