Fix Incorrect Polygon Swapping Behavior and Implement Correct Rules for Shifting Right Edges Left (#1816)

* fix polygons being swapped incorrectly

"borrowed" this from noods
needs verification that the >= and <= signs aren't actually supposed to be > and <

* proper rules for moving vertical right slopes left

* nvm most of that was actually pointless

that's on me for not checking
This commit is contained in:
Jaklyy 2023-08-27 07:29:12 -04:00 committed by GitHub
parent dc8efb62b8
commit d69745b3a8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 14 additions and 13 deletions

View File

@ -1067,7 +1067,7 @@ void SubmitPolygon()
dot = ((s64)v1->Position[0] * normalX) + ((s64)v1->Position[1] * normalY) + ((s64)v1->Position[3] * normalZ); dot = ((s64)v1->Position[0] * normalX) + ((s64)v1->Position[1] * normalY) + ((s64)v1->Position[3] * normalZ);
bool facingview = (dot < 0); bool facingview = (dot <= 0);
if (facingview) if (facingview)
{ {

View File

@ -742,6 +742,11 @@ void SoftRenderer::RenderShadowMaskScanline(RendererPolygon* rp, s32 y)
s32 zl = rp->SlopeL.Interp.InterpolateZ(polygon->FinalZ[rp->CurVL], polygon->FinalZ[rp->NextVL], polygon->WBuffer); s32 zl = rp->SlopeL.Interp.InterpolateZ(polygon->FinalZ[rp->CurVL], polygon->FinalZ[rp->NextVL], polygon->WBuffer);
s32 zr = rp->SlopeR.Interp.InterpolateZ(polygon->FinalZ[rp->CurVR], polygon->FinalZ[rp->NextVR], polygon->WBuffer); s32 zr = rp->SlopeR.Interp.InterpolateZ(polygon->FinalZ[rp->CurVR], polygon->FinalZ[rp->NextVR], polygon->WBuffer);
// right vertical edges are pushed 1px to the left as long as either:
// the left edge slope is not 0, or the span is not 0 pixels wide, and it is not at the leftmost pixel of the screen
if (rp->SlopeR.Increment==0 && (rp->SlopeL.Increment!=0 || xstart != xend) && (xend != 0))
xend--;
// if the left and right edges are swapped, render backwards. // if the left and right edges are swapped, render backwards.
if (xstart > xend) if (xstart > xend)
{ {
@ -956,6 +961,11 @@ void SoftRenderer::RenderPolygonScanline(RendererPolygon* rp, s32 y)
s32 zl = rp->SlopeL.Interp.InterpolateZ(polygon->FinalZ[rp->CurVL], polygon->FinalZ[rp->NextVL], polygon->WBuffer); s32 zl = rp->SlopeL.Interp.InterpolateZ(polygon->FinalZ[rp->CurVL], polygon->FinalZ[rp->NextVL], polygon->WBuffer);
s32 zr = rp->SlopeR.Interp.InterpolateZ(polygon->FinalZ[rp->CurVR], polygon->FinalZ[rp->NextVR], polygon->WBuffer); s32 zr = rp->SlopeR.Interp.InterpolateZ(polygon->FinalZ[rp->CurVR], polygon->FinalZ[rp->NextVR], polygon->WBuffer);
// right vertical edges are pushed 1px to the left as long as either:
// the left edge slope is not 0, or the span is not 0 pixels wide, and it is not at the leftmost pixel of the screen
if (rp->SlopeR.Increment==0 && (rp->SlopeL.Increment!=0 || xstart != xend) && (xend != 0))
xend--;
// if the left and right edges are swapped, render backwards. // if the left and right edges are swapped, render backwards.
// on hardware, swapped edges seem to break edge length calculation, // on hardware, swapped edges seem to break edge length calculation,
// causing X-major edges to be rendered wrong when filled, // causing X-major edges to be rendered wrong when filled,

View File

@ -233,15 +233,7 @@ private:
s32 SetupDummy(s32 x0) s32 SetupDummy(s32 x0)
{ {
if (side) dx = 0;
{
dx = -0x40000;
x0--;
}
else
{
dx = 0;
}
this->x0 = x0; this->x0 = x0;
this->xmin = x0; this->xmin = x0;
@ -278,7 +270,6 @@ private:
else else
{ {
this->xmin = x0; this->xmin = x0;
if (side) this->xmin--;
this->xmax = this->xmin; this->xmax = this->xmin;
this->Negative = false; this->Negative = false;
} }
@ -309,7 +300,7 @@ private:
if (XMajor) dx = Negative ? (0x20000 + 0x40000) : (Increment - 0x20000); if (XMajor) dx = Negative ? (0x20000 + 0x40000) : (Increment - 0x20000);
else if (Increment != 0) dx = Negative ? 0x40000 : 0; else if (Increment != 0) dx = Negative ? 0x40000 : 0;
else dx = -0x40000; else dx = 0;
} }
else else
{ {