]> git.tdb.fi Git - libs/gl.git/commitdiff
Add a shadowing term from the planet to atmospheric transmittance
authorMikko Rasa <tdb@tdb.fi>
Fri, 8 Oct 2021 06:16:41 +0000 (09:16 +0300)
committerMikko Rasa <tdb@tdb.fi>
Fri, 8 Oct 2021 06:18:57 +0000 (09:18 +0300)
This makes the sky properly dark if the sun is below the horizon.

builtin_data/_sky.glsl

index 3493b5a48e92711bcf9a0ceaa7d53871bb753b35..81f9d16398693ba16018b9f17ebe9bfbd04b780b 100644 (file)
@@ -123,11 +123,15 @@ OpticalPathInfo raymarch_path(float start_height, vec3 look_dir)
 
                AtmosphericEvents ev = calculate_events(height);
                vec3 transmittance = exp(-path_extinction);
-               vec3 in_transmittance = texture(transmittance_lookup, vec2(sqrt(height/atmosphere_thickness), light_z)).rgb;
-               vec3 in_luminance = (ev.rayleigh_scatter*p_rayleigh+ev.mie_scatter*p_mie)*step_size;
-               if(i==n_steps && ground_t>0.0)
-                       in_luminance += ground_albedo*light_z/PI;
-               path_luminance += transmittance*in_transmittance*in_luminance;
+               float in_ground_t = ray_sphere_intersect(pos+light_dir, light_dir, planet_center, planet_radius);
+               if(in_ground_t<0.0)
+               {
+                       vec3 in_transmittance = texture(transmittance_lookup, vec2(sqrt(height/atmosphere_thickness), light_z)).rgb;
+                       vec3 in_luminance = (ev.rayleigh_scatter*p_rayleigh+ev.mie_scatter*p_mie)*step_size;
+                       if(i==n_steps && ground_t>0.0 && light_z>0.0)
+                               in_luminance += ground_albedo*light_z/PI;
+                       path_luminance += transmittance*in_transmittance*in_luminance;
+               }
 
                path_extinction += total_extinction(ev)*step_size;
                pos += look_dir*step_size;