Views: 1,461,321 Homepage | Main | Rules/FAQ | Memberlist | Active users | Last posts | Calendar | Stats | Online users | Search 01-20-21 10:51 AM
Guest:

0 users reading GPU3D: culling research | 1 bot

Main - Development - GPU3D: culling research New reply


Arisotura
Posted on 05-24-20 07:13 AM (rev. 3 of 05-24-20 02:55 PM) Link | #1773
okay so

// culling
// TODO: work out how it works on the real thing
// the normalization part is a wild guess

Vertex *v0, *v1, *v2, *v3;
s64 normalX, normalY, normalZ;
s64 dot;

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))
{
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);

if (facingview)
{
if (!(CurPolygonAttr & (1<<7)))
{
LastStripPolygon = NULL;
return;
}
}
else if (dot > 0)
{
if (!(CurPolygonAttr & (1<<6)))
{
LastStripPolygon = NULL;
return;
}
}
this is the culling code that melonDS employs atm. it's not too far away from what the DS seems to use. however:


* on the DS, polygons always pass culling if they have v0==v2 or v1==v2, even if cull mode is 0.

** this would imply that the DS uses v2 as a base vertex. melonDS is using v1.
** it only checks X, Y and W. Z can be whatever.


* cases of dot=0 pass both culling modes 1 and 2, but not 0 (unless they match the exception above).


* the DS employs some mechanism for reducing precision of the normal components as needed so it doesn't overflow. the mechanism is weird tho. but for example specific input can cause erroneous cases of dot=0.


*actually, testing tends to hint the DS is using v0 as a base.

____________________
Kuribo64


Main - Development - GPU3D: culling research New reply

Page rendered in 0.017 seconds. (2048KB of memory used)
MySQL - queries: 26, rows: 74/74, time: 0.014 seconds.
[powered by Acmlm] Acmlmboard 2.064 (2018-07-20)
© 2005-2008 Acmlm, Xkeeper, blackhole89 et al.