gbadev.org forum archive

This is a read-only mirror of the content originally found on forum.gbadev.org (now offline), salvaged from Wayback machine copies. A new forum can be found here.

DS development > DS negative depth

#178040 - nocash - Thu Aug 15, 2013 12:04 pm

I have just noticed that no$zoomer applies a patch to no$gba, which allows it to render polygons with negative depth values (ie. negative Z or W coordinates). The patch is called "EX4". What is that for?

Normally these values should be positive. Registers like CLEAR_DEPTH, FOG_OFFSET, DISP_1DOT_DEPTH, and RearPlaneBitmap are restricted to 15bit positive values. And near plane clipping should occur at Z<0.

Maybe W buffering can end up with negative W values, even when Z passed near plane clipping? And if so, can the NDS hardware store negative W values in the "framebuffer"?

Or maybe my rendering code has rounding errors, unintentionally ending up with negative values when Z coordinates are getting too close to zero?

Did anybody experience negative depth related problems in no$gba? Or used such stuff on real NDS hardware?

#178047 - nocash - Mon Aug 19, 2013 12:01 pm

After gazing at the patch for some more time, I think maybe it doesn't want to handle negative depths at all.
In the depth comparision, it's replacing a "jnb" opcode by a "jg" opcode. The signed/unsigned stuff looked most eye-catching to me, but the other difference is that "jg" doesn't jump-if-equal.

If there are problems on equal depths in no$gba... that might be related to manual/auto-sorted polygons, rounding-errors, or even on the nds hardware's "depth=less" check (maybe it does actually check "depth=lessorequal")... I'll need to do some tests.
If somebody has experiences with equal depth's (in no$gba or on real nds) please let me know what you have observed!