mostly fix culling

This commit is contained in:
StapleButter 2017-03-07 21:38:47 +01:00
parent 7799b33dfe
commit c24245c59a
2 changed files with 15 additions and 34 deletions

View File

@ -885,7 +885,7 @@ void GPU2D::DrawBG_3D(u32 line, u32* dst)
i = (0x100 - (xoff & 0xFF)); i = (0x100 - (xoff & 0xFF));
xoff += i; xoff += i;
} }
if ((xoff + iend - 1) & 0x100) if ((xoff - i + iend - 1) & 0x100)
{ {
iend -= (xoff & 0xFF); iend -= (xoff & 0xFF);
} }

View File

@ -452,39 +452,20 @@ void SubmitPolygon()
// culling // culling
// checkme: does it work this way for quads and up? Vertex *v0, *v1, *v2;
/*s32 _x1 = TempVertexBuffer[1].Position[0] - TempVertexBuffer[0].Position[0]; s64 normalX, normalY, normalZ;
s32 _x2 = TempVertexBuffer[2].Position[0] - TempVertexBuffer[0].Position[0]; s64 dot;
s32 _y1 = TempVertexBuffer[1].Position[1] - TempVertexBuffer[0].Position[1];
s32 _y2 = TempVertexBuffer[2].Position[1] - TempVertexBuffer[0].Position[1]; v0 = &TempVertexBuffer[0];
s32 _z1 = TempVertexBuffer[1].Position[2] - TempVertexBuffer[0].Position[2]; v1 = &TempVertexBuffer[1];
s32 _z2 = TempVertexBuffer[2].Position[2] - TempVertexBuffer[0].Position[2]; v2 = &TempVertexBuffer[2];
s32 normalX = (((s64)_y1 * _z2) - ((s64)_z1 * _y2)) >> 12; normalX = (((s64)v0->Position[1] * v2->Position[3]) - ((s64)v0->Position[3] * v2->Position[1])) >> 12;
s32 normalY = (((s64)_z1 * _x2) - ((s64)_x1 * _z2)) >> 12; normalY = (((s64)v0->Position[3] * v2->Position[0]) - ((s64)v0->Position[0] * v2->Position[3])) >> 12;
s32 normalZ = (((s64)_x1 * _y2) - ((s64)_y1 * _x2)) >> 12;*/ normalZ = (((s64)v0->Position[0] * v2->Position[1]) - ((s64)v0->Position[1] * v2->Position[0])) >> 12;
/*s32 centerX = ((s64)TempVertexBuffer[0].Position[3] * ClipMatrix[12]) >> 12; dot = ((s64)(v1->Position[0] >> 0) * normalX) + ((s64)(v1->Position[1] >> 0) * normalY) + ((s64)(v1->Position[3] >> 0) * normalZ);
s32 centerY = ((s64)TempVertexBuffer[0].Position[3] * ClipMatrix[13]) >> 12;
s32 centerZ = ((s64)TempVertexBuffer[0].Position[3] * ClipMatrix[14]) >> 12;*/
/*s64 dot = ((s64)(-TempVertexBuffer[0].Position[0]) * normalX) +
((s64)(-TempVertexBuffer[0].Position[1]) * normalY) +
((s64)(-TempVertexBuffer[0].Position[2]) * normalZ); // checkme*/
// code inspired from Dolphin's software renderer.
// maybe not 100% right
s32 _x0 = TempVertexBuffer[0].Position[0];
s32 _x1 = TempVertexBuffer[1].Position[0];
s32 _x2 = TempVertexBuffer[2].Position[0];
s32 _y0 = TempVertexBuffer[0].Position[1];
s32 _y1 = TempVertexBuffer[1].Position[1];
s32 _y2 = TempVertexBuffer[2].Position[1];
s32 _z0 = TempVertexBuffer[0].Position[3];
s32 _z1 = TempVertexBuffer[1].Position[3];
s32 _z2 = TempVertexBuffer[2].Position[3];
s32 normalX = (((s64)_y0 * _z2) - ((s64)_z0 * _y2)) >> 12;
s32 normalY = (((s64)_z0 * _x2) - ((s64)_x0 * _z2)) >> 12;
s32 normalZ = (((s64)_x0 * _y2) - ((s64)_y0 * _x2)) >> 12;
s64 dot = ((s64)_x1 * normalX) + ((s64)_y1 * normalY) + ((s64)_z1 * normalZ);
bool facingview = (dot < 0); bool facingview = (dot < 0);
//printf("Z: %d %d\n", normalZ, -TempVertexBuffer[0].Position[2]);
if (facingview) if (facingview)
{ {
if (!(CurPolygonAttr & (1<<7))) if (!(CurPolygonAttr & (1<<7)))
@ -493,7 +474,7 @@ void SubmitPolygon()
return; return;
} }
} }
else else if (dot > 0)
{ {
if (!(CurPolygonAttr & (1<<6))) if (!(CurPolygonAttr & (1<<6)))
{ {