]> git.tdb.fi Git - libs/gl.git/blobdiff - builtin_data/_sky.glsl
Use image-based lighting in the entire desert pillars scene
[libs/gl.git] / builtin_data / _sky.glsl
index 45ca330dd80afd89f7845f07d353fc8f5fe2d4e5..81f9d16398693ba16018b9f17ebe9bfbd04b780b 100644 (file)
@@ -32,7 +32,6 @@ struct OpticalPathInfo
        vec3 luminance;
 };
 
-const float pi = 3.1415926535;
 const float mie_asymmetry = 0.8;
 
 uniform sampler2D transmittance_lookup;
@@ -44,7 +43,7 @@ vec3 rayleigh_density(vec3 base, float height)
 
 float rayleigh_phase(float cos_theta)
 {
-       return 3.0*(1.0+cos_theta*cos_theta)/(16.0*pi);
+       return 3.0*(1.0+cos_theta*cos_theta)/(16.0*PI);
 }
 
 vec3 mie_density(vec3 base, float height)
@@ -57,7 +56,7 @@ float mie_phase(float cos_theta)
        float g = mie_asymmetry;
        float num = (1.0-g*g)*(1.0+cos_theta*cos_theta);
        float denom = (2.0+g*g)*pow(1.0+g*g-2.0*g*cos_theta, 1.5);
-       return 3.0/(8.0*pi)*num/denom;
+       return 3.0/(8.0*PI)*num/denom;
 }
 
 vec3 ozone_density(vec3 base, float height)
@@ -124,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;