 
             if(false == shadow_enter && s <= shadow_uv.z)
             {
+                // Check if the ray enters the earth.
+                if(render_ground && length(world_pos - earth_center) < earth_radius)
+                {
+                    s_in = 0.0;
+                    s_out = 0.0;
+                    break;
+                }
+
                 shadow_enter = true;
                 s_in = world_pos.z;
                 continue;

uniform vec3 SUN_RADIANCE_TO_LUMINANCE;




float get_shadow_factor(vec2 screen_tex_coord, vec3 world_position, sampler2D texture_shadow)
{
    float shadow_factor = 0.0;
    vec4 shadow_uv = SHADOW_MATRIX * vec4(world_position, 1.0);
    shadow_uv.xyz /= shadow_uv.w;
    shadow_uv.xyz = shadow_uv.xyz * 0.5 + 0.5;
    float shadow_depth = shadow_uv.z;

    const float shadow_radius = 2.0;
    const vec2 texture_size = textureSize(texture_shadow, 0);
    const vec2 sample_scale = shadow_radius / texture_size;

    float angle = rand(screen_tex_coord);

    const int sample_count = min(4, PoissonSampleCount);

    for(int i=0; i<sample_count; ++i)
    {
        // random poisson
        vec2 uv = PoissonSamples[int(JITTER_FRAME + i + angle * PoissonSampleCount) % PoissonSampleCount];

        uv = shadow_uv.xy + uv * sample_scale;
        vec4 s = textureGather(texture_shadow, uv, 0);
        shadow_factor += s[0] <= shadow_depth ? 0.0 : 1.0;
        shadow_factor += s[1] <= shadow_depth ? 0.0 : 1.0;
        shadow_factor += s[2] <= shadow_depth ? 0.0 : 1.0;
        shadow_factor += s[3] <= shadow_depth ? 0.0 : 1.0;
    }
    shadow_factor /= sample_count * 4.0;
    return shadow_factor;
}

vec3 GetSolarRadiance()
{
    return ATMOSPHERE.solar_irradiance /

#include "precomputed_atmosphere/atmosphere_predefine.glsl"
#include "precomputed_atmosphere/atmosphere_vs.glsl"

const vec3 kSphereCenter = vec3(1.0, 1.0, -2.0);
const float kSphereRadius = 1.0;
const vec3 kSphereAlbedo = vec3(0.8);
const vec3 kGroundAlbedo = vec3(0.0, 0.0, 0.04);
