Compare commits

...

9 Commits

Author SHA1 Message Date
Jakly 8f67267f4f
Merge 094af17674 into 2179ca2a41 2024-09-19 17:52:47 +01:00
CasualPokePlayer 2179ca2a41
Set the correct save type for Puzzler World USA (#2156)
Fixes #1804
2024-09-18 20:58:55 +02:00
Jaklyy 094af17674 vectors need to be 64 bit
or alternatively we might need to normalize them somehow?
2024-08-17 23:34:02 -04:00
Jaklyy 4c9e16d5d4 rework polygon orientation calcs
but this time actually correct
2024-08-16 20:56:36 -04:00
Jaklyy f79eb72ca5 undo everything 2024-08-16 20:11:59 -04:00
Jaklyy f8589d5566 w is used on hw 2024-08-16 19:41:16 -04:00
Jaklyy 57d1043699 correct some errors
was not actually 27 bit oops
2024-08-16 12:57:08 -04:00
Jaklyy 047dccd859 vertex coords appear to be 27 bit signed ints
at least for determining the orientation?
2024-08-15 18:55:10 -04:00
Jaklyy 0a908dd49d attempt at re-implementing algorithm
maybe better explains the weird behavior with the 3rd vertex (vtx2)
2024-08-15 16:37:40 -04:00
2 changed files with 38 additions and 30 deletions

View File

@ -967,50 +967,58 @@ void GPU3D::SubmitPolygon() noexcept
VertexSlotCounter = 1;
VertexSlotsFree = 0b11110;
// culling
// polygon orientation
// TODO: work out how it works on the real thing
// the normalization part is a wild guess
Vertex *v0, *v1, *v2, *v3;
Vertex *v0, *v1, *v2;
s64 normalX, normalY, normalZ;
s64 dot;
bool facingview;
v0 = &TempVertexBuffer[0];
v1 = &TempVertexBuffer[1];
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]));
while ((((normalX>>31) ^ (normalX>>63)) != 0) ||
(((normalY>>31) ^ (normalY>>63)) != 0) ||
(((normalZ>>31) ^ (normalZ>>63)) != 0))
// setup vectors for v0->v2 and v1->v2, with w serving as the z axis
s64 vector0[3] = { (s64)v0->Position[0] - v2->Position[0], (s64)v0->Position[1] - v2->Position[1], (s64)v0->Position[3] - v2->Position[3] };
s64 vector1[3] = { (s64)v1->Position[0] - v2->Position[0], (s64)v1->Position[1] - v2->Position[1], (s64)v1->Position[3] - v2->Position[3] };
// if either vector is entirely 0, the polygon is accepted, and the front facing flag is set for the rasterizer
if (((vector0[0] | vector0[1] | vector0[2]) == 0) || ((vector1[0] | vector1[1] | vector1[2]) == 0))
{
normalX >>= 4;
normalY >>= 4;
normalZ >>= 4;
facingview = true;
}
dot = ((s64)v1->Position[0] * normalX) + ((s64)v1->Position[1] * normalY) + ((s64)v1->Position[3] * normalZ);
bool facingview = (dot <= 0);
if (dot < 0)
else
{
if (!(CurPolygonAttr & (1<<7)))
// calculate cross product of the two vectors
normalX = ((s64)vector0[1] * vector1[2]) - ((s64)vector0[2] * vector1[1]);
normalY = ((s64)vector0[2] * vector1[0]) - ((s64)vector0[0] * vector1[2]);
normalZ = ((s64)vector0[0] * vector1[1]) - ((s64)vector0[1] * vector1[0]);
// normalization (currently a guess)
while ((((normalX>>31) ^ (normalX>>63)) != 0) ||
(((normalY>>31) ^ (normalY>>63)) != 0) ||
(((normalZ>>31) ^ (normalZ>>63)) != 0))
{
LastStripPolygon = NULL;
return;
normalX >>= 4;
normalY >>= 4;
normalZ >>= 4;
}
}
else if (dot > 0)
{
if (!(CurPolygonAttr & (1<<6)))
// calculate dot product against the "camera vector" (we can use any of the vertices to do that)
dot = (v1->Position[0] * normalX) + (v1->Position[1] * normalY) + (v1->Position[3] * normalZ);
// front facing flag is set for the rasterizer to be used for:
// unwinding vertices
// determining whether slopes should be treated as "swapped"
// and whether to overwrite a pixel with equal depth when using the < depth test
facingview = (dot >= 0);
// cull polygon faces
if (!(((dot >= 0) && (CurPolygonAttr & (1<<7))) || // front facing
((dot <= 0) && (CurPolygonAttr & (1<<6))))) // back facing
{
LastStripPolygon = NULL;
return;

View File

@ -1830,7 +1830,7 @@ const ROMListEntry ROMList[] =
{0x45564E43, 0x10000000, 0x00000005},
{0x45564F59, 0x00800000, 0x00000001},
{0x45565041, 0x00800000, 0x00000002},
{0x45565042, 0x00800000, 0x00000004},
{0x45565042, 0x00800000, 0x00000002},
{0x45565043, 0x04000000, 0x00000002},
{0x45565056, 0x04000000, 0x00000002},
{0x45565059, 0x04000000, 0x00000001},
@ -6804,4 +6804,4 @@ const ROMListEntry ROMList[] =
const size_t ROMListEntryCount = sizeof(ROMList) / sizeof(ROMListEntry);
}
}