Depth peeling confusion

I’m trying to do depth peeling with ARB_fragment_program on a very simple scene (just a cube), but I’m having problems. Using a GF FX5600, drivers 61.77.

The first layer shows up correctly, and on the second peel, the second layer of pixels is showing up correctly but the first layer (which is supposed to be peeled away, and not be there) shows up in bands, as if z-fighting were occuring.

On the first pass I use this program to pass through color:

!!ARBfp1.0
MOV result.color, fragment.color.primary;
END

and then glCopyTexSubImage2D() that into my zbuffer texture which was created as:

GLuint zbuffer;
glGenTextures(1, &zbuffer);
glBindTexture(GL_TEXTURE_RECTANGLE_NV, zbuffer);
glTexImage2D(GL_TEXTURE_RECTANGLE_NV, 0, GL_DEPTH_COMPONENT24_ARB, rc.ViewportWidth, rc.ViewportHeight, 0, GL_DEPTH_COMPONENT, GL_UNSIGNED_INT, NULL);
glBindTexture(GL_TEXTURE_RECTANGLE_NV, 0);
glTexParameteri(GL_TEXTURE_RECTANGLE_NV, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_RECTANGLE_NV, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_RECTANGLE_NV, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_RECTANGLE_NV, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_RECTANGLE_NV, GL_TEXTURE_COMPARE_MODE_ARB, GL_COMPARE_R_TO_TEXTURE_ARB);
glTexParameteri(GL_TEXTURE_RECTANGLE_NV, GL_TEXTURE_COMPARE_FUNC_ARB, GL_GREATER);

That depth texture is then bound on tex unit 3 and this program is used for remaining passes:

!!ARBfp1.0
PARAM bias = { 0.000 };
TEMP depth, depthComparison;
TEX depth, fragment.position, texture[3], RECT;
ADD depth, depth.x, bias.x;
SGE depthComparison, depth.x, fragment.position.z;
KIL -depthComparison.x;
MOV result.color, fragment.color;
END

I’ve been reading through various older posts and there seem to be a number of issues that could be the problem, but I don’t see that they apply here:

*somehow I’m not getting 24 bit precision on the depth texture

*could there be a conventional/fragment shader invariance problem for the z values? I’m not using any z-replace shader programs…

*do I need to use a bias? I haven’t seen any one else using a bias for peeling code before. I’ve been experimenting with biasing, it helps if the bias is pretty large… but there always artifacts

*I’ve tried setting GL_TEXTURE_COMPARE_MODE_ARB to GL_NONE in the above code, but it didn’t help

I’ve also tried changing the shader to use the ARB_fragment_program_shadow option, but it wasn’t working, so I cut down the shader until it gave me this:

!!ARBfp1.0
OPTION ARB_fragment_program_shadow;
PARAM bias = { 0, 0, 0, 0};
TEMP isShadowed, pos;
ADD pos, fragment.position, bias;
TEX isShadowed, fragment.position, texture[3], SHADOWRECT;
MOV result.color, isShadowed;
END

The funny thing, if I understand correctly, the result of the TEX should be 1.0/0.0, but the scene is rendered in greyscale depth… /boggle

Okay, I got the ARB_fragment_program_shadow version working, the problem was a silly bug (there was some leftover debugging code I forgot to remove). Biasing was not needed, here’s the final shader:

!!ARBfp1.0
OPTION ARB_fragment_program_shadow;
TEMP test;
TEX test.x, fragment.position, texture[3], SHADOWRECT;
ADD test.x, test.x, -0.5;
KIL test.x;
MOV result.color, fragment.color;
END

I can’t get the plain ARB_fragment_program shader working without z-fighting… here’s my shader:

!!ARBfp1.0
TEMP depth, depthComp;
TEX depth, fragment.position, texture[3], RECT;
SLT depthComp, depth.x, fragment.position.z;
ADD depthComp, depthComp.x, -0.5;
KIL depthComp.x;
MOV result.color, fragment.color;
END

is there some special (undocumented?) behaviour that occurs when you sample a SHADOWRECT texture that makes this work?

Hi,

Have you finally been able to make this work ?

Thanks.