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
1 changed files with 26 additions and 28 deletions

View File

@ -977,41 +977,39 @@ void GPU3D::SubmitPolygon() noexcept
v1 = &TempVertexBuffer[1]; v1 = &TempVertexBuffer[1];
v2 = &TempVertexBuffer[2]; v2 = &TempVertexBuffer[2];
v3 = &TempVertexBuffer[3]; v3 = &TempVertexBuffer[3];
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];
normalX = ((s64)(v0->Position[1]-v1->Position[1]) * (v2->Position[3]-v1->Position[3])) bool facingview;
- ((s64)(v0->Position[3]-v1->Position[3]) * (v2->Position[1]-v1->Position[1])); 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.
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]));
while ((((normalX>>31) ^ (normalX>>63)) != 0) ||
(((normalY>>31) ^ (normalY>>63)) != 0) ||
(((normalZ>>31) ^ (normalZ>>63)) != 0))
{ {
normalX >>= 4; facingview = true;
normalY >>= 4;
normalZ >>= 4;
} }
else
dot = ((s64)v1->Position[0] * normalX) + ((s64)v1->Position[1] * normalY) + ((s64)v1->Position[3] * normalZ);
bool facingview = (dot <= 0);
if (dot < 0)
{ {
if (!(CurPolygonAttr & (1<<7))) s64 cross = (vector[0] * vector[3]) - (vector[1] * vector[2]);
facingview = (cross >= 0);
if (cross >= 0)
{ {
LastStripPolygon = NULL; if (!(CurPolygonAttr & (1<<7)))
return; {
LastStripPolygon = NULL;
return;
}
} }
} else if (cross <= 0)
else if (dot > 0)
{
if (!(CurPolygonAttr & (1<<6)))
{ {
LastStripPolygon = NULL; if (!(CurPolygonAttr & (1<<6)))
return; {
LastStripPolygon = NULL;
return;
}
} }
} }