attempt at re-implementing algorithm

maybe better explains the weird behavior with the 3rd vertex (vtx2)
This commit is contained in:
Jaklyy 2024-08-15 16:37:40 -04:00
parent 0e6235a7c4
commit 0a908dd49d

View File

@ -978,27 +978,24 @@ void GPU3D::SubmitPolygon() noexcept
v2 = &TempVertexBuffer[2];
v3 = &TempVertexBuffer[3];
normalX = ((s64)(v0->Position[1]-v1->Position[1]) * (v2->Position[3]-v1->Position[3]))
- ((s64)(v0->Position[3]-v1->Position[3]) * (v2->Position[1]-v1->Position[1]));
normalY = ((s64)(v0->Position[3]-v1->Position[3]) * (v2->Position[0]-v1->Position[0]))
- ((s64)(v0->Position[0]-v1->Position[0]) * (v2->Position[3]-v1->Position[3]));
normalZ = ((s64)(v0->Position[0]-v1->Position[0]) * (v2->Position[1]-v1->Position[1]))
- ((s64)(v0->Position[1]-v1->Position[1]) * (v2->Position[0]-v1->Position[0]));
s32 vector[4];
vector[0] = v0->Position[0] - v2->Position[0];
vector[1] = v0->Position[1] - v2->Position[1];
vector[2] = v1->Position[0] - v2->Position[0];
vector[3] = v1->Position[1] - v2->Position[1];
while ((((normalX>>31) ^ (normalX>>63)) != 0) ||
(((normalY>>31) ^ (normalY>>63)) != 0) ||
(((normalZ>>31) ^ (normalZ>>63)) != 0))
bool facingview;
if ((vector[0] | vector[1]) == 0 || (vector[2] | vector[3]) == 0) // if either vector is 0 the polygon is accepted and treated as front facing.
{
normalX >>= 4;
normalY >>= 4;
normalZ >>= 4;
facingview = true;
}
else
{
s64 cross = (vector[0] * vector[3]) - (vector[1] * vector[2]);
dot = ((s64)v1->Position[0] * normalX) + ((s64)v1->Position[1] * normalY) + ((s64)v1->Position[3] * normalZ);
facingview = (cross >= 0);
bool facingview = (dot <= 0);
if (dot < 0)
if (cross >= 0)
{
if (!(CurPolygonAttr & (1<<7)))
{
@ -1006,7 +1003,7 @@ void GPU3D::SubmitPolygon() noexcept
return;
}
}
else if (dot > 0)
else if (cross <= 0)
{
if (!(CurPolygonAttr & (1<<6)))
{
@ -1014,6 +1011,7 @@ void GPU3D::SubmitPolygon() noexcept
return;
}
}
}
// for strips, check whether we can attach to the previous polygon
// this requires two original vertices shared with the previous polygon, and that