Vector3Refract function
Refraction direction for incident ray v, surface normal n, index ratio r.
Implementation
Vector3 Vector3Refract(Vector3 v, Vector3 n, double r) {
final dot = v.dot(n);
final d = 1.0 - r * r * (1.0 - dot * dot);
if (d < 0) return .zero();
return v.scaled(r) - n.scaled(r * dot + math.sqrt(d));
}