shader_type sky; uniform samplerCube sky_cube : filter_linear_mipmap; uniform vec3 tint = vec3(1.0); uniform bool define_add_stars = false; uniform bool define_add_moon = false; uniform bool define_test_clouds_2 = false; uniform bool define_moreclouds = false; #include "level.gdshaderinc" const float SPEC = 2.0; vec3 sky_spec(vec3 normal, float lod) { return has_level_sky ? og_spec(normal, lod) : textureLod(sky_cube, normal, lod + SPEC).rgb; } vec2 og_simplex_hash(vec2 p) { p = vec2(dot(p, vec2(127.1, 311.7)), dot(p, vec2(269.5, 183.3))); return -1.0 + 2.0 * fract(sin(p) * 43758.5453123); } float og_simplex(vec2 p) { const float K1 = 0.366025404; const float K2 = 0.211324865; vec2 i = floor(p + (p.x + p.y) * K1); vec2 a = p - i + (i.x + i.y) * K2; vec2 o = a.x > a.y ? vec2(1.0, 0.0) : vec2(0.0, 1.0); vec2 b = a - o + K2; vec2 c = a - 1.0 + 2.0 * K2; vec3 h = max(0.5 - vec3(dot(a, a), dot(b, b), dot(c, c)), 0.0); vec3 n = h * h * h * h * vec3(dot(a, og_simplex_hash(i)), dot(b, og_simplex_hash(i + o)), dot(c, og_simplex_hash(i + 1.0))); return dot(n, vec3(70.0)); } float og_clouds_fbm(vec2 n) { mat2 m = mat2(vec2(1.6, 1.2), vec2(-1.2, 1.6)); float total = 0.0; float amplitude = 0.1; for (int i = 0; i < 7; i++) { total += og_simplex(n) * amplitude; n = m * n; amplitude *= 0.4; } return total; } vec3 og_clouds(vec3 colour, vec3 normal, float time) { mat2 m = mat2(vec2(1.6, 1.2), vec2(-1.2, 1.6)); const float cloudscale = 1.1; const float speed = 0.01; vec2 old_uv = (normal / (normal.y + 0.2)).xz; float q = og_clouds_fbm(old_uv * cloudscale * 0.5); float t = time * speed; float r = 0.0; vec2 uv = old_uv * cloudscale - (q - t); float weight = 0.8; for (int i = 0; i < 8; i++) { r += abs(weight * og_noise(uv)); uv = m * uv + t; weight *= 0.7; } float f = 0.0; uv = old_uv * cloudscale - (q - t); weight = 0.7; for (int i = 0; i < 8; i++) { f += weight * og_noise(uv); uv = m * uv + t; weight *= 0.6; } f *= r + f; float c = 0.0; t = time * speed * 2.0; uv = old_uv * cloudscale * 2.0 - (q - t); weight = 0.4; for (int i = 0; i < 7; i++) { c += weight * og_noise(uv); uv = m * uv + t; weight *= 0.6; } float c1 = 0.0; t = time * speed * 3.0; uv = old_uv * cloudscale * 3.0 - (q - t); weight = 0.4; for (int i = 0; i < 7; i++) { c1 += abs(weight * og_noise(uv)); uv = m * uv + t; weight *= 0.6; } c += c1; vec3 sky = mix(vec3(0.4, 0.7, 1.0), vec3(0.2, 0.4, 0.6), normal.y); vec3 cloud = vec3(1.1, 1.1, 0.9) * clamp(0.5 + 0.3 * c, 0.0, 1.0); f = (define_moreclouds ? 0.8 : 0.2) + 8.0 * f * r; vec3 result = mix(sky, clamp(0.5 * sky + cloud, 0.0, 1.0), clamp(f + c, 0.0, 1.0)); return mix(colour, result * 0.5, max(normal.y, 0.0)); } void sky() { vec3 normal = normalize(EYEDIR); vec3 colour = texture(sky_cube, normal).rgb; if (AT_CUBEMAP_PASS) { COLOR = has_level_sky ? og_spec(normal, -level_sky_bias) : colour; } else { float foggy = define_water_horizon ? 0.0 : clamp((level_fog_amount - 1.0) / 2.0, 0.0, 1.0); float fogness = mix(-1.0, 1.0, foggy); if (normal.y < 0.0) { fogness = mix(fogness, 1.0, -normal.y * level_fog_amount / 5.0); } if (!define_misty && !define_misty2 && !define_sky_ark && !define_waterfall_arena) { float blur = clamp(1.0 - abs(normal.y) + fogness, 0.0, 1.0); colour = mix(colour, textureLod(sky_cube, normal, mix(pow(blur, 2.0), 1.0, fogness * 0.5 + 0.5) * 5.0 + SPEC).rgb, min(1.0, blur * 4.0)); } colour *= tint; if (define_add_stars) { float star = max(0.0, og_simplex(normal.xz / (normal.y + 2.0) * 200.0 + vec2(TIME * 0.05, 0.0)) - 0.7) * 100.0; star *= max(0.0, 1.0 - abs(og_simplex(normal.xz / (normal.y + 2.0) * 20.0 + vec2(TIME, 0.0)))); if (colour.b < 0.1) { colour += vec3(star) * 0.01; } } if (define_add_moon) { float k = dot(normal, level_sun); if (k > 0.9999) { colour += vec3(2.0); } else if (k > 0.999) { colour += vec3(pow((k - 0.9989) * 1000.0, 40.0)) * 2.0; } } if (define_volcano) { colour += (sky_spec(normal, 5.0) - colour) * clamp(1.0 - normal.y, 0.0, 1.0); } vec3 mult = og_fog_colour_mult(normal, 1000.0, POSITION); if (define_misty || define_misty2 || define_sky_ark || define_cave || define_rainy || define_wet) { float haze = og_haze(normal * 1000.0, POSITION, TIME); colour = mix(colour, sky_spec(normal, 3.0) * mult, haze); } if (define_sky_ark && normal.y < -0.02) { float val = 1.0 - clamp((normal.y + 0.04) / 0.02, 0.0, 1.0); colour = mix(colour, sky_spec(normal, 0.0) * vec3(1.2, 1.1, 1.0), val); } if (define_water_horizon) { float opac = min(1.0, pow(max(0.0, 1.0 - normal.y), 8.0)); colour = mix(colour, (define_alt2 ? vec3(1.0) : sky_spec(normal, 3.0)) * mult, opac); } if (define_snow_everywhere2) { colour = mult; } if (define_test_clouds_2) { colour = og_clouds(colour, normal, TIME); } if (define_waterfall_arena && !define_cave) { colour = sky_spec(normal, 3.0) * mult; } COLOR = colour; } }