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)
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;
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;