2021-07-28 07:40:04 +00:00
|
|
|
#version 330 core
|
|
|
|
|
2023-04-07 06:17:37 +00:00
|
|
|
layout(location = 0) out vec4 fragColor;
|
2021-07-28 07:40:04 +00:00
|
|
|
|
2023-04-07 06:17:37 +00:00
|
|
|
in vec2 texcoord;
|
2021-07-28 07:40:04 +00:00
|
|
|
|
|
|
|
const int TRANSMITTANCE_STEPS = 40;
|
|
|
|
|
2023-04-07 06:17:37 +00:00
|
|
|
// atmos.glsl
|
|
|
|
float get_earth_radius();
|
|
|
|
float get_atmosphere_radius();
|
2023-02-19 15:47:55 +00:00
|
|
|
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-04-07 06:17:37 +00:00
|
|
|
float sun_cos_theta = texcoord.x * 2.0 - 1.0;
|
2023-02-19 15:47:55 +00:00
|
|
|
vec3 sun_dir = vec3(-sqrt(1.0 - sun_cos_theta*sun_cos_theta), 0.0, sun_cos_theta);
|
|
|
|
|
2023-04-07 06:17:37 +00:00
|
|
|
float distance_to_earth_center = mix(get_earth_radius(),
|
|
|
|
get_atmosphere_radius(),
|
|
|
|
texcoord.y);
|
2023-02-19 15:47:55 +00:00
|
|
|
vec3 ray_origin = vec3(0.0, 0.0, distance_to_earth_center);
|
2021-07-28 07:40:04 +00:00
|
|
|
|
2023-04-07 06:17:37 +00:00
|
|
|
float t_d = ray_sphere_intersection(ray_origin, sun_dir, get_atmosphere_radius());
|
2023-02-19 15:47:55 +00:00
|
|
|
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-04-07 06:17:37 +00:00
|
|
|
float altitude = length(x_t) - get_earth_radius();
|
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;
|
|
|
|
}
|