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 > Matrix manipulation -> Screen Coordinates?

#172143 - DiscoStew - Mon Jan 18, 2010 8:03 pm

Some months ago, I had asked about if it were possible to do something like the Painter's Algorithm on the NDS, where you rely on drawing objects from back to front rather than using a depth buffer for sorting. For some time now, I felt that it couldn't be done because of the way the NDS handles the geometry by hardware, but lately, I was thinking about it, and was wondering...

Is it possible to set up the Perspective Matrix (or one of the others) so that when geometry is sent in, the matrix will convert it to screen coordinates with a constant depth from anything sent in?

I ask this because I remembered that with POLY_ATTR, bit14 is the Depth Test, where when set, polygons will only be drawn if they match the depth in the internal buffer. While usually used to give the appearance of multi-texturing, if the depth of everything were the same in, then wouldn't that be a reasonable method for setting up a Painter's Algorithm?
_________________
DS - It's all about DiscoStew

#172144 - kusma - Mon Jan 18, 2010 8:20 pm

Why do you want to sort yourself, when the zbuffer is for free?

#172146 - DiscoStew - Mon Jan 18, 2010 8:46 pm

It's just a thought if there was ever a need for it. A possible example is a viewing screen within a 3D-scene, that doesn't resort to using up a block of VRAM and using the display capture unit (also forcing the frame limit down), but then again, such an idea would require the same mechanics but on a 3D plane, and because of accuracy, that may not work either. :(
_________________
DS - It's all about DiscoStew

#172147 - sajiimori - Tue Jan 19, 2010 12:41 am

The viewing screen example still tends to require capture because you can't disable the Z buffer even if you want to.

That is, the DS will always drop pixels that don't pass the Z test -- you can't turn off the Z test and do your own sorting. :(

#172148 - elhobbs - Tue Jan 19, 2010 3:46 am

I suspect you would also loose perspective correct texturing.

#172166 - Exophase - Wed Jan 20, 2010 9:15 pm

W is used for perspective correction - if you stay with Z-buffering and manage to get a constant Z then it should work. I think you have two options - either Z = 0 or Z = W * C where C is some constant. W of all the incoming vertexes should be a constant 1.

Since clipping is done before perspective correction it should be from +/- W, so you want to make sure the Z value is within this range, which 0 should satisfy. Making the entire third row of the projection matrix 0 should accomplish this.