Page 1 of 1

Problem with z buffer

Posted: Thu Sep 13, 2007 3:36 am
by MaikeruDev
I'm developing my own layer over ps2 hardware and I have problem with z-buffer.

I wrote code that draw white sprite on entire screen and two triangles over this sprite. But when I swap z values of triangle 1 vertices with triangle 2 I have same effect on the screen.

What I'm doing with z buffer in loop:
- set ZBUF_1 register fields to:
ZBP = byte pointer to z buf / 8192
PSM = 0
ZMSK = 0 (z buffer is updated always)
- draw sprite on entire screen with z coordinate = 1
- set ZBUF_1 ZMSK field to 1 (z buffer is updated regardless of depth test)
- set TEST_1 register fields to:
ZTE = 1
ZTST = 11 (GREATER)
- draw triangle 1 with z value = 100
- draw triangle 2 over triangle 1 with z value = 10

After this operations triangle 2 is over triangle 1.
I think that z values don't fill z-buffer but z-test is working because when sprite is not drawed I have "doted" triangles (tested with random z values) on the sreeen

Can anyone say what I'm doing wrong?

Posted: Thu Sep 13, 2007 5:21 am
by Lukasz
Your description looks correct, the only thing I can think of with the z-buffer is that it is prohibited to set ZTE=0 in TEST, as this can cause a malfunction.

That being said, there could many other origins of the problems like incorrect code, errors in gif packet, etc. I'd recommend to printf what youre actually sending to the GS and make sure you are waiting for GS FINISH, so you are 100% sure everything is correctly setup and the GS is done drawing.

Posted: Thu Sep 13, 2007 7:18 am
by MaikeruDev
Lukasz wrote:Your description looks correct, the only thing I can think of with the z-buffer is that it is prohibited to set ZTE=0 in TEST, as this can cause a malfunction.
I setted ZBUF.ZMSK = 1, TEST.ZTE = 1 and TEST.ZTST = ALWAYS before sending sprite and now everything is OK. You have right that setting ZTE to 0 may cause malfunction, thank You.
Lukasz wrote: That being said, there could many other origins of the problems like incorrect code, errors in gif packet, etc. I'd recommend to printf what youre actually sending to the GS and make sure you are waiting for GS FINISH, so you are 100% sure everything is correctly setup and the GS is done drawing.
I know. I have checked everything n-times :)
And I have question about GS FINISH event. When I'm using only PATH3 Am I supposed to check this event? Acctualy I tested code with FINISH event checking in CSR register and without it (Of course with writing to FINISH register at end of drawing). Results was the same - nice triangles without any bugs :)

Thank You again. Now I can do another step :)

Posted: Thu Sep 13, 2007 5:14 pm
by Lukasz
You run into problems without using FINISH, if you try to render more polygons than what's possible timewise within a frame. Because if you only wait for VBLANK you might get artifacts as some of the polygons are drawn after vblank. But if you wait for FINISH, you will get a slowdown, but no articfacts :-)

Checking for this event on PATH3 I find important, as you are probably generating all your gif packets on the fly and therefor using alot of EE power just to setup packets. If you start stressing the EE, you might not be able to setup the gif packet on EE and have the GS render it, all within a frame.

Posted: Thu Sep 13, 2007 6:28 pm
by MaikeruDev
I was thinking about it after my post. So I don't know actually how GS draws everything without artifacts when I'm not synchronizing it with FINISH but only with VBLANK.

My result: Image

PS. Check PM

Posted: Fri Sep 14, 2007 7:17 am
by emoon
hint:

include screenshot.h and use ps2_screenshot_file(...)

Posted: Wed Nov 07, 2007 8:38 am
by MaikeruDev
Sorry for late, but thanks for hint emoon. I wrote "download texture" and after "screenshot" functions based on Your code and documentation distributed with linux, but using my own object-oriented library that I'm developing.