From 4ea8d2d92af80d64a16b3d20f899b22921aa42d0 Mon Sep 17 00:00:00 2001 From: ladevieq Date: Fri, 20 Aug 2021 22:53:57 +0200 Subject: Use simd for vec3 computations --- include/vec3.hpp | 41 +++++++++++++++++++++-------------------- 1 file changed, 21 insertions(+), 20 deletions(-) (limited to 'include/vec3.hpp') diff --git a/include/vec3.hpp b/include/vec3.hpp index 6291e30..429d747 100644 --- a/include/vec3.hpp +++ b/include/vec3.hpp @@ -2,6 +2,7 @@ #define __VEC3_HPP_ #include +#include class vec3 { public: @@ -9,10 +10,15 @@ class vec3 { vec3(float x); vec3(float x, float y, float z); + vec3(__m128& v); + vec3(__m128&& v); + vec3(const vec3& vec); vec3 operator-() const; - vec3& operator+=(vec3 vec); + vec3& operator=(const vec3& vec); + + vec3& operator+=(const vec3& vec); vec3& operator*=(float scale); @@ -28,7 +34,11 @@ class vec3 { vec3 cross(const vec3& vec) const; - vec3 unit() const; + vec3& min(const vec3& vec); + + vec3& max(const vec3& vec); + + vec3& normalize(); bool near_zero() const; @@ -36,38 +46,29 @@ class vec3 { static vec3 random(float min, float max); - float x, y, z; - float padding; + __m128 v; }; -vec3 lerp(vec3 u, vec3 v, float t); +vec3 lerp(const vec3& u, const vec3& v, float t); -vec3 operator+(vec3 u, vec3 v); +vec3 operator+(const vec3& u, const vec3& v); -vec3 operator-(vec3 u, vec3 v); +vec3 operator-(const vec3& u, const vec3& v); -vec3 operator*(vec3 u, vec3 v); +vec3 operator*(const vec3& u, const vec3& v); -vec3 operator*(vec3 u, float scale); +vec3 operator*(const vec3& u, float scale); -vec3 operator*(float scale, vec3 u); +vec3 operator*(float scale, const vec3& u); -vec3 operator/(vec3 u, float scale); +vec3 operator/(const vec3& u, float scale); -vec3 reflect(vec3 v, vec3 n); +vec3 reflect(const vec3& v, const vec3& n); vec3 refract(const vec3& uv, const vec3& n, float etai_over_etat); std::ostream& operator<<(std::ostream& out, vec3 vec); -vec3 random_in_unit_sphere(); - -vec3 random_unit_vector(); - -vec3 random_in_hemisphere(const vec3& normal); - -vec3 random_in_unit_disk(); - using point3 = vec3; using color = vec3; -- cgit v1.3