From 37753f96afec65c80e02ae98bd40182dd5025fcf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?arvid=20schr=C3=B6der?= Date: Thu, 17 Nov 2022 22:26:43 +0100 Subject: [PATCH] Removed superfluous normalizations --- primitive/infiniteplane.cpp | 6 +++--- primitive/sphere.cpp | 2 +- shader/refractionshader.cpp | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/primitive/infiniteplane.cpp b/primitive/infiniteplane.cpp index ddfe0d2..78452d8 100644 --- a/primitive/infiniteplane.cpp +++ b/primitive/infiniteplane.cpp @@ -27,10 +27,10 @@ bool InfinitePlane::intersect(Ray &ray) const { return false; // Set the normal - if (std::acos(dotProduct(ray.direction, this->normal)) > 0) { - ray.normal = normalized(this->normal); + if (dotProduct(normalized(ray.direction), normalized(this->normal)) > 0) { + ray.normal = this->normal; } else { - ray.normal = normalized((-1.0f * this->normal)); + ray.normal = -1.0f * this->normal; } diff --git a/primitive/sphere.cpp b/primitive/sphere.cpp index 1da5c09..a1ec0b2 100644 --- a/primitive/sphere.cpp +++ b/primitive/sphere.cpp @@ -38,7 +38,7 @@ bool Sphere::intersect(Ray &ray) const { // Calculate the normal auto intersectPoint = ray.origin + ray.direction * t; auto normalDirection = intersectPoint - this->center; // Point of intersect - origin of sphere creates a line along the normal, pointing outwards - ray.normal = normalized(normalDirection); + ray.normal = (normalDirection); // Calculate the surface position and tangent vector float const phi = std::acos(ray.normal.y); diff --git a/shader/refractionshader.cpp b/shader/refractionshader.cpp index 4cd4ea1..a3cc481 100644 --- a/shader/refractionshader.cpp +++ b/shader/refractionshader.cpp @@ -18,7 +18,7 @@ Color RefractionShader::shade(Scene const &scene, Ray const &ray) const { float eta2 = indexInside; - Vector3d v = normalized(ray.direction); + Vector3d v = (ray.direction); Vector3d n = normalized(ray.normal); // Check whether we are entering or leaving the object @@ -43,7 +43,7 @@ Color RefractionShader::shade(Scene const &scene, Ray const &ray) const { } // Calculate refracted ray direction t - Vector3d t = normalized( + Vector3d t = ( eta1 / eta2 * (v - dotProduct(v, n) * n) - n * std::sqrt(denominator));