[−][src]Macro raytracer::refract
Alternative for Vec3::refract
.
Examples
// Glass surface let n = 1.5; // n1 / n2, where n1 = 1.5 (glass) and n2 = 1.0 (air) let normal = vec3!(0.0, 1.0, 0.0); // Rays perpendicular to the surface aren't affected by refraction let incident = vec3!(0.0, -1.0, 0.0); assert_eq!(refract!(incident, normal, n), Some(incident)); // Rays coming from an angle are refracted let incident = vec3!(-0.7, -1.0, 0.0); assert_eq!(refract!(incident, normal, n), Some(vec3!(-0.86019355, -0.5099678, 0.0))); // At critical angles (nearing 0), rays aren't refracted, only reflected let incident = vec3!(-1.0, -0.05, 0.0); assert_eq!(refract!(incident, normal, n), None); // from outside of the surface let incident = vec3!(1.0, 0.05, 0.0); assert_eq!(refract!(incident, normal, n), None); // from inside of the surface