Files
render/sky.frag
2025-11-19 20:11:18 +05:00

46 lines
1.5 KiB
GLSL
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#version 330 core
out vec4 FragColor;
in vec3 FragPos;
in vec3 Normal;
uniform float height;
uniform float sunElevation;
uniform float sunIntensity;
void main()
{
// Константы - цвета неба
vec3 C_strato = vec3(0x05, 0x0F, 0x1F) / 255.0; // #050F1F
vec3 C_sea = vec3(0x87, 0xBD, 0xFF) / 255.0; // #87BDFF
vec3 C_warm = vec3(0xFF, 0xF2, 0xD9) / 255.0; // #FFF2D9
vec3 C_sunset = vec3(0xFF, 0x8C, 0x4D) / 255.0; // #FF8C4D
// 1. Зависимость цвета от высоты наблюдателя
float H = 8000.0;
float t = clamp(exp(-height / H), 0.0, 1.0);
// C_base - линейная интерполяция от C_strato до C_sea с параметром t
vec3 C_base = mix(C_strato, C_sea, t);
// 2. Параметры положения Солнца
float d = smoothstep(0.0, 0.6, sunElevation);
float s = clamp(sunIntensity, 0.0, 1.0);
// 3. Тёплая добавка при низком Солнце
// C_tint - линейная интерполяция от C_sunset до C_warm с параметром d
vec3 C_tint = mix(C_sunset, C_warm, d);
// Коэффициент тёплой добавки
float alpha = 0.6 * s * (1.0 - d) * t;
// 4. Итоговый цвет неба
vec3 C_lit = C_base * (0.55 + 0.45 * s * d) + alpha * C_tint;
// Финальный цвет с ограничением
vec3 C_out = clamp(C_lit, 0.0, 1.0);
FragColor = vec4(C_out, 1.0);
}