Reading the depthbuffer - Problem with format?

Discuss the development of new homebrew software, tools and libraries.

Moderators: cheriff, TyRaNiD

Post Reply
J-Fox
Posts: 15
Joined: Wed Sep 26, 2007 12:25 am
Location: Hannover, Germany

Reading the depthbuffer - Problem with format?

Post by J-Fox »

Hey,

Code: Select all

#define BUF_WIDTH (512)
#define SCR_WIDTH (480)
#define SCR_HEIGHT (272)
...
sceGuDepthBuffer(zbp,BUF_WIDTH);
sceGuDepthRange(0xFFFF,0x0);
...
sceGuTexMode(GU_PSM_4444,0,0,0);
sceGuCopyImage(GU_PSM_4444,0,0,512,512,512,(void*)(((unsigned int)zbp)+0x4000000),0,0,512,depth);
sceGuTexImage(0,512,512,512,depth);

This is some code I wrote for reading the zbuffer to an new array which I would like to use as a sprite-texture.

I have no problems reading the data for the color-framebuffer (format GU_PSM_8888), however, the zbuffer seems to use some weird format:

Rendering the texture "depth" will result in weird colors (well thats ok), some blocks which seem to be 32x32 pixel each (but totally wrong positions - which made me think its swizzled, it doesnt seem to be though) and other weird rotations of the drawn noise which don't match the object in the color-framebuffer.

What do I have to change / do to get the zbuffer as a texture?
(If there is a function which does that - even better!)

PS: Outputting the array to a file gave me unexpected results: It looks like the pixels I wrote to, get a value which loops through ABCDEFG... and 123456...
snow
Posts: 31
Joined: Sat Dec 15, 2007 12:34 pm

Post by snow »

I'm still being educated but if I'm not mistaken the zbuffer isn't any sort of image. It's meta data about the depth of the pixels and their color values. Also the order of the meta data is not a contiguous array of pixels as the color(draw) buffer is. Rendering it will give you garbage.
ufoz
Posts: 86
Joined: Thu Nov 10, 2005 2:36 am
Location: Tokyo
Contact:

Post by ufoz »

J-Fox
Posts: 15
Joined: Wed Sep 26, 2007 12:25 am
Location: Hannover, Germany

Post by J-Fox »

Thanks for pointing that out snow - and thanks alot for the link ufoz, I believed the zbufferfog sample was just using another fogmode made by sony, it was exactly what I have been looking for though =)

Thanks again!
snow
Posts: 31
Joined: Sat Dec 15, 2007 12:34 pm

Post by snow »

Ah, cool. So an image can be extracted from it. Can I ask what you're doing with it by any chance?
J-Fox
Posts: 15
Joined: Wed Sep 26, 2007 12:25 am
Location: Hannover, Germany

Post by J-Fox »

Well, I m only trying to do some cool graphics on psp.

- Reading the zbuffer 16bpp - FAILS
- Reading the zbuffer 32bpp - WORKS
- Render to texture 16bpp - WORKS
- Render to texture 32bpp - SLOW

Does anyone know how to read the zbuffer in GU_PSM_5650 just like in GU_PSM_8888?
Visigotico
Posts: 11
Joined: Wed Apr 23, 2008 11:44 am

Post by Visigotico »

with GU_PSM_4444 (16 bit draw and display buffers), linear zbuffer seems to be at zbuffer + 2MB.
Post Reply