mirror of
https://github.com/citra-emu/citra.git
synced 2024-12-23 22:10:05 +00:00
SwRasterizer: Flip the vertex quaternions before clipping (if necessary).
This commit is contained in:
parent
2a75837bc3
commit
73566ff7a9
@ -462,7 +462,7 @@ public:
|
|||||||
z -= other.z;
|
z -= other.z;
|
||||||
w -= other.w;
|
w -= other.w;
|
||||||
}
|
}
|
||||||
template <typename Q = T, class = typename std::enable_if<std::is_signed<Q>::value>::type>
|
template <typename Q = T>
|
||||||
Vec4<decltype(-T{})> operator-() const {
|
Vec4<decltype(-T{})> operator-() const {
|
||||||
return MakeVec(-x, -y, -z, -w);
|
return MakeVec(-x, -y, -z, -w);
|
||||||
}
|
}
|
||||||
|
@ -95,6 +95,17 @@ void ProcessTriangle(const OutputVertex& v0, const OutputVertex& v1, const Outpu
|
|||||||
static const size_t MAX_VERTICES = 9;
|
static const size_t MAX_VERTICES = 9;
|
||||||
static_vector<Vertex, MAX_VERTICES> buffer_a = {v0, v1, v2};
|
static_vector<Vertex, MAX_VERTICES> buffer_a = {v0, v1, v2};
|
||||||
static_vector<Vertex, MAX_VERTICES> buffer_b;
|
static_vector<Vertex, MAX_VERTICES> 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* output_list = &buffer_a;
|
||||||
auto* input_list = &buffer_b;
|
auto* input_list = &buffer_b;
|
||||||
|
|
||||||
|
@ -362,13 +362,6 @@ std::tuple<Math::Vec4<u8>, Math::Vec4<u8>> ComputeFragmentsColors(const Math::Qu
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool AreQuaternionsOpposite(Math::Vec4<Pica::float24> qa, Math::Vec4<Pica::float24> 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));
|
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 =
|
int bias2 =
|
||||||
IsRightSideOrFlatBottomEdge(vtxpos[2].xy(), vtxpos[0].xy(), vtxpos[1].xy()) ? -1 : 0;
|
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 w_inverse = Math::MakeVec(v0.pos.w, v1.pos.w, v2.pos.w);
|
||||||
|
|
||||||
auto textures = regs.texturing.GetTextures();
|
auto textures = regs.texturing.GetTextures();
|
||||||
@ -571,11 +555,11 @@ static void ProcessTriangleInternal(const Vertex& v0, const Vertex& v1, const Ve
|
|||||||
|
|
||||||
Math::Quaternion<float> normquat{
|
Math::Quaternion<float> normquat{
|
||||||
{
|
{
|
||||||
GetInterpolatedAttribute(v0.quat.x, v1_quat.x, v2_quat.x).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.y, v1.quat.y, v2.quat.y).ToFloat32(),
|
||||||
GetInterpolatedAttribute(v0.quat.z, v1_quat.z, v2_quat.z).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<float> fragment_position{
|
Math::Vec3<float> fragment_position{
|
||||||
|
Loading…
Reference in New Issue
Block a user