From bc3eff9f961ab1d9dd39a3fc9c43ace59a2ea35c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ars=C3=A8ne=20P=C3=A9rard-Gayot?= Date: Thu, 19 Aug 2021 13:07:11 +0200 Subject: [PATCH] Add option to eliminate dot product in sphere intersection, when the ray is known to be normalized --- include/bvh/sphere.hpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/include/bvh/sphere.hpp b/include/bvh/sphere.hpp index ef609c86..bab1d669 100644 --- a/include/bvh/sphere.hpp +++ b/include/bvh/sphere.hpp @@ -37,9 +37,10 @@ struct Sphere { return BoundingBox(origin - Vector3(radius), origin + Vector3(radius)); } + template std::optional intersect(const Ray& ray) const { auto oc = ray.origin - origin; - auto a = dot(ray.direction, ray.direction); + auto a = AssumeNormalized ? Scalar(1) : dot(ray.direction, ray.direction); auto b = 2 * dot(ray.direction, oc); auto c = dot(oc, oc) - radius * radius;