| 7 |
| 8 | uniform int modelIndex; |
| 9 | uniform vec2 resolution; |
| 10 | uniform int type; |
| 11 | uniform bool night; |
| 12 | uniform float time; |
| 13 | uniform mat4 world; |
| 14 | uniform bool behind; |
| 15 |
| 16 | vec3 gradient( |
| 17 | float x1, vec3 y1, |
| 18 | float x2, vec3 y2, |
| 19 | float x3, vec3 y3, |
| 20 |
| 21 | float t |
| 22 | ) { |
| 23 | if (t < x1) return y1; |
| 24 | if (t < x2) return mix(y1, y2, (t - x1) / (x2 - x1)); |
| 25 | if (t < x3) return mix(y2, y3, (t - x2) / (x3 - x2)); |
| 26 | return y3; |
| 27 | } |
| 28 |
| 29 | void main() { |
| 30 | if (modelIndex == 0) { |
| 31 | if (behind) { |
| 32 | gl_FragColor = vec4(night ? RGB#2457A9 : RGB#1E69E8, 1.0); |
| 33 | } else { |
| 34 | vec2 pos = 3.0 * gl_FragCoord.xy / resolution; |
| 35 | float t = time; |
| 36 | t = fract(t / 9.0) * 9.0; |
| 37 | t *= 1.8; |
| 38 | if (t > 1.1) { |
| 39 | discard; |
| 40 | } |
| 41 | float x = fract((pos.x - pos.y + 0.05 * depth) * 0.2 - t - 0.32); |
| 42 | float a = x < 0.15 || x < 0.25 && x > 0.2 ? 0.4 : 0.0; |
| 43 | gl_FragColor = vec4(vec3(1.0), a); |
| 44 | } |
| 45 | } else if (modelIndex == 1) { |
| 46 | vec3 pos = modelViewVertex / 10.0 + .5; |
| 47 | vec3 lightPos = vec3(-3., 20., 20.); |
| 48 | vec3 lightDir = normalize(lightPos - pos); |
| 49 |
| 50 | vec3 norm = normalize(vec3(world * vec4(vNormal, 0.0))); |
| 51 | if (behind) { |
| 52 | float diffuse = max(dot(norm, lightDir), 0.0); |
| 53 |
| 54 | gl_FragColor = vec4( |
| 55 | mix( |
| 56 | vec3(0.35, 0.59, 0.94), |
| 57 | vec3(0.52, 0.70, 0.97), |
| 58 | clamp(diffuse, 0.0, 1.0) |
| 59 | ) |
| 60 | , 1.0); |
| 61 | } else { |
| 62 | float spec2 = 0.0; |
| 63 | lightPos = vec3(0., -100., 50.0); |
| 64 | spec2 += 0.5 * pow(max(dot(normalize(vec3(0.0) - pos), reflect(-normalize(lightPos - pos), norm)), 0.0), 2.0); |
| 65 |
| 66 | lightPos = vec3(0., 0., 0.0); |
| 67 | spec2 += 0.4 * pow(max(dot(normalize(vec3(0.0) - pos), reflect(-normalize(lightPos - pos), norm)), 0.0), 2.0); |
| 68 |
| 69 | if (!night) { |
| 70 | spec2 *= 0.5; |
| 71 | } |
| 72 |
| 73 | gl_FragColor = vec4(vec3(1.0), spec2); |
| 74 | } |
| 75 | } else if (modelIndex == 2) { |
| 76 | vec3 pos = modelViewVertex / 10.0 + .5; |
| 77 | vec3 lightPos = vec3(-8., 12., 20.); |
| 78 | vec3 lightDir = normalize(lightPos - pos); |
| 79 |
| 80 | vec3 norm = normalize(vec3(world * vec4(vNormal, 0.0))); |
| 81 | float diffuse = max(dot(norm, lightDir), 0.0); |
| 82 |
| 83 | float spec = 0.0; |
| 84 | lightPos = vec3(20., -150., 50.0); |
| 85 | spec += .75 * pow(max(dot(normalize(vec3(0.0) - pos), reflect(-normalize(lightPos - pos), norm)), 0.0), 2.0); |
| 86 |
| 87 | vec3 color = gradient( |
| 88 | 0.0, RGB#58A8F6, |
| 89 | .58, RGB#8ED4FB, |
| 90 | 1.0, RGB#CEE8FD, |
| 91 |
| 92 | diffuse |
| 93 | ); |
| 94 |
| 95 | color += RGB#C5E5FC * spec; |
| 96 |
| 97 | gl_FragColor = vec4(color, 1.5); |
| 98 | } |
| 99 | } |