mirror of
https://github.com/melonDS-emu/melonDS.git
synced 2025-07-22 22:01:06 -06:00
3D: attempt at fixing culling. players in Madden are no longer full of holes, and that also fixes occasional missing polygons in RaymanDS, and probably others.
This commit is contained in:
@ -610,6 +610,8 @@ void SubmitPolygon()
|
||||
int prev, next;
|
||||
|
||||
// culling
|
||||
// TODO: work out how it works on the real thing
|
||||
// the normalization part is a wild guess
|
||||
|
||||
Vertex *v0, *v1, *v2;
|
||||
s64 normalX, normalY, normalZ;
|
||||
@ -618,9 +620,19 @@ void SubmitPolygon()
|
||||
v0 = &TempVertexBuffer[0];
|
||||
v1 = &TempVertexBuffer[1];
|
||||
v2 = &TempVertexBuffer[2];
|
||||
normalX = (((s64)v0->Position[1] * v2->Position[3]) - ((s64)v0->Position[3] * v2->Position[1])) >> 12;
|
||||
normalY = (((s64)v0->Position[3] * v2->Position[0]) - ((s64)v0->Position[0] * v2->Position[3])) >> 12;
|
||||
normalZ = (((s64)v0->Position[0] * v2->Position[1]) - ((s64)v0->Position[1] * v2->Position[0])) >> 12;
|
||||
normalX = ((s64)v0->Position[1] * v2->Position[3]) - ((s64)v0->Position[3] * v2->Position[1]);
|
||||
normalY = ((s64)v0->Position[3] * v2->Position[0]) - ((s64)v0->Position[0] * v2->Position[3]);
|
||||
normalZ = ((s64)v0->Position[0] * v2->Position[1]) - ((s64)v0->Position[1] * v2->Position[0]);
|
||||
|
||||
while ((((normalX>>31) ^ (normalX>>63)) != 0) ||
|
||||
(((normalY>>31) ^ (normalY>>63)) != 0) ||
|
||||
(((normalZ>>31) ^ (normalZ>>63)) != 0))
|
||||
{
|
||||
normalX >>= 4;
|
||||
normalY >>= 4;
|
||||
normalZ >>= 4;
|
||||
}
|
||||
|
||||
dot = ((s64)v1->Position[0] * normalX) + ((s64)v1->Position[1] * normalY) + ((s64)v1->Position[3] * normalZ);
|
||||
|
||||
bool facingview = (dot < 0);
|
||||
@ -807,6 +819,7 @@ void SubmitPolygon()
|
||||
// determine bounds of the polygon
|
||||
// also determine the W shift and normalize W
|
||||
// TODO: 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;
|
||||
|
Reference in New Issue
Block a user