private void get_relevant_body(Ray input, out int body_id, out double dist, out Triple point_of_incidence, out Triple normal_vector_out) { double min_dist = -1; double dummy; normal_vector_out = null; point_of_incidence = backdrop.GetFloorPoint(input); body_id = BACKGROUND_ID; List <int> candidate_ids = new List <int>(); for (int i = 0; i < bodies.Count; i++) { if (check_bounding_box_incidence(input, bodies[i], out dummy)) { candidate_ids.Add(i); } } foreach (int cur_idx in candidate_ids) { double current_dist; Triple current_point_of_incidence; Triple normal_vector; if (bodies[cur_idx].CheckIncidence(input, out current_dist, out current_point_of_incidence, out normal_vector)) { if (min_dist < 0 || current_dist < min_dist) { point_of_incidence = current_point_of_incidence; min_dist = current_dist; body_id = cur_idx; normal_vector_out = normal_vector; } } } dist = min_dist; }
private void adjust_for_diffuse_lighting(Triple collision_point, Triple normal_vector_in, Ray reflected_ray, ref Triple color, double body_reflection_parameter) { bool shadow = true; foreach (ILightSource light_source in lights) { int bid; double dist_null; Triple point_null; Triple normal_vector_null; //Need the small normal correction otherwise machine error gives spottiness. Ray pointing_ray = light_source.ComputeDiffuseLightingRay(collision_point + NORMAL_EPSILON * normal_vector_in); get_relevant_body(pointing_ray, out bid, out dist_null, out point_null, out normal_vector_null); if (bid == BACKGROUND_ID || !do_shadows) { shadow = false; double t = body_reflection_parameter * light_source.GetPercentLightReception(pointing_ray); color = (1 - t) * color + t * light_source.BaseColor; double t2 = body_reflection_parameter * light_source.GetPercentLightReception(reflected_ray); color = (1 - t2) * color + t2 * light_source.BaseColor; double t3 = body_reflection_parameter * light_source.GetPercentLightReception(new Ray(collision_point, normal_vector_in)); color = (1 - t3) * color + t3 * light_source.BaseColor; } } if (shadow) { color = backdrop.Lightness * color; /*Ray face_normal_ray = new Ray(collision_point + NORMAL_EPSILON*normal_vector_in, normal_vector_in); * Ray face_reflected_ray = new Ray(collision_point + NORMAL_EPSILON*normal_vector_in, reflected_ray.Direction); * face_normal_ray.Position = face_normal_ray.Position + NORMAL_EPSILON * face_normal_ray.Direction; * * * int bid_normal; * double distance_normal; * Triple normal_incident_point; * Triple normal_vector_null; * * //adjust for normal proximity * get_relevant_body(face_normal_ray, out bid_normal, out distance_normal, out normal_incident_point, out normal_vector_null); * if (bid_normal != BACKGROUND_ID) * { * double null1; * Triple null2, null3; * int id; * bool is_lit = false; * foreach (ILightSource light_source in lights) * { * Ray pointing_ray = light_source.ComputeDiffuseLightingRay(normal_incident_point); * pointing_ray.Position = pointing_ray.Position + NORMAL_EPSILON*normal_vector_null; * get_relevant_body(pointing_ray, out id, out null1, out null2, out null3); * if (id != BACKGROUND_ID) * { * is_lit = true; * break; * } * } * Triple body_target_color = bodies[bid_normal].BodyOpticalProperties.BaseColor; * double t = Math.Exp(-GLOBAL_DIFFUSIVE_CONST_NORMAL*distance_normal); * if (is_lit) color = t*body_target_color + (1-t)*color; * } * * int bid_reflect; * double distance_reflect; * Triple reflect_incident_point; * Triple reflect_vector_null; * //adjust for reflected proximity * get_relevant_body(face_reflected_ray, out bid_reflect, out distance_reflect, out reflect_incident_point, out reflect_vector_null); * if (bid_reflect != BACKGROUND_ID) * { * //Ray pointing_ray = light_source.ComputeDiffuseLightingRay(reflect_incident_point); * double null1; * Triple null2, null3; * int id; * bool is_lit = false; * foreach (ILightSource light_source in lights) * { * Ray pointing_ray = light_source.ComputeDiffuseLightingRay(reflect_incident_point); * pointing_ray.Position = pointing_ray.Position + NORMAL_EPSILON*reflect_vector_null; * get_relevant_body(pointing_ray, out id, out null1, out null2, out null3); * if (id != BACKGROUND_ID) * { * is_lit = true; * break; * } * } * Triple body_target_color = bodies[bid_reflect].BodyOpticalProperties.BaseColor; * double t = Math.Exp(-GLOBAL_DIFFUSIVE_CONST_REFLECT*distance_reflect); * if (is_lit) color = t*body_target_color + (1-t)*color; * }*/ } }