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 > Access depth and/or stencil-buffer

#146248 - Peter - Sat Dec 01, 2007 10:42 am

Does anyone know if it is possible to access (read) the depth and/or stencil buffers from the 3d-hardware somehow? With the DS Video Capture only image data can be captured as I understand GBATek.
_________________
Kind Regards,
Peter

#146264 - Cydrak - Sat Dec 01, 2007 6:02 pm

No, not really. :/ All you can do is make a second capture, squeezing it out indirectly.

For depth: Render unlit, untextured, in black with white fog. Since hardware Z ranges over 0...0x7fff, like the RGB, this gives a rough but usable 5 bit approximation. I've personally done this--it works on the rear plane too, if you wanna have occluding "RGBZ" backdrops. See the recent discussion on multi-pass...

(5.5 to 6 bits _might_ be gotten with a color like RGB(29,30,31) - rounding should cause R and G to increment sooner than the high blue bits. I played with it and that's exactly what happens, but I couldn't see a visual improvement. I think postprocessing is needed to move the rounding upward a few bits.)

I haven't tried capturing the stencil, but it shouldn't be much worse than Z. A couple of useful arrangements come to mind:

(1) Blue fog and red shadows - to get them for software use;
(2) White fog and black shadows - the fog would be normal Z, and the black (Z=0) should occlude everything, so it could make a useful stencil on the rear plane.

#146265 - Peter - Sat Dec 01, 2007 6:34 pm

Cydrak wrote:
For depth: Render unlit, untextured, in black with white fog. Since hardware Z ranges over 0...0x7fff, like the RGB, this gives a rough but usable 5 bit approximation.

That's crafty, thanks a lot!
_________________
Kind Regards,
Peter

#146415 - silent_code - Mon Dec 03, 2007 11:13 pm

but after all, the depth and stencil buffers are just line buffers, so there are no such buffers as on the pc. sadly. ;^p

#146417 - Mighty Max - Mon Dec 03, 2007 11:33 pm

That might be the reason why we talk about rendering tricks to create something aequivalent to the depth/stencil buffer output instead of accessing the buffers themself.

Even if there would be a complete frame in the HW buffers, we can't read it out, so the size of the actual buffer is irrelevant.
_________________
GBAMP Multiboot

#146419 - silent_code - Mon Dec 03, 2007 11:50 pm

this is just an idea:
well, the buffers *have* to be somewhere. if we knew the adress of the db, couldn't we get its contents during hblank?
this won't probably happen, though.

ps: the topic was on reading the buffers, not computing approximations of them, so i thought i'd post a line about it not being possible (as of now).
the tricks mentioned are pretty usable and shouldn't make a great differnece to the real thing on such low precision hw like the nds. memory usage it a concern, though.
and if there *were* fullscreen buffers, who says they *couldn't* be read out? ;^P let's not talk about that any further. :^)


Last edited by silent_code on Mon Dec 03, 2007 11:53 pm; edited 1 time in total

#146420 - kusma - Mon Dec 03, 2007 11:52 pm

silent_code wrote:
this is just an idea:
well, the buffers *have* to be somewhere. if we knew the adress of the db, couldn't we get its contents during hblank?

No, those are buffers not accessible to the CPU.

#146421 - silent_code - Mon Dec 03, 2007 11:54 pm

so, they are on chip (gfx) and not memory mapped. makes sense. :^)
else, i bet someone had done it by now.