From f2d4d5c2191275bd91f2f42b880f3edf3bccfd63 Mon Sep 17 00:00:00 2001 From: Subv Date: Fri, 9 Jun 2017 17:33:25 -0500 Subject: SwRasterizer: Corrected the light LUT lookups. --- src/common/quaternion.h | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'src/common') diff --git a/src/common/quaternion.h b/src/common/quaternion.h index 84ac82ed3..77f626bcb 100644 --- a/src/common/quaternion.h +++ b/src/common/quaternion.h @@ -30,6 +30,11 @@ public: return {xyz * other.w + other.xyz * w + Cross(xyz, other.xyz), w * other.w - Dot(xyz, other.xyz)}; } + + Quaternion Normalized() const { + T length = std::sqrt(xyz.Length2() + w * w); + return {xyz / length, w / length}; + } }; template -- cgit v1.2.3 From 73566ff7a990cdfe8d8f023997b57942dc785fc4 Mon Sep 17 00:00:00 2001 From: Subv Date: Sun, 11 Jun 2017 11:55:35 -0500 Subject: SwRasterizer: Flip the vertex quaternions before clipping (if necessary). --- src/common/vector_math.h | 2 +- src/video_core/swrasterizer/clipper.cpp | 11 +++++++++++ src/video_core/swrasterizer/rasterizer.cpp | 24 ++++-------------------- 3 files changed, 16 insertions(+), 21 deletions(-) (limited to 'src/common') diff --git a/src/common/vector_math.h b/src/common/vector_math.h index c7a461a1e..d0fe0e405 100644 --- a/src/common/vector_math.h +++ b/src/common/vector_math.h @@ -462,7 +462,7 @@ public: z -= other.z; w -= other.w; } - template ::value>::type> + template Vec4 operator-() const { return MakeVec(-x, -y, -z, -w); } diff --git a/src/video_core/swrasterizer/clipper.cpp b/src/video_core/swrasterizer/clipper.cpp index 6fb923756..7537689b7 100644 --- a/src/video_core/swrasterizer/clipper.cpp +++ b/src/video_core/swrasterizer/clipper.cpp @@ -95,6 +95,17 @@ void ProcessTriangle(const OutputVertex& v0, const OutputVertex& v1, const Outpu static const size_t MAX_VERTICES = 9; static_vector buffer_a = {v0, v1, v2}; static_vector buffer_b; + + auto FlipQuaternionIfOpposite = [](auto& a, const auto& b) { + if (Math::Dot(a, b) < float24::Zero()) + a = -a; + }; + + // Flip the quaternions if they are opposite to prevent interpolating them over the wrong + // direction. + FlipQuaternionIfOpposite(buffer_a[1].quat, buffer_a[0].quat); + FlipQuaternionIfOpposite(buffer_a[2].quat, buffer_a[0].quat); + auto* output_list = &buffer_a; auto* input_list = &buffer_b; diff --git a/src/video_core/swrasterizer/rasterizer.cpp b/src/video_core/swrasterizer/rasterizer.cpp index 2c804b6e7..76f793c86 100644 --- a/src/video_core/swrasterizer/rasterizer.cpp +++ b/src/video_core/swrasterizer/rasterizer.cpp @@ -362,13 +362,6 @@ std::tuple, Math::Vec4> ComputeFragmentsColors(const Math::Qu }; } -static bool AreQuaternionsOpposite(Math::Vec4 qa, Math::Vec4 qb) { - Math::Vec4f a{ qa.x.ToFloat32(), qa.y.ToFloat32(), qa.z.ToFloat32(), qa.w.ToFloat32() }; - Math::Vec4f b{ qb.x.ToFloat32(), qb.y.ToFloat32(), qb.z.ToFloat32(), qb.w.ToFloat32() }; - - return (Math::Dot(a, b) < 0.f); -} - MICROPROFILE_DEFINE(GPU_Rasterization, "GPU", "Rasterization", MP_RGB(50, 50, 240)); /** @@ -462,15 +455,6 @@ static void ProcessTriangleInternal(const Vertex& v0, const Vertex& v1, const Ve int bias2 = IsRightSideOrFlatBottomEdge(vtxpos[2].xy(), vtxpos[0].xy(), vtxpos[1].xy()) ? -1 : 0; - // Flip the quaternions if they are opposite to prevent interpolating them over the wrong direction. - auto v1_quat = v1.quat; - auto v2_quat = v2.quat; - - if (AreQuaternionsOpposite(v0.quat, v1.quat)) - v1_quat = v1_quat * float24::FromFloat32(-1.0f); - if (AreQuaternionsOpposite(v0.quat, v2.quat)) - v2_quat = v2_quat * float24::FromFloat32(-1.0f); - auto w_inverse = Math::MakeVec(v0.pos.w, v1.pos.w, v2.pos.w); auto textures = regs.texturing.GetTextures(); @@ -571,11 +555,11 @@ static void ProcessTriangleInternal(const Vertex& v0, const Vertex& v1, const Ve Math::Quaternion normquat{ { - GetInterpolatedAttribute(v0.quat.x, v1_quat.x, v2_quat.x).ToFloat32(), - GetInterpolatedAttribute(v0.quat.y, v1_quat.y, v2_quat.y).ToFloat32(), - GetInterpolatedAttribute(v0.quat.z, v1_quat.z, v2_quat.z).ToFloat32() + GetInterpolatedAttribute(v0.quat.x, v1.quat.x, v2.quat.x).ToFloat32(), + GetInterpolatedAttribute(v0.quat.y, v1.quat.y, v2.quat.y).ToFloat32(), + GetInterpolatedAttribute(v0.quat.z, v1.quat.z, v2.quat.z).ToFloat32() }, - GetInterpolatedAttribute(v0.quat.w, v1_quat.w, v2_quat.w).ToFloat32(), + GetInterpolatedAttribute(v0.quat.w, v1.quat.w, v2.quat.w).ToFloat32(), }; Math::Vec3 fragment_position{ -- cgit v1.2.3 From f3660ba9dd13f342c591aaa9901e94b6caee8d9a Mon Sep 17 00:00:00 2001 From: wwylele Date: Tue, 11 Jul 2017 19:51:29 +0300 Subject: vector_math: remove broken SFINAE stuff this was originally added to eliminate warnings on MSVC, but it doesn't work for custom types. --- src/common/vector_math.h | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'src/common') diff --git a/src/common/vector_math.h b/src/common/vector_math.h index d0fe0e405..49ae87f6d 100644 --- a/src/common/vector_math.h +++ b/src/common/vector_math.h @@ -31,7 +31,6 @@ #pragma once #include -#include namespace Math { @@ -90,7 +89,7 @@ public: x -= other.x; y -= other.y; } - template ::value>::type> + Vec2 operator-() const { return MakeVec(-x, -y); } @@ -247,7 +246,7 @@ public: y -= other.y; z -= other.z; } - template ::value>::type> + Vec3 operator-() const { return MakeVec(-x, -y, -z); } -- cgit v1.2.3 From fe44e843fe1e300491d3bcd9072948407a86e7e1 Mon Sep 17 00:00:00 2001 From: wwylele Date: Tue, 11 Jul 2017 20:08:56 +0300 Subject: vector_math: remove dead template parameter --- src/common/vector_math.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/common') diff --git a/src/common/vector_math.h b/src/common/vector_math.h index 49ae87f6d..6e2a5ad60 100644 --- a/src/common/vector_math.h +++ b/src/common/vector_math.h @@ -461,7 +461,7 @@ public: z -= other.z; w -= other.w; } - template + Vec4 operator-() const { return MakeVec(-x, -y, -z, -w); } -- cgit v1.2.3