2021-07-28 07:40:04 +00:00
|
|
|
#version 330 core
|
|
|
|
|
2023-02-19 15:47:55 +00:00
|
|
|
out vec4 fragColor;
|
2021-07-28 07:40:04 +00:00
|
|
|
|
|
|
|
in vec2 texCoord;
|
|
|
|
|
2021-08-19 10:50:01 +00:00
|
|
|
uniform float fg_EarthRadius;
|
2021-07-28 07:40:04 +00:00
|
|
|
|
|
|
|
const float ATMOSPHERE_RADIUS = 6471e3;
|
|
|
|
const int TRANSMITTANCE_STEPS = 40;
|
|
|
|
|
2023-02-19 15:47:55 +00:00
|
|
|
// atmos-include.frag
|
|
|
|
float ray_sphere_intersection(vec3 ro, vec3 rd, float radius);
|
|
|
|
void get_atmosphere_collision_coefficients(in float h,
|
|
|
|
out vec4 aerosol_absorption,
|
|
|
|
out vec4 aerosol_scattering,
|
|
|
|
out vec4 molecular_absorption,
|
|
|
|
out vec4 molecular_scattering,
|
|
|
|
out vec4 extinction);
|
2021-07-28 07:40:04 +00:00
|
|
|
|
|
|
|
void main()
|
|
|
|
{
|
2023-02-19 15:47:55 +00:00
|
|
|
float sun_cos_theta = texCoord.x * 2.0 - 1.0;
|
|
|
|
vec3 sun_dir = vec3(-sqrt(1.0 - sun_cos_theta*sun_cos_theta), 0.0, sun_cos_theta);
|
|
|
|
|
|
|
|
float distance_to_earth_center = mix(fg_EarthRadius, ATMOSPHERE_RADIUS, texCoord.y);
|
|
|
|
vec3 ray_origin = vec3(0.0, 0.0, distance_to_earth_center);
|
2021-07-28 07:40:04 +00:00
|
|
|
|
2023-02-19 15:47:55 +00:00
|
|
|
float t_d = ray_sphere_intersection(ray_origin, sun_dir, ATMOSPHERE_RADIUS);
|
|
|
|
float dt = t_d / float(TRANSMITTANCE_STEPS);
|
2021-07-28 07:40:04 +00:00
|
|
|
|
2023-02-19 15:47:55 +00:00
|
|
|
vec4 result = vec4(0.0);
|
2021-07-28 07:40:04 +00:00
|
|
|
|
|
|
|
for (int i = 0; i < TRANSMITTANCE_STEPS; ++i) {
|
2023-02-19 15:47:55 +00:00
|
|
|
float t = (float(i) + 0.5) * dt;
|
|
|
|
vec3 x_t = ray_origin + sun_dir * t;
|
2021-07-28 07:40:04 +00:00
|
|
|
|
2023-02-19 15:47:55 +00:00
|
|
|
float altitude = length(x_t) - fg_EarthRadius;
|
2021-07-28 07:40:04 +00:00
|
|
|
|
2023-02-19 15:47:55 +00:00
|
|
|
vec4 aerosol_absorption, aerosol_scattering;
|
|
|
|
vec4 molecular_absorption, molecular_scattering;
|
|
|
|
vec4 extinction;
|
|
|
|
get_atmosphere_collision_coefficients(
|
|
|
|
altitude,
|
|
|
|
aerosol_absorption, aerosol_scattering,
|
|
|
|
molecular_absorption, molecular_scattering,
|
|
|
|
extinction);
|
2021-07-28 07:40:04 +00:00
|
|
|
|
2023-02-19 15:47:55 +00:00
|
|
|
result += extinction * dt;
|
2021-07-28 07:40:04 +00:00
|
|
|
}
|
|
|
|
|
2023-02-19 15:47:55 +00:00
|
|
|
vec4 transmittance = exp(-result);
|
2021-07-28 07:40:04 +00:00
|
|
|
fragColor = transmittance;
|
|
|
|
}
|