]> git.tdb.fi Git - libs/gl.git/blobdiff - builtin_data/_sky.glsl
Check the flat qualifier from the correct member
[libs/gl.git] / builtin_data / _sky.glsl
index 81f9d16398693ba16018b9f17ebe9bfbd04b780b..4ece8e579a3f7ad5e186e21a5793ebdaef3e0263 100644 (file)
@@ -6,7 +6,7 @@ struct AtmosphericEvents
        vec3 ozone_absorb;
 };
 
-uniform Atmosphere
+layout(set=2) uniform Atmosphere
 {
        AtmosphericEvents events;
        float rayleigh_density_decay;
@@ -19,7 +19,7 @@ uniform Atmosphere
        int n_steps;
 };
 
-uniform View
+layout(set=2) uniform View
 {
        float view_height;
        vec4 light_color;
@@ -34,7 +34,7 @@ struct OpticalPathInfo
 
 const float mie_asymmetry = 0.8;
 
-uniform sampler2D transmittance_lookup;
+layout(set=2) uniform sampler2D transmittance_lookup;
 
 vec3 rayleigh_density(vec3 base, float height)
 {
@@ -88,13 +88,8 @@ float ray_sphere_intersect(vec3 ray_start, vec3 ray_dir, vec3 sphere_center, flo
        if(d_sq>r_sq)
                return -1.0;
 
-       float offset = sqrt(r_sq-d_sq);
-       if(offset<t)
-               return t-offset;
-       else if(offset>-t)
-               return t+offset;
-       else
-               return -1.0;
+       float offset = sqrt(r_sq-d_sq)*sign(sphere_radius);
+       return t-offset;
 }
 
 #pragma MSP stage(fragment)
@@ -110,7 +105,7 @@ OpticalPathInfo raymarch_path(float start_height, vec3 look_dir)
        vec3 path_extinction = vec3(0.0);
 
        float ground_t = ray_sphere_intersect(pos, look_dir, planet_center, planet_radius);
-       float space_t = ray_sphere_intersect(pos, look_dir, planet_center, planet_radius+atmosphere_thickness);
+       float space_t = ray_sphere_intersect(pos, look_dir, planet_center, -(planet_radius+atmosphere_thickness));
        float ray_length = (ground_t>0.0 ? ground_t : space_t);
        float step_size = ray_length/n_steps;
 
@@ -123,7 +118,7 @@ OpticalPathInfo raymarch_path(float start_height, vec3 look_dir)
 
                AtmosphericEvents ev = calculate_events(height);
                vec3 transmittance = exp(-path_extinction);
-               float in_ground_t = ray_sphere_intersect(pos+light_dir, light_dir, planet_center, planet_radius);
+               float in_ground_t = ray_sphere_intersect(pos, 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;