diff options
author | StapleButter <thetotalworm@gmail.com> | 2017-07-06 18:54:51 +0200 |
---|---|---|
committer | StapleButter <thetotalworm@gmail.com> | 2017-07-06 18:54:51 +0200 |
commit | 8f031f698b4ff2841062537b931a1825247e8113 (patch) | |
tree | 9103dcca0921c40c7bbc4371b49d1b84a099d35f /src | |
parent | 3aa83ae6418efb01a53d40f07db9780a83d106fa (diff) |
normalize W values in both directions (0123-0157 -> 1230-1570)
Diffstat (limited to 'src')
-rw-r--r-- | src/GPU3D.cpp | 30 | ||||
-rw-r--r-- | src/GPU3D.h | 1 |
2 files changed, 21 insertions, 10 deletions
diff --git a/src/GPU3D.cpp b/src/GPU3D.cpp index ed928d8..71a6711 100644 --- a/src/GPU3D.cpp +++ b/src/GPU3D.cpp @@ -823,13 +823,13 @@ void SubmitPolygon() // determine bounds of the polygon // also determine the W shift and normalize W - // TODO: normalization works both ways + // normalization works both ways // (ie two W's that span 12 bits or less will be brought to 16 bits) u32 vtop = 0, vbot = 0; s32 ytop = 192, ybot = 0; s32 xtop = 256, xbot = 0; - u32 wshift = 0; + u32 wsize = 0; for (int i = 0; i < nverts; i++) { @@ -849,8 +849,8 @@ void SubmitPolygon() } u32 w = (u32)vtx->Position[3]; - while ((w >> wshift) & 0xFFFF0000) - wshift += 4; + while (w >> wsize) + wsize += 4; } poly->VTop = vtop; poly->VBottom = vbot; @@ -860,20 +860,32 @@ void SubmitPolygon() poly->SortKey = (ybot << 8) | ytop; if (poly->Translucent) poly->SortKey |= 0x10000; - poly->WShift = wshift; poly->WBuffer = (FlushAttributes & 0x2); for (int i = 0; i < nverts; i++) { Vertex* vtx = poly->Vertices[i]; - s32 w = vtx->Position[3] >> wshift; + s32 w, wshifted; + + if (wsize < 16) + { + w = vtx->Position[3] << (16 - wsize); + wshifted = w >> (16 - wsize); + } + else + { + w = vtx->Position[3] >> (wsize - 16); + wshifted = w << (wsize - 16); + } s32 z; if (FlushAttributes & 0x2) - z = w << wshift; + z = wshifted; + else if (wshifted) + z = (((s64)vtx->Position[2] * 0x800000) / wshifted) + 0x7FFEFF; else - z = (((s64)vtx->Position[2] * 0x800000) / (w << wshift)) + 0x7FFEFF; -//printf("poly%d v%d: %d %d Z=%08X (%08X %08X)\n", NumPolygons-1, i, vtx->FinalPosition[0], vtx->FinalPosition[1], z, vtx->Position[2], vtx->Position[3]); + z = 0x7FFEFF; + // checkme if (z < 0) z = 0; else if (z > 0xFFFFFF) z = 0xFFFFFF; diff --git a/src/GPU3D.h b/src/GPU3D.h index d89acf5..7394148 100644 --- a/src/GPU3D.h +++ b/src/GPU3D.h @@ -47,7 +47,6 @@ typedef struct s32 FinalZ[10]; s32 FinalW[10]; - u8 WShift; bool WBuffer; u32 Attr; |