X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=builtin_data%2F_sky.glsl;h=1dbda5793f2d838018b1f8558ede2da7f03437da;hb=2f2048a186c6a10f04999d8a01a3bcf63adc7c75;hp=3493b5a48e92711bcf9a0ceaa7d53871bb753b35;hpb=9208e0ff263a287e456e082a4a8b8fd0bbd41f9e;p=libs%2Fgl.git diff --git a/builtin_data/_sky.glsl b/builtin_data/_sky.glsl index 3493b5a4..1dbda579 100644 --- a/builtin_data/_sky.glsl +++ b/builtin_data/_sky.glsl @@ -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 - 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,11 +118,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, 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;