Open beantowel opened 1 year ago
In the demo shader atmosphere/demo/demo.glsl, when testing whether the view ray intersects with the ground:
atmosphere/demo/demo.glsl
p = camera - earth_center; p_dot_v = dot(p, view_direction); p_dot_p = dot(p, p); float ray_earth_center_squared_distance = p_dot_p - p_dot_v * p_dot_v; distance_to_intersection = -p_dot_v - sqrt( earth_center.z * earth_center.z - ray_earth_center_squared_distance); //... if (distance_to_intersection > 0.0) { //... }
There may be negative values passing into the sqrt function. When testing on PC, it's ok, but when I ported the code to android platform, the horizon had the wrong color. We'd better test if the inner value is positive before testing the distance:
sqrt
float delta_intersection_square = earth_center.z * earth_center.z - ray_earth_center_squared_distance; distance_to_intersection = -p_dot_v - sqrt(delta_intersection_square); //... if (delta_intersection_square > 0.0 && distance_to_intersection > 0.0) { //... }
In the demo shader
atmosphere/demo/demo.glsl
, when testing whether the view ray intersects with the ground:There may be negative values passing into the
sqrt
function. When testing on PC, it's ok, but when I ported the code to android platform, the horizon had the wrong color. We'd better test if the inner value is positive before testing the distance: